123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- if(!dojo._hasResource["dojox.form.CheckedMultiSelect"]){
- dojo._hasResource["dojox.form.CheckedMultiSelect"] = true;
- dojo.provide("dojox.form.CheckedMultiSelect");
- dojo.require("dijit.form.CheckBox");
- dojo.require("dijit.Tooltip");
- dojo.require("dijit.form._FormSelectWidget");
- dojo.declare("dojox.form._CheckedMultiSelectItem",
- [dijit._Widget, dijit._Templated],
- {
-
-
- widgetsInTemplate: true,
- templateString: dojo.cache("dojox.form", "resources/_CheckedMultiSelectItem.html", "<div class=\"dijitReset ${baseClass}\"\n\t><input class=\"${baseClass}Box\" dojoType=\"dijit.form.CheckBox\" dojoAttachPoint=\"checkBox\" \n\t\tdojoAttachEvent=\"_onClick:_changeBox\" type=\"${_type.type}\" data-dojo-props='disabled:${disabled}, readOnly:${readOnly}' baseClass=\"${_type.baseClass}\"\n\t/><div class=\"dijitInline ${baseClass}Label\" dojoAttachPoint=\"labelNode\" dojoAttachEvent=\"onclick:_onClick\"></div\n></div>\n"),
- baseClass: "dojoxMultiSelectItem",
-
-
- option: null,
- parent: null,
-
-
-
- disabled: false,
-
-
- readOnly: false,
- postMixInProperties: function(){
-
-
-
- this._type = this.parent.multiple ?
- {type: "checkbox", baseClass: "dijitCheckBox"} :
- {type: "radio", baseClass: "dijitRadio"};
-
- if(!this.disabled){
- this.disabled = this.option.disabled = this.option.disabled||false;
- }
- if(!this.readOnly){
- this.readOnly = this.option.readOnly = this.option.readOnly||false;
- }
- this.inherited(arguments);
- },
- postCreate: function(){
-
-
-
- this.inherited(arguments);
- this.labelNode.innerHTML = this.option.label;
- },
- _changeBox: function(){
-
-
-
-
- if(this.get("disabled") || this.get("readOnly")){ return; }
- if(this.parent.multiple){
- this.option.selected = this.checkBox.get('value') && true;
- }else{
- this.parent.set('value', this.option.value);
- }
-
- this.parent._updateSelection();
-
-
- this.parent.focus();
- },
-
- _onClick: function(e){
-
-
- if(this.get("disabled") || this.get("readOnly")){
- dojo.stopEvent(e);
- }else{
- this.checkBox._onClick(e);
- }
- },
-
- _updateBox: function(){
-
-
- this.checkBox.set('value', this.option.selected);
- },
-
- _setDisabledAttr: function(value){
-
-
- this.disabled = value||this.option.disabled;
- this.checkBox.set("disabled", this.disabled);
- dojo.toggleClass(this.domNode, "dojoxMultiSelectDisabled", this.disabled);
- },
-
- _setReadOnlyAttr: function(value){
-
-
- this.checkBox.set("readOnly", value);
- this.readOnly = value;
- }
- });
- dojo.declare("dojox.form.CheckedMultiSelect", dijit.form._FormSelectWidget, {
-
-
- templateString: dojo.cache("dojox.form", "resources/CheckedMultiSelect.html", "<div class=\"dijit dijitReset dijitInline\" dojoAttachEvent=\"onmousedown:_onMouseDown,onclick:focus\"\n\t><select class=\"${baseClass}Select\" multiple=\"true\" dojoAttachPoint=\"containerNode,focusNode\"></select\n\t><div dojoAttachPoint=\"wrapperDiv\"></div\n></div>\n"),
- baseClass: "dojoxMultiSelect",
-
-
-
- required: false,
-
-
-
- invalidMessage: "At least one item must be selected.",
-
-
-
- _message: "",
-
-
-
- tooltipPosition: [],
- _onMouseDown: function(e){
-
-
-
- dojo.stopEvent(e);
- },
-
- validator: function() {
-
-
-
-
-
- if (!this.required){ return true; }
- return dojo.some(this.getOptions(), function(opt){
- return opt.selected && opt.value != null && opt.value.toString().length != 0;
- });
- },
-
- validate: function(isFocused) {
- dijit.hideTooltip(this.domNode);
- var isValid = this.isValid(isFocused);
- if(!isValid){ this.displayMessage(this.invalidMessage); }
- return isValid;
- },
-
- isValid: function(/*Boolean*/ isFocused) {
-
-
-
-
-
- return this.validator();
- },
- getErrorMessage: function(/*Boolean*/ isFocused) {
-
-
-
-
- return this.invalidMessage;
- },
-
- displayMessage: function(/*String*/ message) {
-
-
-
-
-
- dijit.hideTooltip(this.domNode);
- if(message){
- dijit.showTooltip(message, this.domNode, this.tooltipPosition);
- }
- },
-
- onAfterAddOptionItem: function(item, option){
-
-
-
- },
-
- _addOptionItem: function(/* dojox.form.__SelectOption */ option){
- var item = new dojox.form._CheckedMultiSelectItem({
- option: option,
- parent: this,
- disabled: this.disabled,
- readOnly: this.readOnly
- });
- this.wrapperDiv.appendChild(item.domNode);
- this.onAfterAddOptionItem(item, option);
- },
-
- _refreshState: function(){
-
-
- this.validate(this._focused);
- },
- onChange: function(newValue){
-
-
- this._refreshState();
- },
-
- reset: function(){
-
- this.inherited(arguments);
- dijit.hideTooltip(this.domNode);
- },
-
- _updateSelection: function(){
- this.inherited(arguments);
- this._handleOnChange(this.value);
- dojo.forEach(this._getChildren(), function(c){ c._updateBox(); });
- },
-
- _getChildren: function(){
- return dojo.map(this.wrapperDiv.childNodes, function(n){
- return dijit.byNode(n);
- });
- },
- invertSelection: function(onChange){
-
-
-
- dojo.forEach(this.options, function(i){
- i.selected = !i.selected;
- });
- this._updateSelection();
- },
- _setDisabledAttr: function(value){
-
-
- this.inherited(arguments);
- dojo.forEach(this._getChildren(), function(node){
- if(node && node.set){
- node.set("disabled", value);
- }
- });
- },
-
- _setReadOnlyAttr: function(value){
-
-
- if("readOnly" in this.attributeMap){
- this._attrToDom("readOnly", value);
- }
- this.readOnly = value;
- dojo.forEach(this._getChildren(), function(node){
- if(node && node.set){
- node.set("readOnly", value);
- }
- });
- },
- uninitialize: function(){
- dijit.hideTooltip(this.domNode);
-
- dojo.forEach(this._getChildren(), function(child){
- child.destroyRecursive();
- });
- this.inherited(arguments);
- }
- });
- }
|