aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/controller/array-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/controller/array-controller.js')
-rwxr-xr-xnode_modules/montage/ui/controller/array-controller.js73
1 files changed, 71 insertions, 2 deletions
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,
47 47
48 //TODO for right now assume that any content change invalidates the selection completely; we'll need to address this of course 48 //TODO for right now assume that any content change invalidates the selection completely; we'll need to address this of course
49 this.selectedObjects = null; 49 this.selectedObjects = null;
50
51 this.organizeObjects(); 50 this.organizeObjects();
51 this._initSelections();
52 } 52 }
53 }, 53 },
54 54
@@ -599,7 +599,7 @@ var ArrayController = exports.ArrayController = Montage.create(ObjectController,
599 599
600 return this._selectedContentIndexes; 600 return this._selectedContentIndexes;
601 }, 601 },
602 set: function(value) { 602 set: function(value, internalSet) {
603 var selectedIndexesChangeEvent, 603 var selectedIndexesChangeEvent,
604 selectedObjectsChangeEvent; 604 selectedObjectsChangeEvent;
605 605
@@ -642,9 +642,78 @@ var ArrayController = exports.ArrayController = Montage.create(ObjectController,
642 642
643 this.dispatchEvent(selectedIndexesChangeEvent.withPlusValue(this.selectedIndexes)); 643 this.dispatchEvent(selectedIndexesChangeEvent.withPlusValue(this.selectedIndexes));
644 this.dispatchEvent(selectedObjectsChangeEvent.withPlusValue(this.selectedObjects)); 644 this.dispatchEvent(selectedObjectsChangeEvent.withPlusValue(this.selectedObjects));
645
646 if(!internalSet) {
647 // update the selections only if the selectedContentIndexes is set directly
648 this._updateSelections();
649 }
650
651 }
652 },
653
654
655 _initSelections: {
656 value: function() {
657 // create an array with null values with same
658 // length as organizedObjects
659 var len = this._organizedObjects.length;
660 var arr = [];
661 arr[0] = null;
662 arr[len-1] = null;
663
664 this._selections = arr;
665 //Object.getPropertyDescriptor(this, "selections").set.call(this, arr, true);
645 } 666 }
646 }, 667 },
647 668
669 _updateSelections: {
670 value: function() {
671
672 if(this.selectedIndexes) {
673 this._initSelections();
674 var arr = this._selections;
675 var selectedIndexes = this.selectedIndexes || [];
676 var len = selectedIndexes.length, i=0, index;
677
678 for(i=0; i< len; i++) {
679 index = selectedIndexes[i];
680 if(index < arr.length-1) {
681 arr[index] = true;
682 }
683 }
684 }
685
686 Object.getPropertyDescriptor(this, "selections").set.call(this, arr, true);
687
688 }
689 },
690
691 // parse array with same length as objects but contains true / false(falsy)
692 _selections: {value: null},
693 selections: {
694 get: function() {
695 return this._selections;
696 },
697 set: function(v, internalSet) {
698 this._selections = v;
699 if(this._selections) {
700
701 if(!internalSet) {
702 var arr = [];
703 this._selections.forEach(function(item, i) {
704 if(item) {
705 arr.push(i);
706 }
707 });
708 // use the internalSet flag to prevent setting the selections again,
709 Object.getPropertyDescriptor(this, "selectedIndexes").set.call(this, arr, true);
710 }
711
712 }
713 }
714 },
715
716
648 /** 717 /**
649 Initalizes the ArrayController with the specified content. 718 Initalizes the ArrayController with the specified content.
650 @function 719 @function