| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom-attr", |
| 5 |
"dojo/has", |
| 6 |
"dojo/i18n", |
| 7 |
"dojo/i18n!./nls/ComboBox" |
| 8 |
], function(array, declare, domAttr, has, i18n){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var ComboBoxMenuMixin = declare("dijit.form._ComboBoxMenuMixin" + (has("dojo-bidi") ? "_NoBidi" : ""), null, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
_messages: null, |
| 22 |
|
| 23 |
postMixInProperties: function(){ |
| 24 |
this.inherited(arguments); |
| 25 |
this._messages = i18n.getLocalization("dijit.form", "ComboBox", this.lang); |
| 26 |
}, |
| 27 |
|
| 28 |
buildRendering: function(){ |
| 29 |
this.inherited(arguments); |
| 30 |
|
| 31 |
|
| 32 |
this.previousButton.innerHTML = this._messages["previousMessage"]; |
| 33 |
this.nextButton.innerHTML = this._messages["nextMessage"]; |
| 34 |
}, |
| 35 |
|
| 36 |
_setValueAttr: function( value){ |
| 37 |
this._set("value", value); |
| 38 |
this.onChange(value); |
| 39 |
}, |
| 40 |
|
| 41 |
onClick: function( node){ |
| 42 |
if(node == this.previousButton){ |
| 43 |
this._setSelectedAttr(null); |
| 44 |
this.onPage(-1); |
| 45 |
}else if(node == this.nextButton){ |
| 46 |
this._setSelectedAttr(null); |
| 47 |
this.onPage(1); |
| 48 |
}else{ |
| 49 |
this.onChange(node); |
| 50 |
} |
| 51 |
}, |
| 52 |
|
| 53 |
|
| 54 |
onChange: function( ){ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
}, |
| 60 |
|
| 61 |
onPage: function( ){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
}, |
| 67 |
|
| 68 |
onClose: function(){ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
this._setSelectedAttr(null); |
| 74 |
}, |
| 75 |
|
| 76 |
_createOption: function( item, labelFunc){ |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
var menuitem = this._createMenuItem(); |
| 82 |
var labelObject = labelFunc(item); |
| 83 |
if(labelObject.html){ |
| 84 |
menuitem.innerHTML = labelObject.label; |
| 85 |
}else{ |
| 86 |
menuitem.appendChild( |
| 87 |
menuitem.ownerDocument.createTextNode(labelObject.label) |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
if(menuitem.innerHTML == ""){ |
| 92 |
menuitem.innerHTML = " "; |
| 93 |
} |
| 94 |
|
| 95 |
return menuitem; |
| 96 |
}, |
| 97 |
|
| 98 |
createOptions: function(results, options, labelFunc){ |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
this.items = results; |
| 110 |
|
| 111 |
|
| 112 |
this.previousButton.style.display = (options.start == 0) ? "none" : ""; |
| 113 |
domAttr.set(this.previousButton, "id", this.id + "_prev"); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
array.forEach(results, function(item, i){ |
| 119 |
var menuitem = this._createOption(item, labelFunc); |
| 120 |
menuitem.setAttribute("item", i); |
| 121 |
domAttr.set(menuitem, "id", this.id + i); |
| 122 |
this.nextButton.parentNode.insertBefore(menuitem, this.nextButton); |
| 123 |
}, this); |
| 124 |
|
| 125 |
var displayMore = false; |
| 126 |
|
| 127 |
if(results.total && !results.total.then && results.total != -1){ |
| 128 |
if((options.start + options.count) < results.total){ |
| 129 |
displayMore = true; |
| 130 |
}else if((options.start + options.count) > results.total && options.count == results.length){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
displayMore = true; |
| 135 |
} |
| 136 |
}else if(options.count == results.length){ |
| 137 |
|
| 138 |
|
| 139 |
displayMore = true; |
| 140 |
} |
| 141 |
|
| 142 |
this.nextButton.style.display = displayMore ? "" : "none"; |
| 143 |
domAttr.set(this.nextButton, "id", this.id + "_next"); |
| 144 |
}, |
| 145 |
|
| 146 |
clearResultList: function(){ |
| 147 |
|
| 148 |
|
| 149 |
var container = this.containerNode; |
| 150 |
while(container.childNodes.length > 2){ |
| 151 |
container.removeChild(container.childNodes[container.childNodes.length - 2]); |
| 152 |
} |
| 153 |
this._setSelectedAttr(null); |
| 154 |
}, |
| 155 |
|
| 156 |
highlightFirstOption: function(){ |
| 157 |
|
| 158 |
|
| 159 |
this.selectFirstNode(); |
| 160 |
}, |
| 161 |
|
| 162 |
highlightLastOption: function(){ |
| 163 |
|
| 164 |
|
| 165 |
this.selectLastNode(); |
| 166 |
}, |
| 167 |
|
| 168 |
selectFirstNode: function(){ |
| 169 |
this.inherited(arguments); |
| 170 |
if(this.getHighlightedOption() == this.previousButton){ |
| 171 |
this.selectNextNode(); |
| 172 |
} |
| 173 |
}, |
| 174 |
|
| 175 |
selectLastNode: function(){ |
| 176 |
this.inherited(arguments); |
| 177 |
if(this.getHighlightedOption() == this.nextButton){ |
| 178 |
this.selectPreviousNode(); |
| 179 |
} |
| 180 |
}, |
| 181 |
|
| 182 |
getHighlightedOption: function(){ |
| 183 |
return this.selected; |
| 184 |
} |
| 185 |
}); |
| 186 |
|
| 187 |
if(has("dojo-bidi")){ |
| 188 |
ComboBoxMenuMixin = declare("dijit.form._ComboBoxMenuMixin", ComboBoxMenuMixin, { |
| 189 |
_createOption: function(){ |
| 190 |
var menuitem = this.inherited(arguments); |
| 191 |
|
| 192 |
|
| 193 |
this.applyTextDir(menuitem); |
| 194 |
|
| 195 |
return menuitem; |
| 196 |
} |
| 197 |
}); |
| 198 |
} |
| 199 |
|
| 200 |
return ComboBoxMenuMixin; |
| 201 |
}); |