Changeset 513 for Dev/trunk/src/client/qed-client/widgets/ListWidget.js
- Timestamp:
- 03/13/14 22:21:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/widgets/ListWidget.js
r511 r513 1 1 define([ 2 " dijit/_Container",2 "./_ComplexValueMixin", 3 3 "dijit/_WidgetBase", 4 4 "dijit/registry", 5 5 "dojo/_base/array", 6 6 "dojo/_base/declare", 7 "dojo/_base/event", 7 8 "dojo/_base/lang", 8 9 "dojo/dnd/Source", 9 10 "dojo/dnd/common", 10 11 "dojo/dom-construct", 11 "dojo/_base/event",12 12 "dojo/on" 13 ], function(_Container, _WidgetBase, registry, array, declare, lang, Source, dnd, domConstruct, event, on) { 14 return declare([_WidgetBase,_Container],{ 15 name: "", 16 value: null, 17 disabled: false, 18 readOnly: false, 13 ], function(_ComplexValueMixin, _WidgetBase, registry, array, declare, event, lang, Source, dnd, domConstruct, on) { 14 return declare([_WidgetBase,_ComplexValueMixin],{ 19 15 multiple: true, 20 16 type: "text", … … 65 61 this.own(this.source.on('Drop', 66 62 lang.hitch(this,'_handleDrop'))); 67 this.own(on(this.domNode,'change',68 lang.hitch(this,'_handleChange')));69 },70 create: function() {71 this.inherited(arguments);72 this._onChangeActive = true;73 63 }, 74 64 creator: function(item, hint) { … … 83 73 } else { 84 74 if ( this.createListElement ) { 85 nodeOrWidget = this.createListElement(id,item,this._fromDrop); 75 nodeOrWidget = 76 this.createListElement(id,item,this._fromDrop); 86 77 } else { 87 78 return this.source.defaultCreator(item, hint); 88 79 } 89 80 } 90 var node = nodeOrWidget.domNode ? nodeOrWidget.domNode : nodeOrWidget; 81 if ( nodeOrWidget.on ) { 82 this.connectChildsChanges(nodeOrWidget); 83 } 84 var node = nodeOrWidget.domNode ? 85 nodeOrWidget.domNode : 86 nodeOrWidget; 91 87 if ( hint !== "avatar" && node.id !== id ) { 92 88 console.warn("Node id '%s' not equal to generated id '%s'. Is this intended?", node.id, id); … … 101 97 createListElement: null, /* function(id,item,fromDrop){},*/ 102 98 _getValueAttr: function() { 103 this.value = array.map(this.source.getAllNodes(),function(node){ 104 var widget = registry.byNode(node); 105 if ( widget && "value" in widget ) { 106 return widget.get('value'); 107 } else { 108 return this.source.getItem(node.id).data; 109 } 110 },this); 111 return this.value; 99 return array.map( 100 this._getDescendantFormWidgets(), 101 function(child) { return child.get('value'); } 102 ,this); 112 103 }, 113 104 _setValueAttr: function(value,priorityChange) { 114 105 this.clear(); 115 this.appendItems(value || []); 106 this._setValueInternal(value || [], priorityChange); 107 this.appendItems(this.value); 116 108 }, 117 _setDisabledAttr: function(value) { 118 this._set("disabled", value); 119 array.forEach(this.getChildren(), function(child){ 120 child.set("disabled", value); 121 }); 122 this._updateContainer(); 109 _setReadOnlyAttr: function() { 110 this.inherited(arguments); 111 this._updateSource(); 123 112 }, 124 _setReadOnlyAttr: function(value) { 125 this._set("readOnly", value); 126 array.forEach(this.getChildren(), function(child){ 127 child.set("readOnly", value); 128 }); 129 this._updateContainer(); 113 _setDisabledAttr: function() { 114 this.inherited(arguments); 115 this._updateSource(); 130 116 }, 131 _update Container: function() {117 _updateSource: function() { 132 118 if ( this.disabled || this.readOnly ) { 133 119 this.source.accept = []; … … 139 125 } 140 126 }, 141 focus: function() { 142 var children = this.getChildren(); 143 if ( children.length > 0 ) { 144 children[0].focus(); 145 } 127 getChildren: function() { 128 return array.filter( 129 array.map(this.source.getAllNodes(), function(node){ 130 return registry.byNode(node); 131 }), 132 function(widget){ return widget !== null; }); 146 133 }, 134 _getDescendantFormWidgets: function() { 135 return array.filter( 136 this.getChildren(), 137 function(child){ return 'value' in child; }); 138 }, 139 147 140 appendItems: function(items,forceEvent) { 148 141 this._fromDrop = false; 149 142 this.source.insertNodes(false,items); 150 if ( forceEvent ) { this._handleDrop(); } 143 this._setValueInternal( 144 this.get('value'), 145 forceEvent === true ? true : null); 151 146 this._fromDrop = true; 152 147 }, … … 154 149 this._fromDrop = false; 155 150 this.source.insertNodes(false,[item]); 156 if ( forceEvent ) { this._handleDrop(); } 151 this._setValueInternal( 152 this.get('value'), 153 forceEvent === true ? true : null); 157 154 this._fromDrop = true; 158 155 }, 159 156 removeItem: function(key,forceEvent) { 160 array.forEach(array.filter(this.source.getAllNodes(), function(node){ 161 return node.id === key; 162 }), lang.hitch(this, "_destroyNodeOrWidget")); 157 array.forEach( 158 array.filter(this.source.getAllNodes(), function(node){ 159 return node.id === key; 160 }), 161 lang.hitch(this, "_destroyNodeOrWidget")); 163 162 this.source.delItem(key); 164 if ( forceEvent ) { this._handleDrop(); } 165 }, 166 getChildren: function() { 167 return array.filter(array.map(this.source.getAllNodes(), function(node){ 168 return registry.byNode(node); 169 }),function(widget){ return widget !== null; }); 163 this._setValueInternal( 164 this.get('value'), 165 forceEvent === true ? true : null); 170 166 }, 171 167 clear: function(forceEvent) { … … 173 169 lang.hitch(this, "_destroyNodeOrWidget")); 174 170 this.source.clearItems(); 175 if ( forceEvent ) { this._handleDrop(); } 171 this._setValueInternal( 172 this.get('value'), 173 forceEvent === true ? true : null); 176 174 }, 177 175 _destroyNodeOrWidget: function(node) { … … 183 181 } 184 182 }, 185 validate: function() {186 return array.every(array.map(this.source.getAllNodes(),function(node){187 var widget = registry.byNode(node);188 return !widget || widget.disabled || !widget.validate || widget.validate();189 }), function(item){ return item; });190 },191 183 destroy: function() { 192 184 this.source.destroy(); 193 185 this.inherited(arguments); 194 186 }, 195 _handleChange: function(evt) { 196 if ( evt.target !== this.domNode ) { 197 this._onChange(); 198 if ( evt ) { event.stop(evt); } 199 return false; 200 } else { 201 return evt; 202 } 203 }, 204 _handleDrop: function(evt) { 205 this._onChange(); 206 }, 207 _onChange: function() { 208 if ( this._onChangeActive && 209 !(this.readOnly || this.disabled) ) { 210 if ( this._onChangeHandle ) { 211 this._onChangeHandle.cancel(); 212 } 213 this._onChangeHandle = this.defer(function(){ 214 this._onChangeHandle = null; 215 on.emit(this.domNode,'change',{ 216 target: this.domNode, 217 value: this.get('value'), 218 bubbles: true, 219 cancellable: true 220 }); 221 }); 222 } 187 _handleDrop: function() { 188 this._setValueInternal(this.get('value')); 223 189 } 224 190 });
Note: See TracChangeset
for help on using the changeset viewer.