+Ext.namespace('Ext.ux.form');\r
+/**\r
+ * <p>SuperBoxSelect is an extension of the ComboBox component that displays selected items as labelled boxes within the form field. As seen on facebook, hotmail and other sites.</p>\r
+ * <p>The SuperBoxSelect component was inspired by the BoxSelect component found here: http://efattal.fr/en/extjs/extuxboxselect/</p>\r
+ * \r
+ * @author <a href="mailto:dan.humphrey@technomedia.co.uk">Dan Humphrey</a>\r
+ * @class Ext.ux.form.SuperBoxSelect\r
+ * @extends Ext.form.ComboBox\r
+ * @constructor\r
+ * @component\r
+ * @version 1.0\r
+ * @license TBA (To be announced)\r
+ * \r
+ */\r
+Ext.ux.form.SuperBoxSelect = function(config) {\r
+ Ext.ux.form.SuperBoxSelect.superclass.constructor.call(this,config);\r
+ this.addEvents(\r
+ /**\r
+ * Fires before an item is added to the component via user interaction. Return false from the callback function to prevent the item from being added.\r
+ * @event beforeadditem\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ * @param {Mixed} value The value of the item to be added\r
+ */\r
+ 'beforeadditem',\r
+\r
+ /**\r
+ * Fires after a new item is added to the component.\r
+ * @event additem\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ * @param {Mixed} value The value of the item which was added\r
+ * @param {Record} record The store record which was added\r
+ */\r
+ 'additem',\r
+\r
+ /**\r
+ * Fires when the allowAddNewData config is set to true, and a user attempts to add an item that is not in the data store.\r
+ * @event newitem\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ * @param {Mixed} value The new item's value\r
+ */\r
+ 'newitem',\r
+\r
+ /**\r
+ * Fires when an item's remove button is clicked. Return false from the callback function to prevent the item from being removed.\r
+ * @event beforeremoveitem\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ * @param {Mixed} value The value of the item to be removed\r
+ */\r
+ 'beforeremoveitem',\r
+\r
+ /**\r
+ * Fires after an item has been removed.\r
+ * @event removeitem\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ * @param {Mixed} value The value of the item which was removed\r
+ * @param {Record} record The store record which was removed\r
+ */\r
+ 'removeitem',\r
+ /**\r
+ * Fires after the component values have been cleared.\r
+ * @event clear\r
+ * @memberOf Ext.ux.form.SuperBoxSelect\r
+ * @param {SuperBoxSelect} this\r
+ */\r
+ 'clear'\r
+ );\r
+ \r
+};\r
+/**\r
+ * @private hide from doc gen\r
+ */\r
+Ext.ux.form.SuperBoxSelect = Ext.extend(Ext.ux.form.SuperBoxSelect,Ext.form.ComboBox,{\r
+ /**\r
+ * @cfg {Boolean} allowAddNewData When set to true, allows items to be added (via the setValueEx and addItem methods) that do not already exist in the data store. Defaults to false.\r
+ */\r
+ allowAddNewData: false,\r
+\r
+ /**\r
+ * @cfg {Boolean} backspaceDeletesLastItem When set to false, the BACKSPACE key will focus the last selected item. When set to true, the last item will be immediately deleted. Defaults to true.\r
+ */\r
+ backspaceDeletesLastItem: true,\r
+\r
+ /**\r
+ * @cfg {String} classField The underlying data field that will be used to supply an additional class to each item.\r
+ */\r
+ classField: null,\r
+\r
+ /**\r
+ * @cfg {String} clearBtnCls An additional class to add to the in-field clear button.\r
+ */\r
+ clearBtnCls: '',\r
+\r
+ /**\r
+ * @cfg {String/XTemplate} displayFieldTpl A template for rendering the displayField in each selected item. Defaults to null.\r
+ */\r
+ displayFieldTpl: null,\r
+\r
+ /**\r
+ * @cfg {String} extraItemCls An additional css class to apply to each item.\r
+ */\r
+ extraItemCls: '',\r
+\r
+ /**\r
+ * @cfg {String/Object/Function} extraItemStyle Additional css style(s) to apply to each item. Should be a valid argument to Ext.Element.applyStyles.\r
+ */\r
+ extraItemStyle: '',\r
+\r
+ /**\r
+ * @cfg {String} expandBtnCls An additional class to add to the in-field expand button.\r
+ */\r
+ expandBtnCls: '',\r
+\r
+ /**\r
+ * @cfg {Boolean} fixFocusOnTabSelect When set to true, the component will not lose focus when a list item is selected with the TAB key. Defaults to true.\r
+ */\r
+ fixFocusOnTabSelect: true,\r
+ \r
+ /**\r
+ * @cfg {Boolean} forceFormValue When set to true, the component will always return a value to the parent form getValues method, and when the parent form is submitted manually. Defaults to false, meaning the component will only be included in the parent form submission (or getValues) if at least 1 item has been selected. \r
+ */\r
+ forceFormValue: true,\r
+ /**\r
+ * @cfg {Number} itemDelimiterKey The key code which terminates keying in of individual items, and adds the current\r
+ * item to the list. Defaults to the ENTER key.\r
+ */\r
+ itemDelimiterKey: Ext.EventObject.ENTER, \r
+ /**\r
+ * @cfg {Boolean} navigateItemsWithTab When set to true the tab key will navigate between selected items. Defaults to true.\r
+ */\r
+ navigateItemsWithTab: true,\r
+\r
+ /**\r
+ * @cfg {Boolean} pinList When set to true the select list will be pinned to allow for multiple selections. Defaults to true.\r
+ */\r
+ pinList: true,\r
+\r
+ /**\r
+ * @cfg {Boolean} preventDuplicates When set to true unique item values will be enforced. Defaults to true.\r
+ */\r
+ preventDuplicates: true,\r
+ \r
+ /**\r
+ * @cfg {String} queryValuesDelimiter Used to delimit multiple values queried from the server when mode is remote.\r
+ */\r
+ queryValuesDelimiter: '|',\r
+ \r
+ /**\r
+ * @cfg {String} queryValuesIndicator A request variable that is sent to the server (as true) to indicate that we are querying values rather than display data (as used in autocomplete) when mode is remote.\r
+ */\r
+ queryValuesIndicator: 'valuesqry',\r
+\r
+ /**\r
+ * @cfg {Boolean} removeValuesFromStore When set to true, selected records will be removed from the store. Defaults to true.\r
+ */\r
+ removeValuesFromStore: true,\r
+\r
+ /**\r
+ * @cfg {String} renderFieldBtns When set to true, will render in-field buttons for clearing the component, and displaying the list for selection. Defaults to true.\r
+ */\r
+ renderFieldBtns: true,\r
+\r
+ /**\r
+ * @cfg {Boolean} stackItems When set to true, the items will be stacked 1 per line. Defaults to false which displays the items inline.\r
+ */\r
+ stackItems: false,\r
+\r
+ /**\r
+ * @cfg {String} styleField The underlying data field that will be used to supply additional css styles to each item.\r
+ */\r
+ styleField : null,\r
+ \r
+ /**\r
+ * @cfg {Boolean} supressClearValueRemoveEvents When true, the removeitem event will not be fired for each item when the clearValue method is called, or when the clear button is used. Defaults to false.\r
+ */\r
+ supressClearValueRemoveEvents : false,\r
+ \r
+ /**\r
+ * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable automatic validation (defaults to 'blur').\r
+ */\r
+ validationEvent : 'blur',\r
+ \r
+ /**\r
+ * @cfg {String} valueDelimiter The delimiter to use when joining and splitting value arrays and strings.\r
+ */\r
+ valueDelimiter: ',',\r
+ initComponent:function() {\r
+ Ext.apply(this, {\r
+ items : new Ext.util.MixedCollection(false),\r
+ usedRecords : new Ext.util.MixedCollection(false),\r
+ addedRecords : [],\r
+ remoteLookup : [],\r
+ hideTrigger : true,\r
+ grow : false,\r
+ resizable : false,\r
+ multiSelectMode : false,\r
+ preRenderValue : null\r
+ });\r
+ \r
+ if(this.transform){\r
+ this.doTransform();\r
+ }\r
+ if(this.forceFormValue){\r
+ this.items.on({\r
+ add: this.manageNameAttribute,\r
+ remove: this.manageNameAttribute,\r
+ clear: this.manageNameAttribute,\r
+ scope: this\r
+ });\r
+ }\r
+ \r
+ Ext.ux.form.SuperBoxSelect.superclass.initComponent.call(this);\r
+ if(this.mode === 'remote' && this.store){\r
+ this.store.on('load', this.onStoreLoad, this);\r
+ }\r
+ },\r
+ onRender:function(ct, position) {\r
+ var h = this.hiddenName;\r
+ this.hiddenName = null;\r
+ Ext.ux.form.SuperBoxSelect.superclass.onRender.call(this, ct, position);\r
+ this.hiddenName = h;\r
+ this.manageNameAttribute();\r
+ \r
+ var extraClass = (this.stackItems === true) ? 'x-superboxselect-stacked' : '';\r
+ if(this.renderFieldBtns){\r
+ extraClass += ' x-superboxselect-display-btns';\r
+ }\r
+ this.el.removeClass('x-form-text').addClass('x-superboxselect-input-field');\r
+ \r
+ this.wrapEl = this.el.wrap({\r
+ tag : 'ul'\r
+ });\r
+ \r
+ this.outerWrapEl = this.wrapEl.wrap({\r
+ tag : 'div',\r
+ cls: 'x-form-text x-superboxselect ' + extraClass\r
+ });\r
+ \r
+ this.inputEl = this.el.wrap({\r
+ tag : 'li',\r
+ cls : 'x-superboxselect-input'\r
+ });\r
+ \r
+ if(this.renderFieldBtns){\r
+ this.setupFieldButtons().manageClearBtn();\r
+ }\r
+ \r
+ this.setupFormInterception();\r
+ },\r
+ onStoreLoad : function(store, records, options){\r
+ //accomodating for bug in Ext 3.0.0 where options.params are empty\r
+ var q = options.params[this.queryParam] || store.baseParams[this.queryParam] || "",\r
+ isValuesQuery = options.params[this.queryValuesIndicator] || store.baseParams[this.queryValuesIndicator];\r
+ \r
+ if(this.removeValuesFromStore){\r
+ this.store.each(function(record) {\r
+ if(this.usedRecords.containsKey(record.get(this.valueField))){\r
+ this.store.remove(record);\r
+ }\r
+ }, this);\r
+ }\r
+ //queried values\r
+ if(isValuesQuery){\r
+ var params = q.split(this.queryValuesDelimiter);\r
+ Ext.each(params,function(p){\r
+ this.remoteLookup.remove(p);\r
+ var rec = this.findRecord(this.valueField,p);\r
+ if(rec){\r
+ this.addRecord(rec);\r
+ }\r
+ },this);\r
+ \r
+ if(this.setOriginal){\r
+ this.setOriginal = false;\r
+ this.originalValue = this.getValue();\r
+ }\r
+ }\r
+\r
+ //queried display (autocomplete) & addItem\r
+ if(q !== '' && this.allowAddNewData){\r
+ Ext.each(this.remoteLookup,function(r){\r
+ if(typeof r == "object" && r[this.displayField] == q){\r
+ this.remoteLookup.remove(r);\r
+ if(records.length && records[0].get(this.displayField) === q) {\r
+ this.addRecord(records[0]);\r
+ return;\r
+ }\r
+ var rec = this.createRecord(r);\r
+ this.store.add(rec);\r
+ this.addRecord(rec);\r
+ this.addedRecords.push(rec); //keep track of records added to store\r
+ (function(){\r
+ if(this.isExpanded()){\r
+ this.collapse();\r
+ }\r
+ }).defer(10,this);\r
+ return;\r
+ }\r
+ },this);\r
+ }\r
+ \r
+ var toAdd = [];\r
+ if(q === ''){\r
+ Ext.each(this.addedRecords,function(rec){\r
+ if(this.preventDuplicates && this.usedRecords.containsKey(rec.get(this.valueField))){\r
+ return; \r
+ }\r
+ toAdd.push(rec);\r
+ \r
+ },this);\r
+ \r
+ }else{\r
+ var re = new RegExp(Ext.escapeRe(q) + '.*','i');\r
+ Ext.each(this.addedRecords,function(rec){\r
+ if(this.preventDuplicates && this.usedRecords.containsKey(rec.get(this.valueField))){\r
+ return; \r
+ }\r
+ if(re.test(rec.get(this.displayField))){\r
+ toAdd.push(rec);\r
+ }\r
+ },this);\r
+ }\r
+ this.store.add(toAdd);\r
+ this.store.sort(this.displayField, 'ASC');\r
+ \r
+ if(this.store.getCount() === 0 && this.isExpanded()){\r
+ this.collapse();\r
+ }\r
+ \r
+ },\r
+ doTransform : function() {\r
+ var s = Ext.getDom(this.transform), transformValues = [];\r
+ if(!this.store){\r
+ this.mode = 'local';\r
+ var d = [], opts = s.options;\r
+ for(var i = 0, len = opts.length;i < len; i++){\r
+ var o = opts[i], oe = Ext.get(o),\r
+ value = oe.getAttributeNS(null,'value') || '',\r
+ cls = oe.getAttributeNS(null,'className') || '',\r
+ style = oe.getAttributeNS(null,'style') || '';\r
+ if(o.selected) {\r
+ transformValues.push(value);\r
+ }\r
+ d.push([value, o.text, cls, typeof(style) === "string" ? style : style.cssText]);\r
+ }\r
+ this.store = new Ext.data.SimpleStore({\r
+ 'id': 0,\r
+ fields: ['value', 'text', 'cls', 'style'],\r
+ data : d\r
+ });\r
+ Ext.apply(this,{\r
+ valueField: 'value',\r
+ displayField: 'text',\r
+ classField: 'cls',\r
+ styleField: 'style'\r
+ });\r
+ }\r
+ \r
+ if(transformValues.length){\r
+ this.value = transformValues.join(',');\r
+ }\r
+ },\r
+ setupFieldButtons : function(){\r
+ this.buttonWrap = this.outerWrapEl.createChild({\r
+ cls: 'x-superboxselect-btns'\r
+ });\r
+ \r
+ this.buttonClear = this.buttonWrap.createChild({\r
+ tag:'div',\r
+ cls: 'x-superboxselect-btn-clear ' + this.clearBtnCls\r
+ });\r
+ \r
+ this.buttonExpand = this.buttonWrap.createChild({\r
+ tag:'div',\r
+ cls: 'x-superboxselect-btn-expand ' + this.expandBtnCls\r
+ });\r
+ \r
+ this.initButtonEvents();\r
+ \r
+ return this;\r
+ },\r
+ initButtonEvents : function() {\r
+ this.buttonClear.addClassOnOver('x-superboxselect-btn-over').on('click', function(e) {\r
+ e.stopEvent();\r
+ if (this.disabled) {\r
+ return;\r
+ }\r
+ this.clearValue();\r
+ this.el.focus();\r
+ }, this);\r
+\r
+ this.buttonExpand.addClassOnOver('x-superboxselect-btn-over').on('click', function(e) {\r
+ e.stopEvent();\r
+ if (this.disabled) {\r
+ return;\r
+ }\r
+ if (this.isExpanded()) {\r
+ this.multiSelectMode = false;\r
+ } else if (this.pinList) {\r
+ this.multiSelectMode = true;\r
+ }\r
+ this.onTriggerClick();\r
+ }, this);\r
+ },\r
+ removeButtonEvents : function() {\r
+ this.buttonClear.removeAllListeners();\r
+ this.buttonExpand.removeAllListeners();\r
+ return this;\r
+ },\r
+ clearCurrentFocus : function(){\r
+ if(this.currentFocus){\r
+ this.currentFocus.onLnkBlur();\r
+ this.currentFocus = null;\r
+ } \r
+ return this; \r
+ },\r
+ initEvents : function() {\r
+ var el = this.el;\r
+\r
+ el.on({\r
+ click : this.onClick,\r
+ focus : this.clearCurrentFocus,\r
+ blur : this.onBlur,\r
+\r
+ keydown : this.onKeyDownHandler,\r
+ keyup : this.onKeyUpBuffered,\r
+\r
+ scope : this\r
+ });\r
+\r
+ this.on({\r
+ collapse: this.onCollapse,\r
+ expand: this.clearCurrentFocus,\r
+ scope: this\r
+ });\r
+\r
+ this.wrapEl.on('click', this.onWrapClick, this);\r
+ this.outerWrapEl.on('click', this.onWrapClick, this);\r
+ \r
+ this.inputEl.focus = function() {\r
+ el.focus();\r
+ };\r
+\r
+ Ext.ux.form.SuperBoxSelect.superclass.initEvents.call(this);\r
+\r
+ Ext.apply(this.keyNav, {\r
+ tab: function(e) {\r
+ if (this.fixFocusOnTabSelect && this.isExpanded()) {\r
+ e.stopEvent();\r
+ el.blur();\r
+ this.onViewClick(false);\r
+ this.focus(false, 10);\r
+ return true;\r
+ }\r
+\r
+ this.onViewClick(false);\r
+ if (el.dom.value !== '') {\r
+ this.setRawValue('');\r
+ }\r
+\r
+ return true;\r
+ },\r
+\r
+ down: function(e) {\r
+ if (!this.isExpanded() && !this.currentFocus) {\r
+ this.onTriggerClick();\r
+ } else {\r
+ this.inKeyMode = true;\r
+ this.selectNext();\r
+ }\r
+ },\r
+\r
+ enter: function(){}\r
+ });\r
+ },\r
+\r
+ onClick: function() {\r
+ this.clearCurrentFocus();\r
+ this.collapse();\r
+ this.autoSize();\r
+ },\r
+\r
+ beforeBlur: Ext.form.ComboBox.superclass.beforeBlur,\r
+\r
+ onFocus: function() {\r
+ this.outerWrapEl.addClass(this.focusClass);\r
+\r
+ Ext.ux.form.SuperBoxSelect.superclass.onFocus.call(this);\r
+ },\r
+\r
+ onBlur: function() {\r
+ this.outerWrapEl.removeClass(this.focusClass);\r
+\r
+ this.clearCurrentFocus();\r
+\r
+ if (this.el.dom.value !== '') {\r
+ this.applyEmptyText();\r
+ this.autoSize();\r
+ }\r
+\r
+ Ext.ux.form.SuperBoxSelect.superclass.onBlur.call(this);\r
+ },\r
+\r
+ onCollapse: function() {\r
+ this.view.clearSelections();\r
+ this.multiSelectMode = false;\r
+ },\r
+\r
+ onWrapClick: function(e) {\r
+ e.stopEvent();\r
+ this.collapse();\r
+ this.el.focus();\r
+ this.clearCurrentFocus();\r
+ },\r
+ markInvalid : function(msg) {\r
+ var elp, t;\r
+\r
+ if (!this.rendered || this.preventMark ) {\r
+ return;\r
+ }\r
+ this.outerWrapEl.addClass(this.invalidClass);\r
+ msg = msg || this.invalidText;\r
+\r
+ switch (this.msgTarget) {\r
+ case 'qtip':\r
+ Ext.apply(this.el.dom, {\r
+ qtip : msg,\r
+ qclass : 'x-form-invalid-tip'\r
+ });\r
+ Ext.apply(this.wrapEl.dom, {\r
+ qtip : msg,\r
+ qclass : 'x-form-invalid-tip'\r
+ });\r
+ if (Ext.QuickTips) { // fix for floating editors interacting with DND\r
+ Ext.QuickTips.enable();\r
+ }\r
+ break;\r
+ case 'title':\r
+ this.el.dom.title = msg;\r
+ this.wrapEl.dom.title = msg;\r
+ this.outerWrapEl.dom.title = msg;\r
+ break;\r
+ case 'under':\r
+ if (!this.errorEl) {\r
+ elp = this.getErrorCt();\r
+ if (!elp) { // field has no container el\r
+ this.el.dom.title = msg;\r
+ break;\r
+ }\r
+ this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});\r
+ this.errorEl.setWidth(elp.getWidth(true) - 20);\r
+ }\r
+ this.errorEl.update(msg);\r
+ Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this);\r
+ break;\r
+ case 'side':\r
+ if (!this.errorIcon) {\r
+ elp = this.getErrorCt();\r
+ if (!elp) { // field has no container el\r
+ this.el.dom.title = msg;\r
+ break;\r
+ }\r
+ this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});\r
+ }\r
+ this.alignErrorIcon();\r
+ Ext.apply(this.errorIcon.dom, {\r
+ qtip : msg,\r
+ qclass : 'x-form-invalid-tip'\r
+ });\r
+ this.errorIcon.show();\r
+ this.on('resize', this.alignErrorIcon, this);\r
+ break;\r
+ default:\r
+ t = Ext.getDom(this.msgTarget);\r
+ t.innerHTML = msg;\r
+ t.style.display = this.msgDisplay;\r
+ break;\r
+ }\r
+ this.fireEvent('invalid', this, msg);\r
+ },\r
+ clearInvalid : function(){\r
+ if(!this.rendered || this.preventMark){ // not rendered\r
+ return;\r
+ }\r
+ this.outerWrapEl.removeClass(this.invalidClass);\r
+ switch(this.msgTarget){\r
+ case 'qtip':\r
+ this.el.dom.qtip = '';\r
+ this.wrapEl.dom.qtip ='';\r
+ break;\r
+ case 'title':\r
+ this.el.dom.title = '';\r
+ this.wrapEl.dom.title = '';\r
+ this.outerWrapEl.dom.title = '';\r
+ break;\r
+ case 'under':\r
+ if(this.errorEl){\r
+ Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);\r
+ }\r
+ break;\r
+ case 'side':\r
+ if(this.errorIcon){\r
+ this.errorIcon.dom.qtip = '';\r
+ this.errorIcon.hide();\r
+ this.un('resize', this.alignErrorIcon, this);\r
+ }\r
+ break;\r
+ default:\r
+ var t = Ext.getDom(this.msgTarget);\r
+ t.innerHTML = '';\r
+ t.style.display = 'none';\r
+ break;\r
+ }\r
+ this.fireEvent('valid', this);\r
+ },\r
+ alignErrorIcon : function(){\r
+ if(this.wrap){\r
+ this.errorIcon.alignTo(this.wrap, 'tl-tr', [Ext.isIE ? 5 : 2, 3]);\r
+ }\r
+ },\r
+ expand : function(){\r
+ if (this.isExpanded() || !this.hasFocus) {\r
+ return;\r
+ }\r
+ this.list.alignTo(this.outerWrapEl, this.listAlign).show();\r
+ this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac\r
+ Ext.getDoc().on({\r
+ mousewheel: this.collapseIf,\r
+ mousedown: this.collapseIf,\r
+ scope: this\r
+ });\r
+ this.fireEvent('expand', this);\r
+ },\r
+ restrictHeight : function(){\r
+ var inner = this.innerList.dom,\r
+ st = inner.scrollTop, \r
+ list = this.list;\r
+ \r
+ inner.style.height = '';\r
+ \r
+ var pad = list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight,\r
+ h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),\r
+ ha = this.getPosition()[1]-Ext.getBody().getScroll().top,\r
+ hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,\r
+ space = Math.max(ha, hb, this.minHeight || 0)-list.shadowOffset-pad-5;\r
+ \r
+ h = Math.min(h, space, this.maxHeight);\r
+ this.innerList.setHeight(h);\r
+\r
+ list.beginUpdate();\r
+ list.setHeight(h+pad);\r
+ list.alignTo(this.outerWrapEl, this.listAlign);\r
+ list.endUpdate();\r
+ \r
+ if(this.multiSelectMode){\r
+ inner.scrollTop = st;\r
+ }\r
+ },\r
+ \r
+ validateValue: function(val){\r
+ if(this.items.getCount() === 0){\r
+ if(this.allowBlank){\r
+ this.clearInvalid();\r
+ return true;\r
+ }else{\r
+ this.markInvalid(this.blankText);\r
+ return false;\r
+ }\r
+ }\r
+ \r
+ this.clearInvalid();\r
+ return true;\r
+ },\r
+\r
+ manageNameAttribute : function(){\r
+ if(this.items.getCount() === 0 && this.forceFormValue){\r
+ this.el.dom.setAttribute('name', this.hiddenName || this.name);\r
+ }else{\r
+ this.el.dom.removeAttribute('name');\r
+ }\r
+ },\r
+ setupFormInterception : function(){\r
+ var form;\r
+ this.findParentBy(function(p){ \r
+ if(p.getForm){\r
+ form = p.getForm();\r
+ }\r
+ });\r
+ if(form){\r
+ \r
+ var formGet = form.getValues;\r
+ form.getValues = function(asString){\r
+ this.el.dom.disabled = true;\r
+ var oldVal = this.el.dom.value;\r
+ this.setRawValue('');\r
+ var vals = formGet.call(form);\r
+ this.el.dom.disabled = false;\r
+ this.setRawValue(oldVal);\r
+ if(this.forceFormValue && this.items.getCount() === 0){\r
+ vals[this.name] = '';\r
+ }\r
+ return asString ? Ext.urlEncode(vals) : vals ;\r
+ }.createDelegate(this);\r
+ }\r
+ },\r
+ onResize : function(w, h, rw, rh) {\r
+ var reduce = Ext.isIE6 ? 4 : Ext.isIE7 ? 1 : Ext.isIE8 ? 1 : 0;\r
+ if(this.wrapEl){\r
+ this._width = w;\r
+ this.outerWrapEl.setWidth(w - reduce);\r
+ if (this.renderFieldBtns) {\r
+ reduce += (this.buttonWrap.getWidth() + 20);\r
+ this.wrapEl.setWidth(w - reduce);\r
+ }\r
+ }\r
+ Ext.ux.form.SuperBoxSelect.superclass.onResize.call(this, w, h, rw, rh);\r
+ this.autoSize();\r
+ },\r
+ onEnable: function(){\r
+ Ext.ux.form.SuperBoxSelect.superclass.onEnable.call(this);\r
+ this.items.each(function(item){\r
+ item.enable();\r
+ });\r
+ if (this.renderFieldBtns) {\r
+ this.initButtonEvents();\r
+ }\r
+ },\r
+ onDisable: function(){\r
+ Ext.ux.form.SuperBoxSelect.superclass.onDisable.call(this);\r
+ this.items.each(function(item){\r
+ item.disable();\r
+ });\r
+ if(this.renderFieldBtns){\r
+ this.removeButtonEvents();\r
+ }\r
+ },\r
+ /**\r
+ * Clears all values from the component.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name clearValue\r
+ * @param {Boolean} supressRemoveEvent [Optional] When true, the 'removeitem' event will not fire for each item that is removed. \r
+ */\r
+ clearValue : function(supressRemoveEvent){\r
+ Ext.ux.form.SuperBoxSelect.superclass.clearValue.call(this);\r
+ this.preventMultipleRemoveEvents = supressRemoveEvent || this.supressClearValueRemoveEvents || false;\r
+ this.removeAllItems();\r
+ this.preventMultipleRemoveEvents = false;\r
+ this.fireEvent('clear',this);\r
+ return this;\r
+ },\r
+ onKeyUp : function(e) {\r
+ if (this.editable !== false && (!e.isSpecialKey() || e.getKey() === e.BACKSPACE) && e.getKey() !== this.itemDelimiterKey && (!e.hasModifier() || e.shiftKey)) {\r
+ this.lastKey = e.getKey();\r
+ this.dqTask.delay(this.queryDelay);\r
+ } \r
+ },\r
+ onKeyDownHandler : function(e,t) {\r
+ \r
+ var toDestroy,nextFocus,idx;\r
+ if ((e.getKey() === e.DELETE || e.getKey() === e.SPACE) && this.currentFocus){\r
+ e.stopEvent();\r
+ toDestroy = this.currentFocus;\r
+ this.on('expand',function(){this.collapse();},this,{single: true});\r
+ idx = this.items.indexOfKey(this.currentFocus.key);\r
+ \r
+ this.clearCurrentFocus();\r
+ \r
+ if(idx < (this.items.getCount() -1)){\r
+ nextFocus = this.items.itemAt(idx+1);\r
+ }\r
+ \r
+ toDestroy.preDestroy(true);\r
+ if(nextFocus){\r
+ (function(){\r
+ nextFocus.onLnkFocus();\r
+ this.currentFocus = nextFocus;\r
+ }).defer(200,this);\r
+ }\r
+ \r
+ return true;\r
+ }\r
+ \r
+ var val = this.el.dom.value, it, ctrl = e.ctrlKey;\r
+ if(e.getKey() === this.itemDelimiterKey){\r
+ e.stopEvent();\r
+ if (val !== "") {\r
+ if (ctrl || !this.isExpanded()) { //ctrl+enter for new items\r
+ this.view.clearSelections();\r
+ this.collapse();\r
+ this.setRawValue('');\r
+ this.fireEvent('newitem', this, val);\r
+ }\r
+ else {\r
+ this.onViewClick();\r
+ //removed from 3.0.1\r
+ if(this.unsetDelayCheck){\r
+ this.delayedCheck = true;\r
+ this.unsetDelayCheck.defer(10, this);\r
+ }\r
+ }\r
+ }else{\r
+ if(!this.isExpanded()){\r
+ return;\r
+ }\r
+ this.onViewClick();\r
+ //removed from 3.0.1\r
+ if(this.unsetDelayCheck){\r
+ this.delayedCheck = true;\r
+ this.unsetDelayCheck.defer(10, this);\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ if(val !== '') {\r
+ this.autoSize();\r
+ return;\r
+ }\r
+ \r
+ //select first item\r
+ if(e.getKey() === e.HOME){\r
+ e.stopEvent();\r
+ if(this.items.getCount() > 0){\r
+ this.collapse();\r
+ it = this.items.get(0);\r
+ it.el.focus();\r
+ \r
+ }\r
+ return true;\r
+ }\r
+ //backspace remove\r
+ if(e.getKey() === e.BACKSPACE){\r
+ e.stopEvent();\r
+ if(this.currentFocus) {\r
+ toDestroy = this.currentFocus;\r
+ this.on('expand',function(){\r
+ this.collapse();\r
+ },this,{single: true});\r
+ \r
+ idx = this.items.indexOfKey(toDestroy.key);\r
+ \r
+ this.clearCurrentFocus();\r
+ if(idx < (this.items.getCount() -1)){\r
+ nextFocus = this.items.itemAt(idx+1);\r
+ }\r
+ \r
+ toDestroy.preDestroy(true);\r
+ \r
+ if(nextFocus){\r
+ (function(){\r
+ nextFocus.onLnkFocus();\r
+ this.currentFocus = nextFocus;\r
+ }).defer(200,this);\r
+ }\r
+ \r
+ return;\r
+ }else{\r
+ it = this.items.get(this.items.getCount() -1);\r
+ if(it){\r
+ if(this.backspaceDeletesLastItem){\r
+ this.on('expand',function(){this.collapse();},this,{single: true});\r
+ it.preDestroy(true);\r
+ }else{\r
+ if(this.navigateItemsWithTab){\r
+ it.onElClick();\r
+ }else{\r
+ this.on('expand',function(){\r
+ this.collapse();\r
+ this.currentFocus = it;\r
+ this.currentFocus.onLnkFocus.defer(20,this.currentFocus);\r
+ },this,{single: true});\r
+ }\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ }\r
+ \r
+ if(!e.isNavKeyPress()){\r
+ this.multiSelectMode = false;\r
+ this.clearCurrentFocus();\r
+ return;\r
+ }\r
+ //arrow nav\r
+ if(e.getKey() === e.LEFT || (e.getKey() === e.UP && !this.isExpanded())){\r
+ e.stopEvent();\r
+ this.collapse();\r
+ //get last item\r
+ it = this.items.get(this.items.getCount()-1);\r
+ if(this.navigateItemsWithTab){ \r
+ //focus last el\r
+ if(it){\r
+ it.focus(); \r
+ }\r
+ }else{\r
+ //focus prev item\r
+ if(this.currentFocus){\r
+ idx = this.items.indexOfKey(this.currentFocus.key);\r
+ this.clearCurrentFocus();\r
+ \r
+ if(idx !== 0){\r
+ this.currentFocus = this.items.itemAt(idx-1);\r
+ this.currentFocus.onLnkFocus();\r
+ }\r
+ }else{\r
+ this.currentFocus = it;\r
+ if(it){\r
+ it.onLnkFocus();\r
+ }\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ if(e.getKey() === e.DOWN){\r
+ if(this.currentFocus){\r
+ this.collapse();\r
+ e.stopEvent();\r
+ idx = this.items.indexOfKey(this.currentFocus.key);\r
+ if(idx == (this.items.getCount() -1)){\r
+ this.clearCurrentFocus.defer(10,this);\r
+ }else{\r
+ this.clearCurrentFocus();\r
+ this.currentFocus = this.items.itemAt(idx+1);\r
+ if(this.currentFocus){\r
+ this.currentFocus.onLnkFocus();\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ }\r
+ if(e.getKey() === e.RIGHT){\r
+ this.collapse();\r
+ it = this.items.itemAt(0);\r
+ if(this.navigateItemsWithTab){ \r
+ //focus first el\r
+ if(it){\r
+ it.focus(); \r
+ }\r
+ }else{\r
+ if(this.currentFocus){\r
+ idx = this.items.indexOfKey(this.currentFocus.key);\r
+ this.clearCurrentFocus();\r
+ if(idx < (this.items.getCount() -1)){\r
+ this.currentFocus = this.items.itemAt(idx+1);\r
+ if(this.currentFocus){\r
+ this.currentFocus.onLnkFocus();\r
+ }\r
+ }\r
+ }else{\r
+ this.currentFocus = it;\r
+ if(it){\r
+ it.onLnkFocus();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ },\r
+ onKeyUpBuffered : function(e){\r
+ if(!e.isNavKeyPress()){\r
+ this.autoSize();\r
+ }\r
+ },\r
+ reset : function(){\r
+ this.killItems();\r
+ Ext.ux.form.SuperBoxSelect.superclass.reset.call(this);\r
+ this.addedRecords = [];\r
+ this.autoSize().setRawValue('');\r
+ },\r
+ applyEmptyText : function(){\r
+ this.setRawValue('');\r
+ if(this.items.getCount() > 0){\r
+ this.el.removeClass(this.emptyClass);\r
+ this.setRawValue('');\r
+ return this;\r
+ }\r
+ if(this.rendered && this.emptyText && this.getRawValue().length < 1){\r
+ this.setRawValue(this.emptyText);\r
+ this.el.addClass(this.emptyClass);\r
+ }\r
+ return this;\r
+ },\r
+ /**\r
+ * @private\r
+ * \r
+ * Use clearValue instead\r
+ */\r
+ removeAllItems: function(){\r
+ this.items.each(function(item){\r
+ item.preDestroy(true);\r
+ },this);\r
+ this.manageClearBtn();\r
+ return this;\r
+ },\r
+ killItems : function(){\r
+ this.items.each(function(item){\r
+ item.kill();\r
+ },this);\r
+ this.resetStore();\r
+ this.items.clear();\r
+ this.manageClearBtn();\r
+ return this;\r
+ },\r
+ resetStore: function(){\r
+ this.store.clearFilter();\r
+ if(!this.removeValuesFromStore){\r
+ return this;\r
+ }\r
+ this.usedRecords.each(function(rec){\r
+ this.store.add(rec);\r
+ },this);\r
+ this.usedRecords.clear();\r
+ this.sortStore();\r
+ return this;\r
+ },\r
+ sortStore: function(){\r
+ var ss = this.store.getSortState();\r
+ if(ss && ss.field){\r
+ this.store.sort(ss.field, ss.direction);\r
+ }\r
+ return this;\r
+ },\r
+ getCaption: function(dataObject){\r
+ if(typeof this.displayFieldTpl === 'string') {\r
+ this.displayFieldTpl = new Ext.XTemplate(this.displayFieldTpl);\r
+ }\r
+ var caption, recordData = dataObject instanceof Ext.data.Record ? dataObject.data : dataObject;\r
+ \r
+ if(this.displayFieldTpl) {\r
+ caption = this.displayFieldTpl.apply(recordData);\r
+ } else if(this.displayField) {\r
+ caption = recordData[this.displayField];\r
+ }\r
+ \r
+ return caption;\r
+ },\r
+ addRecord : function(record) {\r
+ var display = record.data[this.displayField],\r
+ caption = this.getCaption(record),\r
+ val = record.data[this.valueField],\r
+ cls = this.classField ? record.data[this.classField] : '',\r
+ style = this.styleField ? record.data[this.styleField] : '';\r
+\r
+ if (this.removeValuesFromStore) {\r
+ this.usedRecords.add(val, record);\r
+ this.store.remove(record);\r
+ }\r
+ \r
+ this.addItemBox(val, display, caption, cls, style);\r
+ this.fireEvent('additem', this, val, record);\r
+ },\r
+ createRecord : function(recordData){\r
+ if(!this.recordConstructor){\r
+ var recordFields = [\r
+ {name: this.valueField},\r
+ {name: this.displayField}\r
+ ];\r
+ if(this.classField){\r
+ recordFields.push({name: this.classField});\r
+ }\r
+ if(this.styleField){\r
+ recordFields.push({name: this.styleField});\r
+ }\r
+ this.recordConstructor = Ext.data.Record.create(recordFields);\r
+ }\r
+ return new this.recordConstructor(recordData);\r
+ },\r
+ /**\r
+ * Adds an array of items to the SuperBoxSelect component if the {@link #Ext.ux.form.SuperBoxSelect-allowAddNewData} config is set to true.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name addItem\r
+ * @param {Array} newItemObjects An Array of object literals containing the property names and values for an item. The property names must match those specified in {@link #Ext.ux.form.SuperBoxSelect-displayField}, {@link #Ext.ux.form.SuperBoxSelect-valueField} and {@link #Ext.ux.form.SuperBoxSelect-classField} \r
+ */\r
+ addItems : function(newItemObjects){\r
+ if (Ext.isArray(newItemObjects)) {\r
+ Ext.each(newItemObjects, function(item) {\r
+ this.addItem(item);\r
+ }, this);\r
+ } else {\r
+ this.addItem(newItemObjects);\r
+ }\r
+ },\r
+ /**\r
+ * Adds a new non-existing item to the SuperBoxSelect component if the {@link #Ext.ux.form.SuperBoxSelect-allowAddNewData} config is set to true.\r
+ * This method should be used in place of addItem from within the newitem event handler.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name addNewItem\r
+ * @param {Object} newItemObject An object literal containing the property names and values for an item. The property names must match those specified in {@link #Ext.ux.form.SuperBoxSelect-displayField}, {@link #Ext.ux.form.SuperBoxSelect-valueField} and {@link #Ext.ux.form.SuperBoxSelect-classField} \r
+ */\r
+ addNewItem : function(newItemObject){\r
+ this.addItem(newItemObject,true);\r
+ },\r
+ /**\r
+ * Adds an item to the SuperBoxSelect component if the {@link #Ext.ux.form.SuperBoxSelect-allowAddNewData} config is set to true.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name addItem\r
+ * @param {Object} newItemObject An object literal containing the property names and values for an item. The property names must match those specified in {@link #Ext.ux.form.SuperBoxSelect-displayField}, {@link #Ext.ux.form.SuperBoxSelect-valueField} and {@link #Ext.ux.form.SuperBoxSelect-classField} \r
+ */\r
+ addItem : function(newItemObject, /*hidden param*/ forcedAdd){\r
+ \r
+ var val = newItemObject[this.valueField];\r
+\r
+ if(this.disabled) {\r
+ return false;\r
+ }\r
+ if(this.preventDuplicates && this.hasValue(val)){\r
+ return;\r
+ }\r
+ \r
+ //use existing record if found\r
+ var record = this.findRecord(this.valueField, val);\r
+ if (record) {\r
+ this.addRecord(record);\r
+ return;\r
+ } else if (!this.allowAddNewData) { // else it's a new item\r
+ return;\r
+ }\r
+ \r
+ if(this.mode === 'remote'){\r
+ this.remoteLookup.push(newItemObject); \r
+ this.doQuery(val,false,false,forcedAdd);\r
+ return;\r
+ }\r
+ \r
+ var rec = this.createRecord(newItemObject);\r
+ this.store.add(rec);\r
+ this.addRecord(rec);\r
+ \r
+ return true;\r
+ },\r
+ addItemBox : function(itemVal,itemDisplay,itemCaption, itemClass, itemStyle) {\r
+ var hConfig, parseStyle = function(s){\r
+ var ret = '';\r
+ if(typeof s == 'function'){\r
+ ret = s.call();\r
+ }else if(typeof s == 'object'){\r
+ for(var p in s){\r
+ ret+= p +':'+s[p]+';';\r
+ }\r
+ }else if(typeof s == 'string'){\r
+ ret = s + ';';\r
+ }\r
+ return ret;\r
+ }, itemKey = Ext.id(null,'sbx-item'), box = new Ext.ux.form.SuperBoxSelectItem({\r
+ owner: this,\r
+ disabled: this.disabled,\r
+ renderTo: this.wrapEl,\r
+ cls: this.extraItemCls + ' ' + itemClass,\r
+ style: parseStyle(this.extraItemStyle) + ' ' + itemStyle,\r
+ caption: itemCaption,\r
+ display: itemDisplay,\r
+ value: itemVal,\r
+ key: itemKey,\r
+ listeners: {\r
+ 'remove': function(item){\r
+ if(this.fireEvent('beforeremoveitem',this,item.value) === false){\r
+ return;\r
+ }\r
+ this.items.removeKey(item.key);\r
+ if(this.removeValuesFromStore){\r
+ if(this.usedRecords.containsKey(item.value)){\r
+ this.store.add(this.usedRecords.get(item.value));\r
+ this.usedRecords.removeKey(item.value);\r
+ this.sortStore();\r
+ if(this.view){\r
+ this.view.render();\r
+ }\r
+ }\r
+ }\r
+ if(!this.preventMultipleRemoveEvents){\r
+ this.fireEvent.defer(250,this,['removeitem',this,item.value, this.findInStore(item.value)]);\r
+ }\r
+ },\r
+ destroy: function(){\r
+ this.collapse();\r
+ this.autoSize().manageClearBtn().validateValue();\r
+ },\r
+ scope: this\r
+ }\r
+ });\r
+ box.render();\r
+ \r
+ hConfig = {\r
+ tag :'input', \r
+ type :'hidden', \r
+ value : itemVal,\r
+ name : (this.hiddenName || this.name)\r
+ };\r
+ \r
+ if(this.disabled){\r
+ Ext.apply(hConfig,{\r
+ disabled : 'disabled'\r
+ })\r
+ }\r
+ box.hidden = this.el.insertSibling(hConfig,'before');\r
+\r
+ this.items.add(itemKey,box);\r
+ this.applyEmptyText().autoSize().manageClearBtn().validateValue();\r
+ },\r
+ manageClearBtn : function() {\r
+ if (!this.renderFieldBtns || !this.rendered) {\r
+ return this;\r
+ }\r
+ var cls = 'x-superboxselect-btn-hide';\r
+ if (this.items.getCount() === 0) {\r
+ this.buttonClear.addClass(cls);\r
+ } else {\r
+ this.buttonClear.removeClass(cls);\r
+ }\r
+ return this;\r
+ },\r
+ findInStore : function(val){\r
+ var index = this.store.find(this.valueField, val);\r
+ if(index > -1){\r
+ return this.store.getAt(index);\r
+ }\r
+ return false;\r
+ },\r
+ /**\r
+ * Returns a String value containing a concatenated list of item values. The list is concatenated with the {@link #Ext.ux.form.SuperBoxSelect-valueDelimiter}.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name getValue\r
+ * @return {String} a String value containing a concatenated list of item values. \r
+ */\r
+ getValue : function() {\r
+ var ret = [];\r
+ this.items.each(function(item){\r
+ ret.push(item.value);\r
+ });\r
+ return ret.join(this.valueDelimiter);\r
+ },\r
+ /**\r
+ * Returns an Array of item objects containing the {@link #Ext.ux.form.SuperBoxSelect-displayField}, {@link #Ext.ux.form.SuperBoxSelect-valueField}, {@link #Ext.ux.form.SuperBoxSelect-classField} and {@link #Ext.ux.form.SuperBoxSelect-styleField} properties.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name getValueEx\r
+ * @return {Array} an array of item objects. \r
+ */\r
+ getValueEx : function() {\r
+ var ret = [];\r
+ this.items.each(function(item){\r
+ var newItem = {};\r
+ newItem[this.valueField] = item.value;\r
+ newItem[this.displayField] = item.display;\r
+ if(this.classField){\r
+ newItem[this.classField] = item.cls || '';\r
+ }\r
+ if(this.styleField){\r
+ newItem[this.styleField] = item.style || '';\r
+ }\r
+ ret.push(newItem);\r
+ },this);\r
+ return ret;\r
+ },\r
+ // private\r
+ initValue : function(){\r
+ \r
+ Ext.ux.form.SuperBoxSelect.superclass.initValue.call(this);\r
+ if(this.mode === 'remote') {\r
+ this.setOriginal = true;\r
+ }\r
+ },\r
+ /**\r
+ * Sets the value of the SuperBoxSelect component.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name setValue\r
+ * @param {String|Array} value An array of item values, or a String value containing a delimited list of item values. (The list should be delimited with the {@link #Ext.ux.form.SuperBoxSelect-valueDelimiter) \r
+ */\r
+ setValue : function(value){\r
+ if(!this.rendered){\r
+ this.value = value;\r
+ return;\r
+ }\r
+ \r
+ this.removeAllItems().resetStore();\r
+ this.remoteLookup = [];\r
+ \r
+ if(Ext.isEmpty(value)){\r
+ return;\r
+ }\r
+ \r
+ var values = value;\r
+ if(!Ext.isArray(value)){\r
+ value = '' + value;\r
+ values = value.split(this.valueDelimiter); \r
+ }\r
+ \r
+ Ext.each(values,function(val){\r
+ var record = this.findRecord(this.valueField, val);\r
+ if(record){\r
+ this.addRecord(record);\r
+ }else if(this.mode === 'remote'){\r
+ this.remoteLookup.push(val); \r
+ }\r
+ },this);\r
+ \r
+ if(this.mode === 'remote'){\r
+ var q = this.remoteLookup.join(this.queryValuesDelimiter); \r
+ this.doQuery(q,false, true); //3rd param to specify a values query\r
+ }\r
+ \r
+ },\r
+ /**\r
+ * Sets the value of the SuperBoxSelect component, adding new items that don't exist in the data store if the {@link #Ext.ux.form.SuperBoxSelect-allowAddNewData} config is set to true.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name setValue\r
+ * @param {Array} data An Array of item objects containing the {@link #Ext.ux.form.SuperBoxSelect-displayField}, {@link #Ext.ux.form.SuperBoxSelect-valueField} and {@link #Ext.ux.form.SuperBoxSelect-classField} properties. \r
+ */\r
+ setValueEx : function(data){\r
+ this.removeAllItems().resetStore();\r
+ \r
+ if(!Ext.isArray(data)){\r
+ data = [data];\r
+ }\r
+ this.remoteLookup = [];\r
+ \r
+ if(this.allowAddNewData && this.mode === 'remote'){ // no need to query\r
+ Ext.each(data, function(d){\r
+ var r = this.findRecord(this.valueField, d[this.valueField]) || this.createRecord(d);\r
+ this.addRecord(r);\r
+ },this);\r
+ return;\r
+ }\r
+ \r
+ Ext.each(data,function(item){\r
+ this.addItem(item);\r
+ },this);\r
+ },\r
+ /**\r
+ * Returns true if the SuperBoxSelect component has a selected item with a value matching the 'val' parameter.\r
+ * @methodOf Ext.ux.form.SuperBoxSelect\r
+ * @name hasValue\r
+ * @param {Mixed} val The value to test.\r
+ * @return {Boolean} true if the component has the selected value, false otherwise.\r
+ */\r
+ hasValue: function(val){\r
+ var has = false;\r
+ this.items.each(function(item){\r
+ if(item.value == val){\r
+ has = true;\r
+ return false;\r
+ }\r
+ },this);\r
+ return has;\r
+ },\r
+ onSelect : function(record, index) {\r
+ if (this.fireEvent('beforeselect', this, record, index) !== false){\r
+ var val = record.data[this.valueField];\r
+ \r
+ if(this.preventDuplicates && this.hasValue(val)){\r
+ return;\r
+ }\r
+ \r
+ this.setRawValue('');\r
+ this.lastSelectionText = '';\r
+ \r
+ if(this.fireEvent('beforeadditem',this,val) !== false){\r
+ this.addRecord(record);\r
+ }\r
+ if(this.store.getCount() === 0 || !this.multiSelectMode){\r
+ this.collapse();\r
+ }else{\r
+ this.restrictHeight();\r
+ }\r
+ }\r
+ },\r
+ onDestroy : function() {\r
+ this.items.purgeListeners();\r
+ this.killItems();\r
+ if (this.renderFieldBtns) {\r
+ Ext.destroy(\r
+ this.buttonClear,\r
+ this.buttonExpand,\r
+ this.buttonWrap\r
+ );\r
+ }\r
+\r
+ Ext.destroy(\r
+ this.inputEl,\r
+ this.wrapEl,\r
+ this.outerWrapEl\r
+ );\r
+\r
+ Ext.ux.form.SuperBoxSelect.superclass.onDestroy.call(this);\r
+ },\r
+ autoSize : function(){\r
+ if(!this.rendered){\r
+ return this;\r
+ }\r
+ if(!this.metrics){\r
+ this.metrics = Ext.util.TextMetrics.createInstance(this.el);\r
+ }\r
+ var el = this.el,\r
+ v = el.dom.value,\r
+ d = document.createElement('div');\r
+\r
+ if(v === "" && this.emptyText && this.items.getCount() < 1){\r
+ v = this.emptyText;\r
+ }\r
+ d.appendChild(document.createTextNode(v));\r
+ v = d.innerHTML;\r
+ d = null;\r
+ v += " ";\r
+ var w = Math.max(this.metrics.getWidth(v) + 24, 24);\r
+ if(typeof this._width != 'undefined'){\r
+ w = Math.min(this._width, w);\r
+ }\r
+ this.el.setWidth(w);\r
+ \r
+ if(Ext.isIE){\r
+ this.el.dom.style.top='0';\r
+ }\r
+ return this;\r
+ },\r
+ doQuery : function(q, forceAll,valuesQuery, forcedAdd){\r
+ q = Ext.isEmpty(q) ? '' : q;\r
+ var qe = {\r
+ query: q,\r
+ forceAll: forceAll,\r
+ combo: this,\r
+ cancel:false\r
+ };\r
+ if(this.fireEvent('beforequery', qe)===false || qe.cancel){\r
+ return false;\r
+ }\r
+ q = qe.query;\r
+ forceAll = qe.forceAll;\r
+ if(forceAll === true || (q.length >= this.minChars) || valuesQuery && !Ext.isEmpty(q)){\r
+ if(this.lastQuery !== q || forcedAdd){\r
+ this.lastQuery = q;\r
+ if(this.mode == 'local'){\r
+ this.selectedIndex = -1;\r
+ if(forceAll){\r
+ this.store.clearFilter();\r
+ }else{\r
+ this.store.filter(this.displayField, q);\r
+ }\r
+ this.onLoad();\r
+ }else{\r
+ \r
+ this.store.baseParams[this.queryParam] = q;\r
+ this.store.baseParams[this.queryValuesIndicator] = valuesQuery;\r
+ this.store.load({\r
+ params: this.getParams(q)\r
+ });\r
+ if(!forcedAdd){\r
+ this.expand();\r
+ }\r
+ }\r
+ }else{\r
+ this.selectedIndex = -1;\r
+ this.onLoad();\r
+ }\r
+ }\r
+ }\r
+});\r
+Ext.reg('superboxselect', Ext.ux.form.SuperBoxSelect);\r
+/*\r
+ * @private\r
+ */\r
+Ext.ux.form.SuperBoxSelectItem = function(config){\r
+ Ext.apply(this,config);\r
+ Ext.ux.form.SuperBoxSelectItem.superclass.constructor.call(this); \r
+};\r
+/*\r
+ * @private\r
+ */\r
+Ext.ux.form.SuperBoxSelectItem = Ext.extend(Ext.ux.form.SuperBoxSelectItem,Ext.Component, {\r
+ initComponent : function(){\r
+ Ext.ux.form.SuperBoxSelectItem.superclass.initComponent.call(this); \r
+ },\r
+ onElClick : function(e){\r
+ var o = this.owner;\r
+ o.clearCurrentFocus().collapse();\r
+ if(o.navigateItemsWithTab){\r
+ this.focus();\r
+ }else{\r
+ o.el.dom.focus();\r
+ var that = this;\r
+ (function(){\r
+ this.onLnkFocus();\r
+ o.currentFocus = this;\r
+ }).defer(10,this);\r
+ }\r
+ },\r
+ \r
+ onLnkClick : function(e){\r
+ if(e) {\r
+ e.stopEvent();\r
+ }\r
+ this.preDestroy();\r
+ if(!this.owner.navigateItemsWithTab){\r
+ this.owner.el.focus();\r
+ }\r
+ },\r
+ onLnkFocus : function(){\r
+ this.el.addClass("x-superboxselect-item-focus");\r
+ this.owner.outerWrapEl.addClass("x-form-focus");\r
+ },\r
+ \r
+ onLnkBlur : function(){\r
+ this.el.removeClass("x-superboxselect-item-focus");\r
+ this.owner.outerWrapEl.removeClass("x-form-focus");\r
+ },\r
+ \r
+ enableElListeners : function() {\r
+ this.el.on('click', this.onElClick, this, {stopEvent:true});\r
+ \r
+ this.el.addClassOnOver('x-superboxselect-item x-superboxselect-item-hover');\r
+ },\r
+\r
+ enableLnkListeners : function() {\r
+ this.lnk.on({\r
+ click: this.onLnkClick,\r
+ focus: this.onLnkFocus,\r
+ blur: this.onLnkBlur,\r
+ scope: this\r
+ });\r
+ },\r
+ \r
+ enableAllListeners : function() {\r
+ this.enableElListeners();\r
+ this.enableLnkListeners();\r
+ },\r
+ disableAllListeners : function() {\r
+ this.el.removeAllListeners();\r
+ this.lnk.un('click', this.onLnkClick, this);\r
+ this.lnk.un('focus', this.onLnkFocus, this);\r
+ this.lnk.un('blur', this.onLnkBlur, this);\r
+ },\r
+ onRender : function(ct, position){\r
+ \r
+ Ext.ux.form.SuperBoxSelectItem.superclass.onRender.call(this, ct, position);\r
+ \r
+ var el = this.el;\r
+ if(el){\r
+ el.remove();\r
+ }\r
+ \r
+ this.el = el = ct.createChild({ tag: 'li' }, ct.last());\r
+ el.addClass('x-superboxselect-item');\r
+ \r
+ var btnEl = this.owner.navigateItemsWithTab ? ( Ext.isSafari ? 'button' : 'a') : 'span';\r
+ var itemKey = this.key;\r
+ \r
+ Ext.apply(el, {\r
+ focus: function(){\r
+ var c = this.down(btnEl +'.x-superboxselect-item-close');\r
+ if(c){\r
+ c.focus();\r
+ }\r
+ },\r
+ preDestroy: function(){\r
+ this.preDestroy();\r
+ }.createDelegate(this)\r
+ });\r
+ \r
+ this.enableElListeners();\r
+\r
+ el.update(this.caption);\r
+\r
+ var cfg = {\r
+ tag: btnEl,\r
+ 'class': 'x-superboxselect-item-close',\r
+ tabIndex : this.owner.navigateItemsWithTab ? '0' : '-1'\r
+ };\r
+ if(btnEl === 'a'){\r
+ cfg.href = '#';\r
+ }\r
+ this.lnk = el.createChild(cfg);\r
+ \r
+ \r
+ if(!this.disabled) {\r
+ this.enableLnkListeners();\r
+ }else {\r
+ this.disableAllListeners();\r
+ }\r
+ \r
+ this.on({\r
+ disable: this.disableAllListeners,\r
+ enable: this.enableAllListeners,\r
+ scope: this\r
+ });\r
+\r
+ this.setupKeyMap();\r
+ },\r
+ setupKeyMap : function(){\r
+ this.keyMap = new Ext.KeyMap(this.lnk, [\r
+ {\r
+ key: [\r
+ Ext.EventObject.BACKSPACE, \r
+ Ext.EventObject.DELETE, \r
+ Ext.EventObject.SPACE\r
+ ],\r
+ fn: this.preDestroy,\r
+ scope: this\r
+ }, {\r
+ key: [\r
+ Ext.EventObject.RIGHT,\r
+ Ext.EventObject.DOWN\r
+ ],\r
+ fn: function(){\r
+ this.moveFocus('right');\r
+ },\r
+ scope: this\r
+ },\r
+ {\r
+ key: [Ext.EventObject.LEFT,Ext.EventObject.UP],\r
+ fn: function(){\r
+ this.moveFocus('left');\r
+ },\r
+ scope: this\r
+ },\r
+ {\r
+ key: [Ext.EventObject.HOME],\r
+ fn: function(){\r
+ var l = this.owner.items.get(0).el.focus();\r
+ if(l){\r
+ l.el.focus();\r
+ }\r
+ },\r
+ scope: this\r
+ },\r
+ {\r
+ key: [Ext.EventObject.END],\r
+ fn: function(){\r
+ this.owner.el.focus();\r
+ },\r
+ scope: this\r
+ },\r
+ {\r
+ key: Ext.EventObject.ENTER,\r
+ fn: function(){\r
+ }\r
+ }\r
+ ]);\r
+ this.keyMap.stopEvent = true;\r
+ },\r
+ moveFocus : function(dir) {\r
+ var el = this.el[dir == 'left' ? 'prev' : 'next']() || this.owner.el;\r
+ \r
+ el.focus.defer(100,el);\r
+ },\r
+\r
+ preDestroy : function(supressEffect) {\r
+ if(this.fireEvent('remove', this) === false){\r
+ return;\r
+ } \r
+ var actionDestroy = function(){\r
+ if(this.owner.navigateItemsWithTab){\r
+ this.moveFocus('right');\r
+ }\r
+ this.hidden.remove();\r
+ this.hidden = null;\r
+ this.destroy();\r
+ };\r
+ \r
+ if(supressEffect){\r
+ actionDestroy.call(this);\r
+ } else {\r
+ this.el.hide({\r
+ duration: 0.2,\r
+ callback: actionDestroy,\r
+ scope: this\r
+ });\r
+ }\r
+ return this;\r
+ },\r
+ kill : function(){\r
+ this.hidden.remove();\r
+ this.hidden = null;\r
+ this.purgeListeners();\r
+ this.destroy();\r
+ },\r
+ onDisable : function() {\r
+ if(this.hidden){\r
+ this.hidden.dom.setAttribute('disabled', 'disabled');\r
+ }\r
+ this.keyMap.disable();\r
+ Ext.ux.form.SuperBoxSelectItem.superclass.onDisable.call(this);\r
+ },\r
+ onEnable : function() {\r
+ if(this.hidden){\r
+ this.hidden.dom.removeAttribute('disabled');\r
+ }\r
+ this.keyMap.enable();\r
+ Ext.ux.form.SuperBoxSelectItem.superclass.onEnable.call(this);\r
+ },\r
+ onDestroy : function() {\r
+ Ext.destroy(\r
+ this.lnk,\r
+ this.el\r
+ );\r
+ \r
+ Ext.ux.form.SuperBoxSelectItem.superclass.onDestroy.call(this);\r
+ }\r
+});
\ No newline at end of file