var _aLookupWidgets = {}; function getJSONLookupWidget(name) { if(!isUndefinedOrNull(_aLookupWidgets[name])) { return _aLookupWidgets[name]; } else { return false; } } function JSONLookupWidget() { } JSONLookupWidget.prototype = { /* bind_add and bind_remove are functions to be called with the key:value's of selected items */ 'initialize' : function(name, action) { bindMethods(this); this.sName = name; this.sAction = action; this.oSelectAvail = $('select_' + name + '_avail'); this.oSelectAssigned = $('select_' + name + '_assigned'); this.oFilterAvail = $('filter_' + name + '_avail'); this.oFilterAssigned = $('filter_' + name + '_assigned'); this.savedFilter = this.oFilterAvail.value; this.savedSelector = this.oFilterAssigned.value; this.filterTimer = null; this.aItemsAdded = []; this.aItemsRemoved = []; connect(this.oFilterAvail, 'onkeyup', this, 'onchangeFilter'); connect(this.oFilterAssigned, 'onkeyup', this, 'onchangeSelector'); connect(name + '_add', 'onclick', this, 'onclickAdd'); connect(name + '_remove', 'onclick', this, 'onclickRemove'); connect(name + '_show_all', 'onclick', this, 'onclickShowAll'); this.triggers = {}; this.triggers['add'] = null; this.triggers['remove'] = null; this.initialValuesLoaded = false; var d = this.getValues(); d.addCallback(this.postInitialize); }, 'addTrigger' : function(event, func) { this.triggers[event] = func; }, // values handling 'getValues' : function(all) { var act = this.sAction; if(!isUndefinedOrNull(all)) { act += '&' + queryString({'filter' : '%'}); } else if(this.savedFilter) { act += '&' + queryString({'filter' : this.savedFilter}); } else if(!this.initialValuesLoaded) { act += '&' + queryString({'selected' : '1'}); } var d = loadJSONDoc(act); d.addErrback(this.errGetValues); d.addCallback(checkKTError); d.addCallback(this.saveValues); d.addCallback(this.renderValues); return d; }, 'errGetValues' : function(res) { alert('There was an error retrieving data. Please check connectivity and try again.'); this.oValues = {'off':'-- Error fetching values --'}; this.renderValues(); }, 'saveValues' : function(res) { this.oValues = res; return res; }, 'renderValues' : function() { var aOptions = []; var bSelFound = false; for(var k in this.oValues) { var found = false; for(var i=0; i