|
40 |
dojo.require("umc.widgets._FormWidgetMixin"); |
40 |
dojo.require("umc.widgets._FormWidgetMixin"); |
41 |
dojo.require("umc.widgets._WidgetsInWidgetsMixin"); |
41 |
dojo.require("umc.widgets._WidgetsInWidgetsMixin"); |
42 |
|
42 |
|
|
|
43 |
dojo.require("dojo.store.DataStore"); |
44 |
|
43 |
dojo.declare("umc.widgets.MultiObjectSelect", [ umc.widgets.ContainerWidget, umc.i18n.Mixin, umc.widgets._FormWidgetMixin ], { |
45 |
dojo.declare("umc.widgets.MultiObjectSelect", [ umc.widgets.ContainerWidget, umc.i18n.Mixin, umc.widgets._FormWidgetMixin ], { |
44 |
// summary: |
46 |
// summary: |
45 |
// ??? |
47 |
// ??? |
|
66 |
// the widget's class name as CSS class |
68 |
// the widget's class name as CSS class |
67 |
'class': 'umcMultiObjectSelect', |
69 |
'class': 'umcMultiObjectSelect', |
68 |
|
70 |
|
69 |
// internal reference to all values |
|
|
70 |
_values: [], |
71 |
|
72 |
// internal reference to the parsed formatter function |
71 |
// internal reference to the parsed formatter function |
73 |
_formatter: function(ids) { return ids; }, |
72 |
_formatter: function(ids) { return ids; }, |
74 |
|
73 |
|
|
|
74 |
// object store adapter for the data store of the MultiSelect widget |
75 |
_objectStore: null, |
76 |
|
75 |
// reference to the MultiSelect widget |
77 |
// reference to the MultiSelect widget |
76 |
_multiSelect: null, |
78 |
_multiSelect: null, |
77 |
|
79 |
|
78 |
// reference to the detail dialog |
80 |
// reference to the detail dialog |
79 |
_detailDialog: null, |
81 |
_detailDialog: null, |
80 |
|
82 |
|
|
|
83 |
// encapsulate the data store fo the multi select widget |
81 |
postMixInProperties: function() { |
84 |
postMixInProperties: function() { |
82 |
this.inherited(arguments); |
85 |
this.inherited(arguments); |
83 |
|
86 |
|
|
90 |
this._formatter = umc.tools.stringOrFunction(this.formatter); |
93 |
this._formatter = umc.tools.stringOrFunction(this.formatter); |
91 |
}, |
94 |
}, |
92 |
|
95 |
|
|
|
96 |
_attachObjectStore: function() { |
97 |
this._objectStore = new dojo.store.DataStore( { |
98 |
store: this._multiSelect.store |
99 |
} ); |
100 |
}, |
101 |
|
93 |
buildRendering: function() { |
102 |
buildRendering: function() { |
94 |
this.inherited(arguments); |
103 |
this.inherited(arguments); |
95 |
|
104 |
|
96 |
// add the MultiSelect widget |
105 |
// add the MultiSelect widget |
97 |
this._multiSelect = new umc.widgets.MultiSelect({}); |
106 |
this._multiSelect = new umc.widgets.MultiSelect({}); |
|
|
107 |
this._attachObjectStore(); |
108 |
if ( 'setStore' in this._multiSelect ) { |
109 |
dojo.connect( this._multiSelect, 'setStore', this, '_attachObjectStore' ); |
110 |
} |
98 |
var container = new umc.widgets.ContainerWidget({}); |
111 |
var container = new umc.widgets.ContainerWidget({}); |
99 |
container.addChild(this._multiSelect); |
112 |
container.addChild(this._multiSelect); |
100 |
this.addChild(container); |
113 |
this.addChild(container); |
|
138 |
// callback handler |
151 |
// callback handler |
139 |
this._multiSelect.set('staticValues', values); |
152 |
this._multiSelect.set('staticValues', values); |
140 |
})); |
153 |
})); |
141 |
|
|
|
142 |
// cache the specified values for any case |
143 |
this._values = _values; |
144 |
}, |
154 |
}, |
145 |
|
155 |
|
146 |
_getValueAttr: function() { |
156 |
_getValueAttr: function() { |
147 |
// return a copy |
157 |
// return a copy |
148 |
return dojo.clone(this._values); |
158 |
var values = []; |
|
|
159 |
this._objectStore.query( {} ).map( function( item ) { |
160 |
values.push( item.id ); |
161 |
} ); |
162 |
return values; |
149 |
}, |
163 |
}, |
150 |
|
164 |
|
151 |
getQueryWidget: function(name) { |
165 |
getQueryWidget: function(name) { |
|
154 |
return this._detailDialog._form.getWidget(name); |
168 |
return this._detailDialog._form.getWidget(name); |
155 |
}, |
169 |
}, |
156 |
|
170 |
|
157 |
_addElements: function(values) { |
171 |
_addElements: function( ids ) { |
158 |
// get all current entries |
|
|
159 |
var newValues = this._values; |
160 |
var map = {}; |
161 |
dojo.forEach(newValues, function(iid) { |
162 |
map[iid] = true; |
163 |
}); |
164 |
|
165 |
// only add elements that do not exist already |
172 |
// only add elements that do not exist already |
166 |
dojo.forEach(values, function(iid) { |
173 |
var dialog_store = dojo.store.DataStore( { store: this._detailDialog._multiSelect.store } ); |
167 |
if (!(iid in map)) { |
174 |
dojo.forEach( ids , dojo.hitch( this, function( id ) { |
168 |
newValues.push(iid); |
175 |
var item = dialog_store.get( id ); |
|
|
176 |
try { |
177 |
this._objectStore.get( id ); |
178 |
} catch( e ) { |
179 |
// object does not exist ... |
180 |
this._objectStore.put( item ); |
169 |
} |
181 |
} |
170 |
}); |
182 |
} ) ); |
171 |
|
183 |
this._multiSelect.store.save(); |
172 |
// save the new values |
|
|
173 |
this.set('value', newValues); |
174 |
}, |
184 |
}, |
175 |
|
185 |
|
176 |
_removeSelectedElements: function() { |
186 |
_removeSelectedElements: function() { |
177 |
// create a dict for all selected elements |
187 |
// create a dict for all selected elements |
178 |
var selection = {}; |
188 |
dojo.forEach(this._multiSelect.getSelectedItems(), dojo.hitch( this, function( iid ) { |
179 |
dojo.forEach(this._multiSelect.get('value'), function(iid) { |
189 |
this._objectStore.remove( iid.id ); |
180 |
selection[iid] = true; |
190 |
} ) ); |
181 |
}); |
191 |
this._multiSelect.selection.clear(); |
182 |
|
192 |
this._multiSelect.store.save(); |
183 |
// get all items |
|
|
184 |
var newValues = dojo.filter(this.get('value'), function(iid) { |
185 |
return !(iid in selection); |
186 |
}); |
187 |
|
188 |
// set the new values |
189 |
this.set('value', newValues); |
190 |
}, |
193 |
}, |
191 |
|
194 |
|
192 |
uninitialize: function() { |
195 |
uninitialize: function() { |