diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-06-07 03:57:17 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-06-07 03:57:17 -0400 |
commit | e10517db8efe907cadb805a05b4c948a4e5264d5 (patch) | |
tree | ab8eecc1165e7ce9c171865fb93d4efe00a3aaaa | |
parent | 9f679e83639c642d903eeacde695baef1be44ec1 (diff) | |
download | askbot-e10517db8efe907cadb805a05b4c948a4e5264d5.tar.gz askbot-e10517db8efe907cadb805a05b4c948a4e5264d5.tar.bz2 askbot-e10517db8efe907cadb805a05b4c948a4e5264d5.zip |
hopefully fixed remaining post-merge bugs
-rw-r--r-- | askbot/skins/common/media/js/utils.js | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/askbot/skins/common/media/js/utils.js b/askbot/skins/common/media/js/utils.js index 4e0f91f1..fcb22197 100644 --- a/askbot/skins/common/media/js/utils.js +++ b/askbot/skins/common/media/js/utils.js @@ -858,6 +858,10 @@ SelectBoxItem.prototype.setDescription = function(description) { } }; +SelectBoxItem.prototype.getId = function() { + return this._id; +}; + SelectBoxItem.prototype.getData = function () { //todo: stuck using old key names, change after merge //with the user-groups branch @@ -915,31 +919,47 @@ SelectBox.prototype.isEditable = function() { return this._is_editable; }; -SelectBox.prototype.removeItem = function(id){ - var item = this.getItem(id); - item.fadeOut(); - item.remove(); -}; - SelectBox.prototype.removeAllItems = function() { - $.each(this._items, function(idx, item) { + var items = this._items; + $.each(items, function(idx, item){ item.dispose(); }); + this._items = []; }; SelectBox.prototype.getItem = function(id){ - return this._items[id]; + var items = this._items; + for (var i = 0; i < items.length; i++) { + if (items[i].getId() === id) { + return items[i]; + } + } + return undefined; }; SelectBox.prototype.setItemClass = function(id, css_class) { this.getItem(id).getElement().addClass(css_class); }; +//why do we have these two almost identical methods? +SelectBox.prototype.removeItem = function(id){ + var item = this.getItem(id); + item.getElement().fadeOut(); + item.dispose(); + var idx = $.inArray(item, this._items); + if (idx !== -1) { + this._items.splice(idx, 1); + } +}; SelectBox.prototype.deleteItem = function(id) { var item = this.getItem(id); - if (item !== undefined) { - item.dispose(); - this._items[id] = null; + if (item === undefined) { + return; + } + item.dispose(); + var idx = $.inArray(item, this._items); + if (idx !== -1) { + this._items.splice(idx, 1); } }; @@ -961,7 +981,7 @@ SelectBox.prototype.addItem = function(id, name, description){ item.setName(name); item.setDescription(description); //add item to the SelectBox - this._items[id] = item; + this._items.push(item); this._element.append(item.getElement()); this.selectItem(item); //set event handler |