implement a reset() method for the tag autocompleter, and use it
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 3 Apr 2009 05:30:42 +0000 (01:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 3 Apr 2009 05:52:11 +0000 (01:52 -0400)
to make sure the relevant fields are in the initial state when
the event form opens.

kronolith/js/src/kronolith.js
kronolith/js/src/taggerAutoCompleter.js

index a6edd16..d85a07c 100644 (file)
@@ -1024,7 +1024,6 @@ KronolithCore = {
 
             case 'kronolithEventCancel':
                 this._closeRedBox();
-                // TODO: Need to clear the tagger fields.
                 e.stop();
                 return;
 
@@ -1160,6 +1159,7 @@ KronolithCore = {
         };
 
         this.doAction('ListTopTags', {}, this._topTags);
+        $('kronolithTagACTrigger').kronolithTagger.reset();
         if (id) {
             RedBox.loading();
             this.doAction('GetEvent', { 'cal': calendar, 'id': id }, this._editEvent.bind(this));
index 49f2a6e..1059a84 100644 (file)
@@ -36,6 +36,19 @@ var KronolithTagger = Class.create({
 
         },
 
+        reset: function(e)
+        {
+            // TODO: Resize the trigger field to fill the current line?
+            //$(this.p.trigger).value = '';
+
+            // Clear the hidden input field
+            //$(this.p.tags).value = '';
+
+            if (this.p.selectedTags.length) {
+                $('kronolithTagACBox').select('li.kronolithTagACListItem').each(function(item) {this.removeTagNode(item) }.bind(this));
+            }
+        },
+
         _onKeyDown: function(e)
         {
             // Check for a comma
@@ -71,7 +84,7 @@ var KronolithTagger = Class.create({
 
             var newTag = new Element('li', {class: 'kronolithACListItem kronolithTagACListItem'}).update(value);
             var x = new Element('img', {class: 'kronolithTagACRemove', src:this.p.URI_IMG_HORDE + "/delete-small.png"});
-            x.observe('click', this._removeTag.bindAsEventListener(this));
+            x.observe('click', this._removeTagHandler.bindAsEventListener(this));
             newTag.insert(x);
             $(this.p.container).insert({before: newTag});
             $(this.p.trigger).value = '';
@@ -87,21 +100,21 @@ var KronolithTagger = Class.create({
             this.p.selectedTags.push(value);
         },
 
-        _removeTag: function(e)
+        removeTagNode: function(item)
         {
-            item = Event.element(e).up();
-            // The value to remove from the hidden textbox
             var value = item.collectTextNodesIgnoreClass('informal');
-
             for (var x = 0, len = this.p.selectedTags.length; x < len; x++) {
                 if (this.p.selectedTags[x] == value) {
                     this.p.selectedTags.splice(x, 1);
                 }
             }
+            item.remove();
+        },
 
+        _removeTagHandler: function(e)
+        {
+            item = Event.element(e).up();
+            this.removeTagNode(item);
             $(this.p.tags).value = this.p.selectedTags.join(',');
-
-            // Nuke the node.
-            item.remove();
         }
 });
\ No newline at end of file