View | Details | Raw Unified | Return to bug 26363
Collapse All | Expand All

(-)umc/widgets/MultiObjectSelect.js (-34 / +37 lines)
 Lines 40-45    Link Here 
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
	//		???
 Lines 66-83    Link Here 
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
 Lines 90-100    Link Here 
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);
 Lines 138-151    Link Here 
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) {
 Lines 154-192    Link Here 
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() {
(-)umc/widgets/_SelectMixin.js (-16 / +8 lines)
 Lines 229-250    Link Here 
229
	},
229
	},
230
230
231
	_clearValues: function() {
231
	_clearValues: function() {
232
		if ('setStore' in this) {
232
		this.store.fetch( { 
233
			// there is a method 'setStore' (data grids) which can be used to create a new store object
233
			onComplete: dojo.hitch( this, function( items ) {
234
			var newStore = this._createStore();
234
				dojo.forEach( items, dojo.hitch( this, function( item ) {
235
			this.setStore(newStore, {});
235
					this.store.deleteItem( item );
236
		}
236
				} ) )
237
		else {
237
			} )
238
			// otherwise (combo box) clear the store as described in:
238
		} );
239
			//   http://mail.dojotoolkit.org/pipermail/dojo-interest/2011-January/052159.html
239
		this.store.save();
240
			this.store.save();
241
			this.store.data = {
242
				identifier: 'id',
243
				label: 'label',
244
				items: []
245
			};
246
			this.store.close();
247
		}
248
240
249
		//if (this._isAutoValue) {
241
		//if (this._isAutoValue) {
250
		//	// reset the _initialValue in case we chose it automatically
242
		//	// reset the _initialValue in case we chose it automatically
(-)umc/widgets/MultiSelect.js (-3 / +3 lines)
 Lines 77-91    Link Here 
77
	height: '110px',
77
	height: '110px',
78
78
79
	postMixInProperties: function() {
79
	postMixInProperties: function() {
80
		// initiate a new Deferred object
81
		this._loadingDeferred = new dojo.Deferred();
82
80
		this.inherited(arguments);
83
		this.inherited(arguments);
81
84
82
		// in case 'value' is not specified, generate a new array
85
		// in case 'value' is not specified, generate a new array
83
		if (!dojo.isArray(this.value)) {
86
		if (!dojo.isArray(this.value)) {
84
			this.value = [];
87
			this.value = [];
85
		}
88
		}
86
87
		// initiate a new Deferred object
88
		this._loadingDeferred = new dojo.Deferred();
89
	},
89
	},
90
90
91
	postCreate: function() {
91
	postCreate: function() {

Return to bug 26363