From: Michael J. Rubinsky Date: Fri, 3 Apr 2009 05:30:42 +0000 (-0400) Subject: implement a reset() method for the tag autocompleter, and use it X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=24b461fc9bafcd1bc53c91e3a9b050da1da9a91b;p=horde.git implement a reset() method for the tag autocompleter, and use it to make sure the relevant fields are in the initial state when the event form opens. --- diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index a6edd16a9..d85a07c35 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -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)); diff --git a/kronolith/js/src/taggerAutoCompleter.js b/kronolith/js/src/taggerAutoCompleter.js index 49f2a6e95..1059a8451 100644 --- a/kronolith/js/src/taggerAutoCompleter.js +++ b/kronolith/js/src/taggerAutoCompleter.js @@ -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