Roo/Template.js
[roojs1] / Roo / View.js
index 359fdcf..cab4f6b 100644 (file)
@@ -181,13 +181,17 @@ Roo.extend(Roo.View, Roo.util.Observable, {
     /**
      * @cfg {Boolean} multiSelect Allow multiple selection
      */
-    
     multiSelect : false,
     /**
      * @cfg {Boolean} singleSelect Allow single selection
      */
     singleSelect:  false,
     
+    /**
+     * @cfg {Boolean} toggleSelect - selecting 
+     */
+    toggleSelect : false,
+    
     /**
      * Returns the element this view is bound to.
      * @return {Roo.Element}
@@ -354,10 +358,18 @@ Roo.extend(Roo.View, Roo.util.Observable, {
         }
     },
 
-    onItemClick : function(item, index, e){
+    onItemClick : function(item, index, e)
+    {
         if(this.fireEvent("beforeclick", this, index, item, e) === false){
             return false;
         }
+        if (this.toggleSelect) {
+            var m = this.isSelected(item) ? 'unselect' : 'select';
+            Roo.log(m);
+            var _t = this;
+            _t[m](item, true, false);
+            return true;
+        }
         if(this.multiSelect || this.singleSelect){
             if(this.multiSelect && e.shiftKey && this.lastSelection){
                 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
@@ -463,9 +475,10 @@ Roo.extend(Roo.View, Roo.util.Observable, {
       /**
      * Unselects nodes.
      * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
+     * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
      * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
      */
-    unselect : function(nodeInfo, suppressEvent)
+    unselect : function(nodeInfo, keepExisting, suppressEvent)
     {
         if(nodeInfo instanceof Array){
             Roo.each(this.selections, function(s) {
@@ -475,12 +488,23 @@ Roo.extend(Roo.View, Roo.util.Observable, {
         }
         var node = this.getNode(nodeInfo);
         if(!node || !this.isSelected(node)){
+            Roo.log("not selected");
             return; // not selected.
         }
+        // fireevent???
+        var ns = [];
+        Roo.each(this.selections, function(s) {
+            if (s == node ) {
+                Roo.fly(node).removeClass(this.selectedClass);
+
+                return;
+            }
+            ns.push(s);
+        },this);
         
-        
-        
-    }
+        this.selections= ns;
+        this.fireEvent("selectionchange", this, this.selections);
+    },
 
     /**
      * Gets a template node.