From a3024011a91d3941f81481dd4d600e9684eb0fd4 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 2 Feb 2012 00:11:51 -0800 Subject: upgrading to Montage v0.6 Signed-off-by: Valerio Virgillito --- .../montage/ui/controller/array-controller.js | 73 +++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) (limited to 'node_modules/montage/ui/controller') diff --git a/node_modules/montage/ui/controller/array-controller.js b/node_modules/montage/ui/controller/array-controller.js index 98b0c66f..868ae5de 100755 --- a/node_modules/montage/ui/controller/array-controller.js +++ b/node_modules/montage/ui/controller/array-controller.js @@ -47,8 +47,8 @@ var ArrayController = exports.ArrayController = Montage.create(ObjectController, //TODO for right now assume that any content change invalidates the selection completely; we'll need to address this of course this.selectedObjects = null; - this.organizeObjects(); + this._initSelections(); } }, @@ -599,7 +599,7 @@ var ArrayController = exports.ArrayController = Montage.create(ObjectController, return this._selectedContentIndexes; }, - set: function(value) { + set: function(value, internalSet) { var selectedIndexesChangeEvent, selectedObjectsChangeEvent; @@ -642,9 +642,78 @@ var ArrayController = exports.ArrayController = Montage.create(ObjectController, this.dispatchEvent(selectedIndexesChangeEvent.withPlusValue(this.selectedIndexes)); this.dispatchEvent(selectedObjectsChangeEvent.withPlusValue(this.selectedObjects)); + + if(!internalSet) { + // update the selections only if the selectedContentIndexes is set directly + this._updateSelections(); + } + + } + }, + + + _initSelections: { + value: function() { + // create an array with null values with same + // length as organizedObjects + var len = this._organizedObjects.length; + var arr = []; + arr[0] = null; + arr[len-1] = null; + + this._selections = arr; + //Object.getPropertyDescriptor(this, "selections").set.call(this, arr, true); } }, + _updateSelections: { + value: function() { + + if(this.selectedIndexes) { + this._initSelections(); + var arr = this._selections; + var selectedIndexes = this.selectedIndexes || []; + var len = selectedIndexes.length, i=0, index; + + for(i=0; i< len; i++) { + index = selectedIndexes[i]; + if(index < arr.length-1) { + arr[index] = true; + } + } + } + + Object.getPropertyDescriptor(this, "selections").set.call(this, arr, true); + + } + }, + + // parse array with same length as objects but contains true / false(falsy) + _selections: {value: null}, + selections: { + get: function() { + return this._selections; + }, + set: function(v, internalSet) { + this._selections = v; + if(this._selections) { + + if(!internalSet) { + var arr = []; + this._selections.forEach(function(item, i) { + if(item) { + arr.push(i); + } + }); + // use the internalSet flag to prevent setting the selections again, + Object.getPropertyDescriptor(this, "selectedIndexes").set.call(this, arr, true); + } + + } + } + }, + + /** Initalizes the ArrayController with the specified content. @function -- cgit v1.2.3