﻿/* Advanced Forms */
Ext.form.TriggerField = function (config) { this.mimicing = false; Ext.form.TriggerField.superclass.constructor.call(this, config) }; Ext.extend(Ext.form.TriggerField, Ext.form.TextField, { defaultAutoCreate: { tag: "input", type: "text", size: "16", autocomplete: "off" }, hideTrigger: false, autoSize: Ext.emptyFn, monitorTab: true, deferHeight: true, onResize: function (w, h) { Ext.form.TriggerField.superclass.onResize.apply(this, arguments); if (typeof w == 'number') { this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth())) } }, adjustSize: Ext.BoxComponent.prototype.adjustSize, getResizeEl: function () { return this.wrap }, getPositionEl: function () { return this.wrap }, alignErrorIcon: function () { this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]) }, onRender: function (ct, position) { Ext.form.TriggerField.superclass.onRender.call(this, ct, position); this.wrap = this.el.wrap({ cls: "x-form-field-wrap" }); this.trigger = this.wrap.createChild(this.triggerConfig || { tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass }); if (this.hideTrigger) { this.trigger.setDisplayed(false) } this.initTrigger(); if (!this.width) { this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth()) } }, initTrigger: function () { this.trigger.on("click", this.onTriggerClick, this, { preventDefault: true }); this.trigger.addClassOnOver('x-form-trigger-over'); this.trigger.addClassOnClick('x-form-trigger-click') }, onDestroy: function () { if (this.trigger) { this.trigger.removeAllListeners(); this.trigger.remove() } if (this.wrap) { this.wrap.remove() } Ext.form.TriggerField.superclass.onDestroy.call(this) }, onFocus: function () { Ext.form.TriggerField.superclass.onFocus.call(this); if (!this.mimicing) { this.wrap.addClass('x-trigger-wrap-focus'); this.mimicing = true; Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this); if (this.monitorTab) { this.el.on("keydown", this.checkTab, this) } } }, checkTab: function (e) { if (e.getKey() == e.TAB) { this.triggerBlur() } }, onBlur: function () { }, mimicBlur: function (e, t) { if (!this.wrap.contains(t) && this.validateBlur()) { this.triggerBlur() } }, triggerBlur: function () { this.mimicing = false; Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur); if (this.monitorTab) { this.el.un("keydown", this.checkTab, this) } this.wrap.removeClass('x-trigger-wrap-focus'); Ext.form.TriggerField.superclass.onBlur.call(this) }, validateBlur: function (e, t) { return true }, onDisable: function () { Ext.form.TriggerField.superclass.onDisable.call(this); if (this.wrap) { this.wrap.addClass('x-item-disabled') } }, onEnable: function () { Ext.form.TriggerField.superclass.onEnable.call(this); if (this.wrap) { this.wrap.removeClass('x-item-disabled') } }, onShow: function () { if (this.wrap) { this.wrap.dom.style.display = ''; this.wrap.dom.style.visibility = 'visible' } }, onHide: function () { this.wrap.dom.style.display = 'none' }, onTriggerClick: Ext.emptyFn }); Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, { initComponent: function () { Ext.form.TwinTriggerField.superclass.initComponent.call(this); this.triggerConfig = { tag: 'span', cls: 'x-form-twin-triggers', cn: [{ tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class }, { tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}]} }, getTrigger: function (index) { return this.triggers[index] }, initTrigger: function () { var ts = this.trigger.select('.x-form-trigger', true); this.wrap.setStyle('overflow', 'hidden'); var triggerField = this; ts.each(function (t, all, index) { t.hide = function () { var w = triggerField.wrap.getWidth(); this.dom.style.display = 'none'; triggerField.el.setWidth(w - triggerField.trigger.getWidth()) }; t.show = function () { var w = triggerField.wrap.getWidth(); this.dom.style.display = ''; triggerField.el.setWidth(w - triggerField.trigger.getWidth()) }; var triggerIndex = 'Trigger' + (index + 1); if (this['hide' + triggerIndex]) { t.dom.style.display = 'none' } t.on("click", this['on' + triggerIndex + 'Click'], this, { preventDefault: true }); t.addClassOnOver('x-form-trigger-over'); t.addClassOnClick('x-form-trigger-click') }, this); this.triggers = ts.elements }, onTrigger1Click: Ext.emptyFn, onTrigger2Click: Ext.emptyFn });
Ext.form.ComboBox = function (B) { Ext.form.ComboBox.superclass.constructor.call(this, B); this.addEvents({ "expand": true, "collapse": true, "beforeselect": true, "select": true, "beforequery": true }); if (this.transform) { this.allowDomMove = false; var D = Ext.getDom(this.transform); if (!this.hiddenName) { this.hiddenName = D.name } if (!this.store) { this.mode = "local"; var H = [], E = D.options; for (var C = 0, A = E.length; C < A; C++) { var G = E[C]; var F = (Ext.isIE ? G.getAttributeNode("value").specified : G.hasAttribute("value")) ? G.value : G.text; if (G.selected) { this.value = F } H.push([F, G.text]) } this.store = new Ext.data.SimpleStore({ "id": 0, fields: ["value", "text"], data: H }); this.valueField = "value"; this.displayField = "text" } D.name = Ext.id(); if (!this.lazyRender) { this.target = true; this.el = Ext.DomHelper.insertBefore(D, this.autoCreate || this.defaultAutoCreate); D.parentNode.removeChild(D); this.render(this.el.parentNode) } else { D.parentNode.removeChild(D) } } this.selectedIndex = -1; if (this.mode == "local") { if (B.queryDelay === undefined) { this.queryDelay = 10 } if (B.minChars === undefined) { this.minChars = 0 } } }; Ext.extend(Ext.form.ComboBox, Ext.form.TriggerField, { defaultAutoCreate: { tag: "input", type: "text", size: "24", autocomplete: "off" }, listWidth: undefined, displayField: undefined, valueField: undefined, hiddenName: undefined, listClass: "", selectedClass: "x-combo-selected", triggerClass: "x-form-arrow-trigger", shadow: "sides", listAlign: "tl-bl?", maxHeight: 300, triggerAction: "query", minChars: 4, typeAhead: false, queryDelay: 500, pageSize: 0, selectOnFocus: false, queryParam: "query", loadingText: "Loading...", resizable: false, handleHeight: 8, editable: true, allQuery: "", mode: "remote", minListWidth: 70, forceSelection: false, typeAheadDelay: 250, valueNotFoundText: undefined, onRender: function (C, A) { Ext.form.ComboBox.superclass.onRender.call(this, C, A); if (this.hiddenName) { this.hiddenField = this.el.insertSibling({ tag: "input", type: "hidden", name: this.hiddenName, id: (this.hiddenId || this.hiddenName) }, "before", true); this.hiddenField.value = this.hiddenValue !== undefined ? this.hiddenValue : this.value !== undefined ? this.value : ""; this.el.dom.removeAttribute("name") } if (Ext.isGecko) { this.el.dom.setAttribute("autocomplete", "off") } var B = "x-combo-list"; this.list = new Ext.Layer({ shadow: this.shadow, cls: [B, this.listClass].join(" "), constrain: false }); var D = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth); this.list.setWidth(D); this.list.swallowEvent("mousewheel"); this.assetHeight = 0; if (this.title) { this.header = this.list.createChild({ cls: B + "-hd", html: this.title }); this.assetHeight += this.header.getHeight() } this.innerList = this.list.createChild({ cls: B + "-inner" }); this.innerList.on("mouseover", this.onViewOver, this); this.innerList.on("mousemove", this.onViewMove, this); this.innerList.setWidth(D - this.list.getFrameWidth("lr")); if (this.pageSize) { this.footer = this.list.createChild({ cls: B + "-ft" }); this.pageTb = new Ext.PagingToolbar(this.footer, this.store, { pageSize: this.pageSize }); this.assetHeight += this.footer.getHeight() } if (!this.tpl) { this.tpl = "<div class=\"" + B + "-item\">{" + this.displayField + "}</div>" } this.view = new Ext.View(this.innerList, this.tpl, { singleSelect: true, store: this.store, selectedClass: this.selectedClass }); this.view.on("click", this.onViewClick, this); this.store.on("beforeload", this.onBeforeLoad, this); this.store.on("load", this.onLoad, this); this.store.on("loadexception", this.collapse, this); if (this.resizable) { this.resizer = new Ext.Resizable(this.list, { pinned: true, handles: "se" }); this.resizer.on("resize", function (G, E, F) { this.maxHeight = F - this.handleHeight - this.list.getFrameWidth("tb") - this.assetHeight; this.listWidth = E; this.innerList.setWidth(E - this.list.getFrameWidth("lr")); this.restrictHeight() }, this); this[this.pageSize ? "footer" : "innerList"].setStyle("margin-bottom", this.handleHeight + "px") } if (!this.editable) { this.editable = true; this.setEditable(false) } }, initEvents: function () { Ext.form.ComboBox.superclass.initEvents.call(this); this.keyNav = new Ext.KeyNav(this.el, { "up": function (A) { this.inKeyMode = true; this.selectPrev() }, "down": function (A) { if (!this.isExpanded()) { this.onTriggerClick() } else { this.inKeyMode = true; this.selectNext() } }, "enter": function (A) { this.onViewClick() }, "esc": function (A) { this.collapse() }, "tab": function (A) { this.onViewClick(false); return true }, scope: this, doRelay: function (C, B, A) { if (A == "down" || this.scope.isExpanded()) { return Ext.KeyNav.prototype.doRelay.apply(this, arguments) } return true }, forceKeyDown: true }); this.queryDelay = Math.max(this.queryDelay || 10, this.mode == "local" ? 10 : 250); this.dqTask = new Ext.util.DelayedTask(this.initQuery, this); if (this.typeAhead) { this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this) } if (this.editable !== false) { this.el.on("keyup", this.onKeyUp, this) } if (this.forceSelection) { this.on("blur", this.doForce, this) } }, onDestroy: function () { if (this.view) { this.view.setStore(null); this.view.el.removeAllListeners(); this.view.el.remove(); this.view.purgeListeners() } if (this.list) { this.list.destroy() } if (this.store) { this.store.un("beforeload", this.onBeforeLoad, this); this.store.un("load", this.onLoad, this); this.store.un("loadexception", this.collapse, this) } Ext.form.ComboBox.superclass.onDestroy.call(this) }, fireKey: function (A) { if (A.isNavKeyPress() && !this.list.isVisible()) { this.fireEvent("specialkey", this, A) } }, onResize: function (A, B) { Ext.form.ComboBox.superclass.onResize.apply(this, arguments); if (this.list && this.listWidth === undefined) { var C = Math.max(A, this.minListWidth); this.list.setWidth(C); this.innerList.setWidth(C - this.list.getFrameWidth("lr")) } }, setEditable: function (A) { if (A == this.editable) { return } this.editable = A; if (!A) { this.el.dom.setAttribute("readOnly", true); this.el.on("mousedown", this.onTriggerClick, this); this.el.addClass("x-combo-noedit") } else { this.el.dom.setAttribute("readOnly", false); this.el.un("mousedown", this.onTriggerClick, this); this.el.removeClass("x-combo-noedit") } }, onBeforeLoad: function () { if (!this.hasFocus) { return } this.innerList.update(this.loadingText ? "<div class=\"loading-indicator\">" + this.loadingText + "</div>" : ""); this.restrictHeight(); this.selectedIndex = -1 }, onLoad: function () { if (!this.hasFocus) { return } if (this.store.getCount() > 0) { this.expand(); this.restrictHeight(); if (this.lastQuery == this.allQuery) { if (this.editable) { this.el.dom.select() } if (!this.selectByValue(this.value, true)) { this.select(0, true) } } else { this.selectNext(); if (this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE) { this.taTask.delay(this.typeAheadDelay) } } } else { this.onEmptyResults() } }, onTypeAhead: function () { if (this.store.getCount() > 0) { var B = this.store.getAt(0); var C = B.data[this.displayField]; var A = C.length; var D = this.getRawValue().length; if (D != A) { this.setRawValue(C); this.selectText(D, C.length) } } }, onSelect: function (A, B) { if (this.fireEvent("beforeselect", this, A, B) !== false) { this.setValue(A.data[this.valueField || this.displayField]); this.collapse(); this.fireEvent("select", this, A, B) } }, getValue: function () { if (this.valueField) { return typeof this.value != "undefined" ? this.value : "" } else { return Ext.form.ComboBox.superclass.getValue.call(this) } }, clearValue: function () { if (this.hiddenField) { this.hiddenField.value = "" } this.setRawValue(""); this.lastSelectionText = ""; this.applyEmptyText() }, setValue: function (A) { var C = A; if (this.valueField) { var B = this.findRecord(this.valueField, A); if (B) { C = B.data[this.displayField] } else { if (this.valueNotFoundText !== undefined) { C = this.valueNotFoundText } } } this.lastSelectionText = C; if (this.hiddenField) { this.hiddenField.value = A } Ext.form.ComboBox.superclass.setValue.call(this, C); this.value = A }, findRecord: function (C, B) { var A; if (this.store.getCount() > 0) { this.store.each(function (D) { if (D.data[C] == B) { A = D; return false } }) } return A }, onViewMove: function (B, A) { this.inKeyMode = false }, onViewOver: function (D, B) { if (this.inKeyMode) { return } var C = this.view.findItemFromChild(B); if (C) { var A = this.view.indexOf(C); this.select(A, false) } }, onViewClick: function (B) { var A = this.view.getSelectedIndexes()[0]; var C = this.store.getAt(A); if (C) { this.onSelect(C, A) } if (B !== false) { this.el.focus() } }, restrictHeight: function () { this.innerList.dom.style.height = ""; var A = this.innerList.dom; var B = Math.max(A.clientHeight, A.offsetHeight, A.scrollHeight); this.innerList.setHeight(B < this.maxHeight ? "auto" : this.maxHeight); this.list.beginUpdate(); this.list.setHeight(this.innerList.getHeight() + this.list.getFrameWidth("tb") + (this.resizable ? this.handleHeight : 0) + this.assetHeight); this.list.alignTo(this.el, this.listAlign); this.list.endUpdate() }, onEmptyResults: function () { this.collapse() }, isExpanded: function () { return this.list.isVisible() }, selectByValue: function (A, C) { if (A !== undefined && A !== null) { var B = this.findRecord(this.valueField || this.displayField, A); if (B) { this.select(this.store.indexOf(B), C); return true } } return false }, select: function (A, C) { this.selectedIndex = A; this.view.select(A); if (C !== false) { var B = this.view.getNode(A); if (B) { this.innerList.scrollChildIntoView(B, false) } } }, selectNext: function () { var A = this.store.getCount(); if (A > 0) { if (this.selectedIndex == -1) { this.select(0) } else { if (this.selectedIndex < A - 1) { this.select(this.selectedIndex + 1) } } } }, selectPrev: function () { var A = this.store.getCount(); if (A > 0) { if (this.selectedIndex == -1) { this.select(0) } else { if (this.selectedIndex != 0) { this.select(this.selectedIndex - 1) } } } }, onKeyUp: function (A) { if (this.editable !== false && !A.isSpecialKey()) { this.lastKey = A.getKey(); this.dqTask.delay(this.queryDelay) } }, validateBlur: function () { return !this.list || !this.list.isVisible() }, initQuery: function () { this.doQuery(this.getRawValue()) }, doForce: function () { if (this.el.dom.value.length > 0) { this.el.dom.value = this.lastSelectionText === undefined ? "" : this.lastSelectionText; this.applyEmptyText() } }, doQuery: function (C, B) { if (C === undefined || C === null) { C = "" } var A = { query: C, forceAll: B, combo: this, cancel: false }; if (this.fireEvent("beforequery", A) === false || A.cancel) { return false } C = A.query; B = A.forceAll; if (B === true || (C.length >= this.minChars)) { if (this.lastQuery != C) { this.lastQuery = C; if (this.mode == "local") { this.selectedIndex = -1; if (B) { this.store.clearFilter() } else { this.store.filter(this.displayField, C) } this.onLoad() } else { this.store.baseParams[this.queryParam] = C; this.store.load({ params: this.getParams(C) }); this.expand() } } else { this.selectedIndex = -1; this.onLoad() } } }, getParams: function (A) { var B = {}; if (this.pageSize) { B.start = 0; B.limit = this.pageSize } return B }, collapse: function () { if (!this.isExpanded()) { return } this.list.hide(); Ext.get(document).un("mousedown", this.collapseIf, this); Ext.get(document).un("mousewheel", this.collapseIf, this); this.fireEvent("collapse", this) }, collapseIf: function (A) { if (!A.within(this.wrap) && !A.within(this.list)) { this.collapse() } }, expand: function () { if (this.isExpanded() || !this.hasFocus) { return } this.list.alignTo(this.el, this.listAlign); this.list.show(); Ext.get(document).on("mousedown", this.collapseIf, this); Ext.get(document).on("mousewheel", this.collapseIf, this); this.fireEvent("expand", this) }, onTriggerClick: function () { if (this.disabled) { return } if (this.isExpanded()) { this.collapse(); this.el.focus() } else { this.hasFocus = true; if (this.triggerAction == "all") { this.doQuery(this.allQuery, true) } else { this.doQuery(this.getRawValue()) } this.el.focus() } } });

