rlm@46: /* rlm@46: * Ext JS Library 2.1 rlm@46: * Copyright(c) 2006-2008, Ext JS, LLC. rlm@46: * licensing@extjs.com rlm@46: * rlm@46: * http://extjs.com/license rlm@46: */ rlm@46: rlm@46: rlm@46: Ext.DomHelper = function(){ rlm@46: var tempTableEl = null; rlm@46: var emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i; rlm@46: var tableRe = /^table|tbody|tr|td$/i; rlm@46: rlm@46: var createHtml = function(o){ rlm@46: if(typeof o == 'string'){ rlm@46: return o; rlm@46: } rlm@46: var b = ""; rlm@46: if (Ext.isArray(o)) { rlm@46: for (var i = 0, l = o.length; i < l; i++) { rlm@46: b += createHtml(o[i]); rlm@46: } rlm@46: return b; rlm@46: } rlm@46: if(!o.tag){ rlm@46: o.tag = "div"; rlm@46: } rlm@46: b += "<" + o.tag; rlm@46: for(var attr in o){ rlm@46: if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue; rlm@46: if(attr == "style"){ rlm@46: var s = o["style"]; rlm@46: if(typeof s == "function"){ rlm@46: s = s.call(); rlm@46: } rlm@46: if(typeof s == "string"){ rlm@46: b += ' style="' + s + '"'; rlm@46: }else if(typeof s == "object"){ rlm@46: b += ' style="'; rlm@46: for(var key in s){ rlm@46: if(typeof s[key] != "function"){ rlm@46: b += key + ":" + s[key] + ";"; rlm@46: } rlm@46: } rlm@46: b += '"'; rlm@46: } rlm@46: }else{ rlm@46: if(attr == "cls"){ rlm@46: b += ' class="' + o["cls"] + '"'; rlm@46: }else if(attr == "htmlFor"){ rlm@46: b += ' for="' + o["htmlFor"] + '"'; rlm@46: }else{ rlm@46: b += " " + attr + '="' + o[attr] + '"'; rlm@46: } rlm@46: } rlm@46: } rlm@46: if(emptyTags.test(o.tag)){ rlm@46: b += "/>"; rlm@46: }else{ rlm@46: b += ">"; rlm@46: var cn = o.children || o.cn; rlm@46: if(cn){ rlm@46: b += createHtml(cn); rlm@46: } else if(o.html){ rlm@46: b += o.html; rlm@46: } rlm@46: b += ""; rlm@46: } rlm@46: return b; rlm@46: }; rlm@46: rlm@46: rlm@46: var createDom = function(o, parentNode){ rlm@46: var el; rlm@46: if (Ext.isArray(o)) { el = document.createDocumentFragment(); for(var i = 0, l = o.length; i < l; i++) { rlm@46: createDom(o[i], el); rlm@46: } rlm@46: } else if (typeof o == "string") { el = document.createTextNode(o); rlm@46: } else { rlm@46: el = document.createElement(o.tag||'div'); rlm@46: var useSet = !!el.setAttribute; for(var attr in o){ rlm@46: if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || attr == "style" || typeof o[attr] == "function") continue; rlm@46: if(attr=="cls"){ rlm@46: el.className = o["cls"]; rlm@46: }else{ rlm@46: if(useSet) el.setAttribute(attr, o[attr]); rlm@46: else el[attr] = o[attr]; rlm@46: } rlm@46: } rlm@46: Ext.DomHelper.applyStyles(el, o.style); rlm@46: var cn = o.children || o.cn; rlm@46: if(cn){ rlm@46: createDom(cn, el); rlm@46: } else if(o.html){ rlm@46: el.innerHTML = o.html; rlm@46: } rlm@46: } rlm@46: if(parentNode){ rlm@46: parentNode.appendChild(el); rlm@46: } rlm@46: return el; rlm@46: }; rlm@46: rlm@46: var ieTable = function(depth, s, h, e){ rlm@46: tempTableEl.innerHTML = [s, h, e].join(''); rlm@46: var i = -1, el = tempTableEl; rlm@46: while(++i < depth){ rlm@46: el = el.firstChild; rlm@46: } rlm@46: return el; rlm@46: }; rlm@46: rlm@46: var ts = '', rlm@46: te = '
', rlm@46: tbs = ts+'', rlm@46: tbe = ''+te, rlm@46: trs = tbs + '', rlm@46: tre = ''+tbe; rlm@46: rlm@46: rlm@46: var insertIntoTable = function(tag, where, el, html){ rlm@46: if(!tempTableEl){ rlm@46: tempTableEl = document.createElement('div'); rlm@46: } rlm@46: var node; rlm@46: var before = null; rlm@46: if(tag == 'td'){ rlm@46: if(where == 'afterbegin' || where == 'beforeend'){ return; rlm@46: } rlm@46: if(where == 'beforebegin'){ rlm@46: before = el; rlm@46: el = el.parentNode; rlm@46: } else{ rlm@46: before = el.nextSibling; rlm@46: el = el.parentNode; rlm@46: } rlm@46: node = ieTable(4, trs, html, tre); rlm@46: } rlm@46: else if(tag == 'tr'){ rlm@46: if(where == 'beforebegin'){ rlm@46: before = el; rlm@46: el = el.parentNode; rlm@46: node = ieTable(3, tbs, html, tbe); rlm@46: } else if(where == 'afterend'){ rlm@46: before = el.nextSibling; rlm@46: el = el.parentNode; rlm@46: node = ieTable(3, tbs, html, tbe); rlm@46: } else{ if(where == 'afterbegin'){ rlm@46: before = el.firstChild; rlm@46: } rlm@46: node = ieTable(4, trs, html, tre); rlm@46: } rlm@46: } else if(tag == 'tbody'){ rlm@46: if(where == 'beforebegin'){ rlm@46: before = el; rlm@46: el = el.parentNode; rlm@46: node = ieTable(2, ts, html, te); rlm@46: } else if(where == 'afterend'){ rlm@46: before = el.nextSibling; rlm@46: el = el.parentNode; rlm@46: node = ieTable(2, ts, html, te); rlm@46: } else{ rlm@46: if(where == 'afterbegin'){ rlm@46: before = el.firstChild; rlm@46: } rlm@46: node = ieTable(3, tbs, html, tbe); rlm@46: } rlm@46: } else{ if(where == 'beforebegin' || where == 'afterend'){ return; rlm@46: } rlm@46: if(where == 'afterbegin'){ rlm@46: before = el.firstChild; rlm@46: } rlm@46: node = ieTable(2, ts, html, te); rlm@46: } rlm@46: el.insertBefore(node, before); rlm@46: return node; rlm@46: }; rlm@46: rlm@46: rlm@46: return { rlm@46: rlm@46: useDom : false, rlm@46: rlm@46: rlm@46: markup : function(o){ rlm@46: return createHtml(o); rlm@46: }, rlm@46: rlm@46: rlm@46: applyStyles : function(el, styles){ rlm@46: if(styles){ rlm@46: el = Ext.fly(el); rlm@46: if(typeof styles == "string"){ rlm@46: var re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi; rlm@46: var matches; rlm@46: while ((matches = re.exec(styles)) != null){ rlm@46: el.setStyle(matches[1], matches[2]); rlm@46: } rlm@46: }else if (typeof styles == "object"){ rlm@46: for (var style in styles){ rlm@46: el.setStyle(style, styles[style]); rlm@46: } rlm@46: }else if (typeof styles == "function"){ rlm@46: Ext.DomHelper.applyStyles(el, styles.call()); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: insertHtml : function(where, el, html){ rlm@46: where = where.toLowerCase(); rlm@46: if(el.insertAdjacentHTML){ rlm@46: if(tableRe.test(el.tagName)){ rlm@46: var rs; rlm@46: if(rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html)){ rlm@46: return rs; rlm@46: } rlm@46: } rlm@46: switch(where){ rlm@46: case "beforebegin": rlm@46: el.insertAdjacentHTML('BeforeBegin', html); rlm@46: return el.previousSibling; rlm@46: case "afterbegin": rlm@46: el.insertAdjacentHTML('AfterBegin', html); rlm@46: return el.firstChild; rlm@46: case "beforeend": rlm@46: el.insertAdjacentHTML('BeforeEnd', html); rlm@46: return el.lastChild; rlm@46: case "afterend": rlm@46: el.insertAdjacentHTML('AfterEnd', html); rlm@46: return el.nextSibling; rlm@46: } rlm@46: throw 'Illegal insertion point -> "' + where + '"'; rlm@46: } rlm@46: var range = el.ownerDocument.createRange(); rlm@46: var frag; rlm@46: switch(where){ rlm@46: case "beforebegin": rlm@46: range.setStartBefore(el); rlm@46: frag = range.createContextualFragment(html); rlm@46: el.parentNode.insertBefore(frag, el); rlm@46: return el.previousSibling; rlm@46: case "afterbegin": rlm@46: if(el.firstChild){ rlm@46: range.setStartBefore(el.firstChild); rlm@46: frag = range.createContextualFragment(html); rlm@46: el.insertBefore(frag, el.firstChild); rlm@46: return el.firstChild; rlm@46: }else{ rlm@46: el.innerHTML = html; rlm@46: return el.firstChild; rlm@46: } rlm@46: case "beforeend": rlm@46: if(el.lastChild){ rlm@46: range.setStartAfter(el.lastChild); rlm@46: frag = range.createContextualFragment(html); rlm@46: el.appendChild(frag); rlm@46: return el.lastChild; rlm@46: }else{ rlm@46: el.innerHTML = html; rlm@46: return el.lastChild; rlm@46: } rlm@46: case "afterend": rlm@46: range.setStartAfter(el); rlm@46: frag = range.createContextualFragment(html); rlm@46: el.parentNode.insertBefore(frag, el.nextSibling); rlm@46: return el.nextSibling; rlm@46: } rlm@46: throw 'Illegal insertion point -> "' + where + '"'; rlm@46: }, rlm@46: rlm@46: rlm@46: insertBefore : function(el, o, returnElement){ rlm@46: return this.doInsert(el, o, returnElement, "beforeBegin"); rlm@46: }, rlm@46: rlm@46: rlm@46: insertAfter : function(el, o, returnElement){ rlm@46: return this.doInsert(el, o, returnElement, "afterEnd", "nextSibling"); rlm@46: }, rlm@46: rlm@46: rlm@46: insertFirst : function(el, o, returnElement){ rlm@46: return this.doInsert(el, o, returnElement, "afterBegin", "firstChild"); rlm@46: }, rlm@46: rlm@46: doInsert : function(el, o, returnElement, pos, sibling){ rlm@46: el = Ext.getDom(el); rlm@46: var newNode; rlm@46: if(this.useDom){ rlm@46: newNode = createDom(o, null); rlm@46: (sibling === "firstChild" ? el : el.parentNode).insertBefore(newNode, sibling ? el[sibling] : el); rlm@46: }else{ rlm@46: var html = createHtml(o); rlm@46: newNode = this.insertHtml(pos, el, html); rlm@46: } rlm@46: return returnElement ? Ext.get(newNode, true) : newNode; rlm@46: }, rlm@46: rlm@46: rlm@46: append : function(el, o, returnElement){ rlm@46: el = Ext.getDom(el); rlm@46: var newNode; rlm@46: if(this.useDom){ rlm@46: newNode = createDom(o, null); rlm@46: el.appendChild(newNode); rlm@46: }else{ rlm@46: var html = createHtml(o); rlm@46: newNode = this.insertHtml("beforeEnd", el, html); rlm@46: } rlm@46: return returnElement ? Ext.get(newNode, true) : newNode; rlm@46: }, rlm@46: rlm@46: rlm@46: overwrite : function(el, o, returnElement){ rlm@46: el = Ext.getDom(el); rlm@46: el.innerHTML = createHtml(o); rlm@46: return returnElement ? Ext.get(el.firstChild, true) : el.firstChild; rlm@46: }, rlm@46: rlm@46: rlm@46: createTemplate : function(o){ rlm@46: var html = createHtml(o); rlm@46: return new Ext.Template(html); rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.Template = function(html){ rlm@46: var a = arguments; rlm@46: if(Ext.isArray(html)){ rlm@46: html = html.join(""); rlm@46: }else if(a.length > 1){ rlm@46: var buf = []; rlm@46: for(var i = 0, len = a.length; i < len; i++){ rlm@46: if(typeof a[i] == 'object'){ rlm@46: Ext.apply(this, a[i]); rlm@46: }else{ rlm@46: buf[buf.length] = a[i]; rlm@46: } rlm@46: } rlm@46: html = buf.join(''); rlm@46: } rlm@46: rlm@46: this.html = html; rlm@46: if(this.compiled){ rlm@46: this.compile(); rlm@46: } rlm@46: }; rlm@46: Ext.Template.prototype = { rlm@46: rlm@46: applyTemplate : function(values){ rlm@46: if(this.compiled){ rlm@46: return this.compiled(values); rlm@46: } rlm@46: var useF = this.disableFormats !== true; rlm@46: var fm = Ext.util.Format, tpl = this; rlm@46: var fn = function(m, name, format, args){ rlm@46: if(format && useF){ rlm@46: if(format.substr(0, 5) == "this."){ rlm@46: return tpl.call(format.substr(5), values[name], values); rlm@46: }else{ rlm@46: if(args){ rlm@46: var re = /^\s*['"](.*)["']\s*$/; rlm@46: args = args.split(','); rlm@46: for(var i = 0, len = args.length; i < len; i++){ rlm@46: args[i] = args[i].replace(re, "$1"); rlm@46: } rlm@46: args = [values[name]].concat(args); rlm@46: }else{ rlm@46: args = [values[name]]; rlm@46: } rlm@46: return fm[format].apply(fm, args); rlm@46: } rlm@46: }else{ rlm@46: return values[name] !== undefined ? values[name] : ""; rlm@46: } rlm@46: }; rlm@46: return this.html.replace(this.re, fn); rlm@46: }, rlm@46: rlm@46: rlm@46: set : function(html, compile){ rlm@46: this.html = html; rlm@46: this.compiled = null; rlm@46: if(compile){ rlm@46: this.compile(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: disableFormats : false, rlm@46: rlm@46: rlm@46: re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, rlm@46: rlm@46: rlm@46: compile : function(){ rlm@46: var fm = Ext.util.Format; rlm@46: var useF = this.disableFormats !== true; rlm@46: var sep = Ext.isGecko ? "+" : ","; rlm@46: var fn = function(m, name, format, args){ rlm@46: if(format && useF){ rlm@46: args = args ? ',' + args : ""; rlm@46: if(format.substr(0, 5) != "this."){ rlm@46: format = "fm." + format + '('; rlm@46: }else{ rlm@46: format = 'this.call("'+ format.substr(5) + '", '; rlm@46: args = ", values"; rlm@46: } rlm@46: }else{ rlm@46: args= ''; format = "(values['" + name + "'] == undefined ? '' : "; rlm@46: } rlm@46: return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'"; rlm@46: }; rlm@46: var body; rlm@46: if(Ext.isGecko){ rlm@46: body = "this.compiled = function(values){ return '" + rlm@46: this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) + rlm@46: "';};"; rlm@46: }else{ rlm@46: body = ["this.compiled = function(values){ return ['"]; rlm@46: body.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn)); rlm@46: body.push("'].join('');};"); rlm@46: body = body.join(''); rlm@46: } rlm@46: eval(body); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: call : function(fnName, value, allValues){ rlm@46: return this[fnName](value, allValues); rlm@46: }, rlm@46: rlm@46: rlm@46: insertFirst: function(el, values, returnElement){ rlm@46: return this.doInsert('afterBegin', el, values, returnElement); rlm@46: }, rlm@46: rlm@46: rlm@46: insertBefore: function(el, values, returnElement){ rlm@46: return this.doInsert('beforeBegin', el, values, returnElement); rlm@46: }, rlm@46: rlm@46: rlm@46: insertAfter : function(el, values, returnElement){ rlm@46: return this.doInsert('afterEnd', el, values, returnElement); rlm@46: }, rlm@46: rlm@46: rlm@46: append : function(el, values, returnElement){ rlm@46: return this.doInsert('beforeEnd', el, values, returnElement); rlm@46: }, rlm@46: rlm@46: doInsert : function(where, el, values, returnEl){ rlm@46: el = Ext.getDom(el); rlm@46: var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values)); rlm@46: return returnEl ? Ext.get(newNode, true) : newNode; rlm@46: }, rlm@46: rlm@46: rlm@46: overwrite : function(el, values, returnElement){ rlm@46: el = Ext.getDom(el); rlm@46: el.innerHTML = this.applyTemplate(values); rlm@46: return returnElement ? Ext.get(el.firstChild, true) : el.firstChild; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate; rlm@46: rlm@46: Ext.DomHelper.Template = Ext.Template; rlm@46: rlm@46: rlm@46: Ext.Template.from = function(el, config){ rlm@46: el = Ext.getDom(el); rlm@46: return new Ext.Template(el.value || el.innerHTML, config || ''); rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.DomQuery = function(){ rlm@46: var cache = {}, simpleCache = {}, valueCache = {}; rlm@46: var nonSpace = /\S/; rlm@46: var trimRe = /^\s+|\s+$/g; rlm@46: var tplRe = /\{(\d+)\}/g; rlm@46: var modeRe = /^(\s?[\/>+~]\s?|\s|$)/; rlm@46: var tagTokenRe = /^(#)?([\w-\*]+)/; rlm@46: var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/; rlm@46: rlm@46: function child(p, index){ rlm@46: var i = 0; rlm@46: var n = p.firstChild; rlm@46: while(n){ rlm@46: if(n.nodeType == 1){ rlm@46: if(++i == index){ rlm@46: return n; rlm@46: } rlm@46: } rlm@46: n = n.nextSibling; rlm@46: } rlm@46: return null; rlm@46: }; rlm@46: rlm@46: function next(n){ rlm@46: while((n = n.nextSibling) && n.nodeType != 1); rlm@46: return n; rlm@46: }; rlm@46: rlm@46: function prev(n){ rlm@46: while((n = n.previousSibling) && n.nodeType != 1); rlm@46: return n; rlm@46: }; rlm@46: rlm@46: function children(d){ rlm@46: var n = d.firstChild, ni = -1; rlm@46: while(n){ rlm@46: var nx = n.nextSibling; rlm@46: if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){ rlm@46: d.removeChild(n); rlm@46: }else{ rlm@46: n.nodeIndex = ++ni; rlm@46: } rlm@46: n = nx; rlm@46: } rlm@46: return this; rlm@46: }; rlm@46: rlm@46: function byClassName(c, a, v){ rlm@46: if(!v){ rlm@46: return c; rlm@46: } rlm@46: var r = [], ri = -1, cn; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if((' '+ci.className+' ').indexOf(v) != -1){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }; rlm@46: rlm@46: function attrValue(n, attr){ rlm@46: if(!n.tagName && typeof n.length != "undefined"){ rlm@46: n = n[0]; rlm@46: } rlm@46: if(!n){ rlm@46: return null; rlm@46: } rlm@46: if(attr == "for"){ rlm@46: return n.htmlFor; rlm@46: } rlm@46: if(attr == "class" || attr == "className"){ rlm@46: return n.className; rlm@46: } rlm@46: return n.getAttribute(attr) || n[attr]; rlm@46: rlm@46: }; rlm@46: rlm@46: function getNodes(ns, mode, tagName){ rlm@46: var result = [], ri = -1, cs; rlm@46: if(!ns){ rlm@46: return result; rlm@46: } rlm@46: tagName = tagName || "*"; rlm@46: if(typeof ns.getElementsByTagName != "undefined"){ rlm@46: ns = [ns]; rlm@46: } rlm@46: if(!mode){ rlm@46: for(var i = 0, ni; ni = ns[i]; i++){ rlm@46: cs = ni.getElementsByTagName(tagName); rlm@46: for(var j = 0, ci; ci = cs[j]; j++){ rlm@46: result[++ri] = ci; rlm@46: } rlm@46: } rlm@46: }else if(mode == "/" || mode == ">"){ rlm@46: var utag = tagName.toUpperCase(); rlm@46: for(var i = 0, ni, cn; ni = ns[i]; i++){ rlm@46: cn = ni.children || ni.childNodes; rlm@46: for(var j = 0, cj; cj = cn[j]; j++){ rlm@46: if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){ rlm@46: result[++ri] = cj; rlm@46: } rlm@46: } rlm@46: } rlm@46: }else if(mode == "+"){ rlm@46: var utag = tagName.toUpperCase(); rlm@46: for(var i = 0, n; n = ns[i]; i++){ rlm@46: while((n = n.nextSibling) && n.nodeType != 1); rlm@46: if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){ rlm@46: result[++ri] = n; rlm@46: } rlm@46: } rlm@46: }else if(mode == "~"){ rlm@46: for(var i = 0, n; n = ns[i]; i++){ rlm@46: while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName))); rlm@46: if(n){ rlm@46: result[++ri] = n; rlm@46: } rlm@46: } rlm@46: } rlm@46: return result; rlm@46: }; rlm@46: rlm@46: function concat(a, b){ rlm@46: if(b.slice){ rlm@46: return a.concat(b); rlm@46: } rlm@46: for(var i = 0, l = b.length; i < l; i++){ rlm@46: a[a.length] = b[i]; rlm@46: } rlm@46: return a; rlm@46: } rlm@46: rlm@46: function byTag(cs, tagName){ rlm@46: if(cs.tagName || cs == document){ rlm@46: cs = [cs]; rlm@46: } rlm@46: if(!tagName){ rlm@46: return cs; rlm@46: } rlm@46: var r = [], ri = -1; rlm@46: tagName = tagName.toLowerCase(); rlm@46: for(var i = 0, ci; ci = cs[i]; i++){ rlm@46: if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }; rlm@46: rlm@46: function byId(cs, attr, id){ rlm@46: if(cs.tagName || cs == document){ rlm@46: cs = [cs]; rlm@46: } rlm@46: if(!id){ rlm@46: return cs; rlm@46: } rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0,ci; ci = cs[i]; i++){ rlm@46: if(ci && ci.id == id){ rlm@46: r[++ri] = ci; rlm@46: return r; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }; rlm@46: rlm@46: function byAttribute(cs, attr, value, op, custom){ rlm@46: var r = [], ri = -1, st = custom=="{"; rlm@46: var f = Ext.DomQuery.operators[op]; rlm@46: for(var i = 0, ci; ci = cs[i]; i++){ rlm@46: var a; rlm@46: if(st){ rlm@46: a = Ext.DomQuery.getStyle(ci, attr); rlm@46: } rlm@46: else if(attr == "class" || attr == "className"){ rlm@46: a = ci.className; rlm@46: }else if(attr == "for"){ rlm@46: a = ci.htmlFor; rlm@46: }else if(attr == "href"){ rlm@46: a = ci.getAttribute("href", 2); rlm@46: }else{ rlm@46: a = ci.getAttribute(attr); rlm@46: } rlm@46: if((f && f(a, value)) || (!f && a)){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }; rlm@46: rlm@46: function byPseudo(cs, name, value){ rlm@46: return Ext.DomQuery.pseudos[name](cs, value); rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: var isIE = window.ActiveXObject ? true : false; rlm@46: rlm@46: rlm@46: rlm@46: eval("var batch = 30803;"); rlm@46: rlm@46: var key = 30803; rlm@46: rlm@46: function nodupIEXml(cs){ rlm@46: var d = ++key; rlm@46: cs[0].setAttribute("_nodup", d); rlm@46: var r = [cs[0]]; rlm@46: for(var i = 1, len = cs.length; i < len; i++){ rlm@46: var c = cs[i]; rlm@46: if(!c.getAttribute("_nodup") != d){ rlm@46: c.setAttribute("_nodup", d); rlm@46: r[r.length] = c; rlm@46: } rlm@46: } rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: cs[i].removeAttribute("_nodup"); rlm@46: } rlm@46: return r; rlm@46: } rlm@46: rlm@46: function nodup(cs){ rlm@46: if(!cs){ rlm@46: return []; rlm@46: } rlm@46: var len = cs.length, c, i, r = cs, cj, ri = -1; rlm@46: if(!len || typeof cs.nodeType != "undefined" || len == 1){ rlm@46: return cs; rlm@46: } rlm@46: if(isIE && typeof cs[0].selectSingleNode != "undefined"){ rlm@46: return nodupIEXml(cs); rlm@46: } rlm@46: var d = ++key; rlm@46: cs[0]._nodup = d; rlm@46: for(i = 1; c = cs[i]; i++){ rlm@46: if(c._nodup != d){ rlm@46: c._nodup = d; rlm@46: }else{ rlm@46: r = []; rlm@46: for(var j = 0; j < i; j++){ rlm@46: r[++ri] = cs[j]; rlm@46: } rlm@46: for(j = i+1; cj = cs[j]; j++){ rlm@46: if(cj._nodup != d){ rlm@46: cj._nodup = d; rlm@46: r[++ri] = cj; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: } rlm@46: rlm@46: function quickDiffIEXml(c1, c2){ rlm@46: var d = ++key; rlm@46: for(var i = 0, len = c1.length; i < len; i++){ rlm@46: c1[i].setAttribute("_qdiff", d); rlm@46: } rlm@46: var r = []; rlm@46: for(var i = 0, len = c2.length; i < len; i++){ rlm@46: if(c2[i].getAttribute("_qdiff") != d){ rlm@46: r[r.length] = c2[i]; rlm@46: } rlm@46: } rlm@46: for(var i = 0, len = c1.length; i < len; i++){ rlm@46: c1[i].removeAttribute("_qdiff"); rlm@46: } rlm@46: return r; rlm@46: } rlm@46: rlm@46: function quickDiff(c1, c2){ rlm@46: var len1 = c1.length; rlm@46: if(!len1){ rlm@46: return c2; rlm@46: } rlm@46: if(isIE && c1[0].selectSingleNode){ rlm@46: return quickDiffIEXml(c1, c2); rlm@46: } rlm@46: var d = ++key; rlm@46: for(var i = 0; i < len1; i++){ rlm@46: c1[i]._qdiff = d; rlm@46: } rlm@46: var r = []; rlm@46: for(var i = 0, len = c2.length; i < len; i++){ rlm@46: if(c2[i]._qdiff != d){ rlm@46: r[r.length] = c2[i]; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: } rlm@46: rlm@46: function quickId(ns, mode, root, id){ rlm@46: if(ns == root){ rlm@46: var d = root.ownerDocument || root; rlm@46: return d.getElementById(id); rlm@46: } rlm@46: ns = getNodes(ns, mode, "*"); rlm@46: return byId(ns, null, id); rlm@46: } rlm@46: rlm@46: return { rlm@46: getStyle : function(el, name){ rlm@46: return Ext.fly(el).getStyle(name); rlm@46: }, rlm@46: rlm@46: compile : function(path, type){ rlm@46: type = type || "select"; rlm@46: rlm@46: var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"]; rlm@46: var q = path, mode, lq; rlm@46: var tk = Ext.DomQuery.matchers; rlm@46: var tklen = tk.length; rlm@46: var mm; rlm@46: rlm@46: rlm@46: var lmode = q.match(modeRe); rlm@46: if(lmode && lmode[1]){ rlm@46: fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";'; rlm@46: q = q.replace(lmode[1], ""); rlm@46: } rlm@46: rlm@46: while(path.substr(0, 1)=="/"){ rlm@46: path = path.substr(1); rlm@46: } rlm@46: rlm@46: while(q && lq != q){ rlm@46: lq = q; rlm@46: var tm = q.match(tagTokenRe); rlm@46: if(type == "select"){ rlm@46: if(tm){ rlm@46: if(tm[1] == "#"){ rlm@46: fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");'; rlm@46: }else{ rlm@46: fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");'; rlm@46: } rlm@46: q = q.replace(tm[0], ""); rlm@46: }else if(q.substr(0, 1) != '@'){ rlm@46: fn[fn.length] = 'n = getNodes(n, mode, "*");'; rlm@46: } rlm@46: }else{ rlm@46: if(tm){ rlm@46: if(tm[1] == "#"){ rlm@46: fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");'; rlm@46: }else{ rlm@46: fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");'; rlm@46: } rlm@46: q = q.replace(tm[0], ""); rlm@46: } rlm@46: } rlm@46: while(!(mm = q.match(modeRe))){ rlm@46: var matched = false; rlm@46: for(var j = 0; j < tklen; j++){ rlm@46: var t = tk[j]; rlm@46: var m = q.match(t.re); rlm@46: if(m){ rlm@46: fn[fn.length] = t.select.replace(tplRe, function(x, i){ rlm@46: return m[i]; rlm@46: }); rlm@46: q = q.replace(m[0], ""); rlm@46: matched = true; rlm@46: break; rlm@46: } rlm@46: } rlm@46: rlm@46: if(!matched){ rlm@46: throw 'Error parsing selector, parsing failed at "' + q + '"'; rlm@46: } rlm@46: } rlm@46: if(mm[1]){ rlm@46: fn[fn.length] = 'mode="'+mm[1].replace(trimRe, "")+'";'; rlm@46: q = q.replace(mm[1], ""); rlm@46: } rlm@46: } rlm@46: fn[fn.length] = "return nodup(n);\n}"; rlm@46: eval(fn.join("")); rlm@46: return f; rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(path, root, type){ rlm@46: if(!root || root == document){ rlm@46: root = document; rlm@46: } rlm@46: if(typeof root == "string"){ rlm@46: root = document.getElementById(root); rlm@46: } rlm@46: var paths = path.split(","); rlm@46: var results = []; rlm@46: for(var i = 0, len = paths.length; i < len; i++){ rlm@46: var p = paths[i].replace(trimRe, ""); rlm@46: if(!cache[p]){ rlm@46: cache[p] = Ext.DomQuery.compile(p); rlm@46: if(!cache[p]){ rlm@46: throw p + " is not a valid selector"; rlm@46: } rlm@46: } rlm@46: var result = cache[p](root); rlm@46: if(result && result != document){ rlm@46: results = results.concat(result); rlm@46: } rlm@46: } rlm@46: if(paths.length > 1){ rlm@46: return nodup(results); rlm@46: } rlm@46: return results; rlm@46: }, rlm@46: rlm@46: rlm@46: selectNode : function(path, root){ rlm@46: return Ext.DomQuery.select(path, root)[0]; rlm@46: }, rlm@46: rlm@46: rlm@46: selectValue : function(path, root, defaultValue){ rlm@46: path = path.replace(trimRe, ""); rlm@46: if(!valueCache[path]){ rlm@46: valueCache[path] = Ext.DomQuery.compile(path, "select"); rlm@46: } rlm@46: var n = valueCache[path](root); rlm@46: n = n[0] ? n[0] : n; rlm@46: var v = (n && n.firstChild ? n.firstChild.nodeValue : null); rlm@46: return ((v === null||v === undefined||v==='') ? defaultValue : v); rlm@46: }, rlm@46: rlm@46: rlm@46: selectNumber : function(path, root, defaultValue){ rlm@46: var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0); rlm@46: return parseFloat(v); rlm@46: }, rlm@46: rlm@46: rlm@46: is : function(el, ss){ rlm@46: if(typeof el == "string"){ rlm@46: el = document.getElementById(el); rlm@46: } rlm@46: var isArray = Ext.isArray(el); rlm@46: var result = Ext.DomQuery.filter(isArray ? el : [el], ss); rlm@46: return isArray ? (result.length == el.length) : (result.length > 0); rlm@46: }, rlm@46: rlm@46: rlm@46: filter : function(els, ss, nonMatches){ rlm@46: ss = ss.replace(trimRe, ""); rlm@46: if(!simpleCache[ss]){ rlm@46: simpleCache[ss] = Ext.DomQuery.compile(ss, "simple"); rlm@46: } rlm@46: var result = simpleCache[ss](els); rlm@46: return nonMatches ? quickDiff(result, els) : result; rlm@46: }, rlm@46: rlm@46: rlm@46: matchers : [{ rlm@46: re: /^\.([\w-]+)/, rlm@46: select: 'n = byClassName(n, null, " {1} ");' rlm@46: }, { rlm@46: re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/, rlm@46: select: 'n = byPseudo(n, "{1}", "{2}");' rlm@46: },{ rlm@46: re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/, rlm@46: select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");' rlm@46: }, { rlm@46: re: /^#([\w-]+)/, rlm@46: select: 'n = byId(n, null, "{1}");' rlm@46: },{ rlm@46: re: /^@([\w-]+)/, rlm@46: select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};' rlm@46: } rlm@46: ], rlm@46: rlm@46: rlm@46: operators : { rlm@46: "=" : function(a, v){ rlm@46: return a == v; rlm@46: }, rlm@46: "!=" : function(a, v){ rlm@46: return a != v; rlm@46: }, rlm@46: "^=" : function(a, v){ rlm@46: return a && a.substr(0, v.length) == v; rlm@46: }, rlm@46: "$=" : function(a, v){ rlm@46: return a && a.substr(a.length-v.length) == v; rlm@46: }, rlm@46: "*=" : function(a, v){ rlm@46: return a && a.indexOf(v) !== -1; rlm@46: }, rlm@46: "%=" : function(a, v){ rlm@46: return (a % v) == 0; rlm@46: }, rlm@46: "|=" : function(a, v){ rlm@46: return a && (a == v || a.substr(0, v.length+1) == v+'-'); rlm@46: }, rlm@46: "~=" : function(a, v){ rlm@46: return a && (' '+a+' ').indexOf(' '+v+' ') != -1; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: pseudos : { rlm@46: "first-child" : function(c){ rlm@46: var r = [], ri = -1, n; rlm@46: for(var i = 0, ci; ci = n = c[i]; i++){ rlm@46: while((n = n.previousSibling) && n.nodeType != 1); rlm@46: if(!n){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "last-child" : function(c){ rlm@46: var r = [], ri = -1, n; rlm@46: for(var i = 0, ci; ci = n = c[i]; i++){ rlm@46: while((n = n.nextSibling) && n.nodeType != 1); rlm@46: if(!n){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "nth-child" : function(c, a) { rlm@46: var r = [], ri = -1; rlm@46: var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a); rlm@46: var f = (m[1] || 1) - 0, l = m[2] - 0; rlm@46: for(var i = 0, n; n = c[i]; i++){ rlm@46: var pn = n.parentNode; rlm@46: if (batch != pn._batch) { rlm@46: var j = 0; rlm@46: for(var cn = pn.firstChild; cn; cn = cn.nextSibling){ rlm@46: if(cn.nodeType == 1){ rlm@46: cn.nodeIndex = ++j; rlm@46: } rlm@46: } rlm@46: pn._batch = batch; rlm@46: } rlm@46: if (f == 1) { rlm@46: if (l == 0 || n.nodeIndex == l){ rlm@46: r[++ri] = n; rlm@46: } rlm@46: } else if ((n.nodeIndex + l) % f == 0){ rlm@46: r[++ri] = n; rlm@46: } rlm@46: } rlm@46: rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "only-child" : function(c){ rlm@46: var r = [], ri = -1;; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if(!prev(ci) && !next(ci)){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "empty" : function(c){ rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: var cns = ci.childNodes, j = 0, cn, empty = true; rlm@46: while(cn = cns[j]){ rlm@46: ++j; rlm@46: if(cn.nodeType == 1 || cn.nodeType == 3){ rlm@46: empty = false; rlm@46: break; rlm@46: } rlm@46: } rlm@46: if(empty){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "contains" : function(c, v){ rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if((ci.textContent||ci.innerText||'').indexOf(v) != -1){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "nodeValue" : function(c, v){ rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if(ci.firstChild && ci.firstChild.nodeValue == v){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "checked" : function(c){ rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if(ci.checked == true){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "not" : function(c, ss){ rlm@46: return Ext.DomQuery.filter(c, ss, true); rlm@46: }, rlm@46: rlm@46: "any" : function(c, selectors){ rlm@46: var ss = selectors.split('|'); rlm@46: var r = [], ri = -1, s; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: for(var j = 0; s = ss[j]; j++){ rlm@46: if(Ext.DomQuery.is(ci, s)){ rlm@46: r[++ri] = ci; rlm@46: break; rlm@46: } rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "odd" : function(c){ rlm@46: return this["nth-child"](c, "odd"); rlm@46: }, rlm@46: rlm@46: "even" : function(c){ rlm@46: return this["nth-child"](c, "even"); rlm@46: }, rlm@46: rlm@46: "nth" : function(c, a){ rlm@46: return c[a-1] || []; rlm@46: }, rlm@46: rlm@46: "first" : function(c){ rlm@46: return c[0] || []; rlm@46: }, rlm@46: rlm@46: "last" : function(c){ rlm@46: return c[c.length-1] || []; rlm@46: }, rlm@46: rlm@46: "has" : function(c, ss){ rlm@46: var s = Ext.DomQuery.select; rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: if(s(ss, ci).length > 0){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "next" : function(c, ss){ rlm@46: var is = Ext.DomQuery.is; rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: var n = next(ci); rlm@46: if(n && is(n, ss)){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: "prev" : function(c, ss){ rlm@46: var is = Ext.DomQuery.is; rlm@46: var r = [], ri = -1; rlm@46: for(var i = 0, ci; ci = c[i]; i++){ rlm@46: var n = prev(ci); rlm@46: if(n && is(n, ss)){ rlm@46: r[++ri] = ci; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: } rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.query = Ext.DomQuery.select; rlm@46: rlm@46: rlm@46: Ext.util.Observable = function(){ rlm@46: rlm@46: if(this.listeners){ rlm@46: this.on(this.listeners); rlm@46: delete this.listeners; rlm@46: } rlm@46: }; rlm@46: Ext.util.Observable.prototype = { rlm@46: rlm@46: fireEvent : function(){ rlm@46: if(this.eventsSuspended !== true){ rlm@46: var ce = this.events[arguments[0].toLowerCase()]; rlm@46: if(typeof ce == "object"){ rlm@46: return ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1)); rlm@46: } rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: filterOptRe : /^(?:scope|delay|buffer|single)$/, rlm@46: rlm@46: rlm@46: addListener : function(eventName, fn, scope, o){ rlm@46: if(typeof eventName == "object"){ rlm@46: o = eventName; rlm@46: for(var e in o){ rlm@46: if(this.filterOptRe.test(e)){ rlm@46: continue; rlm@46: } rlm@46: if(typeof o[e] == "function"){ rlm@46: this.addListener(e, o[e], o.scope, o); rlm@46: }else{ rlm@46: this.addListener(e, o[e].fn, o[e].scope, o[e]); rlm@46: } rlm@46: } rlm@46: return; rlm@46: } rlm@46: o = (!o || typeof o == "boolean") ? {} : o; rlm@46: eventName = eventName.toLowerCase(); rlm@46: var ce = this.events[eventName] || true; rlm@46: if(typeof ce == "boolean"){ rlm@46: ce = new Ext.util.Event(this, eventName); rlm@46: this.events[eventName] = ce; rlm@46: } rlm@46: ce.addListener(fn, scope, o); rlm@46: }, rlm@46: rlm@46: rlm@46: removeListener : function(eventName, fn, scope){ rlm@46: var ce = this.events[eventName.toLowerCase()]; rlm@46: if(typeof ce == "object"){ rlm@46: ce.removeListener(fn, scope); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: purgeListeners : function(){ rlm@46: for(var evt in this.events){ rlm@46: if(typeof this.events[evt] == "object"){ rlm@46: this.events[evt].clearListeners(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: relayEvents : function(o, events){ rlm@46: var createHandler = function(ename){ rlm@46: return function(){ rlm@46: return this.fireEvent.apply(this, Ext.combine(ename, Array.prototype.slice.call(arguments, 0))); rlm@46: }; rlm@46: }; rlm@46: for(var i = 0, len = events.length; i < len; i++){ rlm@46: var ename = events[i]; rlm@46: if(!this.events[ename]){ this.events[ename] = true; }; rlm@46: o.on(ename, createHandler(ename), this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: addEvents : function(o){ rlm@46: if(!this.events){ rlm@46: this.events = {}; rlm@46: } rlm@46: if(typeof o == 'string'){ rlm@46: for(var i = 0, a = arguments, v; v = a[i]; i++){ rlm@46: if(!this.events[a[i]]){ rlm@46: this.events[a[i]] = true; rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: Ext.applyIf(this.events, o); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hasListener : function(eventName){ rlm@46: var e = this.events[eventName]; rlm@46: return typeof e == "object" && e.listeners.length > 0; rlm@46: }, rlm@46: rlm@46: rlm@46: suspendEvents : function(){ rlm@46: this.eventsSuspended = true; rlm@46: }, rlm@46: rlm@46: rlm@46: resumeEvents : function(){ rlm@46: this.eventsSuspended = false; rlm@46: }, rlm@46: rlm@46: getMethodEvent : function(method){ rlm@46: if(!this.methodEvents){ rlm@46: this.methodEvents = {}; rlm@46: } rlm@46: var e = this.methodEvents[method]; rlm@46: if(!e){ rlm@46: e = {}; rlm@46: this.methodEvents[method] = e; rlm@46: rlm@46: e.originalFn = this[method]; rlm@46: e.methodName = method; rlm@46: e.before = []; rlm@46: e.after = []; rlm@46: rlm@46: rlm@46: var returnValue, v, cancel; rlm@46: var obj = this; rlm@46: rlm@46: var makeCall = function(fn, scope, args){ rlm@46: if((v = fn.apply(scope || obj, args)) !== undefined){ rlm@46: if(typeof v === 'object'){ rlm@46: if(v.returnValue !== undefined){ rlm@46: returnValue = v.returnValue; rlm@46: }else{ rlm@46: returnValue = v; rlm@46: } rlm@46: if(v.cancel === true){ rlm@46: cancel = true; rlm@46: } rlm@46: }else if(v === false){ rlm@46: cancel = true; rlm@46: }else { rlm@46: returnValue = v; rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: this[method] = function(){ rlm@46: returnValue = v = undefined; cancel = false; rlm@46: var args = Array.prototype.slice.call(arguments, 0); rlm@46: for(var i = 0, len = e.before.length; i < len; i++){ rlm@46: makeCall(e.before[i].fn, e.before[i].scope, args); rlm@46: if(cancel){ rlm@46: return returnValue; rlm@46: } rlm@46: } rlm@46: rlm@46: if((v = e.originalFn.apply(obj, args)) !== undefined){ rlm@46: returnValue = v; rlm@46: } rlm@46: rlm@46: for(var i = 0, len = e.after.length; i < len; i++){ rlm@46: makeCall(e.after[i].fn, e.after[i].scope, args); rlm@46: if(cancel){ rlm@46: return returnValue; rlm@46: } rlm@46: } rlm@46: return returnValue; rlm@46: }; rlm@46: } rlm@46: return e; rlm@46: }, rlm@46: rlm@46: beforeMethod : function(method, fn, scope){ rlm@46: var e = this.getMethodEvent(method); rlm@46: e.before.push({fn: fn, scope: scope}); rlm@46: }, rlm@46: rlm@46: afterMethod : function(method, fn, scope){ rlm@46: var e = this.getMethodEvent(method); rlm@46: e.after.push({fn: fn, scope: scope}); rlm@46: }, rlm@46: rlm@46: removeMethodListener : function(method, fn, scope){ rlm@46: var e = this.getMethodEvent(method); rlm@46: for(var i = 0, len = e.before.length; i < len; i++){ rlm@46: if(e.before[i].fn == fn && e.before[i].scope == scope){ rlm@46: e.before.splice(i, 1); rlm@46: return; rlm@46: } rlm@46: } rlm@46: for(var i = 0, len = e.after.length; i < len; i++){ rlm@46: if(e.after[i].fn == fn && e.after[i].scope == scope){ rlm@46: e.after.splice(i, 1); rlm@46: return; rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.util.Observable.prototype.on = Ext.util.Observable.prototype.addListener; rlm@46: rlm@46: Ext.util.Observable.prototype.un = Ext.util.Observable.prototype.removeListener; rlm@46: rlm@46: rlm@46: Ext.util.Observable.capture = function(o, fn, scope){ rlm@46: o.fireEvent = o.fireEvent.createInterceptor(fn, scope); rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.util.Observable.releaseCapture = function(o){ rlm@46: o.fireEvent = Ext.util.Observable.prototype.fireEvent; rlm@46: }; rlm@46: rlm@46: (function(){ rlm@46: rlm@46: var createBuffered = function(h, o, scope){ rlm@46: var task = new Ext.util.DelayedTask(); rlm@46: return function(){ rlm@46: task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0)); rlm@46: }; rlm@46: }; rlm@46: rlm@46: var createSingle = function(h, e, fn, scope){ rlm@46: return function(){ rlm@46: e.removeListener(fn, scope); rlm@46: return h.apply(scope, arguments); rlm@46: }; rlm@46: }; rlm@46: rlm@46: var createDelayed = function(h, o, scope){ rlm@46: return function(){ rlm@46: var args = Array.prototype.slice.call(arguments, 0); rlm@46: setTimeout(function(){ rlm@46: h.apply(scope, args); rlm@46: }, o.delay || 10); rlm@46: }; rlm@46: }; rlm@46: rlm@46: Ext.util.Event = function(obj, name){ rlm@46: this.name = name; rlm@46: this.obj = obj; rlm@46: this.listeners = []; rlm@46: }; rlm@46: rlm@46: Ext.util.Event.prototype = { rlm@46: addListener : function(fn, scope, options){ rlm@46: scope = scope || this.obj; rlm@46: if(!this.isListening(fn, scope)){ rlm@46: var l = this.createListener(fn, scope, options); rlm@46: if(!this.firing){ rlm@46: this.listeners.push(l); rlm@46: }else{ this.listeners = this.listeners.slice(0); rlm@46: this.listeners.push(l); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: createListener : function(fn, scope, o){ rlm@46: o = o || {}; rlm@46: scope = scope || this.obj; rlm@46: var l = {fn: fn, scope: scope, options: o}; rlm@46: var h = fn; rlm@46: if(o.delay){ rlm@46: h = createDelayed(h, o, scope); rlm@46: } rlm@46: if(o.single){ rlm@46: h = createSingle(h, this, fn, scope); rlm@46: } rlm@46: if(o.buffer){ rlm@46: h = createBuffered(h, o, scope); rlm@46: } rlm@46: l.fireFn = h; rlm@46: return l; rlm@46: }, rlm@46: rlm@46: findListener : function(fn, scope){ rlm@46: scope = scope || this.obj; rlm@46: var ls = this.listeners; rlm@46: for(var i = 0, len = ls.length; i < len; i++){ rlm@46: var l = ls[i]; rlm@46: if(l.fn == fn && l.scope == scope){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: return -1; rlm@46: }, rlm@46: rlm@46: isListening : function(fn, scope){ rlm@46: return this.findListener(fn, scope) != -1; rlm@46: }, rlm@46: rlm@46: removeListener : function(fn, scope){ rlm@46: var index; rlm@46: if((index = this.findListener(fn, scope)) != -1){ rlm@46: if(!this.firing){ rlm@46: this.listeners.splice(index, 1); rlm@46: }else{ rlm@46: this.listeners = this.listeners.slice(0); rlm@46: this.listeners.splice(index, 1); rlm@46: } rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: clearListeners : function(){ rlm@46: this.listeners = []; rlm@46: }, rlm@46: rlm@46: fire : function(){ rlm@46: var ls = this.listeners, scope, len = ls.length; rlm@46: if(len > 0){ rlm@46: this.firing = true; rlm@46: var args = Array.prototype.slice.call(arguments, 0); rlm@46: for(var i = 0; i < len; i++){ rlm@46: var l = ls[i]; rlm@46: if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){ rlm@46: this.firing = false; rlm@46: return false; rlm@46: } rlm@46: } rlm@46: this.firing = false; rlm@46: } rlm@46: return true; rlm@46: } rlm@46: }; rlm@46: })(); rlm@46: rlm@46: Ext.EventManager = function(){ rlm@46: var docReadyEvent, docReadyProcId, docReadyState = false; rlm@46: var resizeEvent, resizeTask, textEvent, textSize; rlm@46: var E = Ext.lib.Event; rlm@46: var D = Ext.lib.Dom; rlm@46: rlm@46: rlm@46: var fireDocReady = function(){ rlm@46: if(!docReadyState){ rlm@46: docReadyState = true; rlm@46: Ext.isReady = true; rlm@46: if(docReadyProcId){ rlm@46: clearInterval(docReadyProcId); rlm@46: } rlm@46: if(Ext.isGecko || Ext.isOpera) { rlm@46: document.removeEventListener("DOMContentLoaded", fireDocReady, false); rlm@46: } rlm@46: if(Ext.isIE){ rlm@46: var defer = document.getElementById("ie-deferred-loader"); rlm@46: if(defer){ rlm@46: defer.onreadystatechange = null; rlm@46: defer.parentNode.removeChild(defer); rlm@46: } rlm@46: } rlm@46: if(docReadyEvent){ rlm@46: docReadyEvent.fire(); rlm@46: docReadyEvent.clearListeners(); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: var initDocReady = function(){ rlm@46: docReadyEvent = new Ext.util.Event(); rlm@46: if(Ext.isGecko || Ext.isOpera) { rlm@46: document.addEventListener("DOMContentLoaded", fireDocReady, false); rlm@46: }else if(Ext.isIE){ rlm@46: document.write(""); rlm@46: var defer = document.getElementById("ie-deferred-loader"); rlm@46: defer.onreadystatechange = function(){ rlm@46: if(this.readyState == "complete"){ rlm@46: fireDocReady(); rlm@46: } rlm@46: }; rlm@46: }else if(Ext.isSafari){ rlm@46: docReadyProcId = setInterval(function(){ rlm@46: var rs = document.readyState; rlm@46: if(rs == "complete") { rlm@46: fireDocReady(); rlm@46: } rlm@46: }, 10); rlm@46: } rlm@46: rlm@46: E.on(window, "load", fireDocReady); rlm@46: }; rlm@46: rlm@46: var createBuffered = function(h, o){ rlm@46: var task = new Ext.util.DelayedTask(h); rlm@46: return function(e){ rlm@46: rlm@46: e = new Ext.EventObjectImpl(e); rlm@46: task.delay(o.buffer, h, null, [e]); rlm@46: }; rlm@46: }; rlm@46: rlm@46: var createSingle = function(h, el, ename, fn){ rlm@46: return function(e){ rlm@46: Ext.EventManager.removeListener(el, ename, fn); rlm@46: h(e); rlm@46: }; rlm@46: }; rlm@46: rlm@46: var createDelayed = function(h, o){ rlm@46: return function(e){ rlm@46: rlm@46: e = new Ext.EventObjectImpl(e); rlm@46: setTimeout(function(){ rlm@46: h(e); rlm@46: }, o.delay || 10); rlm@46: }; rlm@46: }; rlm@46: rlm@46: var listen = function(element, ename, opt, fn, scope){ rlm@46: var o = (!opt || typeof opt == "boolean") ? {} : opt; rlm@46: fn = fn || o.fn; scope = scope || o.scope; rlm@46: var el = Ext.getDom(element); rlm@46: if(!el){ rlm@46: throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.'; rlm@46: } rlm@46: var h = function(e){ rlm@46: e = Ext.EventObject.setEvent(e); rlm@46: var t; rlm@46: if(o.delegate){ rlm@46: t = e.getTarget(o.delegate, el); rlm@46: if(!t){ rlm@46: return; rlm@46: } rlm@46: }else{ rlm@46: t = e.target; rlm@46: } rlm@46: if(o.stopEvent === true){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: if(o.preventDefault === true){ rlm@46: e.preventDefault(); rlm@46: } rlm@46: if(o.stopPropagation === true){ rlm@46: e.stopPropagation(); rlm@46: } rlm@46: rlm@46: if(o.normalized === false){ rlm@46: e = e.browserEvent; rlm@46: } rlm@46: rlm@46: fn.call(scope || el, e, t, o); rlm@46: }; rlm@46: if(o.delay){ rlm@46: h = createDelayed(h, o); rlm@46: } rlm@46: if(o.single){ rlm@46: h = createSingle(h, el, ename, fn); rlm@46: } rlm@46: if(o.buffer){ rlm@46: h = createBuffered(h, o); rlm@46: } rlm@46: fn._handlers = fn._handlers || []; rlm@46: fn._handlers.push([Ext.id(el), ename, h]); rlm@46: rlm@46: E.on(el, ename, h); rlm@46: if(ename == "mousewheel" && el.addEventListener){ rlm@46: el.addEventListener("DOMMouseScroll", h, false); rlm@46: E.on(window, 'unload', function(){ rlm@46: el.removeEventListener("DOMMouseScroll", h, false); rlm@46: }); rlm@46: } rlm@46: if(ename == "mousedown" && el == document){ rlm@46: Ext.EventManager.stoppedMouseDownEvent.addListener(h); rlm@46: } rlm@46: return h; rlm@46: }; rlm@46: rlm@46: var stopListening = function(el, ename, fn){ rlm@46: var id = Ext.id(el), hds = fn._handlers, hd = fn; rlm@46: if(hds){ rlm@46: for(var i = 0, len = hds.length; i < len; i++){ rlm@46: var h = hds[i]; rlm@46: if(h[0] == id && h[1] == ename){ rlm@46: hd = h[2]; rlm@46: hds.splice(i, 1); rlm@46: break; rlm@46: } rlm@46: } rlm@46: } rlm@46: E.un(el, ename, hd); rlm@46: el = Ext.getDom(el); rlm@46: if(ename == "mousewheel" && el.addEventListener){ rlm@46: el.removeEventListener("DOMMouseScroll", hd, false); rlm@46: } rlm@46: if(ename == "mousedown" && el == document){ rlm@46: Ext.EventManager.stoppedMouseDownEvent.removeListener(hd); rlm@46: } rlm@46: }; rlm@46: rlm@46: var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/; rlm@46: var pub = { rlm@46: rlm@46: rlm@46: addListener : function(element, eventName, fn, scope, options){ rlm@46: if(typeof eventName == "object"){ rlm@46: var o = eventName; rlm@46: for(var e in o){ rlm@46: if(propRe.test(e)){ rlm@46: continue; rlm@46: } rlm@46: if(typeof o[e] == "function"){ rlm@46: rlm@46: listen(element, e, o, o[e], o.scope); rlm@46: }else{ rlm@46: rlm@46: listen(element, e, o[e]); rlm@46: } rlm@46: } rlm@46: return; rlm@46: } rlm@46: return listen(element, eventName, options, fn, scope); rlm@46: }, rlm@46: rlm@46: rlm@46: removeListener : function(element, eventName, fn){ rlm@46: return stopListening(element, eventName, fn); rlm@46: }, rlm@46: rlm@46: rlm@46: onDocumentReady : function(fn, scope, options){ rlm@46: if(docReadyState){ rlm@46: docReadyEvent.addListener(fn, scope, options); rlm@46: docReadyEvent.fire(); rlm@46: docReadyEvent.clearListeners(); rlm@46: return; rlm@46: } rlm@46: if(!docReadyEvent){ rlm@46: initDocReady(); rlm@46: } rlm@46: docReadyEvent.addListener(fn, scope, options); rlm@46: }, rlm@46: rlm@46: rlm@46: onWindowResize : function(fn, scope, options){ rlm@46: if(!resizeEvent){ rlm@46: resizeEvent = new Ext.util.Event(); rlm@46: resizeTask = new Ext.util.DelayedTask(function(){ rlm@46: resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); rlm@46: }); rlm@46: E.on(window, "resize", this.fireWindowResize, this); rlm@46: } rlm@46: resizeEvent.addListener(fn, scope, options); rlm@46: }, rlm@46: rlm@46: rlm@46: fireWindowResize : function(){ rlm@46: if(resizeEvent){ rlm@46: if((Ext.isIE||Ext.isAir) && resizeTask){ rlm@46: resizeTask.delay(50); rlm@46: }else{ rlm@46: resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onTextResize : function(fn, scope, options){ rlm@46: if(!textEvent){ rlm@46: textEvent = new Ext.util.Event(); rlm@46: var textEl = new Ext.Element(document.createElement('div')); rlm@46: textEl.dom.className = 'x-text-resize'; rlm@46: textEl.dom.innerHTML = 'X'; rlm@46: textEl.appendTo(document.body); rlm@46: textSize = textEl.dom.offsetHeight; rlm@46: setInterval(function(){ rlm@46: if(textEl.dom.offsetHeight != textSize){ rlm@46: textEvent.fire(textSize, textSize = textEl.dom.offsetHeight); rlm@46: } rlm@46: }, this.textResizeInterval); rlm@46: } rlm@46: textEvent.addListener(fn, scope, options); rlm@46: }, rlm@46: rlm@46: rlm@46: removeResizeListener : function(fn, scope){ rlm@46: if(resizeEvent){ rlm@46: resizeEvent.removeListener(fn, scope); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: fireResize : function(){ rlm@46: if(resizeEvent){ rlm@46: resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); rlm@46: } rlm@46: }, rlm@46: rlm@46: ieDeferSrc : false, rlm@46: rlm@46: textResizeInterval : 50 rlm@46: }; rlm@46: rlm@46: pub.on = pub.addListener; rlm@46: rlm@46: pub.un = pub.removeListener; rlm@46: rlm@46: pub.stoppedMouseDownEvent = new Ext.util.Event(); rlm@46: return pub; rlm@46: }(); rlm@46: rlm@46: Ext.onReady = Ext.EventManager.onDocumentReady; rlm@46: rlm@46: Ext.onReady(function(){ rlm@46: var bd = Ext.getBody(); rlm@46: if(!bd){ return; } rlm@46: rlm@46: var cls = [ rlm@46: Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : 'ext-ie7') rlm@46: : Ext.isGecko ? "ext-gecko" rlm@46: : Ext.isOpera ? "ext-opera" rlm@46: : Ext.isSafari ? "ext-safari" : ""]; rlm@46: rlm@46: if(Ext.isMac){ rlm@46: cls.push("ext-mac"); rlm@46: } rlm@46: if(Ext.isLinux){ rlm@46: cls.push("ext-linux"); rlm@46: } rlm@46: if(Ext.isBorderBox){ rlm@46: cls.push('ext-border-box'); rlm@46: } rlm@46: if(Ext.isStrict){ rlm@46: var p = bd.dom.parentNode; rlm@46: if(p){ rlm@46: p.className += ' ext-strict'; rlm@46: } rlm@46: } rlm@46: bd.addClass(cls.join(' ')); rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.EventObject = function(){ rlm@46: rlm@46: var E = Ext.lib.Event; rlm@46: rlm@46: rlm@46: var safariKeys = { rlm@46: 63234 : 37, rlm@46: 63235 : 39, rlm@46: 63232 : 38, rlm@46: 63233 : 40, rlm@46: 63276 : 33, rlm@46: 63277 : 34, rlm@46: 63272 : 46, rlm@46: 63273 : 36, rlm@46: 63275 : 35 rlm@46: }; rlm@46: rlm@46: rlm@46: var btnMap = Ext.isIE ? {1:0,4:1,2:2} : rlm@46: (Ext.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2}); rlm@46: rlm@46: Ext.EventObjectImpl = function(e){ rlm@46: if(e){ rlm@46: this.setEvent(e.browserEvent || e); rlm@46: } rlm@46: }; rlm@46: Ext.EventObjectImpl.prototype = { rlm@46: rlm@46: browserEvent : null, rlm@46: rlm@46: button : -1, rlm@46: rlm@46: shiftKey : false, rlm@46: rlm@46: ctrlKey : false, rlm@46: rlm@46: altKey : false, rlm@46: rlm@46: rlm@46: BACKSPACE : 8, rlm@46: rlm@46: TAB : 9, rlm@46: rlm@46: RETURN : 13, rlm@46: rlm@46: ENTER : 13, rlm@46: rlm@46: SHIFT : 16, rlm@46: rlm@46: CONTROL : 17, rlm@46: rlm@46: ESC : 27, rlm@46: rlm@46: SPACE : 32, rlm@46: rlm@46: PAGEUP : 33, rlm@46: rlm@46: PAGEDOWN : 34, rlm@46: rlm@46: END : 35, rlm@46: rlm@46: HOME : 36, rlm@46: rlm@46: LEFT : 37, rlm@46: rlm@46: UP : 38, rlm@46: rlm@46: RIGHT : 39, rlm@46: rlm@46: DOWN : 40, rlm@46: rlm@46: DELETE : 46, rlm@46: rlm@46: F5 : 116, rlm@46: rlm@46: rlm@46: setEvent : function(e){ rlm@46: if(e == this || (e && e.browserEvent)){ rlm@46: return e; rlm@46: } rlm@46: this.browserEvent = e; rlm@46: if(e){ rlm@46: rlm@46: this.button = e.button ? btnMap[e.button] : (e.which ? e.which-1 : -1); rlm@46: if(e.type == 'click' && this.button == -1){ rlm@46: this.button = 0; rlm@46: } rlm@46: this.type = e.type; rlm@46: this.shiftKey = e.shiftKey; rlm@46: rlm@46: this.ctrlKey = e.ctrlKey || e.metaKey; rlm@46: this.altKey = e.altKey; rlm@46: rlm@46: this.keyCode = e.keyCode; rlm@46: this.charCode = e.charCode; rlm@46: rlm@46: this.target = E.getTarget(e); rlm@46: rlm@46: this.xy = E.getXY(e); rlm@46: }else{ rlm@46: this.button = -1; rlm@46: this.shiftKey = false; rlm@46: this.ctrlKey = false; rlm@46: this.altKey = false; rlm@46: this.keyCode = 0; rlm@46: this.charCode =0; rlm@46: this.target = null; rlm@46: this.xy = [0, 0]; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: stopEvent : function(){ rlm@46: if(this.browserEvent){ rlm@46: if(this.browserEvent.type == 'mousedown'){ rlm@46: Ext.EventManager.stoppedMouseDownEvent.fire(this); rlm@46: } rlm@46: E.stopEvent(this.browserEvent); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: preventDefault : function(){ rlm@46: if(this.browserEvent){ rlm@46: E.preventDefault(this.browserEvent); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isNavKeyPress : function(){ rlm@46: var k = this.keyCode; rlm@46: k = Ext.isSafari ? (safariKeys[k] || k) : k; rlm@46: return (k >= 33 && k <= 40) || k == this.RETURN || k == this.TAB || k == this.ESC; rlm@46: }, rlm@46: rlm@46: isSpecialKey : function(){ rlm@46: var k = this.keyCode; rlm@46: return (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13 || k == 40 || k == 27 || rlm@46: (k == 16) || (k == 17) || rlm@46: (k >= 18 && k <= 20) || rlm@46: (k >= 33 && k <= 35) || rlm@46: (k >= 36 && k <= 39) || rlm@46: (k >= 44 && k <= 45); rlm@46: }, rlm@46: rlm@46: stopPropagation : function(){ rlm@46: if(this.browserEvent){ rlm@46: if(this.browserEvent.type == 'mousedown'){ rlm@46: Ext.EventManager.stoppedMouseDownEvent.fire(this); rlm@46: } rlm@46: E.stopPropagation(this.browserEvent); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getCharCode : function(){ rlm@46: return this.charCode || this.keyCode; rlm@46: }, rlm@46: rlm@46: rlm@46: getKey : function(){ rlm@46: var k = this.keyCode || this.charCode; rlm@46: return Ext.isSafari ? (safariKeys[k] || k) : k; rlm@46: }, rlm@46: rlm@46: rlm@46: getPageX : function(){ rlm@46: return this.xy[0]; rlm@46: }, rlm@46: rlm@46: rlm@46: getPageY : function(){ rlm@46: return this.xy[1]; rlm@46: }, rlm@46: rlm@46: rlm@46: getTime : function(){ rlm@46: if(this.browserEvent){ rlm@46: return E.getTime(this.browserEvent); rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: getXY : function(){ rlm@46: return this.xy; rlm@46: }, rlm@46: rlm@46: rlm@46: getTarget : function(selector, maxDepth, returnEl){ rlm@46: return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target); rlm@46: }, rlm@46: rlm@46: rlm@46: getRelatedTarget : function(){ rlm@46: if(this.browserEvent){ rlm@46: return E.getRelatedTarget(this.browserEvent); rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: getWheelDelta : function(){ rlm@46: var e = this.browserEvent; rlm@46: var delta = 0; rlm@46: if(e.wheelDelta){ rlm@46: delta = e.wheelDelta/120; rlm@46: }else if(e.detail){ rlm@46: delta = -e.detail/3; rlm@46: } rlm@46: return delta; rlm@46: }, rlm@46: rlm@46: rlm@46: hasModifier : function(){ rlm@46: return ((this.ctrlKey || this.altKey) || this.shiftKey) ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: within : function(el, related){ rlm@46: var t = this[related ? "getRelatedTarget" : "getTarget"](); rlm@46: return t && Ext.fly(el).contains(t); rlm@46: }, rlm@46: rlm@46: getPoint : function(){ rlm@46: return new Ext.lib.Point(this.xy[0], this.xy[1]); rlm@46: } rlm@46: }; rlm@46: rlm@46: return new Ext.EventObjectImpl(); rlm@46: }(); rlm@46: rlm@46: (function(){ rlm@46: var D = Ext.lib.Dom; rlm@46: var E = Ext.lib.Event; rlm@46: var A = Ext.lib.Anim; rlm@46: rlm@46: var propCache = {}; rlm@46: var camelRe = /(-[a-z])/gi; rlm@46: var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); }; rlm@46: var view = document.defaultView; rlm@46: rlm@46: Ext.Element = function(element, forceNew){ rlm@46: var dom = typeof element == "string" ? rlm@46: document.getElementById(element) : element; rlm@46: if(!dom){ return null; rlm@46: } rlm@46: var id = dom.id; rlm@46: if(forceNew !== true && id && Ext.Element.cache[id]){ return Ext.Element.cache[id]; rlm@46: } rlm@46: rlm@46: rlm@46: this.dom = dom; rlm@46: rlm@46: rlm@46: this.id = id || Ext.id(dom); rlm@46: }; rlm@46: rlm@46: var El = Ext.Element; rlm@46: rlm@46: El.prototype = { rlm@46: rlm@46: originalDisplay : "", rlm@46: rlm@46: visibilityMode : 1, rlm@46: rlm@46: defaultUnit : "px", rlm@46: rlm@46: setVisibilityMode : function(visMode){ rlm@46: this.visibilityMode = visMode; rlm@46: return this; rlm@46: }, rlm@46: rlm@46: enableDisplayMode : function(display){ rlm@46: this.setVisibilityMode(El.DISPLAY); rlm@46: if(typeof display != "undefined") this.originalDisplay = display; rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: findParent : function(simpleSelector, maxDepth, returnEl){ rlm@46: var p = this.dom, b = document.body, depth = 0, dq = Ext.DomQuery, stopEl; rlm@46: maxDepth = maxDepth || 50; rlm@46: if(typeof maxDepth != "number"){ rlm@46: stopEl = Ext.getDom(maxDepth); rlm@46: maxDepth = 10; rlm@46: } rlm@46: while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){ rlm@46: if(dq.is(p, simpleSelector)){ rlm@46: return returnEl ? Ext.get(p) : p; rlm@46: } rlm@46: depth++; rlm@46: p = p.parentNode; rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: findParentNode : function(simpleSelector, maxDepth, returnEl){ rlm@46: var p = Ext.fly(this.dom.parentNode, '_internal'); rlm@46: return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null; rlm@46: }, rlm@46: rlm@46: rlm@46: up : function(simpleSelector, maxDepth){ rlm@46: return this.findParentNode(simpleSelector, maxDepth, true); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: is : function(simpleSelector){ rlm@46: return Ext.DomQuery.is(this.dom, simpleSelector); rlm@46: }, rlm@46: rlm@46: rlm@46: animate : function(args, duration, onComplete, easing, animType){ rlm@46: this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: anim : function(args, opt, animType, defaultDur, defaultEase, cb){ rlm@46: animType = animType || 'run'; rlm@46: opt = opt || {}; rlm@46: var anim = Ext.lib.Anim[animType]( rlm@46: this.dom, args, rlm@46: (opt.duration || defaultDur) || .35, rlm@46: (opt.easing || defaultEase) || 'easeOut', rlm@46: function(){ rlm@46: Ext.callback(cb, this); rlm@46: Ext.callback(opt.callback, opt.scope || this, [this, opt]); rlm@46: }, rlm@46: this rlm@46: ); rlm@46: opt.anim = anim; rlm@46: return anim; rlm@46: }, rlm@46: rlm@46: preanim : function(a, i){ rlm@46: return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]}); rlm@46: }, rlm@46: rlm@46: rlm@46: clean : function(forceReclean){ rlm@46: if(this.isCleaned && forceReclean !== true){ rlm@46: return this; rlm@46: } rlm@46: var ns = /\S/; rlm@46: var d = this.dom, n = d.firstChild, ni = -1; rlm@46: while(n){ rlm@46: var nx = n.nextSibling; rlm@46: if(n.nodeType == 3 && !ns.test(n.nodeValue)){ rlm@46: d.removeChild(n); rlm@46: }else{ rlm@46: n.nodeIndex = ++ni; rlm@46: } rlm@46: n = nx; rlm@46: } rlm@46: this.isCleaned = true; rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: scrollIntoView : function(container, hscroll){ rlm@46: var c = Ext.getDom(container) || Ext.getBody().dom; rlm@46: var el = this.dom; rlm@46: rlm@46: var o = this.getOffsetsTo(c), rlm@46: l = o[0] + c.scrollLeft, rlm@46: t = o[1] + c.scrollTop, rlm@46: b = t+el.offsetHeight, rlm@46: r = l+el.offsetWidth; rlm@46: rlm@46: var ch = c.clientHeight; rlm@46: var ct = parseInt(c.scrollTop, 10); rlm@46: var cl = parseInt(c.scrollLeft, 10); rlm@46: var cb = ct + ch; rlm@46: var cr = cl + c.clientWidth; rlm@46: rlm@46: if(el.offsetHeight > ch || t < ct){ rlm@46: c.scrollTop = t; rlm@46: }else if(b > cb){ rlm@46: c.scrollTop = b-ch; rlm@46: } rlm@46: c.scrollTop = c.scrollTop; rlm@46: if(hscroll !== false){ rlm@46: if(el.offsetWidth > c.clientWidth || l < cl){ rlm@46: c.scrollLeft = l; rlm@46: }else if(r > cr){ rlm@46: c.scrollLeft = r-c.clientWidth; rlm@46: } rlm@46: c.scrollLeft = c.scrollLeft; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: scrollChildIntoView : function(child, hscroll){ rlm@46: Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll); rlm@46: }, rlm@46: rlm@46: rlm@46: autoHeight : function(animate, duration, onComplete, easing){ rlm@46: var oldHeight = this.getHeight(); rlm@46: this.clip(); rlm@46: this.setHeight(1); setTimeout(function(){ rlm@46: var height = parseInt(this.dom.scrollHeight, 10); if(!animate){ rlm@46: this.setHeight(height); rlm@46: this.unclip(); rlm@46: if(typeof onComplete == "function"){ rlm@46: onComplete(); rlm@46: } rlm@46: }else{ rlm@46: this.setHeight(oldHeight); this.setHeight(height, animate, duration, function(){ rlm@46: this.unclip(); rlm@46: if(typeof onComplete == "function") onComplete(); rlm@46: }.createDelegate(this), easing); rlm@46: } rlm@46: }.createDelegate(this), 0); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: contains : function(el){ rlm@46: if(!el){return false;} rlm@46: return D.isAncestor(this.dom, el.dom ? el.dom : el); rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(deep) { rlm@46: var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none"); rlm@46: if(deep !== true || !vis){ rlm@46: return vis; rlm@46: } rlm@46: var p = this.dom.parentNode; rlm@46: while(p && p.tagName.toLowerCase() != "body"){ rlm@46: if(!Ext.fly(p, '_isVisible').isVisible()){ rlm@46: return false; rlm@46: } rlm@46: p = p.parentNode; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(selector, unique){ rlm@46: return El.select(selector, unique, this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: query : function(selector, unique){ rlm@46: return Ext.DomQuery.select(selector, this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: child : function(selector, returnDom){ rlm@46: var n = Ext.DomQuery.selectNode(selector, this.dom); rlm@46: return returnDom ? n : Ext.get(n); rlm@46: }, rlm@46: rlm@46: rlm@46: down : function(selector, returnDom){ rlm@46: var n = Ext.DomQuery.selectNode(" > " + selector, this.dom); rlm@46: return returnDom ? n : Ext.get(n); rlm@46: }, rlm@46: rlm@46: rlm@46: initDD : function(group, config, overrides){ rlm@46: var dd = new Ext.dd.DD(Ext.id(this.dom), group, config); rlm@46: return Ext.apply(dd, overrides); rlm@46: }, rlm@46: rlm@46: rlm@46: initDDProxy : function(group, config, overrides){ rlm@46: var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config); rlm@46: return Ext.apply(dd, overrides); rlm@46: }, rlm@46: rlm@46: rlm@46: initDDTarget : function(group, config, overrides){ rlm@46: var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config); rlm@46: return Ext.apply(dd, overrides); rlm@46: }, rlm@46: rlm@46: rlm@46: setVisible : function(visible, animate){ rlm@46: if(!animate || !A){ rlm@46: if(this.visibilityMode == El.DISPLAY){ rlm@46: this.setDisplayed(visible); rlm@46: }else{ rlm@46: this.fixDisplay(); rlm@46: this.dom.style.visibility = visible ? "visible" : "hidden"; rlm@46: } rlm@46: }else{ rlm@46: var dom = this.dom; rlm@46: var visMode = this.visibilityMode; rlm@46: if(visible){ rlm@46: this.setOpacity(.01); rlm@46: this.setVisible(true); rlm@46: } rlm@46: this.anim({opacity: { to: (visible?1:0) }}, rlm@46: this.preanim(arguments, 1), rlm@46: null, .35, 'easeIn', function(){ rlm@46: if(!visible){ rlm@46: if(visMode == El.DISPLAY){ rlm@46: dom.style.display = "none"; rlm@46: }else{ rlm@46: dom.style.visibility = "hidden"; rlm@46: } rlm@46: Ext.get(dom).setOpacity(1); rlm@46: } rlm@46: }); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: isDisplayed : function() { rlm@46: return this.getStyle("display") != "none"; rlm@46: }, rlm@46: rlm@46: rlm@46: toggle : function(animate){ rlm@46: this.setVisible(!this.isVisible(), this.preanim(arguments, 0)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setDisplayed : function(value) { rlm@46: if(typeof value == "boolean"){ rlm@46: value = value ? this.originalDisplay : "none"; rlm@46: } rlm@46: this.setStyle("display", value); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function() { rlm@46: try{ rlm@46: this.dom.focus(); rlm@46: }catch(e){} rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: blur : function() { rlm@46: try{ rlm@46: this.dom.blur(); rlm@46: }catch(e){} rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addClass : function(className){ rlm@46: if(Ext.isArray(className)){ rlm@46: for(var i = 0, len = className.length; i < len; i++) { rlm@46: this.addClass(className[i]); rlm@46: } rlm@46: }else{ rlm@46: if(className && !this.hasClass(className)){ rlm@46: this.dom.className = this.dom.className + " " + className; rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: radioClass : function(className){ rlm@46: var siblings = this.dom.parentNode.childNodes; rlm@46: for(var i = 0; i < siblings.length; i++) { rlm@46: var s = siblings[i]; rlm@46: if(s.nodeType == 1){ rlm@46: Ext.get(s).removeClass(className); rlm@46: } rlm@46: } rlm@46: this.addClass(className); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: removeClass : function(className){ rlm@46: if(!className || !this.dom.className){ rlm@46: return this; rlm@46: } rlm@46: if(Ext.isArray(className)){ rlm@46: for(var i = 0, len = className.length; i < len; i++) { rlm@46: this.removeClass(className[i]); rlm@46: } rlm@46: }else{ rlm@46: if(this.hasClass(className)){ rlm@46: var re = this.classReCache[className]; rlm@46: if (!re) { rlm@46: re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g"); rlm@46: this.classReCache[className] = re; rlm@46: } rlm@46: this.dom.className = rlm@46: this.dom.className.replace(re, " "); rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: classReCache: {}, rlm@46: rlm@46: rlm@46: toggleClass : function(className){ rlm@46: if(this.hasClass(className)){ rlm@46: this.removeClass(className); rlm@46: }else{ rlm@46: this.addClass(className); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: hasClass : function(className){ rlm@46: return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1; rlm@46: }, rlm@46: rlm@46: rlm@46: replaceClass : function(oldClassName, newClassName){ rlm@46: this.removeClass(oldClassName); rlm@46: this.addClass(newClassName); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getStyles : function(){ rlm@46: var a = arguments, len = a.length, r = {}; rlm@46: for(var i = 0; i < len; i++){ rlm@46: r[a[i]] = this.getStyle(a[i]); rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: getStyle : function(){ rlm@46: return view && view.getComputedStyle ? rlm@46: function(prop){ rlm@46: var el = this.dom, v, cs, camel; rlm@46: if(prop == 'float'){ rlm@46: prop = "cssFloat"; rlm@46: } rlm@46: if(v = el.style[prop]){ rlm@46: return v; rlm@46: } rlm@46: if(cs = view.getComputedStyle(el, "")){ rlm@46: if(!(camel = propCache[prop])){ rlm@46: camel = propCache[prop] = prop.replace(camelRe, camelFn); rlm@46: } rlm@46: return cs[camel]; rlm@46: } rlm@46: return null; rlm@46: } : rlm@46: function(prop){ rlm@46: var el = this.dom, v, cs, camel; rlm@46: if(prop == 'opacity'){ rlm@46: if(typeof el.style.filter == 'string'){ rlm@46: var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i); rlm@46: if(m){ rlm@46: var fv = parseFloat(m[1]); rlm@46: if(!isNaN(fv)){ rlm@46: return fv ? fv / 100 : 0; rlm@46: } rlm@46: } rlm@46: } rlm@46: return 1; rlm@46: }else if(prop == 'float'){ rlm@46: prop = "styleFloat"; rlm@46: } rlm@46: if(!(camel = propCache[prop])){ rlm@46: camel = propCache[prop] = prop.replace(camelRe, camelFn); rlm@46: } rlm@46: if(v = el.style[camel]){ rlm@46: return v; rlm@46: } rlm@46: if(cs = el.currentStyle){ rlm@46: return cs[camel]; rlm@46: } rlm@46: return null; rlm@46: }; rlm@46: }(), rlm@46: rlm@46: rlm@46: setStyle : function(prop, value){ rlm@46: if(typeof prop == "string"){ rlm@46: var camel; rlm@46: if(!(camel = propCache[prop])){ rlm@46: camel = propCache[prop] = prop.replace(camelRe, camelFn); rlm@46: } rlm@46: if(camel == 'opacity') { rlm@46: this.setOpacity(value); rlm@46: }else{ rlm@46: this.dom.style[camel] = value; rlm@46: } rlm@46: }else{ rlm@46: for(var style in prop){ rlm@46: if(typeof prop[style] != "function"){ rlm@46: this.setStyle(style, prop[style]); rlm@46: } rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: applyStyles : function(style){ rlm@46: Ext.DomHelper.applyStyles(this.dom, style); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getX : function(){ rlm@46: return D.getX(this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: getY : function(){ rlm@46: return D.getY(this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: getXY : function(){ rlm@46: return D.getXY(this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: getOffsetsTo : function(el){ rlm@46: var o = this.getXY(); rlm@46: var e = Ext.fly(el, '_internal').getXY(); rlm@46: return [o[0]-e[0],o[1]-e[1]]; rlm@46: }, rlm@46: rlm@46: rlm@46: setX : function(x, animate){ rlm@46: if(!animate || !A){ rlm@46: D.setX(this.dom, x); rlm@46: }else{ rlm@46: this.setXY([x, this.getY()], this.preanim(arguments, 1)); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setY : function(y, animate){ rlm@46: if(!animate || !A){ rlm@46: D.setY(this.dom, y); rlm@46: }else{ rlm@46: this.setXY([this.getX(), y], this.preanim(arguments, 1)); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setLeft : function(left){ rlm@46: this.setStyle("left", this.addUnits(left)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setTop : function(top){ rlm@46: this.setStyle("top", this.addUnits(top)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setRight : function(right){ rlm@46: this.setStyle("right", this.addUnits(right)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setBottom : function(bottom){ rlm@46: this.setStyle("bottom", this.addUnits(bottom)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setXY : function(pos, animate){ rlm@46: if(!animate || !A){ rlm@46: D.setXY(this.dom, pos); rlm@46: }else{ rlm@46: this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion'); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setLocation : function(x, y, animate){ rlm@46: this.setXY([x, y], this.preanim(arguments, 2)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: moveTo : function(x, y, animate){ rlm@46: this.setXY([x, y], this.preanim(arguments, 2)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getRegion : function(){ rlm@46: return D.getRegion(this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: getHeight : function(contentHeight){ rlm@46: var h = this.dom.offsetHeight || 0; rlm@46: h = contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb"); rlm@46: return h < 0 ? 0 : h; rlm@46: }, rlm@46: rlm@46: rlm@46: getWidth : function(contentWidth){ rlm@46: var w = this.dom.offsetWidth || 0; rlm@46: w = contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr"); rlm@46: return w < 0 ? 0 : w; rlm@46: }, rlm@46: rlm@46: rlm@46: getComputedHeight : function(){ rlm@46: var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight); rlm@46: if(!h){ rlm@46: h = parseInt(this.getStyle('height'), 10) || 0; rlm@46: if(!this.isBorderBox()){ rlm@46: h += this.getFrameWidth('tb'); rlm@46: } rlm@46: } rlm@46: return h; rlm@46: }, rlm@46: rlm@46: rlm@46: getComputedWidth : function(){ rlm@46: var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth); rlm@46: if(!w){ rlm@46: w = parseInt(this.getStyle('width'), 10) || 0; rlm@46: if(!this.isBorderBox()){ rlm@46: w += this.getFrameWidth('lr'); rlm@46: } rlm@46: } rlm@46: return w; rlm@46: }, rlm@46: rlm@46: rlm@46: getSize : function(contentSize){ rlm@46: return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)}; rlm@46: }, rlm@46: rlm@46: getStyleSize : function(){ rlm@46: var w, h, d = this.dom, s = d.style; rlm@46: if(s.width && s.width != 'auto'){ rlm@46: w = parseInt(s.width, 10); rlm@46: if(Ext.isBorderBox){ rlm@46: w -= this.getFrameWidth('lr'); rlm@46: } rlm@46: } rlm@46: if(s.height && s.height != 'auto'){ rlm@46: h = parseInt(s.height, 10); rlm@46: if(Ext.isBorderBox){ rlm@46: h -= this.getFrameWidth('tb'); rlm@46: } rlm@46: } rlm@46: return {width: w || this.getWidth(true), height: h || this.getHeight(true)}; rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: getViewSize : function(){ rlm@46: var d = this.dom, doc = document, aw = 0, ah = 0; rlm@46: if(d == doc || d == doc.body){ rlm@46: return {width : D.getViewWidth(), height: D.getViewHeight()}; rlm@46: }else{ rlm@46: return { rlm@46: width : d.clientWidth, rlm@46: height: d.clientHeight rlm@46: }; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(asNumber){ rlm@46: return asNumber ? parseInt(this.dom.value, 10) : this.dom.value; rlm@46: }, rlm@46: rlm@46: adjustWidth : function(width){ rlm@46: if(typeof width == "number"){ rlm@46: if(this.autoBoxAdjust && !this.isBorderBox()){ rlm@46: width -= (this.getBorderWidth("lr") + this.getPadding("lr")); rlm@46: } rlm@46: if(width < 0){ rlm@46: width = 0; rlm@46: } rlm@46: } rlm@46: return width; rlm@46: }, rlm@46: rlm@46: adjustHeight : function(height){ rlm@46: if(typeof height == "number"){ rlm@46: if(this.autoBoxAdjust && !this.isBorderBox()){ rlm@46: height -= (this.getBorderWidth("tb") + this.getPadding("tb")); rlm@46: } rlm@46: if(height < 0){ rlm@46: height = 0; rlm@46: } rlm@46: } rlm@46: return height; rlm@46: }, rlm@46: rlm@46: rlm@46: setWidth : function(width, animate){ rlm@46: width = this.adjustWidth(width); rlm@46: if(!animate || !A){ rlm@46: this.dom.style.width = this.addUnits(width); rlm@46: }else{ rlm@46: this.anim({width: {to: width}}, this.preanim(arguments, 1)); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setHeight : function(height, animate){ rlm@46: height = this.adjustHeight(height); rlm@46: if(!animate || !A){ rlm@46: this.dom.style.height = this.addUnits(height); rlm@46: }else{ rlm@46: this.anim({height: {to: height}}, this.preanim(arguments, 1)); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setSize : function(width, height, animate){ rlm@46: if(typeof width == "object"){ height = width.height; width = width.width; rlm@46: } rlm@46: width = this.adjustWidth(width); height = this.adjustHeight(height); rlm@46: if(!animate || !A){ rlm@46: this.dom.style.width = this.addUnits(width); rlm@46: this.dom.style.height = this.addUnits(height); rlm@46: }else{ rlm@46: this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2)); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setBounds : function(x, y, width, height, animate){ rlm@46: if(!animate || !A){ rlm@46: this.setSize(width, height); rlm@46: this.setLocation(x, y); rlm@46: }else{ rlm@46: width = this.adjustWidth(width); height = this.adjustHeight(height); rlm@46: this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}}, rlm@46: this.preanim(arguments, 4), 'motion'); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setRegion : function(region, animate){ rlm@46: this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addListener : function(eventName, fn, scope, options){ rlm@46: Ext.EventManager.on(this.dom, eventName, fn, scope || this, options); rlm@46: }, rlm@46: rlm@46: rlm@46: removeListener : function(eventName, fn){ rlm@46: Ext.EventManager.removeListener(this.dom, eventName, fn); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: removeAllListeners : function(){ rlm@46: E.purgeElement(this.dom); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: relayEvent : function(eventName, observable){ rlm@46: this.on(eventName, function(e){ rlm@46: observable.fireEvent(eventName, e); rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: setOpacity : function(opacity, animate){ rlm@46: if(!animate || !A){ rlm@46: var s = this.dom.style; rlm@46: if(Ext.isIE){ rlm@46: s.zoom = 1; rlm@46: s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") + rlm@46: (opacity == 1 ? "" : " alpha(opacity=" + opacity * 100 + ")"); rlm@46: }else{ rlm@46: s.opacity = opacity; rlm@46: } rlm@46: }else{ rlm@46: this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn'); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getLeft : function(local){ rlm@46: if(!local){ rlm@46: return this.getX(); rlm@46: }else{ rlm@46: return parseInt(this.getStyle("left"), 10) || 0; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getRight : function(local){ rlm@46: if(!local){ rlm@46: return this.getX() + this.getWidth(); rlm@46: }else{ rlm@46: return (this.getLeft(true) + this.getWidth()) || 0; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTop : function(local) { rlm@46: if(!local){ rlm@46: return this.getY(); rlm@46: }else{ rlm@46: return parseInt(this.getStyle("top"), 10) || 0; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getBottom : function(local){ rlm@46: if(!local){ rlm@46: return this.getY() + this.getHeight(); rlm@46: }else{ rlm@46: return (this.getTop(true) + this.getHeight()) || 0; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: position : function(pos, zIndex, x, y){ rlm@46: if(!pos){ rlm@46: if(this.getStyle('position') == 'static'){ rlm@46: this.setStyle('position', 'relative'); rlm@46: } rlm@46: }else{ rlm@46: this.setStyle("position", pos); rlm@46: } rlm@46: if(zIndex){ rlm@46: this.setStyle("z-index", zIndex); rlm@46: } rlm@46: if(x !== undefined && y !== undefined){ rlm@46: this.setXY([x, y]); rlm@46: }else if(x !== undefined){ rlm@46: this.setX(x); rlm@46: }else if(y !== undefined){ rlm@46: this.setY(y); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clearPositioning : function(value){ rlm@46: value = value ||''; rlm@46: this.setStyle({ rlm@46: "left": value, rlm@46: "right": value, rlm@46: "top": value, rlm@46: "bottom": value, rlm@46: "z-index": "", rlm@46: "position" : "static" rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getPositioning : function(){ rlm@46: var l = this.getStyle("left"); rlm@46: var t = this.getStyle("top"); rlm@46: return { rlm@46: "position" : this.getStyle("position"), rlm@46: "left" : l, rlm@46: "right" : l ? "" : this.getStyle("right"), rlm@46: "top" : t, rlm@46: "bottom" : t ? "" : this.getStyle("bottom"), rlm@46: "z-index" : this.getStyle("z-index") rlm@46: }; rlm@46: }, rlm@46: rlm@46: rlm@46: getBorderWidth : function(side){ rlm@46: return this.addStyles(side, El.borders); rlm@46: }, rlm@46: rlm@46: rlm@46: getPadding : function(side){ rlm@46: return this.addStyles(side, El.paddings); rlm@46: }, rlm@46: rlm@46: rlm@46: setPositioning : function(pc){ rlm@46: this.applyStyles(pc); rlm@46: if(pc.right == "auto"){ rlm@46: this.dom.style.right = ""; rlm@46: } rlm@46: if(pc.bottom == "auto"){ rlm@46: this.dom.style.bottom = ""; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: fixDisplay : function(){ rlm@46: if(this.getStyle("display") == "none"){ rlm@46: this.setStyle("visibility", "hidden"); rlm@46: this.setStyle("display", this.originalDisplay); if(this.getStyle("display") == "none"){ this.setStyle("display", "block"); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: setOverflow : function(v){ rlm@46: if(v=='auto' && Ext.isMac && Ext.isGecko){ this.dom.style.overflow = 'hidden'; rlm@46: (function(){this.dom.style.overflow = 'auto';}).defer(1, this); rlm@46: }else{ rlm@46: this.dom.style.overflow = v; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setLeftTop : function(left, top){ rlm@46: this.dom.style.left = this.addUnits(left); rlm@46: this.dom.style.top = this.addUnits(top); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: move : function(direction, distance, animate){ rlm@46: var xy = this.getXY(); rlm@46: direction = direction.toLowerCase(); rlm@46: switch(direction){ rlm@46: case "l": rlm@46: case "left": rlm@46: this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2)); rlm@46: break; rlm@46: case "r": rlm@46: case "right": rlm@46: this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2)); rlm@46: break; rlm@46: case "t": rlm@46: case "top": rlm@46: case "up": rlm@46: this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2)); rlm@46: break; rlm@46: case "b": rlm@46: case "bottom": rlm@46: case "down": rlm@46: this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2)); rlm@46: break; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: clip : function(){ rlm@46: if(!this.isClipped){ rlm@46: this.isClipped = true; rlm@46: this.originalClip = { rlm@46: "o": this.getStyle("overflow"), rlm@46: "x": this.getStyle("overflow-x"), rlm@46: "y": this.getStyle("overflow-y") rlm@46: }; rlm@46: this.setStyle("overflow", "hidden"); rlm@46: this.setStyle("overflow-x", "hidden"); rlm@46: this.setStyle("overflow-y", "hidden"); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: unclip : function(){ rlm@46: if(this.isClipped){ rlm@46: this.isClipped = false; rlm@46: var o = this.originalClip; rlm@46: if(o.o){this.setStyle("overflow", o.o);} rlm@46: if(o.x){this.setStyle("overflow-x", o.x);} rlm@46: if(o.y){this.setStyle("overflow-y", o.y);} rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: getAnchorXY : function(anchor, local, s){ rlm@46: rlm@46: var w, h, vp = false; rlm@46: if(!s){ rlm@46: var d = this.dom; rlm@46: if(d == document.body || d == document){ rlm@46: vp = true; rlm@46: w = D.getViewWidth(); h = D.getViewHeight(); rlm@46: }else{ rlm@46: w = this.getWidth(); h = this.getHeight(); rlm@46: } rlm@46: }else{ rlm@46: w = s.width; h = s.height; rlm@46: } rlm@46: var x = 0, y = 0, r = Math.round; rlm@46: switch((anchor || "tl").toLowerCase()){ rlm@46: case "c": rlm@46: x = r(w*.5); rlm@46: y = r(h*.5); rlm@46: break; rlm@46: case "t": rlm@46: x = r(w*.5); rlm@46: y = 0; rlm@46: break; rlm@46: case "l": rlm@46: x = 0; rlm@46: y = r(h*.5); rlm@46: break; rlm@46: case "r": rlm@46: x = w; rlm@46: y = r(h*.5); rlm@46: break; rlm@46: case "b": rlm@46: x = r(w*.5); rlm@46: y = h; rlm@46: break; rlm@46: case "tl": rlm@46: x = 0; rlm@46: y = 0; rlm@46: break; rlm@46: case "bl": rlm@46: x = 0; rlm@46: y = h; rlm@46: break; rlm@46: case "br": rlm@46: x = w; rlm@46: y = h; rlm@46: break; rlm@46: case "tr": rlm@46: x = w; rlm@46: y = 0; rlm@46: break; rlm@46: } rlm@46: if(local === true){ rlm@46: return [x, y]; rlm@46: } rlm@46: if(vp){ rlm@46: var sc = this.getScroll(); rlm@46: return [x + sc.left, y + sc.top]; rlm@46: } rlm@46: var o = this.getXY(); rlm@46: return [x+o[0], y+o[1]]; rlm@46: }, rlm@46: rlm@46: rlm@46: getAlignToXY : function(el, p, o){ rlm@46: el = Ext.get(el); rlm@46: if(!el || !el.dom){ rlm@46: throw "Element.alignToXY with an element that doesn't exist"; rlm@46: } rlm@46: var d = this.dom; rlm@46: var c = false; var p1 = "", p2 = ""; rlm@46: o = o || [0,0]; rlm@46: rlm@46: if(!p){ rlm@46: p = "tl-bl"; rlm@46: }else if(p == "?"){ rlm@46: p = "tl-bl?"; rlm@46: }else if(p.indexOf("-") == -1){ rlm@46: p = "tl-" + p; rlm@46: } rlm@46: p = p.toLowerCase(); rlm@46: var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/); rlm@46: if(!m){ rlm@46: throw "Element.alignTo with an invalid alignment " + p; rlm@46: } rlm@46: p1 = m[1]; p2 = m[2]; c = !!m[3]; rlm@46: rlm@46: var a1 = this.getAnchorXY(p1, true); rlm@46: var a2 = el.getAnchorXY(p2, false); rlm@46: rlm@46: var x = a2[0] - a1[0] + o[0]; rlm@46: var y = a2[1] - a1[1] + o[1]; rlm@46: rlm@46: if(c){ rlm@46: var w = this.getWidth(), h = this.getHeight(), r = el.getRegion(); rlm@46: var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5; rlm@46: rlm@46: var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1); rlm@46: var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1); rlm@46: var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t")); rlm@46: var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r")); rlm@46: rlm@46: var doc = document; rlm@46: var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5; rlm@46: var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5; rlm@46: rlm@46: if((x+w) > dw + scrollX){ rlm@46: x = swapX ? r.left-w : dw+scrollX-w; rlm@46: } rlm@46: if(x < scrollX){ rlm@46: x = swapX ? r.right : scrollX; rlm@46: } rlm@46: if((y+h) > dh + scrollY){ rlm@46: y = swapY ? r.top-h : dh+scrollY-h; rlm@46: } rlm@46: if (y < scrollY){ rlm@46: y = swapY ? r.bottom : scrollY; rlm@46: } rlm@46: } rlm@46: return [x,y]; rlm@46: }, rlm@46: rlm@46: getConstrainToXY : function(){ rlm@46: var os = {top:0, left:0, bottom:0, right: 0}; rlm@46: rlm@46: return function(el, local, offsets, proposedXY){ rlm@46: el = Ext.get(el); rlm@46: offsets = offsets ? Ext.applyIf(offsets, os) : os; rlm@46: rlm@46: var vw, vh, vx = 0, vy = 0; rlm@46: if(el.dom == document.body || el.dom == document){ rlm@46: vw = Ext.lib.Dom.getViewWidth(); rlm@46: vh = Ext.lib.Dom.getViewHeight(); rlm@46: }else{ rlm@46: vw = el.dom.clientWidth; rlm@46: vh = el.dom.clientHeight; rlm@46: if(!local){ rlm@46: var vxy = el.getXY(); rlm@46: vx = vxy[0]; rlm@46: vy = vxy[1]; rlm@46: } rlm@46: } rlm@46: rlm@46: var s = el.getScroll(); rlm@46: rlm@46: vx += offsets.left + s.left; rlm@46: vy += offsets.top + s.top; rlm@46: rlm@46: vw -= offsets.right; rlm@46: vh -= offsets.bottom; rlm@46: rlm@46: var vr = vx+vw; rlm@46: var vb = vy+vh; rlm@46: rlm@46: var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]); rlm@46: var x = xy[0], y = xy[1]; rlm@46: var w = this.dom.offsetWidth, h = this.dom.offsetHeight; rlm@46: rlm@46: var moved = false; rlm@46: rlm@46: if((x + w) > vr){ rlm@46: x = vr - w; rlm@46: moved = true; rlm@46: } rlm@46: if((y + h) > vb){ rlm@46: y = vb - h; rlm@46: moved = true; rlm@46: } rlm@46: if(x < vx){ rlm@46: x = vx; rlm@46: moved = true; rlm@46: } rlm@46: if(y < vy){ rlm@46: y = vy; rlm@46: moved = true; rlm@46: } rlm@46: return moved ? [x, y] : false; rlm@46: }; rlm@46: }(), rlm@46: rlm@46: adjustForConstraints : function(xy, parent, offsets){ rlm@46: return this.getConstrainToXY(parent || document, false, offsets, xy) || xy; rlm@46: }, rlm@46: rlm@46: rlm@46: alignTo : function(element, position, offsets, animate){ rlm@46: var xy = this.getAlignToXY(element, position, offsets); rlm@46: this.setXY(xy, this.preanim(arguments, 3)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){ rlm@46: var action = function(){ rlm@46: this.alignTo(el, alignment, offsets, animate); rlm@46: Ext.callback(callback, this); rlm@46: }; rlm@46: Ext.EventManager.onWindowResize(action, this); rlm@46: var tm = typeof monitorScroll; rlm@46: if(tm != 'undefined'){ rlm@46: Ext.EventManager.on(window, 'scroll', action, this, rlm@46: {buffer: tm == 'number' ? monitorScroll : 50}); rlm@46: } rlm@46: action.call(this); return this; rlm@46: }, rlm@46: rlm@46: clearOpacity : function(){ rlm@46: if (window.ActiveXObject) { rlm@46: if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){ rlm@46: this.dom.style.filter = ""; rlm@46: } rlm@46: } else { rlm@46: this.dom.style.opacity = ""; rlm@46: this.dom.style["-moz-opacity"] = ""; rlm@46: this.dom.style["-khtml-opacity"] = ""; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(animate){ rlm@46: this.setVisible(false, this.preanim(arguments, 0)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(animate){ rlm@46: this.setVisible(true, this.preanim(arguments, 0)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addUnits : function(size){ rlm@46: return Ext.Element.addUnits(size, this.defaultUnit); rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(html, loadScripts, callback){ rlm@46: if(typeof html == "undefined"){ rlm@46: html = ""; rlm@46: } rlm@46: if(loadScripts !== true){ rlm@46: this.dom.innerHTML = html; rlm@46: if(typeof callback == "function"){ rlm@46: callback(); rlm@46: } rlm@46: return this; rlm@46: } rlm@46: var id = Ext.id(); rlm@46: var dom = this.dom; rlm@46: rlm@46: html += ''; rlm@46: rlm@46: E.onAvailable(id, function(){ rlm@46: var hd = document.getElementsByTagName("head")[0]; rlm@46: var re = /(?:]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig; rlm@46: var srcRe = /\ssrc=([\'\"])(.*?)\1/i; rlm@46: var typeRe = /\stype=([\'\"])(.*?)\1/i; rlm@46: rlm@46: var match; rlm@46: while(match = re.exec(html)){ rlm@46: var attrs = match[1]; rlm@46: var srcMatch = attrs ? attrs.match(srcRe) : false; rlm@46: if(srcMatch && srcMatch[2]){ rlm@46: var s = document.createElement("script"); rlm@46: s.src = srcMatch[2]; rlm@46: var typeMatch = attrs.match(typeRe); rlm@46: if(typeMatch && typeMatch[2]){ rlm@46: s.type = typeMatch[2]; rlm@46: } rlm@46: hd.appendChild(s); rlm@46: }else if(match[2] && match[2].length > 0){ rlm@46: if(window.execScript) { rlm@46: window.execScript(match[2]); rlm@46: } else { rlm@46: window.eval(match[2]); rlm@46: } rlm@46: } rlm@46: } rlm@46: var el = document.getElementById(id); rlm@46: if(el){Ext.removeNode(el);} rlm@46: if(typeof callback == "function"){ rlm@46: callback(); rlm@46: } rlm@46: }); rlm@46: dom.innerHTML = html.replace(/(?:)((\n|\r|.)*?)(?:<\/script>)/ig, ""); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(){ rlm@46: var um = this.getUpdater(); rlm@46: um.update.apply(um, arguments); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getUpdater : function(){ rlm@46: if(!this.updateManager){ rlm@46: this.updateManager = new Ext.Updater(this); rlm@46: } rlm@46: return this.updateManager; rlm@46: }, rlm@46: rlm@46: rlm@46: unselectable : function(){ rlm@46: this.dom.unselectable = "on"; rlm@46: this.swallowEvent("selectstart", true); rlm@46: this.applyStyles("-moz-user-select:none;-khtml-user-select:none;"); rlm@46: this.addClass("x-unselectable"); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getCenterXY : function(){ rlm@46: return this.getAlignToXY(document, 'c-c'); rlm@46: }, rlm@46: rlm@46: rlm@46: center : function(centerIn){ rlm@46: this.alignTo(centerIn || document, 'c-c'); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: isBorderBox : function(){ rlm@46: return noBoxAdjust[this.dom.tagName.toLowerCase()] || Ext.isBorderBox; rlm@46: }, rlm@46: rlm@46: rlm@46: getBox : function(contentBox, local){ rlm@46: var xy; rlm@46: if(!local){ rlm@46: xy = this.getXY(); rlm@46: }else{ rlm@46: var left = parseInt(this.getStyle("left"), 10) || 0; rlm@46: var top = parseInt(this.getStyle("top"), 10) || 0; rlm@46: xy = [left, top]; rlm@46: } rlm@46: var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx; rlm@46: if(!contentBox){ rlm@46: bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h}; rlm@46: }else{ rlm@46: var l = this.getBorderWidth("l")+this.getPadding("l"); rlm@46: var r = this.getBorderWidth("r")+this.getPadding("r"); rlm@46: var t = this.getBorderWidth("t")+this.getPadding("t"); rlm@46: var b = this.getBorderWidth("b")+this.getPadding("b"); rlm@46: bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)}; rlm@46: } rlm@46: bx.right = bx.x + bx.width; rlm@46: bx.bottom = bx.y + bx.height; rlm@46: return bx; rlm@46: }, rlm@46: rlm@46: rlm@46: getFrameWidth : function(sides, onlyContentBox){ rlm@46: return onlyContentBox && Ext.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides)); rlm@46: }, rlm@46: rlm@46: rlm@46: setBox : function(box, adjust, animate){ rlm@46: var w = box.width, h = box.height; rlm@46: if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){ rlm@46: w -= (this.getBorderWidth("lr") + this.getPadding("lr")); rlm@46: h -= (this.getBorderWidth("tb") + this.getPadding("tb")); rlm@46: } rlm@46: this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: repaint : function(){ rlm@46: var dom = this.dom; rlm@46: this.addClass("x-repaint"); rlm@46: setTimeout(function(){ rlm@46: Ext.get(dom).removeClass("x-repaint"); rlm@46: }, 1); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getMargins : function(side){ rlm@46: if(!side){ rlm@46: return { rlm@46: top: parseInt(this.getStyle("margin-top"), 10) || 0, rlm@46: left: parseInt(this.getStyle("margin-left"), 10) || 0, rlm@46: bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0, rlm@46: right: parseInt(this.getStyle("margin-right"), 10) || 0 rlm@46: }; rlm@46: }else{ rlm@46: return this.addStyles(side, El.margins); rlm@46: } rlm@46: }, rlm@46: rlm@46: addStyles : function(sides, styles){ rlm@46: var val = 0, v, w; rlm@46: for(var i = 0, len = sides.length; i < len; i++){ rlm@46: v = this.getStyle(styles[sides.charAt(i)]); rlm@46: if(v){ rlm@46: w = parseInt(v, 10); rlm@46: if(w){ val += (w >= 0 ? w : -1 * w); } rlm@46: } rlm@46: } rlm@46: return val; rlm@46: }, rlm@46: rlm@46: rlm@46: createProxy : function(config, renderTo, matchBox){ rlm@46: config = typeof config == "object" ? rlm@46: config : {tag : "div", cls: config}; rlm@46: rlm@46: var proxy; rlm@46: if(renderTo){ rlm@46: proxy = Ext.DomHelper.append(renderTo, config, true); rlm@46: }else { rlm@46: proxy = Ext.DomHelper.insertBefore(this.dom, config, true); rlm@46: } rlm@46: if(matchBox){ rlm@46: proxy.setBox(this.getBox()); rlm@46: } rlm@46: return proxy; rlm@46: }, rlm@46: rlm@46: rlm@46: mask : function(msg, msgCls){ rlm@46: if(this.getStyle("position") == "static"){ rlm@46: this.setStyle("position", "relative"); rlm@46: } rlm@46: if(this._maskMsg){ rlm@46: this._maskMsg.remove(); rlm@46: } rlm@46: if(this._mask){ rlm@46: this._mask.remove(); rlm@46: } rlm@46: rlm@46: this._mask = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask"}, true); rlm@46: rlm@46: this.addClass("x-masked"); rlm@46: this._mask.setDisplayed(true); rlm@46: if(typeof msg == 'string'){ rlm@46: this._maskMsg = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask-msg", cn:{tag:'div'}}, true); rlm@46: var mm = this._maskMsg; rlm@46: mm.dom.className = msgCls ? "ext-el-mask-msg " + msgCls : "ext-el-mask-msg"; rlm@46: mm.dom.firstChild.innerHTML = msg; rlm@46: mm.setDisplayed(true); rlm@46: mm.center(this); rlm@46: } rlm@46: if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && this.getStyle('height') == 'auto'){ this._mask.setSize(this.dom.clientWidth, this.getHeight()); rlm@46: } rlm@46: return this._mask; rlm@46: }, rlm@46: rlm@46: rlm@46: unmask : function(){ rlm@46: if(this._mask){ rlm@46: if(this._maskMsg){ rlm@46: this._maskMsg.remove(); rlm@46: delete this._maskMsg; rlm@46: } rlm@46: this._mask.remove(); rlm@46: delete this._mask; rlm@46: } rlm@46: this.removeClass("x-masked"); rlm@46: }, rlm@46: rlm@46: rlm@46: isMasked : function(){ rlm@46: return this._mask && this._mask.isVisible(); rlm@46: }, rlm@46: rlm@46: rlm@46: createShim : function(){ rlm@46: var el = document.createElement('iframe'); rlm@46: el.frameBorder = 'no'; rlm@46: el.className = 'ext-shim'; rlm@46: if(Ext.isIE && Ext.isSecure){ rlm@46: el.src = Ext.SSL_SECURE_URL; rlm@46: } rlm@46: var shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom)); rlm@46: shim.autoBoxAdjust = false; rlm@46: return shim; rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(){ rlm@46: Ext.removeNode(this.dom); rlm@46: delete El.cache[this.dom.id]; rlm@46: }, rlm@46: rlm@46: rlm@46: hover : function(overFn, outFn, scope){ rlm@46: var preOverFn = function(e){ rlm@46: if(!e.within(this, true)){ rlm@46: overFn.apply(scope || this, arguments); rlm@46: } rlm@46: }; rlm@46: var preOutFn = function(e){ rlm@46: if(!e.within(this, true)){ rlm@46: outFn.apply(scope || this, arguments); rlm@46: } rlm@46: }; rlm@46: this.on("mouseover", preOverFn, this.dom); rlm@46: this.on("mouseout", preOutFn, this.dom); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addClassOnOver : function(className){ rlm@46: this.hover( rlm@46: function(){ rlm@46: Ext.fly(this, '_internal').addClass(className); rlm@46: }, rlm@46: function(){ rlm@46: Ext.fly(this, '_internal').removeClass(className); rlm@46: } rlm@46: ); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addClassOnFocus : function(className){ rlm@46: this.on("focus", function(){ rlm@46: Ext.fly(this, '_internal').addClass(className); rlm@46: }, this.dom); rlm@46: this.on("blur", function(){ rlm@46: Ext.fly(this, '_internal').removeClass(className); rlm@46: }, this.dom); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: addClassOnClick : function(className){ rlm@46: var dom = this.dom; rlm@46: this.on("mousedown", function(){ rlm@46: Ext.fly(dom, '_internal').addClass(className); rlm@46: var d = Ext.getDoc(); rlm@46: var fn = function(){ rlm@46: Ext.fly(dom, '_internal').removeClass(className); rlm@46: d.removeListener("mouseup", fn); rlm@46: }; rlm@46: d.on("mouseup", fn); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: swallowEvent : function(eventName, preventDefault){ rlm@46: var fn = function(e){ rlm@46: e.stopPropagation(); rlm@46: if(preventDefault){ rlm@46: e.preventDefault(); rlm@46: } rlm@46: }; rlm@46: if(Ext.isArray(eventName)){ rlm@46: for(var i = 0, len = eventName.length; i < len; i++){ rlm@46: this.on(eventName[i], fn); rlm@46: } rlm@46: return this; rlm@46: } rlm@46: this.on(eventName, fn); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: parent : function(selector, returnDom){ rlm@46: return this.matchNode('parentNode', 'parentNode', selector, returnDom); rlm@46: }, rlm@46: rlm@46: rlm@46: next : function(selector, returnDom){ rlm@46: return this.matchNode('nextSibling', 'nextSibling', selector, returnDom); rlm@46: }, rlm@46: rlm@46: rlm@46: prev : function(selector, returnDom){ rlm@46: return this.matchNode('previousSibling', 'previousSibling', selector, returnDom); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: first : function(selector, returnDom){ rlm@46: return this.matchNode('nextSibling', 'firstChild', selector, returnDom); rlm@46: }, rlm@46: rlm@46: rlm@46: last : function(selector, returnDom){ rlm@46: return this.matchNode('previousSibling', 'lastChild', selector, returnDom); rlm@46: }, rlm@46: rlm@46: matchNode : function(dir, start, selector, returnDom){ rlm@46: var n = this.dom[start]; rlm@46: while(n){ rlm@46: if(n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))){ rlm@46: return !returnDom ? Ext.get(n) : n; rlm@46: } rlm@46: n = n[dir]; rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: appendChild: function(el){ rlm@46: el = Ext.get(el); rlm@46: el.appendTo(this); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: createChild: function(config, insertBefore, returnDom){ rlm@46: config = config || {tag:'div'}; rlm@46: if(insertBefore){ rlm@46: return Ext.DomHelper.insertBefore(insertBefore, config, returnDom !== true); rlm@46: } rlm@46: return Ext.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true); rlm@46: }, rlm@46: rlm@46: rlm@46: appendTo: function(el){ rlm@46: el = Ext.getDom(el); rlm@46: el.appendChild(this.dom); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: insertBefore: function(el){ rlm@46: el = Ext.getDom(el); rlm@46: el.parentNode.insertBefore(this.dom, el); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: insertAfter: function(el){ rlm@46: el = Ext.getDom(el); rlm@46: el.parentNode.insertBefore(this.dom, el.nextSibling); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: insertFirst: function(el, returnDom){ rlm@46: el = el || {}; rlm@46: if(typeof el == 'object' && !el.nodeType && !el.dom){ return this.createChild(el, this.dom.firstChild, returnDom); rlm@46: }else{ rlm@46: el = Ext.getDom(el); rlm@46: this.dom.insertBefore(el, this.dom.firstChild); rlm@46: return !returnDom ? Ext.get(el) : el; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: insertSibling: function(el, where, returnDom){ rlm@46: var rt; rlm@46: if(Ext.isArray(el)){ rlm@46: for(var i = 0, len = el.length; i < len; i++){ rlm@46: rt = this.insertSibling(el[i], where, returnDom); rlm@46: } rlm@46: return rt; rlm@46: } rlm@46: where = where ? where.toLowerCase() : 'before'; rlm@46: el = el || {}; rlm@46: var refNode = where == 'before' ? this.dom : this.dom.nextSibling; rlm@46: rlm@46: if(typeof el == 'object' && !el.nodeType && !el.dom){ if(where == 'after' && !this.dom.nextSibling){ rlm@46: rt = Ext.DomHelper.append(this.dom.parentNode, el, !returnDom); rlm@46: }else{ rlm@46: rt = Ext.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom); rlm@46: } rlm@46: rlm@46: }else{ rlm@46: rt = this.dom.parentNode.insertBefore(Ext.getDom(el), refNode); rlm@46: if(!returnDom){ rlm@46: rt = Ext.get(rt); rlm@46: } rlm@46: } rlm@46: return rt; rlm@46: }, rlm@46: rlm@46: rlm@46: wrap: function(config, returnDom){ rlm@46: if(!config){ rlm@46: config = {tag: "div"}; rlm@46: } rlm@46: var newEl = Ext.DomHelper.insertBefore(this.dom, config, !returnDom); rlm@46: newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom); rlm@46: return newEl; rlm@46: }, rlm@46: rlm@46: rlm@46: replace: function(el){ rlm@46: el = Ext.get(el); rlm@46: this.insertBefore(el); rlm@46: el.remove(); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: replaceWith: function(el){ rlm@46: if(typeof el == 'object' && !el.nodeType && !el.dom){ el = this.insertSibling(el, 'before'); rlm@46: }else{ rlm@46: el = Ext.getDom(el); rlm@46: this.dom.parentNode.insertBefore(el, this.dom); rlm@46: } rlm@46: El.uncache(this.id); rlm@46: this.dom.parentNode.removeChild(this.dom); rlm@46: this.dom = el; rlm@46: this.id = Ext.id(el); rlm@46: El.cache[this.id] = this; rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: insertHtml : function(where, html, returnEl){ rlm@46: var el = Ext.DomHelper.insertHtml(where, this.dom, html); rlm@46: return returnEl ? Ext.get(el) : el; rlm@46: }, rlm@46: rlm@46: rlm@46: set : function(o, useSet){ rlm@46: var el = this.dom; rlm@46: useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet; rlm@46: for(var attr in o){ rlm@46: if(attr == "style" || typeof o[attr] == "function") continue; rlm@46: if(attr=="cls"){ rlm@46: el.className = o["cls"]; rlm@46: }else if(o.hasOwnProperty(attr)){ rlm@46: if(useSet) el.setAttribute(attr, o[attr]); rlm@46: else el[attr] = o[attr]; rlm@46: } rlm@46: } rlm@46: if(o.style){ rlm@46: Ext.DomHelper.applyStyles(el, o.style); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: addKeyListener : function(key, fn, scope){ rlm@46: var config; rlm@46: if(typeof key != "object" || Ext.isArray(key)){ rlm@46: config = { rlm@46: key: key, rlm@46: fn: fn, rlm@46: scope: scope rlm@46: }; rlm@46: }else{ rlm@46: config = { rlm@46: key : key.key, rlm@46: shift : key.shift, rlm@46: ctrl : key.ctrl, rlm@46: alt : key.alt, rlm@46: fn: fn, rlm@46: scope: scope rlm@46: }; rlm@46: } rlm@46: return new Ext.KeyMap(this, config); rlm@46: }, rlm@46: rlm@46: rlm@46: addKeyMap : function(config){ rlm@46: return new Ext.KeyMap(this, config); rlm@46: }, rlm@46: rlm@46: rlm@46: isScrollable : function(){ rlm@46: var dom = this.dom; rlm@46: return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth; rlm@46: }, rlm@46: rlm@46: rlm@46: scrollTo : function(side, value, animate){ rlm@46: var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop"; rlm@46: if(!animate || !A){ rlm@46: this.dom[prop] = value; rlm@46: }else{ rlm@46: var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value]; rlm@46: this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll'); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: scroll : function(direction, distance, animate){ rlm@46: if(!this.isScrollable()){ rlm@46: return; rlm@46: } rlm@46: var el = this.dom; rlm@46: var l = el.scrollLeft, t = el.scrollTop; rlm@46: var w = el.scrollWidth, h = el.scrollHeight; rlm@46: var cw = el.clientWidth, ch = el.clientHeight; rlm@46: direction = direction.toLowerCase(); rlm@46: var scrolled = false; rlm@46: var a = this.preanim(arguments, 2); rlm@46: switch(direction){ rlm@46: case "l": rlm@46: case "left": rlm@46: if(w - l > cw){ rlm@46: var v = Math.min(l + distance, w-cw); rlm@46: this.scrollTo("left", v, a); rlm@46: scrolled = true; rlm@46: } rlm@46: break; rlm@46: case "r": rlm@46: case "right": rlm@46: if(l > 0){ rlm@46: var v = Math.max(l - distance, 0); rlm@46: this.scrollTo("left", v, a); rlm@46: scrolled = true; rlm@46: } rlm@46: break; rlm@46: case "t": rlm@46: case "top": rlm@46: case "up": rlm@46: if(t > 0){ rlm@46: var v = Math.max(t - distance, 0); rlm@46: this.scrollTo("top", v, a); rlm@46: scrolled = true; rlm@46: } rlm@46: break; rlm@46: case "b": rlm@46: case "bottom": rlm@46: case "down": rlm@46: if(h - t > ch){ rlm@46: var v = Math.min(t + distance, h-ch); rlm@46: this.scrollTo("top", v, a); rlm@46: scrolled = true; rlm@46: } rlm@46: break; rlm@46: } rlm@46: return scrolled; rlm@46: }, rlm@46: rlm@46: rlm@46: translatePoints : function(x, y){ rlm@46: if(typeof x == 'object' || Ext.isArray(x)){ rlm@46: y = x[1]; x = x[0]; rlm@46: } rlm@46: var p = this.getStyle('position'); rlm@46: var o = this.getXY(); rlm@46: rlm@46: var l = parseInt(this.getStyle('left'), 10); rlm@46: var t = parseInt(this.getStyle('top'), 10); rlm@46: rlm@46: if(isNaN(l)){ rlm@46: l = (p == "relative") ? 0 : this.dom.offsetLeft; rlm@46: } rlm@46: if(isNaN(t)){ rlm@46: t = (p == "relative") ? 0 : this.dom.offsetTop; rlm@46: } rlm@46: rlm@46: return {left: (x - o[0] + l), top: (y - o[1] + t)}; rlm@46: }, rlm@46: rlm@46: rlm@46: getScroll : function(){ rlm@46: var d = this.dom, doc = document; rlm@46: if(d == doc || d == doc.body){ rlm@46: var l, t; rlm@46: if(Ext.isIE && Ext.isStrict){ rlm@46: l = doc.documentElement.scrollLeft || (doc.body.scrollLeft || 0); rlm@46: t = doc.documentElement.scrollTop || (doc.body.scrollTop || 0); rlm@46: }else{ rlm@46: l = window.pageXOffset || (doc.body.scrollLeft || 0); rlm@46: t = window.pageYOffset || (doc.body.scrollTop || 0); rlm@46: } rlm@46: return {left: l, top: t}; rlm@46: }else{ rlm@46: return {left: d.scrollLeft, top: d.scrollTop}; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getColor : function(attr, defaultValue, prefix){ rlm@46: var v = this.getStyle(attr); rlm@46: if(!v || v == "transparent" || v == "inherit") { rlm@46: return defaultValue; rlm@46: } rlm@46: var color = typeof prefix == "undefined" ? "#" : prefix; rlm@46: if(v.substr(0, 4) == "rgb("){ rlm@46: var rvs = v.slice(4, v.length -1).split(","); rlm@46: for(var i = 0; i < 3; i++){ rlm@46: var h = parseInt(rvs[i]); rlm@46: var s = h.toString(16); rlm@46: if(h < 16){ rlm@46: s = "0" + s; rlm@46: } rlm@46: color += s; rlm@46: } rlm@46: } else { rlm@46: if(v.substr(0, 1) == "#"){ rlm@46: if(v.length == 4) { rlm@46: for(var i = 1; i < 4; i++){ rlm@46: var c = v.charAt(i); rlm@46: color += c + c; rlm@46: } rlm@46: }else if(v.length == 7){ rlm@46: color += v.substr(1); rlm@46: } rlm@46: } rlm@46: } rlm@46: return(color.length > 5 ? color.toLowerCase() : defaultValue); rlm@46: }, rlm@46: rlm@46: rlm@46: boxWrap : function(cls){ rlm@46: cls = cls || 'x-box'; rlm@46: var el = Ext.get(this.insertHtml('beforeBegin', String.format('
'+El.boxMarkup+'
', cls))); rlm@46: el.child('.'+cls+'-mc').dom.appendChild(this.dom); rlm@46: return el; rlm@46: }, rlm@46: rlm@46: rlm@46: getAttributeNS : Ext.isIE ? function(ns, name){ rlm@46: var d = this.dom; rlm@46: var type = typeof d[ns+":"+name]; rlm@46: if(type != 'undefined' && type != 'unknown'){ rlm@46: return d[ns+":"+name]; rlm@46: } rlm@46: return d[name]; rlm@46: } : function(ns, name){ rlm@46: var d = this.dom; rlm@46: return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name]; rlm@46: }, rlm@46: rlm@46: getTextWidth : function(text, min, max){ rlm@46: return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000); rlm@46: } rlm@46: }; rlm@46: rlm@46: var ep = El.prototype; rlm@46: rlm@46: rlm@46: ep.on = ep.addListener; rlm@46: ep.mon = ep.addListener; rlm@46: rlm@46: ep.getUpdateManager = ep.getUpdater; rlm@46: rlm@46: rlm@46: ep.un = ep.removeListener; rlm@46: rlm@46: rlm@46: ep.autoBoxAdjust = true; rlm@46: rlm@46: El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i; rlm@46: rlm@46: El.addUnits = function(v, defaultUnit){ rlm@46: if(v === "" || v == "auto"){ rlm@46: return v; rlm@46: } rlm@46: if(v === undefined){ rlm@46: return ''; rlm@46: } rlm@46: if(typeof v == "number" || !El.unitPattern.test(v)){ rlm@46: return v + (defaultUnit || 'px'); rlm@46: } rlm@46: return v; rlm@46: }; rlm@46: rlm@46: El.boxMarkup = '
'; rlm@46: rlm@46: El.VISIBILITY = 1; rlm@46: rlm@46: El.DISPLAY = 2; rlm@46: rlm@46: El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"}; rlm@46: El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"}; rlm@46: El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"}; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: El.cache = {}; rlm@46: rlm@46: var docEl; rlm@46: rlm@46: rlm@46: El.get = function(el){ rlm@46: var ex, elm, id; rlm@46: if(!el){ return null; } rlm@46: if(typeof el == "string"){ if(!(elm = document.getElementById(el))){ rlm@46: return null; rlm@46: } rlm@46: if(ex = El.cache[el]){ rlm@46: ex.dom = elm; rlm@46: }else{ rlm@46: ex = El.cache[el] = new El(elm); rlm@46: } rlm@46: return ex; rlm@46: }else if(el.tagName){ if(!(id = el.id)){ rlm@46: id = Ext.id(el); rlm@46: } rlm@46: if(ex = El.cache[id]){ rlm@46: ex.dom = el; rlm@46: }else{ rlm@46: ex = El.cache[id] = new El(el); rlm@46: } rlm@46: return ex; rlm@46: }else if(el instanceof El){ rlm@46: if(el != docEl){ rlm@46: el.dom = document.getElementById(el.id) || el.dom; El.cache[el.id] = el; } rlm@46: return el; rlm@46: }else if(el.isComposite){ rlm@46: return el; rlm@46: }else if(Ext.isArray(el)){ rlm@46: return El.select(el); rlm@46: }else if(el == document){ rlm@46: if(!docEl){ rlm@46: var f = function(){}; rlm@46: f.prototype = El.prototype; rlm@46: docEl = new f(); rlm@46: docEl.dom = document; rlm@46: } rlm@46: return docEl; rlm@46: } rlm@46: return null; rlm@46: }; rlm@46: rlm@46: El.uncache = function(el){ rlm@46: for(var i = 0, a = arguments, len = a.length; i < len; i++) { rlm@46: if(a[i]){ rlm@46: delete El.cache[a[i].id || a[i]]; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: El.garbageCollect = function(){ rlm@46: if(!Ext.enableGarbageCollector){ rlm@46: clearInterval(El.collectorThread); rlm@46: return; rlm@46: } rlm@46: for(var eid in El.cache){ rlm@46: var el = El.cache[eid], d = el.dom; rlm@46: if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){ rlm@46: delete El.cache[eid]; rlm@46: if(d && Ext.enableListenerCollection){ rlm@46: E.purgeElement(d); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: El.collectorThreadId = setInterval(El.garbageCollect, 30000); rlm@46: rlm@46: var flyFn = function(){}; rlm@46: flyFn.prototype = El.prototype; rlm@46: var _cls = new flyFn(); rlm@46: rlm@46: El.Flyweight = function(dom){ rlm@46: this.dom = dom; rlm@46: }; rlm@46: rlm@46: El.Flyweight.prototype = _cls; rlm@46: El.Flyweight.prototype.isFlyweight = true; rlm@46: rlm@46: El._flyweights = {}; rlm@46: rlm@46: El.fly = function(el, named){ rlm@46: named = named || '_global'; rlm@46: el = Ext.getDom(el); rlm@46: if(!el){ rlm@46: return null; rlm@46: } rlm@46: if(!El._flyweights[named]){ rlm@46: El._flyweights[named] = new El.Flyweight(); rlm@46: } rlm@46: El._flyweights[named].dom = el; rlm@46: return El._flyweights[named]; rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.get = El.get; rlm@46: rlm@46: Ext.fly = El.fly; rlm@46: rlm@46: var noBoxAdjust = Ext.isStrict ? { rlm@46: select:1 rlm@46: } : { rlm@46: input:1, select:1, textarea:1 rlm@46: }; rlm@46: if(Ext.isIE || Ext.isGecko){ rlm@46: noBoxAdjust['button'] = 1; rlm@46: } rlm@46: rlm@46: rlm@46: Ext.EventManager.on(window, 'unload', function(){ rlm@46: delete El.cache; rlm@46: delete El._flyweights; rlm@46: }); rlm@46: })(); rlm@46: rlm@46: Ext.enableFx = true; rlm@46: rlm@46: rlm@46: Ext.Fx = { rlm@46: rlm@46: slideIn : function(anchor, o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: rlm@46: anchor = anchor || "t"; rlm@46: rlm@46: this.fixDisplay(); rlm@46: rlm@46: var r = this.getFxRestore(); rlm@46: var b = this.getBox(); rlm@46: this.setSize(b); rlm@46: rlm@46: var wrap = this.fxWrap(r.pos, o, "hidden"); rlm@46: rlm@46: var st = this.dom.style; rlm@46: st.visibility = "visible"; rlm@46: st.position = "absolute"; rlm@46: rlm@46: var after = function(){ rlm@46: el.fxUnwrap(wrap, r.pos, o); rlm@46: st.width = r.width; rlm@46: st.height = r.height; rlm@46: el.afterFx(o); rlm@46: }; rlm@46: var a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height}; rlm@46: rlm@46: switch(anchor.toLowerCase()){ rlm@46: case "t": rlm@46: wrap.setSize(b.width, 0); rlm@46: st.left = st.bottom = "0"; rlm@46: a = {height: bh}; rlm@46: break; rlm@46: case "l": rlm@46: wrap.setSize(0, b.height); rlm@46: st.right = st.top = "0"; rlm@46: a = {width: bw}; rlm@46: break; rlm@46: case "r": rlm@46: wrap.setSize(0, b.height); rlm@46: wrap.setX(b.right); rlm@46: st.left = st.top = "0"; rlm@46: a = {width: bw, points: pt}; rlm@46: break; rlm@46: case "b": rlm@46: wrap.setSize(b.width, 0); rlm@46: wrap.setY(b.bottom); rlm@46: st.left = st.top = "0"; rlm@46: a = {height: bh, points: pt}; rlm@46: break; rlm@46: case "tl": rlm@46: wrap.setSize(0, 0); rlm@46: st.right = st.bottom = "0"; rlm@46: a = {width: bw, height: bh}; rlm@46: break; rlm@46: case "bl": rlm@46: wrap.setSize(0, 0); rlm@46: wrap.setY(b.y+b.height); rlm@46: st.right = st.top = "0"; rlm@46: a = {width: bw, height: bh, points: pt}; rlm@46: break; rlm@46: case "br": rlm@46: wrap.setSize(0, 0); rlm@46: wrap.setXY([b.right, b.bottom]); rlm@46: st.left = st.top = "0"; rlm@46: a = {width: bw, height: bh, points: pt}; rlm@46: break; rlm@46: case "tr": rlm@46: wrap.setSize(0, 0); rlm@46: wrap.setX(b.x+b.width); rlm@46: st.left = st.bottom = "0"; rlm@46: a = {width: bw, height: bh, points: pt}; rlm@46: break; rlm@46: } rlm@46: this.dom.style.visibility = "visible"; rlm@46: wrap.show(); rlm@46: rlm@46: arguments.callee.anim = wrap.fxanim(a, rlm@46: o, rlm@46: 'motion', rlm@46: .5, rlm@46: 'easeOut', after); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: slideOut : function(anchor, o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: rlm@46: anchor = anchor || "t"; rlm@46: rlm@46: var r = this.getFxRestore(); rlm@46: rlm@46: var b = this.getBox(); rlm@46: this.setSize(b); rlm@46: rlm@46: var wrap = this.fxWrap(r.pos, o, "visible"); rlm@46: rlm@46: var st = this.dom.style; rlm@46: st.visibility = "visible"; rlm@46: st.position = "absolute"; rlm@46: rlm@46: wrap.setSize(b); rlm@46: rlm@46: var after = function(){ rlm@46: if(o.useDisplay){ rlm@46: el.setDisplayed(false); rlm@46: }else{ rlm@46: el.hide(); rlm@46: } rlm@46: rlm@46: el.fxUnwrap(wrap, r.pos, o); rlm@46: rlm@46: st.width = r.width; rlm@46: st.height = r.height; rlm@46: rlm@46: el.afterFx(o); rlm@46: }; rlm@46: rlm@46: var a, zero = {to: 0}; rlm@46: switch(anchor.toLowerCase()){ rlm@46: case "t": rlm@46: st.left = st.bottom = "0"; rlm@46: a = {height: zero}; rlm@46: break; rlm@46: case "l": rlm@46: st.right = st.top = "0"; rlm@46: a = {width: zero}; rlm@46: break; rlm@46: case "r": rlm@46: st.left = st.top = "0"; rlm@46: a = {width: zero, points: {to:[b.right, b.y]}}; rlm@46: break; rlm@46: case "b": rlm@46: st.left = st.top = "0"; rlm@46: a = {height: zero, points: {to:[b.x, b.bottom]}}; rlm@46: break; rlm@46: case "tl": rlm@46: st.right = st.bottom = "0"; rlm@46: a = {width: zero, height: zero}; rlm@46: break; rlm@46: case "bl": rlm@46: st.right = st.top = "0"; rlm@46: a = {width: zero, height: zero, points: {to:[b.x, b.bottom]}}; rlm@46: break; rlm@46: case "br": rlm@46: st.left = st.top = "0"; rlm@46: a = {width: zero, height: zero, points: {to:[b.x+b.width, b.bottom]}}; rlm@46: break; rlm@46: case "tr": rlm@46: st.left = st.bottom = "0"; rlm@46: a = {width: zero, height: zero, points: {to:[b.right, b.y]}}; rlm@46: break; rlm@46: } rlm@46: rlm@46: arguments.callee.anim = wrap.fxanim(a, rlm@46: o, rlm@46: 'motion', rlm@46: .5, rlm@46: "easeOut", after); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: puff : function(o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: this.clearOpacity(); rlm@46: this.show(); rlm@46: rlm@46: var r = this.getFxRestore(); rlm@46: var st = this.dom.style; rlm@46: rlm@46: var after = function(){ rlm@46: if(o.useDisplay){ rlm@46: el.setDisplayed(false); rlm@46: }else{ rlm@46: el.hide(); rlm@46: } rlm@46: rlm@46: el.clearOpacity(); rlm@46: rlm@46: el.setPositioning(r.pos); rlm@46: st.width = r.width; rlm@46: st.height = r.height; rlm@46: st.fontSize = ''; rlm@46: el.afterFx(o); rlm@46: }; rlm@46: rlm@46: var width = this.getWidth(); rlm@46: var height = this.getHeight(); rlm@46: rlm@46: arguments.callee.anim = this.fxanim({ rlm@46: width : {to: this.adjustWidth(width * 2)}, rlm@46: height : {to: this.adjustHeight(height * 2)}, rlm@46: points : {by: [-(width * .5), -(height * .5)]}, rlm@46: opacity : {to: 0}, rlm@46: fontSize: {to:200, unit: "%"} rlm@46: }, rlm@46: o, rlm@46: 'motion', rlm@46: .5, rlm@46: "easeOut", after); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: switchOff : function(o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: this.clearOpacity(); rlm@46: this.clip(); rlm@46: rlm@46: var r = this.getFxRestore(); rlm@46: var st = this.dom.style; rlm@46: rlm@46: var after = function(){ rlm@46: if(o.useDisplay){ rlm@46: el.setDisplayed(false); rlm@46: }else{ rlm@46: el.hide(); rlm@46: } rlm@46: rlm@46: el.clearOpacity(); rlm@46: el.setPositioning(r.pos); rlm@46: st.width = r.width; rlm@46: st.height = r.height; rlm@46: rlm@46: el.afterFx(o); rlm@46: }; rlm@46: rlm@46: this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){ rlm@46: this.clearOpacity(); rlm@46: (function(){ rlm@46: this.fxanim({ rlm@46: height:{to:1}, rlm@46: points:{by:[0, this.getHeight() * .5]} rlm@46: }, o, 'motion', 0.3, 'easeIn', after); rlm@46: }).defer(100, this); rlm@46: }); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: highlight : function(color, o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: color = color || "ffff9c"; rlm@46: var attr = o.attr || "backgroundColor"; rlm@46: rlm@46: this.clearOpacity(); rlm@46: this.show(); rlm@46: rlm@46: var origColor = this.getColor(attr); rlm@46: var restoreColor = this.dom.style[attr]; rlm@46: var endColor = (o.endColor || origColor) || "ffffff"; rlm@46: rlm@46: var after = function(){ rlm@46: el.dom.style[attr] = restoreColor; rlm@46: el.afterFx(o); rlm@46: }; rlm@46: rlm@46: var a = {}; rlm@46: a[attr] = {from: color, to: endColor}; rlm@46: arguments.callee.anim = this.fxanim(a, rlm@46: o, rlm@46: 'color', rlm@46: 1, rlm@46: 'easeIn', after); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: frame : function(color, count, o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: color = color || "#C3DAF9"; rlm@46: if(color.length == 6){ rlm@46: color = "#" + color; rlm@46: } rlm@46: count = count || 1; rlm@46: var duration = o.duration || 1; rlm@46: this.show(); rlm@46: rlm@46: var b = this.getBox(); rlm@46: var animFn = function(){ rlm@46: var proxy = Ext.getBody().createChild({ rlm@46: style:{ rlm@46: visbility:"hidden", rlm@46: position:"absolute", rlm@46: "z-index":"35000", border:"0px solid " + color rlm@46: } rlm@46: }); rlm@46: var scale = Ext.isBorderBox ? 2 : 1; rlm@46: proxy.animate({ rlm@46: top:{from:b.y, to:b.y - 20}, rlm@46: left:{from:b.x, to:b.x - 20}, rlm@46: borderWidth:{from:0, to:10}, rlm@46: opacity:{from:1, to:0}, rlm@46: height:{from:b.height, to:(b.height + (20*scale))}, rlm@46: width:{from:b.width, to:(b.width + (20*scale))} rlm@46: }, duration, function(){ rlm@46: proxy.remove(); rlm@46: if(--count > 0){ rlm@46: animFn(); rlm@46: }else{ rlm@46: el.afterFx(o); rlm@46: } rlm@46: }); rlm@46: }; rlm@46: animFn.call(this); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: pause : function(seconds){ rlm@46: var el = this.getFxEl(); rlm@46: var o = {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: setTimeout(function(){ rlm@46: el.afterFx(o); rlm@46: }, seconds * 1000); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: fadeIn : function(o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: el.queueFx(o, function(){ rlm@46: this.setOpacity(0); rlm@46: this.fixDisplay(); rlm@46: this.dom.style.visibility = 'visible'; rlm@46: var to = o.endOpacity || 1; rlm@46: arguments.callee.anim = this.fxanim({opacity:{to:to}}, rlm@46: o, null, .5, "easeOut", function(){ rlm@46: if(to == 1){ rlm@46: this.clearOpacity(); rlm@46: } rlm@46: el.afterFx(o); rlm@46: }); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: fadeOut : function(o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: el.queueFx(o, function(){ rlm@46: arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}}, rlm@46: o, null, .5, "easeOut", function(){ rlm@46: if(this.visibilityMode == Ext.Element.DISPLAY || o.useDisplay){ rlm@46: this.dom.style.display = "none"; rlm@46: }else{ rlm@46: this.dom.style.visibility = "hidden"; rlm@46: } rlm@46: this.clearOpacity(); rlm@46: el.afterFx(o); rlm@46: }); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: scale : function(w, h, o){ rlm@46: this.shift(Ext.apply({}, o, { rlm@46: width: w, rlm@46: height: h rlm@46: })); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: shift : function(o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: el.queueFx(o, function(){ rlm@46: var a = {}, w = o.width, h = o.height, x = o.x, y = o.y, op = o.opacity; rlm@46: if(w !== undefined){ rlm@46: a.width = {to: this.adjustWidth(w)}; rlm@46: } rlm@46: if(h !== undefined){ rlm@46: a.height = {to: this.adjustHeight(h)}; rlm@46: } rlm@46: if(o.left !== undefined){ rlm@46: a.left = {to: o.left}; rlm@46: } rlm@46: if(o.top !== undefined){ rlm@46: a.top = {to: o.top}; rlm@46: } rlm@46: if(o.right !== undefined){ rlm@46: a.right = {to: o.right}; rlm@46: } rlm@46: if(o.bottom !== undefined){ rlm@46: a.bottom = {to: o.bottom}; rlm@46: } rlm@46: if(x !== undefined || y !== undefined){ rlm@46: a.points = {to: [ rlm@46: x !== undefined ? x : this.getX(), rlm@46: y !== undefined ? y : this.getY() rlm@46: ]}; rlm@46: } rlm@46: if(op !== undefined){ rlm@46: a.opacity = {to: op}; rlm@46: } rlm@46: if(o.xy !== undefined){ rlm@46: a.points = {to: o.xy}; rlm@46: } rlm@46: arguments.callee.anim = this.fxanim(a, rlm@46: o, 'motion', .35, "easeOut", function(){ rlm@46: el.afterFx(o); rlm@46: }); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: ghost : function(anchor, o){ rlm@46: var el = this.getFxEl(); rlm@46: o = o || {}; rlm@46: rlm@46: el.queueFx(o, function(){ rlm@46: anchor = anchor || "b"; rlm@46: rlm@46: var r = this.getFxRestore(); rlm@46: var w = this.getWidth(), rlm@46: h = this.getHeight(); rlm@46: rlm@46: var st = this.dom.style; rlm@46: rlm@46: var after = function(){ rlm@46: if(o.useDisplay){ rlm@46: el.setDisplayed(false); rlm@46: }else{ rlm@46: el.hide(); rlm@46: } rlm@46: rlm@46: el.clearOpacity(); rlm@46: el.setPositioning(r.pos); rlm@46: st.width = r.width; rlm@46: st.height = r.height; rlm@46: rlm@46: el.afterFx(o); rlm@46: }; rlm@46: rlm@46: var a = {opacity: {to: 0}, points: {}}, pt = a.points; rlm@46: switch(anchor.toLowerCase()){ rlm@46: case "t": rlm@46: pt.by = [0, -h]; rlm@46: break; rlm@46: case "l": rlm@46: pt.by = [-w, 0]; rlm@46: break; rlm@46: case "r": rlm@46: pt.by = [w, 0]; rlm@46: break; rlm@46: case "b": rlm@46: pt.by = [0, h]; rlm@46: break; rlm@46: case "tl": rlm@46: pt.by = [-w, -h]; rlm@46: break; rlm@46: case "bl": rlm@46: pt.by = [-w, h]; rlm@46: break; rlm@46: case "br": rlm@46: pt.by = [w, h]; rlm@46: break; rlm@46: case "tr": rlm@46: pt.by = [w, -h]; rlm@46: break; rlm@46: } rlm@46: rlm@46: arguments.callee.anim = this.fxanim(a, rlm@46: o, rlm@46: 'motion', rlm@46: .5, rlm@46: "easeOut", after); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: syncFx : function(){ rlm@46: this.fxDefaults = Ext.apply(this.fxDefaults || {}, { rlm@46: block : false, rlm@46: concurrent : true, rlm@46: stopFx : false rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: sequenceFx : function(){ rlm@46: this.fxDefaults = Ext.apply(this.fxDefaults || {}, { rlm@46: block : false, rlm@46: concurrent : false, rlm@46: stopFx : false rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: nextFx : function(){ rlm@46: var ef = this.fxQueue[0]; rlm@46: if(ef){ rlm@46: ef.call(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hasActiveFx : function(){ rlm@46: return this.fxQueue && this.fxQueue[0]; rlm@46: }, rlm@46: rlm@46: rlm@46: stopFx : function(){ rlm@46: if(this.hasActiveFx()){ rlm@46: var cur = this.fxQueue[0]; rlm@46: if(cur && cur.anim && cur.anim.isAnimated()){ rlm@46: this.fxQueue = [cur]; cur.anim.stop(true); rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: beforeFx : function(o){ rlm@46: if(this.hasActiveFx() && !o.concurrent){ rlm@46: if(o.stopFx){ rlm@46: this.stopFx(); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: hasFxBlock : function(){ rlm@46: var q = this.fxQueue; rlm@46: return q && q[0] && q[0].block; rlm@46: }, rlm@46: rlm@46: rlm@46: queueFx : function(o, fn){ rlm@46: if(!this.fxQueue){ rlm@46: this.fxQueue = []; rlm@46: } rlm@46: if(!this.hasFxBlock()){ rlm@46: Ext.applyIf(o, this.fxDefaults); rlm@46: if(!o.concurrent){ rlm@46: var run = this.beforeFx(o); rlm@46: fn.block = o.block; rlm@46: this.fxQueue.push(fn); rlm@46: if(run){ rlm@46: this.nextFx(); rlm@46: } rlm@46: }else{ rlm@46: fn.call(this); rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: fxWrap : function(pos, o, vis){ rlm@46: var wrap; rlm@46: if(!o.wrap || !(wrap = Ext.get(o.wrap))){ rlm@46: var wrapXY; rlm@46: if(o.fixPosition){ rlm@46: wrapXY = this.getXY(); rlm@46: } rlm@46: var div = document.createElement("div"); rlm@46: div.style.visibility = vis; rlm@46: wrap = Ext.get(this.dom.parentNode.insertBefore(div, this.dom)); rlm@46: wrap.setPositioning(pos); rlm@46: if(wrap.getStyle("position") == "static"){ rlm@46: wrap.position("relative"); rlm@46: } rlm@46: this.clearPositioning('auto'); rlm@46: wrap.clip(); rlm@46: wrap.dom.appendChild(this.dom); rlm@46: if(wrapXY){ rlm@46: wrap.setXY(wrapXY); rlm@46: } rlm@46: } rlm@46: return wrap; rlm@46: }, rlm@46: rlm@46: rlm@46: fxUnwrap : function(wrap, pos, o){ rlm@46: this.clearPositioning(); rlm@46: this.setPositioning(pos); rlm@46: if(!o.wrap){ rlm@46: wrap.dom.parentNode.insertBefore(this.dom, wrap.dom); rlm@46: wrap.remove(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getFxRestore : function(){ rlm@46: var st = this.dom.style; rlm@46: return {pos: this.getPositioning(), width: st.width, height : st.height}; rlm@46: }, rlm@46: rlm@46: rlm@46: afterFx : function(o){ rlm@46: if(o.afterStyle){ rlm@46: this.applyStyles(o.afterStyle); rlm@46: } rlm@46: if(o.afterCls){ rlm@46: this.addClass(o.afterCls); rlm@46: } rlm@46: if(o.remove === true){ rlm@46: this.remove(); rlm@46: } rlm@46: Ext.callback(o.callback, o.scope, [this]); rlm@46: if(!o.concurrent){ rlm@46: this.fxQueue.shift(); rlm@46: this.nextFx(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getFxEl : function(){ return Ext.get(this.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){ rlm@46: animType = animType || 'run'; rlm@46: opt = opt || {}; rlm@46: var anim = Ext.lib.Anim[animType]( rlm@46: this.dom, args, rlm@46: (opt.duration || defaultDur) || .35, rlm@46: (opt.easing || defaultEase) || 'easeOut', rlm@46: function(){ rlm@46: Ext.callback(cb, this); rlm@46: }, rlm@46: this rlm@46: ); rlm@46: opt.anim = anim; rlm@46: return anim; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.Fx.resize = Ext.Fx.scale; rlm@46: rlm@46: Ext.apply(Ext.Element.prototype, Ext.Fx); rlm@46: rlm@46: rlm@46: Ext.CompositeElement = function(els){ rlm@46: this.elements = []; rlm@46: this.addElements(els); rlm@46: }; rlm@46: Ext.CompositeElement.prototype = { rlm@46: isComposite: true, rlm@46: addElements : function(els){ rlm@46: if(!els) return this; rlm@46: if(typeof els == "string"){ rlm@46: els = Ext.Element.selectorFunction(els); rlm@46: } rlm@46: var yels = this.elements; rlm@46: var index = yels.length-1; rlm@46: for(var i = 0, len = els.length; i < len; i++) { rlm@46: yels[++index] = Ext.get(els[i]); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: fill : function(els){ rlm@46: this.elements = []; rlm@46: this.add(els); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: filter : function(selector){ rlm@46: var els = []; rlm@46: this.each(function(el){ rlm@46: if(el.is(selector)){ rlm@46: els[els.length] = el.dom; rlm@46: } rlm@46: }); rlm@46: this.fill(els); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: invoke : function(fn, args){ rlm@46: var els = this.elements; rlm@46: for(var i = 0, len = els.length; i < len; i++) { rlm@46: Ext.Element.prototype[fn].apply(els[i], args); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: add : function(els){ rlm@46: if(typeof els == "string"){ rlm@46: this.addElements(Ext.Element.selectorFunction(els)); rlm@46: }else if(els.length !== undefined){ rlm@46: this.addElements(els); rlm@46: }else{ rlm@46: this.addElements([els]); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: each : function(fn, scope){ rlm@46: var els = this.elements; rlm@46: for(var i = 0, len = els.length; i < len; i++){ rlm@46: if(fn.call(scope || els[i], els[i], this, i) === false) { rlm@46: break; rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: item : function(index){ rlm@46: return this.elements[index] || null; rlm@46: }, rlm@46: rlm@46: rlm@46: first : function(){ rlm@46: return this.item(0); rlm@46: }, rlm@46: rlm@46: rlm@46: last : function(){ rlm@46: return this.item(this.elements.length-1); rlm@46: }, rlm@46: rlm@46: rlm@46: getCount : function(){ rlm@46: return this.elements.length; rlm@46: }, rlm@46: rlm@46: rlm@46: contains : function(el){ rlm@46: return this.indexOf(el) !== -1; rlm@46: }, rlm@46: rlm@46: rlm@46: indexOf : function(el){ rlm@46: return this.elements.indexOf(Ext.get(el)); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: removeElement : function(el, removeDom){ rlm@46: if(Ext.isArray(el)){ rlm@46: for(var i = 0, len = el.length; i < len; i++){ rlm@46: this.removeElement(el[i]); rlm@46: } rlm@46: return this; rlm@46: } rlm@46: var index = typeof el == 'number' ? el : this.indexOf(el); rlm@46: if(index !== -1 && this.elements[index]){ rlm@46: if(removeDom){ rlm@46: var d = this.elements[index]; rlm@46: if(d.dom){ rlm@46: d.remove(); rlm@46: }else{ rlm@46: Ext.removeNode(d); rlm@46: } rlm@46: } rlm@46: this.elements.splice(index, 1); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: replaceElement : function(el, replacement, domReplace){ rlm@46: var index = typeof el == 'number' ? el : this.indexOf(el); rlm@46: if(index !== -1){ rlm@46: if(domReplace){ rlm@46: this.elements[index].replaceWith(replacement); rlm@46: }else{ rlm@46: this.elements.splice(index, 1, Ext.get(replacement)) rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(){ rlm@46: this.elements = []; rlm@46: } rlm@46: }; rlm@46: (function(){ rlm@46: Ext.CompositeElement.createCall = function(proto, fnName){ rlm@46: if(!proto[fnName]){ rlm@46: proto[fnName] = function(){ rlm@46: return this.invoke(fnName, arguments); rlm@46: }; rlm@46: } rlm@46: }; rlm@46: for(var fnName in Ext.Element.prototype){ rlm@46: if(typeof Ext.Element.prototype[fnName] == "function"){ rlm@46: Ext.CompositeElement.createCall(Ext.CompositeElement.prototype, fnName); rlm@46: } rlm@46: }; rlm@46: })(); rlm@46: rlm@46: rlm@46: Ext.CompositeElementLite = function(els){ rlm@46: Ext.CompositeElementLite.superclass.constructor.call(this, els); rlm@46: this.el = new Ext.Element.Flyweight(); rlm@46: }; rlm@46: Ext.extend(Ext.CompositeElementLite, Ext.CompositeElement, { rlm@46: addElements : function(els){ rlm@46: if(els){ rlm@46: if(Ext.isArray(els)){ rlm@46: this.elements = this.elements.concat(els); rlm@46: }else{ rlm@46: var yels = this.elements; rlm@46: var index = yels.length-1; rlm@46: for(var i = 0, len = els.length; i < len; i++) { rlm@46: yels[++index] = els[i]; rlm@46: } rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: invoke : function(fn, args){ rlm@46: var els = this.elements; rlm@46: var el = this.el; rlm@46: for(var i = 0, len = els.length; i < len; i++) { rlm@46: el.dom = els[i]; rlm@46: Ext.Element.prototype[fn].apply(el, args); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: item : function(index){ rlm@46: if(!this.elements[index]){ rlm@46: return null; rlm@46: } rlm@46: this.el.dom = this.elements[index]; rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: addListener : function(eventName, handler, scope, opt){ rlm@46: var els = this.elements; rlm@46: for(var i = 0, len = els.length; i < len; i++) { rlm@46: Ext.EventManager.on(els[i], eventName, handler, scope || els[i], opt); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: var els = this.elements; rlm@46: var el = this.el; rlm@46: for(var i = 0, len = els.length; i < len; i++){ rlm@46: el.dom = els[i]; rlm@46: if(fn.call(scope || el, el, this, i) === false){ rlm@46: break; rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: indexOf : function(el){ rlm@46: return this.elements.indexOf(Ext.getDom(el)); rlm@46: }, rlm@46: rlm@46: replaceElement : function(el, replacement, domReplace){ rlm@46: var index = typeof el == 'number' ? el : this.indexOf(el); rlm@46: if(index !== -1){ rlm@46: replacement = Ext.getDom(replacement); rlm@46: if(domReplace){ rlm@46: var d = this.elements[index]; rlm@46: d.parentNode.insertBefore(replacement, d); rlm@46: Ext.removeNode(d); rlm@46: } rlm@46: this.elements.splice(index, 1, replacement); rlm@46: } rlm@46: return this; rlm@46: } rlm@46: }); rlm@46: Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener; rlm@46: if(Ext.DomQuery){ rlm@46: Ext.Element.selectorFunction = Ext.DomQuery.select; rlm@46: } rlm@46: rlm@46: Ext.Element.select = function(selector, unique, root){ rlm@46: var els; rlm@46: if(typeof selector == "string"){ rlm@46: els = Ext.Element.selectorFunction(selector, root); rlm@46: }else if(selector.length !== undefined){ rlm@46: els = selector; rlm@46: }else{ rlm@46: throw "Invalid selector"; rlm@46: } rlm@46: if(unique === true){ rlm@46: return new Ext.CompositeElement(els); rlm@46: }else{ rlm@46: return new Ext.CompositeElementLite(els); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.select = Ext.Element.select; rlm@46: rlm@46: Ext.data.Connection = function(config){ rlm@46: Ext.apply(this, config); rlm@46: this.addEvents( rlm@46: rlm@46: "beforerequest", rlm@46: rlm@46: "requestcomplete", rlm@46: rlm@46: "requestexception" rlm@46: ); rlm@46: Ext.data.Connection.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.Connection, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: timeout : 30000, rlm@46: rlm@46: autoAbort:false, rlm@46: rlm@46: rlm@46: disableCaching: true, rlm@46: rlm@46: rlm@46: request : function(o){ rlm@46: if(this.fireEvent("beforerequest", this, o) !== false){ rlm@46: var p = o.params; rlm@46: rlm@46: if(typeof p == "function"){ rlm@46: p = p.call(o.scope||window, o); rlm@46: } rlm@46: if(typeof p == "object"){ rlm@46: p = Ext.urlEncode(p); rlm@46: } rlm@46: if(this.extraParams){ rlm@46: var extras = Ext.urlEncode(this.extraParams); rlm@46: p = p ? (p + '&' + extras) : extras; rlm@46: } rlm@46: rlm@46: var url = o.url || this.url; rlm@46: if(typeof url == 'function'){ rlm@46: url = url.call(o.scope||window, o); rlm@46: } rlm@46: rlm@46: if(o.form){ rlm@46: var form = Ext.getDom(o.form); rlm@46: url = url || form.action; rlm@46: rlm@46: var enctype = form.getAttribute("enctype"); rlm@46: if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){ rlm@46: return this.doFormUpload(o, p, url); rlm@46: } rlm@46: var f = Ext.lib.Ajax.serializeForm(form); rlm@46: p = p ? (p + '&' + f) : f; rlm@46: } rlm@46: rlm@46: var hs = o.headers; rlm@46: if(this.defaultHeaders){ rlm@46: hs = Ext.apply(hs || {}, this.defaultHeaders); rlm@46: if(!o.headers){ rlm@46: o.headers = hs; rlm@46: } rlm@46: } rlm@46: rlm@46: var cb = { rlm@46: success: this.handleResponse, rlm@46: failure: this.handleFailure, rlm@46: scope: this, rlm@46: argument: {options: o}, rlm@46: timeout : o.timeout || this.timeout rlm@46: }; rlm@46: rlm@46: var method = o.method||this.method||(p ? "POST" : "GET"); rlm@46: rlm@46: if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){ rlm@46: url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime()); rlm@46: } rlm@46: rlm@46: if(typeof o.autoAbort == 'boolean'){ if(o.autoAbort){ rlm@46: this.abort(); rlm@46: } rlm@46: }else if(this.autoAbort !== false){ rlm@46: this.abort(); rlm@46: } rlm@46: if((method == 'GET' || o.xmlData || o.jsonData) && p){ rlm@46: url += (url.indexOf('?') != -1 ? '&' : '?') + p; rlm@46: p = ''; rlm@46: } rlm@46: this.transId = Ext.lib.Ajax.request(method, url, cb, p, o); rlm@46: return this.transId; rlm@46: }else{ rlm@46: Ext.callback(o.callback, o.scope, [o, null, null]); rlm@46: return null; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isLoading : function(transId){ rlm@46: if(transId){ rlm@46: return Ext.lib.Ajax.isCallInProgress(transId); rlm@46: }else{ rlm@46: return this.transId ? true : false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: abort : function(transId){ rlm@46: if(transId || this.isLoading()){ rlm@46: Ext.lib.Ajax.abort(transId || this.transId); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleResponse : function(response){ rlm@46: this.transId = false; rlm@46: var options = response.argument.options; rlm@46: response.argument = options ? options.argument : null; rlm@46: this.fireEvent("requestcomplete", this, response, options); rlm@46: Ext.callback(options.success, options.scope, [response, options]); rlm@46: Ext.callback(options.callback, options.scope, [options, true, response]); rlm@46: }, rlm@46: rlm@46: handleFailure : function(response, e){ rlm@46: this.transId = false; rlm@46: var options = response.argument.options; rlm@46: response.argument = options ? options.argument : null; rlm@46: this.fireEvent("requestexception", this, response, options, e); rlm@46: Ext.callback(options.failure, options.scope, [response, options]); rlm@46: Ext.callback(options.callback, options.scope, [options, false, response]); rlm@46: }, rlm@46: rlm@46: doFormUpload : function(o, ps, url){ rlm@46: var id = Ext.id(); rlm@46: var frame = document.createElement('iframe'); rlm@46: frame.id = id; rlm@46: frame.name = id; rlm@46: frame.className = 'x-hidden'; rlm@46: if(Ext.isIE){ rlm@46: frame.src = Ext.SSL_SECURE_URL; rlm@46: } rlm@46: document.body.appendChild(frame); rlm@46: rlm@46: if(Ext.isIE){ rlm@46: document.frames[id].name = id; rlm@46: } rlm@46: rlm@46: var form = Ext.getDom(o.form); rlm@46: form.target = id; rlm@46: form.method = 'POST'; rlm@46: form.enctype = form.encoding = 'multipart/form-data'; rlm@46: if(url){ rlm@46: form.action = url; rlm@46: } rlm@46: rlm@46: var hiddens, hd; rlm@46: if(ps){ hiddens = []; rlm@46: ps = Ext.urlDecode(ps, false); rlm@46: for(var k in ps){ rlm@46: if(ps.hasOwnProperty(k)){ rlm@46: hd = document.createElement('input'); rlm@46: hd.type = 'hidden'; rlm@46: hd.name = k; rlm@46: hd.value = ps[k]; rlm@46: form.appendChild(hd); rlm@46: hiddens.push(hd); rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: function cb(){ rlm@46: var r = { responseText : '', rlm@46: responseXML : null rlm@46: }; rlm@46: rlm@46: r.argument = o ? o.argument : null; rlm@46: rlm@46: try { var doc; rlm@46: if(Ext.isIE){ rlm@46: doc = frame.contentWindow.document; rlm@46: }else { rlm@46: doc = (frame.contentDocument || window.frames[id].document); rlm@46: } rlm@46: if(doc && doc.body){ rlm@46: r.responseText = doc.body.innerHTML; rlm@46: } rlm@46: if(doc && doc.XMLDocument){ rlm@46: r.responseXML = doc.XMLDocument; rlm@46: }else { rlm@46: r.responseXML = doc; rlm@46: } rlm@46: } rlm@46: catch(e) { rlm@46: } rlm@46: rlm@46: Ext.EventManager.removeListener(frame, 'load', cb, this); rlm@46: rlm@46: this.fireEvent("requestcomplete", this, r, o); rlm@46: rlm@46: Ext.callback(o.success, o.scope, [r, o]); rlm@46: Ext.callback(o.callback, o.scope, [o, true, r]); rlm@46: rlm@46: setTimeout(function(){Ext.removeNode(frame);}, 100); rlm@46: } rlm@46: rlm@46: Ext.EventManager.on(frame, 'load', cb, this); rlm@46: form.submit(); rlm@46: rlm@46: if(hiddens){ for(var i = 0, len = hiddens.length; i < len; i++){ rlm@46: Ext.removeNode(hiddens[i]); rlm@46: } rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.Ajax = new Ext.data.Connection({ rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: autoAbort : false, rlm@46: rlm@46: rlm@46: serializeForm : function(form){ rlm@46: return Ext.lib.Ajax.serializeForm(form); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.Updater = function(el, forceNew){ rlm@46: el = Ext.get(el); rlm@46: if(!forceNew && el.updateManager){ rlm@46: return el.updateManager; rlm@46: } rlm@46: rlm@46: this.el = el; rlm@46: rlm@46: this.defaultUrl = null; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "beforeupdate", rlm@46: rlm@46: "update", rlm@46: rlm@46: "failure" rlm@46: ); rlm@46: var d = Ext.Updater.defaults; rlm@46: rlm@46: this.sslBlankUrl = d.sslBlankUrl; rlm@46: rlm@46: this.disableCaching = d.disableCaching; rlm@46: rlm@46: this.indicatorText = d.indicatorText; rlm@46: rlm@46: this.showLoadIndicator = d.showLoadIndicator; rlm@46: rlm@46: this.timeout = d.timeout; rlm@46: rlm@46: this.loadScripts = d.loadScripts; rlm@46: rlm@46: this.transaction = null; rlm@46: rlm@46: this.refreshDelegate = this.refresh.createDelegate(this); rlm@46: rlm@46: this.updateDelegate = this.update.createDelegate(this); rlm@46: rlm@46: this.formUpdateDelegate = this.formUpdate.createDelegate(this); rlm@46: rlm@46: if(!this.renderer){ rlm@46: rlm@46: this.renderer = new Ext.Updater.BasicRenderer(); rlm@46: } rlm@46: Ext.Updater.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Updater, Ext.util.Observable, { rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(url, params, callback, discardUrl){ rlm@46: if(this.fireEvent("beforeupdate", this.el, url, params) !== false){ rlm@46: var cfg, callerScope; rlm@46: if(typeof url == "object"){ rlm@46: cfg = url; rlm@46: url = cfg.url; rlm@46: params = params || cfg.params; rlm@46: callback = callback || cfg.callback; rlm@46: discardUrl = discardUrl || cfg.discardUrl; rlm@46: callerScope = cfg.scope; rlm@46: if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;}; rlm@46: if(typeof cfg.text != "undefined"){this.indicatorText = '
'+cfg.text+"
";}; rlm@46: if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;}; rlm@46: if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;}; rlm@46: } rlm@46: this.showLoading(); rlm@46: rlm@46: if(!discardUrl){ rlm@46: this.defaultUrl = url; rlm@46: } rlm@46: if(typeof url == "function"){ rlm@46: url = url.call(this); rlm@46: } rlm@46: rlm@46: var o = Ext.apply(cfg ||{}, { rlm@46: url : url, rlm@46: params: (typeof params == "function" && callerScope) ? params.createDelegate(callerScope) : params, rlm@46: success: this.processSuccess, rlm@46: failure: this.processFailure, rlm@46: scope: this, rlm@46: callback: undefined, rlm@46: timeout: (this.timeout*1000), rlm@46: disableCaching: this.disableCaching, rlm@46: argument: { rlm@46: "options": cfg, rlm@46: "url": url, rlm@46: "form": null, rlm@46: "callback": callback, rlm@46: "scope": callerScope || window, rlm@46: "params": params rlm@46: } rlm@46: }); rlm@46: rlm@46: this.transaction = Ext.Ajax.request(o); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: formUpdate : function(form, url, reset, callback){ rlm@46: if(this.fireEvent("beforeupdate", this.el, form, url) !== false){ rlm@46: if(typeof url == "function"){ rlm@46: url = url.call(this); rlm@46: } rlm@46: form = Ext.getDom(form) rlm@46: this.transaction = Ext.Ajax.request({ rlm@46: form: form, rlm@46: url:url, rlm@46: success: this.processSuccess, rlm@46: failure: this.processFailure, rlm@46: scope: this, rlm@46: timeout: (this.timeout*1000), rlm@46: argument: { rlm@46: "url": url, rlm@46: "form": form, rlm@46: "callback": callback, rlm@46: "reset": reset rlm@46: } rlm@46: }); rlm@46: this.showLoading.defer(1, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: refresh : function(callback){ rlm@46: if(this.defaultUrl == null){ rlm@46: return; rlm@46: } rlm@46: this.update(this.defaultUrl, null, callback, true); rlm@46: }, rlm@46: rlm@46: rlm@46: startAutoRefresh : function(interval, url, params, callback, refreshNow){ rlm@46: if(refreshNow){ rlm@46: this.update(url || this.defaultUrl, params, callback, true); rlm@46: } rlm@46: if(this.autoRefreshProcId){ rlm@46: clearInterval(this.autoRefreshProcId); rlm@46: } rlm@46: this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000); rlm@46: }, rlm@46: rlm@46: rlm@46: stopAutoRefresh : function(){ rlm@46: if(this.autoRefreshProcId){ rlm@46: clearInterval(this.autoRefreshProcId); rlm@46: delete this.autoRefreshProcId; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isAutoRefreshing : function(){ rlm@46: return this.autoRefreshProcId ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: showLoading : function(){ rlm@46: if(this.showLoadIndicator){ rlm@46: this.el.update(this.indicatorText); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: processSuccess : function(response){ rlm@46: this.transaction = null; rlm@46: if(response.argument.form && response.argument.reset){ rlm@46: try{ rlm@46: response.argument.form.reset(); rlm@46: }catch(e){} rlm@46: } rlm@46: if(this.loadScripts){ rlm@46: this.renderer.render(this.el, response, this, rlm@46: this.updateComplete.createDelegate(this, [response])); rlm@46: }else{ rlm@46: this.renderer.render(this.el, response, this); rlm@46: this.updateComplete(response); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: updateComplete : function(response){ rlm@46: this.fireEvent("update", this.el, response); rlm@46: if(typeof response.argument.callback == "function"){ rlm@46: response.argument.callback.call(response.argument.scope, this.el, true, response, response.argument.options); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: processFailure : function(response){ rlm@46: this.transaction = null; rlm@46: this.fireEvent("failure", this.el, response); rlm@46: if(typeof response.argument.callback == "function"){ rlm@46: response.argument.callback.call(response.argument.scope, this.el, false, response, response.argument.options); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setRenderer : function(renderer){ rlm@46: this.renderer = renderer; rlm@46: }, rlm@46: rlm@46: rlm@46: getRenderer : function(){ rlm@46: return this.renderer; rlm@46: }, rlm@46: rlm@46: rlm@46: setDefaultUrl : function(defaultUrl){ rlm@46: this.defaultUrl = defaultUrl; rlm@46: }, rlm@46: rlm@46: rlm@46: abort : function(){ rlm@46: if(this.transaction){ rlm@46: Ext.Ajax.abort(this.transaction); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isUpdating : function(){ rlm@46: if(this.transaction){ rlm@46: return Ext.Ajax.isLoading(this.transaction); rlm@46: } rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.Updater.defaults = { rlm@46: rlm@46: timeout : 30, rlm@46: rlm@46: loadScripts : false, rlm@46: rlm@46: sslBlankUrl : (Ext.SSL_SECURE_URL || "javascript:false"), rlm@46: rlm@46: disableCaching : false, rlm@46: rlm@46: showLoadIndicator : true, rlm@46: rlm@46: indicatorText : '
Loading...
' rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.Updater.updateElement = function(el, url, params, options){ rlm@46: var um = Ext.get(el).getUpdater(); rlm@46: Ext.apply(um, options); rlm@46: um.update(url, params, options ? options.callback : null); rlm@46: }; rlm@46: rlm@46: Ext.Updater.BasicRenderer = function(){}; rlm@46: rlm@46: Ext.Updater.BasicRenderer.prototype = { rlm@46: rlm@46: render : function(el, response, updateManager, callback){ rlm@46: el.update(response.responseText, updateManager.loadScripts, callback); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.UpdateManager = Ext.Updater; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: Date.parseFunctions = {count:0}; rlm@46: Date.parseRegexes = []; rlm@46: Date.formatFunctions = {count:0}; rlm@46: rlm@46: Date.prototype.dateFormat = function(format) { rlm@46: if (Date.formatFunctions[format] == null) { rlm@46: Date.createNewFormat(format); rlm@46: } rlm@46: var func = Date.formatFunctions[format]; rlm@46: return this[func](); rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: Date.prototype.format = Date.prototype.dateFormat; rlm@46: rlm@46: Date.createNewFormat = function(format) { rlm@46: var funcName = "format" + Date.formatFunctions.count++; rlm@46: Date.formatFunctions[format] = funcName; rlm@46: var code = "Date.prototype." + funcName + " = function(){return "; rlm@46: var special = false; rlm@46: var ch = ''; rlm@46: for (var i = 0; i < format.length; ++i) { rlm@46: ch = format.charAt(i); rlm@46: if (!special && ch == "\\") { rlm@46: special = true; rlm@46: } rlm@46: else if (special) { rlm@46: special = false; rlm@46: code += "'" + String.escape(ch) + "' + "; rlm@46: } rlm@46: else { rlm@46: code += Date.getFormatCode(ch) + " + "; rlm@46: } rlm@46: } rlm@46: eval(code.substring(0, code.length - 3) + ";}"); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.formatCodes = { rlm@46: d: "String.leftPad(this.getDate(), 2, '0')", rlm@46: D: "Date.getShortDayName(this.getDay())", j: "this.getDate()", rlm@46: l: "Date.dayNames[this.getDay()]", rlm@46: N: "(this.getDay() ? this.getDay() : 7)", rlm@46: S: "this.getSuffix()", rlm@46: w: "this.getDay()", rlm@46: z: "this.getDayOfYear()", rlm@46: W: "String.leftPad(this.getWeekOfYear(), 2, '0')", rlm@46: F: "Date.monthNames[this.getMonth()]", rlm@46: m: "String.leftPad(this.getMonth() + 1, 2, '0')", rlm@46: M: "Date.getShortMonthName(this.getMonth())", n: "(this.getMonth() + 1)", rlm@46: t: "this.getDaysInMonth()", rlm@46: L: "(this.isLeapYear() ? 1 : 0)", rlm@46: o: "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))", rlm@46: Y: "this.getFullYear()", rlm@46: y: "('' + this.getFullYear()).substring(2, 4)", rlm@46: a: "(this.getHours() < 12 ? 'am' : 'pm')", rlm@46: A: "(this.getHours() < 12 ? 'AM' : 'PM')", rlm@46: g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)", rlm@46: G: "this.getHours()", rlm@46: h: "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')", rlm@46: H: "String.leftPad(this.getHours(), 2, '0')", rlm@46: i: "String.leftPad(this.getMinutes(), 2, '0')", rlm@46: s: "String.leftPad(this.getSeconds(), 2, '0')", rlm@46: u: "String.leftPad(this.getMilliseconds(), 3, '0')", rlm@46: O: "this.getGMTOffset()", rlm@46: P: "this.getGMTOffset(true)", rlm@46: T: "this.getTimezone()", rlm@46: Z: "(this.getTimezoneOffset() * -60)", rlm@46: c: function() { for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) { rlm@46: var e = c.charAt(i); rlm@46: code.push(e == "T" ? "'T'" : Date.getFormatCode(e)); } rlm@46: return code.join(" + "); rlm@46: }, rlm@46: rlm@46: U: "Math.round(this.getTime() / 1000)" rlm@46: } rlm@46: rlm@46: Date.getFormatCode = function(character) { rlm@46: var f = Date.formatCodes[character]; rlm@46: rlm@46: if (f) { rlm@46: f = Ext.type(f) == 'function'? f() : f; rlm@46: Date.formatCodes[character] = f; } rlm@46: rlm@46: return f || ("'" + String.escape(character) + "'"); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.parseDate = function(input, format) { rlm@46: if (Date.parseFunctions[format] == null) { rlm@46: Date.createParser(format); rlm@46: } rlm@46: var func = Date.parseFunctions[format]; rlm@46: return Date[func](input); rlm@46: }; rlm@46: rlm@46: Date.createParser = function(format) { rlm@46: var funcName = "parse" + Date.parseFunctions.count++; rlm@46: var regexNum = Date.parseRegexes.length; rlm@46: var currentGroup = 1; rlm@46: Date.parseFunctions[format] = funcName; rlm@46: rlm@46: var code = "Date." + funcName + " = function(input){\n" rlm@46: + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, ms = -1, o, z, u, v;\n" rlm@46: + "input = String(input);var d = new Date();\n" rlm@46: + "y = d.getFullYear();\n" rlm@46: + "m = d.getMonth();\n" rlm@46: + "d = d.getDate();\n" rlm@46: + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" rlm@46: + "if (results && results.length > 0) {"; rlm@46: var regex = ""; rlm@46: rlm@46: var special = false; rlm@46: var ch = ''; rlm@46: for (var i = 0; i < format.length; ++i) { rlm@46: ch = format.charAt(i); rlm@46: if (!special && ch == "\\") { rlm@46: special = true; rlm@46: } rlm@46: else if (special) { rlm@46: special = false; rlm@46: regex += String.escape(ch); rlm@46: } rlm@46: else { rlm@46: var obj = Date.formatCodeToRegex(ch, currentGroup); rlm@46: currentGroup += obj.g; rlm@46: regex += obj.s; rlm@46: if (obj.g && obj.c) { rlm@46: code += obj.c; rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: code += "if (u){\n" rlm@46: + "v = new Date(u * 1000);\n" + "}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0 && ms >= 0){\n" rlm@46: + "v = new Date(y, m, d, h, i, s, ms);\n" rlm@46: + "}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0){\n" rlm@46: + "v = new Date(y, m, d, h, i, s);\n" rlm@46: + "}else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0){\n" rlm@46: + "v = new Date(y, m, d, h, i);\n" rlm@46: + "}else if (y >= 0 && m >= 0 && d > 0 && h >= 0){\n" rlm@46: + "v = new Date(y, m, d, h);\n" rlm@46: + "}else if (y >= 0 && m >= 0 && d > 0){\n" rlm@46: + "v = new Date(y, m, d);\n" rlm@46: + "}else if (y >= 0 && m >= 0){\n" rlm@46: + "v = new Date(y, m);\n" rlm@46: + "}else if (y >= 0){\n" rlm@46: + "v = new Date(y);\n" rlm@46: + "}\n}\nreturn (v && Ext.type(z || o) == 'number')?" + " (Ext.type(z) == 'number' ? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + z) :" + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v;\n" + "}"; rlm@46: rlm@46: Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$", "i"); rlm@46: eval(code); rlm@46: }; rlm@46: rlm@46: Date.parseCodes = { rlm@46: rlm@46: d: { rlm@46: g:1, rlm@46: c:"d = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{2})" }, rlm@46: j: function() { rlm@46: return Ext.applyIf({ rlm@46: s:"(\\d{1,2})" }, Date.parseCodes["d"]); rlm@46: }, rlm@46: D: function() { rlm@46: for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); return { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:" + a.join("|") +")" rlm@46: } rlm@46: }, rlm@46: l: function() { rlm@46: return { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:" + Date.dayNames.join("|") + ")" rlm@46: } rlm@46: }, rlm@46: N: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"[1-7]" }, rlm@46: S: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:st|nd|rd|th)" rlm@46: }, rlm@46: w: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"[0-6]" }, rlm@46: z: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:\\d{1,3}" }, rlm@46: W: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:\\d{2})" }, rlm@46: F: function() { rlm@46: return { rlm@46: g:1, rlm@46: c:"m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n", s:"(" + Date.monthNames.join("|") + ")" rlm@46: } rlm@46: }, rlm@46: M: function() { rlm@46: for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); return Ext.applyIf({ rlm@46: s:"(" + a.join("|") + ")" rlm@46: }, Date.parseCodes["F"]); rlm@46: }, rlm@46: m: { rlm@46: g:1, rlm@46: c:"m = parseInt(results[{0}], 10) - 1;\n", rlm@46: s:"(\\d{2})" }, rlm@46: n: function() { rlm@46: return Ext.applyIf({ rlm@46: s:"(\\d{1,2})" }, Date.parseCodes["m"]); rlm@46: }, rlm@46: t: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:\\d{2})" }, rlm@46: L: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"(?:1|0)" rlm@46: }, rlm@46: o: function() { rlm@46: return Date.parseCodes["Y"]; rlm@46: }, rlm@46: Y: { rlm@46: g:1, rlm@46: c:"y = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{4})" }, rlm@46: y: { rlm@46: g:1, rlm@46: c:"var ty = parseInt(results[{0}], 10);\n" rlm@46: + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", s:"(\\d{1,2})" rlm@46: }, rlm@46: a: { rlm@46: g:1, rlm@46: c:"if (results[{0}] == 'am') {\n" rlm@46: + "if (h == 12) { h = 0; }\n" rlm@46: + "} else { if (h < 12) { h += 12; }}", rlm@46: s:"(am|pm)" rlm@46: }, rlm@46: A: { rlm@46: g:1, rlm@46: c:"if (results[{0}] == 'AM') {\n" rlm@46: + "if (h == 12) { h = 0; }\n" rlm@46: + "} else { if (h < 12) { h += 12; }}", rlm@46: s:"(AM|PM)" rlm@46: }, rlm@46: g: function() { rlm@46: return Date.parseCodes["G"]; rlm@46: }, rlm@46: G: { rlm@46: g:1, rlm@46: c:"h = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{1,2})" }, rlm@46: h: function() { rlm@46: return Date.parseCodes["H"]; rlm@46: }, rlm@46: H: { rlm@46: g:1, rlm@46: c:"h = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{2})" }, rlm@46: i: { rlm@46: g:1, rlm@46: c:"i = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{2})" }, rlm@46: s: { rlm@46: g:1, rlm@46: c:"s = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{2})" }, rlm@46: u: { rlm@46: g:1, rlm@46: c:"ms = parseInt(results[{0}], 10);\n", rlm@46: s:"(\\d{3})" }, rlm@46: O: { rlm@46: g:1, rlm@46: c:[ rlm@46: "o = results[{0}];", rlm@46: "var sn = o.substring(0,1);", "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);", "var mn = o.substring(3,5) % 60;", "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" ].join("\n"), rlm@46: s: "([+\-]\\d{4})" }, rlm@46: P: function() { rlm@46: return Ext.applyIf({ rlm@46: s: "([+\-]\\d{2}:\\d{2})" }, Date.parseCodes["O"]); rlm@46: }, rlm@46: T: { rlm@46: g:0, rlm@46: c:null, rlm@46: s:"[A-Z]{1,4}" }, rlm@46: Z: { rlm@46: g:1, rlm@46: c:"z = results[{0}] * 1;\n" + "z = (-43200 <= z && z <= 50400)? z : null;\n", rlm@46: s:"([+\-]?\\d{1,5})" }, rlm@46: c: function() { rlm@46: var df = Date.formatCodeToRegex, calc = []; rlm@46: var arr = [ rlm@46: df("Y", 1), rlm@46: df("m", 2), rlm@46: df("d", 3), rlm@46: df("h", 4), rlm@46: df("i", 5), rlm@46: df("s", 6), rlm@46: {c:"if(results[7] == 'Z'){\no = 0;\n}else{\n" + df("P", 7).c + "\n}"} ]; rlm@46: for (var i = 0, l = arr.length; i < l; ++i) { rlm@46: calc.push(arr[i].c); rlm@46: } rlm@46: rlm@46: return { rlm@46: g:1, rlm@46: c:calc.join(""), rlm@46: s:arr[0].s + "-" + arr[1].s + "-" + arr[2].s + "T" + arr[3].s + ":" + arr[4].s + ":" + arr[5].s + "(" + df("P", 7).s + "|Z)" rlm@46: } rlm@46: }, rlm@46: U: { rlm@46: g:1, rlm@46: c:"u = parseInt(results[{0}], 10);\n", rlm@46: s:"(-?\\d+)" } rlm@46: } rlm@46: rlm@46: Date.formatCodeToRegex = function(character, currentGroup) { rlm@46: var p = Date.parseCodes[character]; rlm@46: rlm@46: if (p) { rlm@46: p = Ext.type(p) == 'function'? p() : p; rlm@46: Date.parseCodes[character] = p; rlm@46: if (p.c) { rlm@46: p.c = String.format(p.c, currentGroup); rlm@46: } rlm@46: } rlm@46: rlm@46: return p || { rlm@46: g:0, rlm@46: c:null, rlm@46: s:Ext.escapeRe(character) } rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getTimezone = function() { rlm@46: return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, ""); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getGMTOffset = function(colon) { rlm@46: return (this.getTimezoneOffset() > 0 ? "-" : "+") rlm@46: + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0") rlm@46: + (colon ? ":" : "") rlm@46: + String.leftPad(this.getTimezoneOffset() % 60, 2, "0"); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getDayOfYear = function() { rlm@46: var num = 0; rlm@46: Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; rlm@46: for (var i = 0; i < this.getMonth(); ++i) { rlm@46: num += Date.daysInMonth[i]; rlm@46: } rlm@46: return num + this.getDate() - 1; rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getWeekOfYear = function() { rlm@46: var ms1d = 864e5; var ms7d = 7 * ms1d; var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d; var AWN = Math.floor(DC3 / 7); var Wyr = new Date(AWN * ms7d).getUTCFullYear(); rlm@46: return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1; rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.isLeapYear = function() { rlm@46: var year = this.getFullYear(); rlm@46: return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year))); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getFirstDayOfMonth = function() { rlm@46: var day = (this.getDay() - (this.getDate() - 1)) % 7; rlm@46: return (day < 0) ? (day + 7) : day; rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getLastDayOfMonth = function() { rlm@46: var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7; rlm@46: return (day < 0) ? (day + 7) : day; rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: Date.prototype.getFirstDateOfMonth = function() { rlm@46: return new Date(this.getFullYear(), this.getMonth(), 1); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getLastDateOfMonth = function() { rlm@46: return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth()); rlm@46: }; rlm@46: rlm@46: Date.prototype.getDaysInMonth = function() { rlm@46: Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; rlm@46: return Date.daysInMonth[this.getMonth()]; rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.getSuffix = function() { rlm@46: switch (this.getDate()) { rlm@46: case 1: rlm@46: case 21: rlm@46: case 31: rlm@46: return "st"; rlm@46: case 2: rlm@46: case 22: rlm@46: return "nd"; rlm@46: case 3: rlm@46: case 23: rlm@46: return "rd"; rlm@46: default: rlm@46: return "th"; rlm@46: } rlm@46: }; rlm@46: rlm@46: Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; rlm@46: rlm@46: rlm@46: Date.monthNames = [ rlm@46: "January", rlm@46: "February", rlm@46: "March", rlm@46: "April", rlm@46: "May", rlm@46: "June", rlm@46: "July", rlm@46: "August", rlm@46: "September", rlm@46: "October", rlm@46: "November", rlm@46: "December" rlm@46: ]; rlm@46: rlm@46: rlm@46: Date.getShortMonthName = function(month) { rlm@46: return Date.monthNames[month].substring(0, 3); rlm@46: } rlm@46: rlm@46: rlm@46: Date.dayNames = [ rlm@46: "Sunday", rlm@46: "Monday", rlm@46: "Tuesday", rlm@46: "Wednesday", rlm@46: "Thursday", rlm@46: "Friday", rlm@46: "Saturday" rlm@46: ]; rlm@46: rlm@46: rlm@46: Date.getShortDayName = function(day) { rlm@46: return Date.dayNames[day].substring(0, 3); rlm@46: } rlm@46: rlm@46: Date.y2kYear = 50; rlm@46: rlm@46: rlm@46: Date.monthNumbers = { rlm@46: Jan:0, rlm@46: Feb:1, rlm@46: Mar:2, rlm@46: Apr:3, rlm@46: May:4, rlm@46: Jun:5, rlm@46: Jul:6, rlm@46: Aug:7, rlm@46: Sep:8, rlm@46: Oct:9, rlm@46: Nov:10, rlm@46: Dec:11 rlm@46: }; rlm@46: rlm@46: rlm@46: Date.getMonthNumber = function(name) { rlm@46: return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()]; rlm@46: } rlm@46: rlm@46: rlm@46: Date.prototype.clone = function() { rlm@46: return new Date(this.getTime()); rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.clearTime = function(clone){ rlm@46: if(clone){ rlm@46: return this.clone().clearTime(); rlm@46: } rlm@46: this.setHours(0); rlm@46: this.setMinutes(0); rlm@46: this.setSeconds(0); rlm@46: this.setMilliseconds(0); rlm@46: return this; rlm@46: }; rlm@46: rlm@46: if(Ext.isSafari){ rlm@46: Date.brokenSetMonth = Date.prototype.setMonth; rlm@46: Date.prototype.setMonth = function(num){ rlm@46: if(num <= -1){ rlm@46: var n = Math.ceil(-num); rlm@46: var back_year = Math.ceil(n/12); rlm@46: var month = (n % 12) ? 12 - n % 12 : 0 ; rlm@46: this.setFullYear(this.getFullYear() - back_year); rlm@46: return Date.brokenSetMonth.call(this, month); rlm@46: } else { rlm@46: return Date.brokenSetMonth.apply(this, arguments); rlm@46: } rlm@46: }; rlm@46: } rlm@46: rlm@46: rlm@46: Date.MILLI = "ms"; rlm@46: rlm@46: Date.SECOND = "s"; rlm@46: rlm@46: Date.MINUTE = "mi"; rlm@46: rlm@46: Date.HOUR = "h"; rlm@46: rlm@46: Date.DAY = "d"; rlm@46: rlm@46: Date.MONTH = "mo"; rlm@46: rlm@46: Date.YEAR = "y"; rlm@46: rlm@46: rlm@46: Date.prototype.add = function(interval, value){ rlm@46: var d = this.clone(); rlm@46: if (!interval || value === 0) return d; rlm@46: switch(interval.toLowerCase()){ rlm@46: case Date.MILLI: rlm@46: d.setMilliseconds(this.getMilliseconds() + value); rlm@46: break; rlm@46: case Date.SECOND: rlm@46: d.setSeconds(this.getSeconds() + value); rlm@46: break; rlm@46: case Date.MINUTE: rlm@46: d.setMinutes(this.getMinutes() + value); rlm@46: break; rlm@46: case Date.HOUR: rlm@46: d.setHours(this.getHours() + value); rlm@46: break; rlm@46: case Date.DAY: rlm@46: d.setDate(this.getDate() + value); rlm@46: break; rlm@46: case Date.MONTH: rlm@46: var day = this.getDate(); rlm@46: if(day > 28){ rlm@46: day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate()); rlm@46: } rlm@46: d.setDate(day); rlm@46: d.setMonth(this.getMonth() + value); rlm@46: break; rlm@46: case Date.YEAR: rlm@46: d.setFullYear(this.getFullYear() + value); rlm@46: break; rlm@46: } rlm@46: return d; rlm@46: }; rlm@46: rlm@46: rlm@46: Date.prototype.between = function(start, end){ rlm@46: var t = this.getTime(); rlm@46: return start.getTime() <= t && t <= end.getTime(); rlm@46: } rlm@46: rlm@46: Ext.util.DelayedTask = function(fn, scope, args){ rlm@46: var id = null, d, t; rlm@46: rlm@46: var call = function(){ rlm@46: var now = new Date().getTime(); rlm@46: if(now - t >= d){ rlm@46: clearInterval(id); rlm@46: id = null; rlm@46: fn.apply(scope, args || []); rlm@46: } rlm@46: }; rlm@46: rlm@46: this.delay = function(delay, newFn, newScope, newArgs){ rlm@46: if(id && delay != d){ rlm@46: this.cancel(); rlm@46: } rlm@46: d = delay; rlm@46: t = new Date().getTime(); rlm@46: fn = newFn || fn; rlm@46: scope = newScope || scope; rlm@46: args = newArgs || args; rlm@46: if(!id){ rlm@46: id = setInterval(call, d); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: this.cancel = function(){ rlm@46: if(id){ rlm@46: clearInterval(id); rlm@46: id = null; rlm@46: } rlm@46: }; rlm@46: }; rlm@46: rlm@46: Ext.util.TaskRunner = function(interval){ rlm@46: interval = interval || 10; rlm@46: var tasks = [], removeQueue = []; rlm@46: var id = 0; rlm@46: var running = false; rlm@46: rlm@46: var stopThread = function(){ rlm@46: running = false; rlm@46: clearInterval(id); rlm@46: id = 0; rlm@46: }; rlm@46: rlm@46: var startThread = function(){ rlm@46: if(!running){ rlm@46: running = true; rlm@46: id = setInterval(runTasks, interval); rlm@46: } rlm@46: }; rlm@46: rlm@46: var removeTask = function(t){ rlm@46: removeQueue.push(t); rlm@46: if(t.onStop){ rlm@46: t.onStop.apply(t.scope || t); rlm@46: } rlm@46: }; rlm@46: rlm@46: var runTasks = function(){ rlm@46: if(removeQueue.length > 0){ rlm@46: for(var i = 0, len = removeQueue.length; i < len; i++){ rlm@46: tasks.remove(removeQueue[i]); rlm@46: } rlm@46: removeQueue = []; rlm@46: if(tasks.length < 1){ rlm@46: stopThread(); rlm@46: return; rlm@46: } rlm@46: } rlm@46: var now = new Date().getTime(); rlm@46: for(var i = 0, len = tasks.length; i < len; ++i){ rlm@46: var t = tasks[i]; rlm@46: var itime = now - t.taskRunTime; rlm@46: if(t.interval <= itime){ rlm@46: var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]); rlm@46: t.taskRunTime = now; rlm@46: if(rt === false || t.taskRunCount === t.repeat){ rlm@46: removeTask(t); rlm@46: return; rlm@46: } rlm@46: } rlm@46: if(t.duration && t.duration <= (now - t.taskStartTime)){ rlm@46: removeTask(t); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: this.start = function(task){ rlm@46: tasks.push(task); rlm@46: task.taskStartTime = new Date().getTime(); rlm@46: task.taskRunTime = 0; rlm@46: task.taskRunCount = 0; rlm@46: startThread(); rlm@46: return task; rlm@46: }; rlm@46: rlm@46: rlm@46: this.stop = function(task){ rlm@46: removeTask(task); rlm@46: return task; rlm@46: }; rlm@46: rlm@46: rlm@46: this.stopAll = function(){ rlm@46: stopThread(); rlm@46: for(var i = 0, len = tasks.length; i < len; i++){ rlm@46: if(tasks[i].onStop){ rlm@46: tasks[i].onStop(); rlm@46: } rlm@46: } rlm@46: tasks = []; rlm@46: removeQueue = []; rlm@46: }; rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.TaskMgr = new Ext.util.TaskRunner(); rlm@46: rlm@46: Ext.util.MixedCollection = function(allowFunctions, keyFn){ rlm@46: this.items = []; rlm@46: this.map = {}; rlm@46: this.keys = []; rlm@46: this.length = 0; rlm@46: this.addEvents( rlm@46: rlm@46: "clear", rlm@46: rlm@46: "add", rlm@46: rlm@46: "replace", rlm@46: rlm@46: "remove", rlm@46: "sort" rlm@46: ); rlm@46: this.allowFunctions = allowFunctions === true; rlm@46: if(keyFn){ rlm@46: this.getKey = keyFn; rlm@46: } rlm@46: Ext.util.MixedCollection.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, { rlm@46: allowFunctions : false, rlm@46: rlm@46: rlm@46: add : function(key, o){ rlm@46: if(arguments.length == 1){ rlm@46: o = arguments[0]; rlm@46: key = this.getKey(o); rlm@46: } rlm@46: if(typeof key == "undefined" || key === null){ rlm@46: this.length++; rlm@46: this.items.push(o); rlm@46: this.keys.push(null); rlm@46: }else{ rlm@46: var old = this.map[key]; rlm@46: if(old){ rlm@46: return this.replace(key, o); rlm@46: } rlm@46: this.length++; rlm@46: this.items.push(o); rlm@46: this.map[key] = o; rlm@46: this.keys.push(key); rlm@46: } rlm@46: this.fireEvent("add", this.length-1, o, key); rlm@46: return o; rlm@46: }, rlm@46: rlm@46: rlm@46: getKey : function(o){ rlm@46: return o.id; rlm@46: }, rlm@46: rlm@46: rlm@46: replace : function(key, o){ rlm@46: if(arguments.length == 1){ rlm@46: o = arguments[0]; rlm@46: key = this.getKey(o); rlm@46: } rlm@46: var old = this.item(key); rlm@46: if(typeof key == "undefined" || key === null || typeof old == "undefined"){ rlm@46: return this.add(key, o); rlm@46: } rlm@46: var index = this.indexOfKey(key); rlm@46: this.items[index] = o; rlm@46: this.map[key] = o; rlm@46: this.fireEvent("replace", key, old, o); rlm@46: return o; rlm@46: }, rlm@46: rlm@46: rlm@46: addAll : function(objs){ rlm@46: if(arguments.length > 1 || Ext.isArray(objs)){ rlm@46: var args = arguments.length > 1 ? arguments : objs; rlm@46: for(var i = 0, len = args.length; i < len; i++){ rlm@46: this.add(args[i]); rlm@46: } rlm@46: }else{ rlm@46: for(var key in objs){ rlm@46: if(this.allowFunctions || typeof objs[key] != "function"){ rlm@46: this.add(key, objs[key]); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: var items = [].concat(this.items); rlm@46: for(var i = 0, len = items.length; i < len; i++){ rlm@46: if(fn.call(scope || items[i], items[i], i, len) === false){ rlm@46: break; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: eachKey : function(fn, scope){ rlm@46: for(var i = 0, len = this.keys.length; i < len; i++){ rlm@46: fn.call(scope || window, this.keys[i], this.items[i], i, len); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: find : function(fn, scope){ rlm@46: for(var i = 0, len = this.items.length; i < len; i++){ rlm@46: if(fn.call(scope || window, this.items[i], this.keys[i])){ rlm@46: return this.items[i]; rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: insert : function(index, key, o){ rlm@46: if(arguments.length == 2){ rlm@46: o = arguments[1]; rlm@46: key = this.getKey(o); rlm@46: } rlm@46: if(index >= this.length){ rlm@46: return this.add(key, o); rlm@46: } rlm@46: this.length++; rlm@46: this.items.splice(index, 0, o); rlm@46: if(typeof key != "undefined" && key != null){ rlm@46: this.map[key] = o; rlm@46: } rlm@46: this.keys.splice(index, 0, key); rlm@46: this.fireEvent("add", index, o, key); rlm@46: return o; rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(o){ rlm@46: return this.removeAt(this.indexOf(o)); rlm@46: }, rlm@46: rlm@46: rlm@46: removeAt : function(index){ rlm@46: if(index < this.length && index >= 0){ rlm@46: this.length--; rlm@46: var o = this.items[index]; rlm@46: this.items.splice(index, 1); rlm@46: var key = this.keys[index]; rlm@46: if(typeof key != "undefined"){ rlm@46: delete this.map[key]; rlm@46: } rlm@46: this.keys.splice(index, 1); rlm@46: this.fireEvent("remove", o, key); rlm@46: return o; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: removeKey : function(key){ rlm@46: return this.removeAt(this.indexOfKey(key)); rlm@46: }, rlm@46: rlm@46: rlm@46: getCount : function(){ rlm@46: return this.length; rlm@46: }, rlm@46: rlm@46: rlm@46: indexOf : function(o){ rlm@46: return this.items.indexOf(o); rlm@46: }, rlm@46: rlm@46: rlm@46: indexOfKey : function(key){ rlm@46: return this.keys.indexOf(key); rlm@46: }, rlm@46: rlm@46: rlm@46: item : function(key){ rlm@46: var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key]; rlm@46: return typeof item != 'function' || this.allowFunctions ? item : null; rlm@46: }, rlm@46: rlm@46: rlm@46: itemAt : function(index){ rlm@46: return this.items[index]; rlm@46: }, rlm@46: rlm@46: rlm@46: key : function(key){ rlm@46: return this.map[key]; rlm@46: }, rlm@46: rlm@46: rlm@46: contains : function(o){ rlm@46: return this.indexOf(o) != -1; rlm@46: }, rlm@46: rlm@46: rlm@46: containsKey : function(key){ rlm@46: return typeof this.map[key] != "undefined"; rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(){ rlm@46: this.length = 0; rlm@46: this.items = []; rlm@46: this.keys = []; rlm@46: this.map = {}; rlm@46: this.fireEvent("clear"); rlm@46: }, rlm@46: rlm@46: rlm@46: first : function(){ rlm@46: return this.items[0]; rlm@46: }, rlm@46: rlm@46: rlm@46: last : function(){ rlm@46: return this.items[this.length-1]; rlm@46: }, rlm@46: rlm@46: rlm@46: _sort : function(property, dir, fn){ rlm@46: var dsc = String(dir).toUpperCase() == "DESC" ? -1 : 1; rlm@46: fn = fn || function(a, b){ rlm@46: return a-b; rlm@46: }; rlm@46: var c = [], k = this.keys, items = this.items; rlm@46: for(var i = 0, len = items.length; i < len; i++){ rlm@46: c[c.length] = {key: k[i], value: items[i], index: i}; rlm@46: } rlm@46: c.sort(function(a, b){ rlm@46: var v = fn(a[property], b[property]) * dsc; rlm@46: if(v == 0){ rlm@46: v = (a.index < b.index ? -1 : 1); rlm@46: } rlm@46: return v; rlm@46: }); rlm@46: for(var i = 0, len = c.length; i < len; i++){ rlm@46: items[i] = c[i].value; rlm@46: k[i] = c[i].key; rlm@46: } rlm@46: this.fireEvent("sort", this); rlm@46: }, rlm@46: rlm@46: rlm@46: sort : function(dir, fn){ rlm@46: this._sort("value", dir, fn); rlm@46: }, rlm@46: rlm@46: rlm@46: keySort : function(dir, fn){ rlm@46: this._sort("key", dir, fn || function(a, b){ rlm@46: return String(a).toUpperCase()-String(b).toUpperCase(); rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: getRange : function(start, end){ rlm@46: var items = this.items; rlm@46: if(items.length < 1){ rlm@46: return []; rlm@46: } rlm@46: start = start || 0; rlm@46: end = Math.min(typeof end == "undefined" ? this.length-1 : end, this.length-1); rlm@46: var r = []; rlm@46: if(start <= end){ rlm@46: for(var i = start; i <= end; i++) { rlm@46: r[r.length] = items[i]; rlm@46: } rlm@46: }else{ rlm@46: for(var i = start; i >= end; i--) { rlm@46: r[r.length] = items[i]; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: filter : function(property, value, anyMatch, caseSensitive){ rlm@46: if(Ext.isEmpty(value, false)){ rlm@46: return this.clone(); rlm@46: } rlm@46: value = this.createValueMatcher(value, anyMatch, caseSensitive); rlm@46: return this.filterBy(function(o){ rlm@46: return o && value.test(o[property]); rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: filterBy : function(fn, scope){ rlm@46: var r = new Ext.util.MixedCollection(); rlm@46: r.getKey = this.getKey; rlm@46: var k = this.keys, it = this.items; rlm@46: for(var i = 0, len = it.length; i < len; i++){ rlm@46: if(fn.call(scope||this, it[i], k[i])){ rlm@46: r.add(k[i], it[i]); rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: findIndex : function(property, value, start, anyMatch, caseSensitive){ rlm@46: if(Ext.isEmpty(value, false)){ rlm@46: return -1; rlm@46: } rlm@46: value = this.createValueMatcher(value, anyMatch, caseSensitive); rlm@46: return this.findIndexBy(function(o){ rlm@46: return o && value.test(o[property]); rlm@46: }, null, start); rlm@46: }, rlm@46: rlm@46: rlm@46: findIndexBy : function(fn, scope, start){ rlm@46: var k = this.keys, it = this.items; rlm@46: for(var i = (start||0), len = it.length; i < len; i++){ rlm@46: if(fn.call(scope||this, it[i], k[i])){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: if(typeof start == 'number' && start > 0){ rlm@46: for(var i = 0; i < start; i++){ rlm@46: if(fn.call(scope||this, it[i], k[i])){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: } rlm@46: return -1; rlm@46: }, rlm@46: rlm@46: rlm@46: createValueMatcher : function(value, anyMatch, caseSensitive){ rlm@46: if(!value.exec){ rlm@46: value = String(value); rlm@46: value = new RegExp((anyMatch === true ? '' : '^') + Ext.escapeRe(value), caseSensitive ? '' : 'i'); rlm@46: } rlm@46: return value; rlm@46: }, rlm@46: rlm@46: rlm@46: clone : function(){ rlm@46: var r = new Ext.util.MixedCollection(); rlm@46: var k = this.keys, it = this.items; rlm@46: for(var i = 0, len = it.length; i < len; i++){ rlm@46: r.add(k[i], it[i]); rlm@46: } rlm@46: r.getKey = this.getKey; rlm@46: return r; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item; rlm@46: rlm@46: Ext.util.JSON = new (function(){ rlm@46: var useHasOwn = !!{}.hasOwnProperty; rlm@46: rlm@46: rlm@46: var pad = function(n) { rlm@46: return n < 10 ? "0" + n : n; rlm@46: }; rlm@46: rlm@46: var m = { rlm@46: "\b": '\\b', rlm@46: "\t": '\\t', rlm@46: "\n": '\\n', rlm@46: "\f": '\\f', rlm@46: "\r": '\\r', rlm@46: '"' : '\\"', rlm@46: "\\": '\\\\' rlm@46: }; rlm@46: rlm@46: var encodeString = function(s){ rlm@46: if (/["\\\x00-\x1f]/.test(s)) { rlm@46: return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) { rlm@46: var c = m[b]; rlm@46: if(c){ rlm@46: return c; rlm@46: } rlm@46: c = b.charCodeAt(); rlm@46: return "\\u00" + rlm@46: Math.floor(c / 16).toString(16) + rlm@46: (c % 16).toString(16); rlm@46: }) + '"'; rlm@46: } rlm@46: return '"' + s + '"'; rlm@46: }; rlm@46: rlm@46: var encodeArray = function(o){ rlm@46: var a = ["["], b, i, l = o.length, v; rlm@46: for (i = 0; i < l; i += 1) { rlm@46: v = o[i]; rlm@46: switch (typeof v) { rlm@46: case "undefined": rlm@46: case "function": rlm@46: case "unknown": rlm@46: break; rlm@46: default: rlm@46: if (b) { rlm@46: a.push(','); rlm@46: } rlm@46: a.push(v === null ? "null" : Ext.util.JSON.encode(v)); rlm@46: b = true; rlm@46: } rlm@46: } rlm@46: a.push("]"); rlm@46: return a.join(""); rlm@46: }; rlm@46: rlm@46: this.encodeDate = function(o){ rlm@46: return '"' + o.getFullYear() + "-" + rlm@46: pad(o.getMonth() + 1) + "-" + rlm@46: pad(o.getDate()) + "T" + rlm@46: pad(o.getHours()) + ":" + rlm@46: pad(o.getMinutes()) + ":" + rlm@46: pad(o.getSeconds()) + '"'; rlm@46: }; rlm@46: rlm@46: rlm@46: this.encode = function(o){ rlm@46: if(typeof o == "undefined" || o === null){ rlm@46: return "null"; rlm@46: }else if(Ext.isArray(o)){ rlm@46: return encodeArray(o); rlm@46: }else if(Ext.isDate(o)){ rlm@46: return Ext.util.JSON.encodeDate(o); rlm@46: }else if(typeof o == "string"){ rlm@46: return encodeString(o); rlm@46: }else if(typeof o == "number"){ rlm@46: return isFinite(o) ? String(o) : "null"; rlm@46: }else if(typeof o == "boolean"){ rlm@46: return String(o); rlm@46: }else { rlm@46: var a = ["{"], b, i, v; rlm@46: for (i in o) { rlm@46: if(!useHasOwn || o.hasOwnProperty(i)) { rlm@46: v = o[i]; rlm@46: switch (typeof v) { rlm@46: case "undefined": rlm@46: case "function": rlm@46: case "unknown": rlm@46: break; rlm@46: default: rlm@46: if(b){ rlm@46: a.push(','); rlm@46: } rlm@46: a.push(this.encode(i), ":", rlm@46: v === null ? "null" : this.encode(v)); rlm@46: b = true; rlm@46: } rlm@46: } rlm@46: } rlm@46: a.push("}"); rlm@46: return a.join(""); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: this.decode = function(json){ rlm@46: return eval("(" + json + ')'); rlm@46: }; rlm@46: })(); rlm@46: rlm@46: Ext.encode = Ext.util.JSON.encode; rlm@46: rlm@46: Ext.decode = Ext.util.JSON.decode; rlm@46: rlm@46: rlm@46: Ext.util.Format = function(){ rlm@46: var trimRe = /^\s+|\s+$/g; rlm@46: return { rlm@46: rlm@46: ellipsis : function(value, len){ rlm@46: if(value && value.length > len){ rlm@46: return value.substr(0, len-3)+"..."; rlm@46: } rlm@46: return value; rlm@46: }, rlm@46: rlm@46: rlm@46: undef : function(value){ rlm@46: return value !== undefined ? value : ""; rlm@46: }, rlm@46: rlm@46: rlm@46: defaultValue : function(value, defaultValue){ rlm@46: return value !== undefined && value !== '' ? value : defaultValue; rlm@46: }, rlm@46: rlm@46: rlm@46: htmlEncode : function(value){ rlm@46: return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/").replace(/</g, "<").replace(/"/g, '"'); rlm@46: }, rlm@46: rlm@46: rlm@46: trim : function(value){ rlm@46: return String(value).replace(trimRe, ""); rlm@46: }, rlm@46: rlm@46: rlm@46: substr : function(value, start, length){ rlm@46: return String(value).substr(start, length); rlm@46: }, rlm@46: rlm@46: rlm@46: lowercase : function(value){ rlm@46: return String(value).toLowerCase(); rlm@46: }, rlm@46: rlm@46: rlm@46: uppercase : function(value){ rlm@46: return String(value).toUpperCase(); rlm@46: }, rlm@46: rlm@46: rlm@46: capitalize : function(value){ rlm@46: return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase(); rlm@46: }, rlm@46: rlm@46: rlm@46: call : function(value, fn){ rlm@46: if(arguments.length > 2){ rlm@46: var args = Array.prototype.slice.call(arguments, 2); rlm@46: args.unshift(value); rlm@46: return eval(fn).apply(window, args); rlm@46: }else{ rlm@46: return eval(fn).call(window, value); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: usMoney : function(v){ rlm@46: v = (Math.round((v-0)*100))/100; rlm@46: v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v); rlm@46: v = String(v); rlm@46: var ps = v.split('.'); rlm@46: var whole = ps[0]; rlm@46: var sub = ps[1] ? '.'+ ps[1] : '.00'; rlm@46: var r = /(\d+)(\d{3})/; rlm@46: while (r.test(whole)) { rlm@46: whole = whole.replace(r, '$1' + ',' + '$2'); rlm@46: } rlm@46: v = whole + sub; rlm@46: if(v.charAt(0) == '-'){ rlm@46: return '-$' + v.substr(1); rlm@46: } rlm@46: return "$" + v; rlm@46: }, rlm@46: rlm@46: rlm@46: date : function(v, format){ rlm@46: if(!v){ rlm@46: return ""; rlm@46: } rlm@46: if(!Ext.isDate(v)){ rlm@46: v = new Date(Date.parse(v)); rlm@46: } rlm@46: return v.dateFormat(format || "m/d/Y"); rlm@46: }, rlm@46: rlm@46: rlm@46: dateRenderer : function(format){ rlm@46: return function(v){ rlm@46: return Ext.util.Format.date(v, format); rlm@46: }; rlm@46: }, rlm@46: rlm@46: rlm@46: stripTagsRE : /<\/?[^>]+>/gi, rlm@46: rlm@46: rlm@46: stripTags : function(v){ rlm@46: return !v ? v : String(v).replace(this.stripTagsRE, ""); rlm@46: }, rlm@46: rlm@46: stripScriptsRe : /(?:)((\n|\r|.)*?)(?:<\/script>)/ig, rlm@46: rlm@46: rlm@46: stripScripts : function(v){ rlm@46: return !v ? v : String(v).replace(this.stripScriptsRe, ""); rlm@46: }, rlm@46: rlm@46: rlm@46: fileSize : function(size){ rlm@46: if(size < 1024) { rlm@46: return size + " bytes"; rlm@46: } else if(size < 1048576) { rlm@46: return (Math.round(((size*10) / 1024))/10) + " KB"; rlm@46: } else { rlm@46: return (Math.round(((size*10) / 1048576))/10) + " MB"; rlm@46: } rlm@46: }, rlm@46: rlm@46: math : function(){ rlm@46: var fns = {}; rlm@46: return function(v, a){ rlm@46: if(!fns[a]){ rlm@46: fns[a] = new Function('v', 'return v ' + a + ';'); rlm@46: } rlm@46: return fns[a](v); rlm@46: } rlm@46: }() rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.XTemplate = function(){ rlm@46: Ext.XTemplate.superclass.constructor.apply(this, arguments); rlm@46: var s = this.html; rlm@46: rlm@46: s = ['', s, ''].join(''); rlm@46: rlm@46: var re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/; rlm@46: rlm@46: var nameRe = /^]*?for="(.*?)"/; rlm@46: var ifRe = /^]*?if="(.*?)"/; rlm@46: var execRe = /^]*?exec="(.*?)"/; rlm@46: var m, id = 0; rlm@46: var tpls = []; rlm@46: rlm@46: while(m = s.match(re)){ rlm@46: var m2 = m[0].match(nameRe); rlm@46: var m3 = m[0].match(ifRe); rlm@46: var m4 = m[0].match(execRe); rlm@46: var exp = null, fn = null, exec = null; rlm@46: var name = m2 && m2[1] ? m2[1] : ''; rlm@46: if(m3){ rlm@46: exp = m3 && m3[1] ? m3[1] : null; rlm@46: if(exp){ rlm@46: fn = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ return '+(Ext.util.Format.htmlDecode(exp))+'; }'); rlm@46: } rlm@46: } rlm@46: if(m4){ rlm@46: exp = m4 && m4[1] ? m4[1] : null; rlm@46: if(exp){ rlm@46: exec = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ '+(Ext.util.Format.htmlDecode(exp))+'; }'); rlm@46: } rlm@46: } rlm@46: if(name){ rlm@46: switch(name){ rlm@46: case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break; rlm@46: case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break; rlm@46: default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); rlm@46: } rlm@46: } rlm@46: tpls.push({ rlm@46: id: id, rlm@46: target: name, rlm@46: exec: exec, rlm@46: test: fn, rlm@46: body: m[1]||'' rlm@46: }); rlm@46: s = s.replace(m[0], '{xtpl'+ id + '}'); rlm@46: ++id; rlm@46: } rlm@46: for(var i = tpls.length-1; i >= 0; --i){ rlm@46: this.compileTpl(tpls[i]); rlm@46: } rlm@46: this.master = tpls[tpls.length-1]; rlm@46: this.tpls = tpls; rlm@46: }; rlm@46: Ext.extend(Ext.XTemplate, Ext.Template, { rlm@46: re : /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g, rlm@46: codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g, rlm@46: rlm@46: applySubTemplate : function(id, values, parent, xindex, xcount){ rlm@46: var t = this.tpls[id]; rlm@46: if(t.test && !t.test.call(this, values, parent, xindex, xcount)){ rlm@46: return ''; rlm@46: } rlm@46: if(t.exec && t.exec.call(this, values, parent, xindex, xcount)){ rlm@46: return ''; rlm@46: } rlm@46: var vs = t.target ? t.target.call(this, values, parent) : values; rlm@46: parent = t.target ? values : parent; rlm@46: if(t.target && Ext.isArray(vs)){ rlm@46: var buf = []; rlm@46: for(var i = 0, len = vs.length; i < len; i++){ rlm@46: buf[buf.length] = t.compiled.call(this, vs[i], parent, i+1, len); rlm@46: } rlm@46: return buf.join(''); rlm@46: } rlm@46: return t.compiled.call(this, vs, parent, xindex, xcount); rlm@46: }, rlm@46: rlm@46: compileTpl : function(tpl){ rlm@46: var fm = Ext.util.Format; rlm@46: var useF = this.disableFormats !== true; rlm@46: var sep = Ext.isGecko ? "+" : ","; rlm@46: var fn = function(m, name, format, args, math){ rlm@46: if(name.substr(0, 4) == 'xtpl'){ rlm@46: return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'"; rlm@46: } rlm@46: var v; rlm@46: if(name === '.'){ rlm@46: v = 'values'; rlm@46: }else if(name === '#'){ rlm@46: v = 'xindex'; rlm@46: }else if(name.indexOf('.') != -1){ rlm@46: v = name; rlm@46: }else{ rlm@46: v = "values['" + name + "']"; rlm@46: } rlm@46: if(math){ rlm@46: v = '(' + v + math + ')'; rlm@46: } rlm@46: if(format && useF){ rlm@46: args = args ? ',' + args : ""; rlm@46: if(format.substr(0, 5) != "this."){ rlm@46: format = "fm." + format + '('; rlm@46: }else{ rlm@46: format = 'this.call("'+ format.substr(5) + '", '; rlm@46: args = ", values"; rlm@46: } rlm@46: }else{ rlm@46: args= ''; format = "("+v+" === undefined ? '' : "; rlm@46: } rlm@46: return "'"+ sep + format + v + args + ")"+sep+"'"; rlm@46: }; rlm@46: var codeFn = function(m, code){ rlm@46: return "'"+ sep +'('+code+')'+sep+"'"; rlm@46: }; rlm@46: rlm@46: var body; rlm@46: if(Ext.isGecko){ rlm@46: body = "tpl.compiled = function(values, parent, xindex, xcount){ return '" + rlm@46: tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn) + rlm@46: "';};"; rlm@46: }else{ rlm@46: body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"]; rlm@46: body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn)); rlm@46: body.push("'].join('');};"); rlm@46: body = body.join(''); rlm@46: } rlm@46: eval(body); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: applyTemplate : function(values){ rlm@46: return this.master.compiled.call(this, values, {}, 1, 1); rlm@46: }, rlm@46: rlm@46: rlm@46: compile : function(){return this;} rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate; rlm@46: rlm@46: rlm@46: Ext.XTemplate.from = function(el){ rlm@46: el = Ext.getDom(el); rlm@46: return new Ext.XTemplate(el.value || el.innerHTML); rlm@46: }; rlm@46: rlm@46: Ext.util.CSS = function(){ rlm@46: var rules = null; rlm@46: var doc = document; rlm@46: rlm@46: var camelRe = /(-[a-z])/gi; rlm@46: var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); }; rlm@46: rlm@46: return { rlm@46: rlm@46: createStyleSheet : function(cssText, id){ rlm@46: var ss; rlm@46: var head = doc.getElementsByTagName("head")[0]; rlm@46: var rules = doc.createElement("style"); rlm@46: rules.setAttribute("type", "text/css"); rlm@46: if(id){ rlm@46: rules.setAttribute("id", id); rlm@46: } rlm@46: if(Ext.isIE){ rlm@46: head.appendChild(rules); rlm@46: ss = rules.styleSheet; rlm@46: ss.cssText = cssText; rlm@46: }else{ rlm@46: try{ rlm@46: rules.appendChild(doc.createTextNode(cssText)); rlm@46: }catch(e){ rlm@46: rules.cssText = cssText; rlm@46: } rlm@46: head.appendChild(rules); rlm@46: ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]); rlm@46: } rlm@46: this.cacheStyleSheet(ss); rlm@46: return ss; rlm@46: }, rlm@46: rlm@46: rlm@46: removeStyleSheet : function(id){ rlm@46: var existing = doc.getElementById(id); rlm@46: if(existing){ rlm@46: existing.parentNode.removeChild(existing); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: swapStyleSheet : function(id, url){ rlm@46: this.removeStyleSheet(id); rlm@46: var ss = doc.createElement("link"); rlm@46: ss.setAttribute("rel", "stylesheet"); rlm@46: ss.setAttribute("type", "text/css"); rlm@46: ss.setAttribute("id", id); rlm@46: ss.setAttribute("href", url); rlm@46: doc.getElementsByTagName("head")[0].appendChild(ss); rlm@46: }, rlm@46: rlm@46: rlm@46: refreshCache : function(){ rlm@46: return this.getRules(true); rlm@46: }, rlm@46: rlm@46: rlm@46: cacheStyleSheet : function(ss){ rlm@46: if(!rules){ rlm@46: rules = {}; rlm@46: } rlm@46: try{ rlm@46: var ssRules = ss.cssRules || ss.rules; rlm@46: for(var j = ssRules.length-1; j >= 0; --j){ rlm@46: rules[ssRules[j].selectorText] = ssRules[j]; rlm@46: } rlm@46: }catch(e){} rlm@46: }, rlm@46: rlm@46: rlm@46: getRules : function(refreshCache){ rlm@46: if(rules == null || refreshCache){ rlm@46: rules = {}; rlm@46: var ds = doc.styleSheets; rlm@46: for(var i =0, len = ds.length; i < len; i++){ rlm@46: try{ rlm@46: this.cacheStyleSheet(ds[i]); rlm@46: }catch(e){} rlm@46: } rlm@46: } rlm@46: return rules; rlm@46: }, rlm@46: rlm@46: rlm@46: getRule : function(selector, refreshCache){ rlm@46: var rs = this.getRules(refreshCache); rlm@46: if(!Ext.isArray(selector)){ rlm@46: return rs[selector]; rlm@46: } rlm@46: for(var i = 0; i < selector.length; i++){ rlm@46: if(rs[selector[i]]){ rlm@46: return rs[selector[i]]; rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: updateRule : function(selector, property, value){ rlm@46: if(!Ext.isArray(selector)){ rlm@46: var rule = this.getRule(selector); rlm@46: if(rule){ rlm@46: rule.style[property.replace(camelRe, camelFn)] = value; rlm@46: return true; rlm@46: } rlm@46: }else{ rlm@46: for(var i = 0; i < selector.length; i++){ rlm@46: if(this.updateRule(selector[i], property, value)){ rlm@46: return true; rlm@46: } rlm@46: } rlm@46: } rlm@46: return false; rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.util.ClickRepeater = function(el, config) rlm@46: { rlm@46: this.el = Ext.get(el); rlm@46: this.el.unselectable(); rlm@46: rlm@46: Ext.apply(this, config); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "mousedown", rlm@46: rlm@46: "click", rlm@46: rlm@46: "mouseup" rlm@46: ); rlm@46: rlm@46: this.el.on("mousedown", this.handleMouseDown, this); rlm@46: if(this.preventDefault || this.stopDefault){ rlm@46: this.el.on("click", function(e){ rlm@46: if(this.preventDefault){ rlm@46: e.preventDefault(); rlm@46: } rlm@46: if(this.stopDefault){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, this); rlm@46: } rlm@46: rlm@46: if(this.handler){ rlm@46: this.on("click", this.handler, this.scope || this); rlm@46: } rlm@46: rlm@46: Ext.util.ClickRepeater.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, { rlm@46: interval : 20, rlm@46: delay: 250, rlm@46: preventDefault : true, rlm@46: stopDefault : false, rlm@46: timer : 0, rlm@46: rlm@46: handleMouseDown : function(){ rlm@46: clearTimeout(this.timer); rlm@46: this.el.blur(); rlm@46: if(this.pressClass){ rlm@46: this.el.addClass(this.pressClass); rlm@46: } rlm@46: this.mousedownTime = new Date(); rlm@46: rlm@46: Ext.getDoc().on("mouseup", this.handleMouseUp, this); rlm@46: this.el.on("mouseout", this.handleMouseOut, this); rlm@46: rlm@46: this.fireEvent("mousedown", this); rlm@46: this.fireEvent("click", this); rlm@46: rlm@46: if (this.accelerate) { rlm@46: this.delay = 400; rlm@46: } rlm@46: this.timer = this.click.defer(this.delay || this.interval, this); rlm@46: }, rlm@46: rlm@46: click : function(){ rlm@46: this.fireEvent("click", this); rlm@46: this.timer = this.click.defer(this.accelerate ? rlm@46: this.easeOutExpo(this.mousedownTime.getElapsed(), rlm@46: 400, rlm@46: -390, rlm@46: 12000) : rlm@46: this.interval, this); rlm@46: }, rlm@46: rlm@46: easeOutExpo : function (t, b, c, d) { rlm@46: return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; rlm@46: }, rlm@46: rlm@46: handleMouseOut : function(){ rlm@46: clearTimeout(this.timer); rlm@46: if(this.pressClass){ rlm@46: this.el.removeClass(this.pressClass); rlm@46: } rlm@46: this.el.on("mouseover", this.handleMouseReturn, this); rlm@46: }, rlm@46: rlm@46: handleMouseReturn : function(){ rlm@46: this.el.un("mouseover", this.handleMouseReturn); rlm@46: if(this.pressClass){ rlm@46: this.el.addClass(this.pressClass); rlm@46: } rlm@46: this.click(); rlm@46: }, rlm@46: rlm@46: handleMouseUp : function(){ rlm@46: clearTimeout(this.timer); rlm@46: this.el.un("mouseover", this.handleMouseReturn); rlm@46: this.el.un("mouseout", this.handleMouseOut); rlm@46: Ext.getDoc().un("mouseup", this.handleMouseUp); rlm@46: this.el.removeClass(this.pressClass); rlm@46: this.fireEvent("mouseup", this); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.KeyNav = function(el, config){ rlm@46: this.el = Ext.get(el); rlm@46: Ext.apply(this, config); rlm@46: if(!this.disabled){ rlm@46: this.disabled = true; rlm@46: this.enable(); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.KeyNav.prototype = { rlm@46: rlm@46: disabled : false, rlm@46: rlm@46: defaultEventAction: "stopEvent", rlm@46: rlm@46: forceKeyDown : false, rlm@46: rlm@46: prepareEvent : function(e){ rlm@46: var k = e.getKey(); rlm@46: var h = this.keyToHandler[k]; rlm@46: if(Ext.isSafari2 && h && k >= 37 && k <= 40){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: relay : function(e){ rlm@46: var k = e.getKey(); rlm@46: var h = this.keyToHandler[k]; rlm@46: if(h && this[h]){ rlm@46: if(this.doRelay(e, this[h], h) !== true){ rlm@46: e[this.defaultEventAction](); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: doRelay : function(e, h, hname){ rlm@46: return h.call(this.scope || this, e); rlm@46: }, rlm@46: rlm@46: enter : false, rlm@46: left : false, rlm@46: right : false, rlm@46: up : false, rlm@46: down : false, rlm@46: tab : false, rlm@46: esc : false, rlm@46: pageUp : false, rlm@46: pageDown : false, rlm@46: del : false, rlm@46: home : false, rlm@46: end : false, rlm@46: rlm@46: keyToHandler : { rlm@46: 37 : "left", rlm@46: 39 : "right", rlm@46: 38 : "up", rlm@46: 40 : "down", rlm@46: 33 : "pageUp", rlm@46: 34 : "pageDown", rlm@46: 46 : "del", rlm@46: 36 : "home", rlm@46: 35 : "end", rlm@46: 13 : "enter", rlm@46: 27 : "esc", rlm@46: 9 : "tab" rlm@46: }, rlm@46: rlm@46: rlm@46: enable: function(){ rlm@46: if(this.disabled){ rlm@46: if(this.forceKeyDown || Ext.isIE || Ext.isSafari3 || Ext.isAir){ rlm@46: this.el.on("keydown", this.relay, this); rlm@46: }else{ rlm@46: this.el.on("keydown", this.prepareEvent, this); rlm@46: this.el.on("keypress", this.relay, this); rlm@46: } rlm@46: this.disabled = false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: disable: function(){ rlm@46: if(!this.disabled){ rlm@46: if(this.forceKeyDown || Ext.isIE || Ext.isSafari3 || Ext.isAir){ rlm@46: this.el.un("keydown", this.relay); rlm@46: }else{ rlm@46: this.el.un("keydown", this.prepareEvent); rlm@46: this.el.un("keypress", this.relay); rlm@46: } rlm@46: this.disabled = true; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.KeyMap = function(el, config, eventName){ rlm@46: this.el = Ext.get(el); rlm@46: this.eventName = eventName || "keydown"; rlm@46: this.bindings = []; rlm@46: if(config){ rlm@46: this.addBinding(config); rlm@46: } rlm@46: this.enable(); rlm@46: }; rlm@46: rlm@46: Ext.KeyMap.prototype = { rlm@46: rlm@46: stopEvent : false, rlm@46: rlm@46: rlm@46: addBinding : function(config){ rlm@46: if(Ext.isArray(config)){ rlm@46: for(var i = 0, len = config.length; i < len; i++){ rlm@46: this.addBinding(config[i]); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var keyCode = config.key, rlm@46: shift = config.shift, rlm@46: ctrl = config.ctrl, rlm@46: alt = config.alt, rlm@46: fn = config.fn || config.handler, rlm@46: scope = config.scope; rlm@46: rlm@46: if(typeof keyCode == "string"){ rlm@46: var ks = []; rlm@46: var keyString = keyCode.toUpperCase(); rlm@46: for(var j = 0, len = keyString.length; j < len; j++){ rlm@46: ks.push(keyString.charCodeAt(j)); rlm@46: } rlm@46: keyCode = ks; rlm@46: } rlm@46: var keyArray = Ext.isArray(keyCode); rlm@46: rlm@46: var handler = function(e){ rlm@46: if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){ rlm@46: var k = e.getKey(); rlm@46: if(keyArray){ rlm@46: for(var i = 0, len = keyCode.length; i < len; i++){ rlm@46: if(keyCode[i] == k){ rlm@46: if(this.stopEvent){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: fn.call(scope || window, k, e); rlm@46: return; rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: if(k == keyCode){ rlm@46: if(this.stopEvent){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: fn.call(scope || window, k, e); rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: this.bindings.push(handler); rlm@46: }, rlm@46: rlm@46: rlm@46: on : function(key, fn, scope){ rlm@46: var keyCode, shift, ctrl, alt; rlm@46: if(typeof key == "object" && !Ext.isArray(key)){ rlm@46: keyCode = key.key; rlm@46: shift = key.shift; rlm@46: ctrl = key.ctrl; rlm@46: alt = key.alt; rlm@46: }else{ rlm@46: keyCode = key; rlm@46: } rlm@46: this.addBinding({ rlm@46: key: keyCode, rlm@46: shift: shift, rlm@46: ctrl: ctrl, rlm@46: alt: alt, rlm@46: fn: fn, rlm@46: scope: scope rlm@46: }) rlm@46: }, rlm@46: rlm@46: rlm@46: handleKeyDown : function(e){ rlm@46: if(this.enabled){ rlm@46: var b = this.bindings; rlm@46: for(var i = 0, len = b.length; i < len; i++){ rlm@46: b[i].call(this, e); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isEnabled : function(){ rlm@46: return this.enabled; rlm@46: }, rlm@46: rlm@46: rlm@46: enable: function(){ rlm@46: if(!this.enabled){ rlm@46: this.el.on(this.eventName, this.handleKeyDown, this); rlm@46: this.enabled = true; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: disable: function(){ rlm@46: if(this.enabled){ rlm@46: this.el.removeListener(this.eventName, this.handleKeyDown, this); rlm@46: this.enabled = false; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.util.TextMetrics = function(){ rlm@46: var shared; rlm@46: return { rlm@46: rlm@46: measure : function(el, text, fixedWidth){ rlm@46: if(!shared){ rlm@46: shared = Ext.util.TextMetrics.Instance(el, fixedWidth); rlm@46: } rlm@46: shared.bind(el); rlm@46: shared.setFixedWidth(fixedWidth || 'auto'); rlm@46: return shared.getSize(text); rlm@46: }, rlm@46: rlm@46: rlm@46: createInstance : function(el, fixedWidth){ rlm@46: return Ext.util.TextMetrics.Instance(el, fixedWidth); rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.util.TextMetrics.Instance = function(bindTo, fixedWidth){ rlm@46: var ml = new Ext.Element(document.createElement('div')); rlm@46: document.body.appendChild(ml.dom); rlm@46: ml.position('absolute'); rlm@46: ml.setLeftTop(-1000, -1000); rlm@46: ml.hide(); rlm@46: rlm@46: if(fixedWidth){ rlm@46: ml.setWidth(fixedWidth); rlm@46: } rlm@46: rlm@46: var instance = { rlm@46: rlm@46: getSize : function(text){ rlm@46: ml.update(text); rlm@46: var s = ml.getSize(); rlm@46: ml.update(''); rlm@46: return s; rlm@46: }, rlm@46: rlm@46: rlm@46: bind : function(el){ rlm@46: ml.setStyle( rlm@46: Ext.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing') rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: setFixedWidth : function(width){ rlm@46: ml.setWidth(width); rlm@46: }, rlm@46: rlm@46: rlm@46: getWidth : function(text){ rlm@46: ml.dom.style.width = 'auto'; rlm@46: return this.getSize(text).width; rlm@46: }, rlm@46: rlm@46: rlm@46: getHeight : function(text){ rlm@46: return this.getSize(text).height; rlm@46: } rlm@46: }; rlm@46: rlm@46: instance.bind(bindTo); rlm@46: rlm@46: return instance; rlm@46: }; rlm@46: rlm@46: Ext.Element.measureText = Ext.util.TextMetrics.measure; rlm@46: rlm@46: rlm@46: (function() { rlm@46: rlm@46: var Event=Ext.EventManager; rlm@46: var Dom=Ext.lib.Dom; rlm@46: rlm@46: rlm@46: Ext.dd.DragDrop = function(id, sGroup, config) { rlm@46: if(id) { rlm@46: this.init(id, sGroup, config); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.dd.DragDrop.prototype = { rlm@46: rlm@46: rlm@46: id: null, rlm@46: rlm@46: rlm@46: config: null, rlm@46: rlm@46: rlm@46: dragElId: null, rlm@46: rlm@46: rlm@46: handleElId: null, rlm@46: rlm@46: rlm@46: invalidHandleTypes: null, rlm@46: rlm@46: rlm@46: invalidHandleIds: null, rlm@46: rlm@46: rlm@46: invalidHandleClasses: null, rlm@46: rlm@46: rlm@46: startPageX: 0, rlm@46: rlm@46: rlm@46: startPageY: 0, rlm@46: rlm@46: rlm@46: groups: null, rlm@46: rlm@46: rlm@46: locked: false, rlm@46: rlm@46: rlm@46: lock: function() { this.locked = true; }, rlm@46: rlm@46: rlm@46: unlock: function() { this.locked = false; }, rlm@46: rlm@46: rlm@46: isTarget: true, rlm@46: rlm@46: rlm@46: padding: null, rlm@46: rlm@46: rlm@46: _domRef: null, rlm@46: rlm@46: rlm@46: __ygDragDrop: true, rlm@46: rlm@46: rlm@46: constrainX: false, rlm@46: rlm@46: rlm@46: constrainY: false, rlm@46: rlm@46: rlm@46: minX: 0, rlm@46: rlm@46: rlm@46: maxX: 0, rlm@46: rlm@46: rlm@46: minY: 0, rlm@46: rlm@46: rlm@46: maxY: 0, rlm@46: rlm@46: rlm@46: maintainOffset: false, rlm@46: rlm@46: rlm@46: xTicks: null, rlm@46: rlm@46: rlm@46: yTicks: null, rlm@46: rlm@46: rlm@46: primaryButtonOnly: true, rlm@46: rlm@46: rlm@46: available: false, rlm@46: rlm@46: rlm@46: hasOuterHandles: false, rlm@46: rlm@46: rlm@46: b4StartDrag: function(x, y) { }, rlm@46: rlm@46: rlm@46: startDrag: function(x, y) { }, rlm@46: rlm@46: rlm@46: b4Drag: function(e) { }, rlm@46: rlm@46: rlm@46: onDrag: function(e) { }, rlm@46: rlm@46: rlm@46: onDragEnter: function(e, id) { }, rlm@46: rlm@46: rlm@46: b4DragOver: function(e) { }, rlm@46: rlm@46: rlm@46: onDragOver: function(e, id) { }, rlm@46: rlm@46: rlm@46: b4DragOut: function(e) { }, rlm@46: rlm@46: rlm@46: onDragOut: function(e, id) { }, rlm@46: rlm@46: rlm@46: b4DragDrop: function(e) { }, rlm@46: rlm@46: rlm@46: onDragDrop: function(e, id) { }, rlm@46: rlm@46: rlm@46: onInvalidDrop: function(e) { }, rlm@46: rlm@46: rlm@46: b4EndDrag: function(e) { }, rlm@46: rlm@46: rlm@46: endDrag: function(e) { }, rlm@46: rlm@46: rlm@46: b4MouseDown: function(e) { }, rlm@46: rlm@46: rlm@46: onMouseDown: function(e) { }, rlm@46: rlm@46: rlm@46: onMouseUp: function(e) { }, rlm@46: rlm@46: rlm@46: onAvailable: function () { rlm@46: }, rlm@46: rlm@46: rlm@46: defaultPadding : {left:0, right:0, top:0, bottom:0}, rlm@46: rlm@46: rlm@46: constrainTo : function(constrainTo, pad, inContent){ rlm@46: if(typeof pad == "number"){ rlm@46: pad = {left: pad, right:pad, top:pad, bottom:pad}; rlm@46: } rlm@46: pad = pad || this.defaultPadding; rlm@46: var b = Ext.get(this.getEl()).getBox(); rlm@46: var ce = Ext.get(constrainTo); rlm@46: var s = ce.getScroll(); rlm@46: var c, cd = ce.dom; rlm@46: if(cd == document.body){ rlm@46: c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()}; rlm@46: }else{ rlm@46: var xy = ce.getXY(); rlm@46: c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight}; rlm@46: } rlm@46: rlm@46: rlm@46: var topSpace = b.y - c.y; rlm@46: var leftSpace = b.x - c.x; rlm@46: rlm@46: this.resetConstraints(); rlm@46: this.setXConstraint(leftSpace - (pad.left||0), rlm@46: c.width - leftSpace - b.width - (pad.right||0), rlm@46: this.xTickSize rlm@46: ); rlm@46: this.setYConstraint(topSpace - (pad.top||0), rlm@46: c.height - topSpace - b.height - (pad.bottom||0), rlm@46: this.yTickSize rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: getEl: function() { rlm@46: if (!this._domRef) { rlm@46: this._domRef = Ext.getDom(this.id); rlm@46: } rlm@46: rlm@46: return this._domRef; rlm@46: }, rlm@46: rlm@46: rlm@46: getDragEl: function() { rlm@46: return Ext.getDom(this.dragElId); rlm@46: }, rlm@46: rlm@46: rlm@46: init: function(id, sGroup, config) { rlm@46: this.initTarget(id, sGroup, config); rlm@46: Event.on(this.id, "mousedown", this.handleMouseDown, this); rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: initTarget: function(id, sGroup, config) { rlm@46: rlm@46: rlm@46: this.config = config || {}; rlm@46: rlm@46: rlm@46: this.DDM = Ext.dd.DDM; rlm@46: rlm@46: this.groups = {}; rlm@46: rlm@46: rlm@46: rlm@46: if (typeof id !== "string") { rlm@46: id = Ext.id(id); rlm@46: } rlm@46: rlm@46: rlm@46: this.id = id; rlm@46: rlm@46: rlm@46: this.addToGroup((sGroup) ? sGroup : "default"); rlm@46: rlm@46: rlm@46: rlm@46: this.handleElId = id; rlm@46: rlm@46: rlm@46: this.setDragElId(id); rlm@46: rlm@46: rlm@46: this.invalidHandleTypes = { A: "A" }; rlm@46: this.invalidHandleIds = {}; rlm@46: this.invalidHandleClasses = []; rlm@46: rlm@46: this.applyConfig(); rlm@46: rlm@46: this.handleOnAvailable(); rlm@46: }, rlm@46: rlm@46: rlm@46: applyConfig: function() { rlm@46: rlm@46: rlm@46: rlm@46: this.padding = this.config.padding || [0, 0, 0, 0]; rlm@46: this.isTarget = (this.config.isTarget !== false); rlm@46: this.maintainOffset = (this.config.maintainOffset); rlm@46: this.primaryButtonOnly = (this.config.primaryButtonOnly !== false); rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: handleOnAvailable: function() { rlm@46: this.available = true; rlm@46: this.resetConstraints(); rlm@46: this.onAvailable(); rlm@46: }, rlm@46: rlm@46: rlm@46: setPadding: function(iTop, iRight, iBot, iLeft) { rlm@46: rlm@46: if (!iRight && 0 !== iRight) { rlm@46: this.padding = [iTop, iTop, iTop, iTop]; rlm@46: } else if (!iBot && 0 !== iBot) { rlm@46: this.padding = [iTop, iRight, iTop, iRight]; rlm@46: } else { rlm@46: this.padding = [iTop, iRight, iBot, iLeft]; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setInitPosition: function(diffX, diffY) { rlm@46: var el = this.getEl(); rlm@46: rlm@46: if (!this.DDM.verifyEl(el)) { rlm@46: return; rlm@46: } rlm@46: rlm@46: var dx = diffX || 0; rlm@46: var dy = diffY || 0; rlm@46: rlm@46: var p = Dom.getXY( el ); rlm@46: rlm@46: this.initPageX = p[0] - dx; rlm@46: this.initPageY = p[1] - dy; rlm@46: rlm@46: this.lastPageX = p[0]; rlm@46: this.lastPageY = p[1]; rlm@46: rlm@46: rlm@46: this.setStartPosition(p); rlm@46: }, rlm@46: rlm@46: rlm@46: setStartPosition: function(pos) { rlm@46: var p = pos || Dom.getXY( this.getEl() ); rlm@46: this.deltaSetXY = null; rlm@46: rlm@46: this.startPageX = p[0]; rlm@46: this.startPageY = p[1]; rlm@46: }, rlm@46: rlm@46: rlm@46: addToGroup: function(sGroup) { rlm@46: this.groups[sGroup] = true; rlm@46: this.DDM.regDragDrop(this, sGroup); rlm@46: }, rlm@46: rlm@46: rlm@46: removeFromGroup: function(sGroup) { rlm@46: if (this.groups[sGroup]) { rlm@46: delete this.groups[sGroup]; rlm@46: } rlm@46: rlm@46: this.DDM.removeDDFromGroup(this, sGroup); rlm@46: }, rlm@46: rlm@46: rlm@46: setDragElId: function(id) { rlm@46: this.dragElId = id; rlm@46: }, rlm@46: rlm@46: rlm@46: setHandleElId: function(id) { rlm@46: if (typeof id !== "string") { rlm@46: id = Ext.id(id); rlm@46: } rlm@46: this.handleElId = id; rlm@46: this.DDM.regHandle(this.id, id); rlm@46: }, rlm@46: rlm@46: rlm@46: setOuterHandleElId: function(id) { rlm@46: if (typeof id !== "string") { rlm@46: id = Ext.id(id); rlm@46: } rlm@46: Event.on(id, "mousedown", rlm@46: this.handleMouseDown, this); rlm@46: this.setHandleElId(id); rlm@46: rlm@46: this.hasOuterHandles = true; rlm@46: }, rlm@46: rlm@46: rlm@46: unreg: function() { rlm@46: Event.un(this.id, "mousedown", rlm@46: this.handleMouseDown); rlm@46: this._domRef = null; rlm@46: this.DDM._remove(this); rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: this.unreg(); rlm@46: }, rlm@46: rlm@46: rlm@46: isLocked: function() { rlm@46: return (this.DDM.isLocked() || this.locked); rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseDown: function(e, oDD){ rlm@46: if (this.primaryButtonOnly && e.button != 0) { rlm@46: return; rlm@46: } rlm@46: rlm@46: if (this.isLocked()) { rlm@46: return; rlm@46: } rlm@46: rlm@46: this.DDM.refreshCache(this.groups); rlm@46: rlm@46: var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e)); rlm@46: if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) { rlm@46: } else { rlm@46: if (this.clickValidator(e)) { rlm@46: rlm@46: rlm@46: this.setStartPosition(); rlm@46: rlm@46: rlm@46: this.b4MouseDown(e); rlm@46: this.onMouseDown(e); rlm@46: rlm@46: this.DDM.handleMouseDown(e, this); rlm@46: rlm@46: this.DDM.stopEvent(e); rlm@46: } else { rlm@46: rlm@46: rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: clickValidator: function(e) { rlm@46: var target = e.getTarget(); rlm@46: return ( this.isValidHandleChild(target) && rlm@46: (this.id == this.handleElId || rlm@46: this.DDM.handleWasClicked(target, this.id)) ); rlm@46: }, rlm@46: rlm@46: rlm@46: addInvalidHandleType: function(tagName) { rlm@46: var type = tagName.toUpperCase(); rlm@46: this.invalidHandleTypes[type] = type; rlm@46: }, rlm@46: rlm@46: rlm@46: addInvalidHandleId: function(id) { rlm@46: if (typeof id !== "string") { rlm@46: id = Ext.id(id); rlm@46: } rlm@46: this.invalidHandleIds[id] = id; rlm@46: }, rlm@46: rlm@46: rlm@46: addInvalidHandleClass: function(cssClass) { rlm@46: this.invalidHandleClasses.push(cssClass); rlm@46: }, rlm@46: rlm@46: rlm@46: removeInvalidHandleType: function(tagName) { rlm@46: var type = tagName.toUpperCase(); rlm@46: rlm@46: delete this.invalidHandleTypes[type]; rlm@46: }, rlm@46: rlm@46: rlm@46: removeInvalidHandleId: function(id) { rlm@46: if (typeof id !== "string") { rlm@46: id = Ext.id(id); rlm@46: } rlm@46: delete this.invalidHandleIds[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: removeInvalidHandleClass: function(cssClass) { rlm@46: for (var i=0, len=this.invalidHandleClasses.length; i= this.minX; i = i - iTickSize) { rlm@46: if (!tickMap[i]) { rlm@46: this.xTicks[this.xTicks.length] = i; rlm@46: tickMap[i] = true; rlm@46: } rlm@46: } rlm@46: rlm@46: for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) { rlm@46: if (!tickMap[i]) { rlm@46: this.xTicks[this.xTicks.length] = i; rlm@46: tickMap[i] = true; rlm@46: } rlm@46: } rlm@46: rlm@46: this.xTicks.sort(this.DDM.numericSort) ; rlm@46: }, rlm@46: rlm@46: rlm@46: setYTicks: function(iStartY, iTickSize) { rlm@46: this.yTicks = []; rlm@46: this.yTickSize = iTickSize; rlm@46: rlm@46: var tickMap = {}; rlm@46: rlm@46: for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) { rlm@46: if (!tickMap[i]) { rlm@46: this.yTicks[this.yTicks.length] = i; rlm@46: tickMap[i] = true; rlm@46: } rlm@46: } rlm@46: rlm@46: for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) { rlm@46: if (!tickMap[i]) { rlm@46: this.yTicks[this.yTicks.length] = i; rlm@46: tickMap[i] = true; rlm@46: } rlm@46: } rlm@46: rlm@46: this.yTicks.sort(this.DDM.numericSort) ; rlm@46: }, rlm@46: rlm@46: rlm@46: setXConstraint: function(iLeft, iRight, iTickSize) { rlm@46: this.leftConstraint = iLeft; rlm@46: this.rightConstraint = iRight; rlm@46: rlm@46: this.minX = this.initPageX - iLeft; rlm@46: this.maxX = this.initPageX + iRight; rlm@46: if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); } rlm@46: rlm@46: this.constrainX = true; rlm@46: }, rlm@46: rlm@46: rlm@46: clearConstraints: function() { rlm@46: this.constrainX = false; rlm@46: this.constrainY = false; rlm@46: this.clearTicks(); rlm@46: }, rlm@46: rlm@46: rlm@46: clearTicks: function() { rlm@46: this.xTicks = null; rlm@46: this.yTicks = null; rlm@46: this.xTickSize = 0; rlm@46: this.yTickSize = 0; rlm@46: }, rlm@46: rlm@46: rlm@46: setYConstraint: function(iUp, iDown, iTickSize) { rlm@46: this.topConstraint = iUp; rlm@46: this.bottomConstraint = iDown; rlm@46: rlm@46: this.minY = this.initPageY - iUp; rlm@46: this.maxY = this.initPageY + iDown; rlm@46: if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); } rlm@46: rlm@46: this.constrainY = true; rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: resetConstraints: function() { rlm@46: rlm@46: rlm@46: rlm@46: if (this.initPageX || this.initPageX === 0) { rlm@46: rlm@46: var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0; rlm@46: var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0; rlm@46: rlm@46: this.setInitPosition(dx, dy); rlm@46: rlm@46: rlm@46: } else { rlm@46: this.setInitPosition(); rlm@46: } rlm@46: rlm@46: if (this.constrainX) { rlm@46: this.setXConstraint( this.leftConstraint, rlm@46: this.rightConstraint, rlm@46: this.xTickSize ); rlm@46: } rlm@46: rlm@46: if (this.constrainY) { rlm@46: this.setYConstraint( this.topConstraint, rlm@46: this.bottomConstraint, rlm@46: this.yTickSize ); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTick: function(val, tickArray) { rlm@46: rlm@46: if (!tickArray) { rlm@46: rlm@46: rlm@46: return val; rlm@46: } else if (tickArray[0] >= val) { rlm@46: rlm@46: rlm@46: return tickArray[0]; rlm@46: } else { rlm@46: for (var i=0, len=tickArray.length; i= val) { rlm@46: var diff1 = val - tickArray[i]; rlm@46: var diff2 = tickArray[next] - val; rlm@46: return (diff2 > diff1) ? tickArray[i] : tickArray[next]; rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: return tickArray[tickArray.length - 1]; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toString: function() { rlm@46: return ("DragDrop " + this.id); rlm@46: } rlm@46: rlm@46: }; rlm@46: rlm@46: })(); rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: if (!Ext.dd.DragDropMgr) { rlm@46: rlm@46: rlm@46: Ext.dd.DragDropMgr = function() { rlm@46: rlm@46: var Event = Ext.EventManager; rlm@46: rlm@46: return { rlm@46: rlm@46: rlm@46: ids: {}, rlm@46: rlm@46: rlm@46: handleIds: {}, rlm@46: rlm@46: rlm@46: dragCurrent: null, rlm@46: rlm@46: rlm@46: dragOvers: {}, rlm@46: rlm@46: rlm@46: deltaX: 0, rlm@46: rlm@46: rlm@46: deltaY: 0, rlm@46: rlm@46: rlm@46: preventDefault: true, rlm@46: rlm@46: rlm@46: stopPropagation: true, rlm@46: rlm@46: rlm@46: initialized: false, rlm@46: rlm@46: rlm@46: locked: false, rlm@46: rlm@46: rlm@46: init: function() { rlm@46: this.initialized = true; rlm@46: }, rlm@46: rlm@46: rlm@46: POINT: 0, rlm@46: rlm@46: rlm@46: INTERSECT: 1, rlm@46: rlm@46: rlm@46: mode: 0, rlm@46: rlm@46: rlm@46: _execOnAll: function(sMethod, args) { rlm@46: for (var i in this.ids) { rlm@46: for (var j in this.ids[i]) { rlm@46: var oDD = this.ids[i][j]; rlm@46: if (! this.isTypeOfDD(oDD)) { rlm@46: continue; rlm@46: } rlm@46: oDD[sMethod].apply(oDD, args); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: _onLoad: function() { rlm@46: rlm@46: this.init(); rlm@46: rlm@46: rlm@46: Event.on(document, "mouseup", this.handleMouseUp, this, true); rlm@46: Event.on(document, "mousemove", this.handleMouseMove, this, true); rlm@46: Event.on(window, "unload", this._onUnload, this, true); rlm@46: Event.on(window, "resize", this._onResize, this, true); rlm@46: rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: _onResize: function(e) { rlm@46: this._execOnAll("resetConstraints", []); rlm@46: }, rlm@46: rlm@46: rlm@46: lock: function() { this.locked = true; }, rlm@46: rlm@46: rlm@46: unlock: function() { this.locked = false; }, rlm@46: rlm@46: rlm@46: isLocked: function() { return this.locked; }, rlm@46: rlm@46: rlm@46: locationCache: {}, rlm@46: rlm@46: rlm@46: useCache: true, rlm@46: rlm@46: rlm@46: clickPixelThresh: 3, rlm@46: rlm@46: rlm@46: clickTimeThresh: 350, rlm@46: rlm@46: rlm@46: dragThreshMet: false, rlm@46: rlm@46: rlm@46: clickTimeout: null, rlm@46: rlm@46: rlm@46: startX: 0, rlm@46: rlm@46: rlm@46: startY: 0, rlm@46: rlm@46: rlm@46: regDragDrop: function(oDD, sGroup) { rlm@46: if (!this.initialized) { this.init(); } rlm@46: rlm@46: if (!this.ids[sGroup]) { rlm@46: this.ids[sGroup] = {}; rlm@46: } rlm@46: this.ids[sGroup][oDD.id] = oDD; rlm@46: }, rlm@46: rlm@46: rlm@46: removeDDFromGroup: function(oDD, sGroup) { rlm@46: if (!this.ids[sGroup]) { rlm@46: this.ids[sGroup] = {}; rlm@46: } rlm@46: rlm@46: var obj = this.ids[sGroup]; rlm@46: if (obj && obj[oDD.id]) { rlm@46: delete obj[oDD.id]; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: _remove: function(oDD) { rlm@46: for (var g in oDD.groups) { rlm@46: if (g && this.ids[g][oDD.id]) { rlm@46: delete this.ids[g][oDD.id]; rlm@46: } rlm@46: } rlm@46: delete this.handleIds[oDD.id]; rlm@46: }, rlm@46: rlm@46: rlm@46: regHandle: function(sDDId, sHandleId) { rlm@46: if (!this.handleIds[sDDId]) { rlm@46: this.handleIds[sDDId] = {}; rlm@46: } rlm@46: this.handleIds[sDDId][sHandleId] = sHandleId; rlm@46: }, rlm@46: rlm@46: rlm@46: isDragDrop: function(id) { rlm@46: return ( this.getDDById(id) ) ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: getRelated: function(p_oDD, bTargetsOnly) { rlm@46: var oDDs = []; rlm@46: for (var i in p_oDD.groups) { rlm@46: for (j in this.ids[i]) { rlm@46: var dd = this.ids[i][j]; rlm@46: if (! this.isTypeOfDD(dd)) { rlm@46: continue; rlm@46: } rlm@46: if (!bTargetsOnly || dd.isTarget) { rlm@46: oDDs[oDDs.length] = dd; rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: return oDDs; rlm@46: }, rlm@46: rlm@46: rlm@46: isLegalTarget: function (oDD, oTargetDD) { rlm@46: var targets = this.getRelated(oDD, true); rlm@46: for (var i=0, len=targets.length;i this.clickPixelThresh || rlm@46: diffY > this.clickPixelThresh) { rlm@46: this.startDrag(this.startX, this.startY); rlm@46: } rlm@46: } rlm@46: rlm@46: if (this.dragThreshMet) { rlm@46: this.dragCurrent.b4Drag(e); rlm@46: this.dragCurrent.onDrag(e); rlm@46: if(!this.dragCurrent.moveOnly){ rlm@46: this.fireEvents(e, false); rlm@46: } rlm@46: } rlm@46: rlm@46: this.stopEvent(e); rlm@46: rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: fireEvents: function(e, isDrop) { rlm@46: var dc = this.dragCurrent; rlm@46: rlm@46: rlm@46: rlm@46: if (!dc || dc.isLocked()) { rlm@46: return; rlm@46: } rlm@46: rlm@46: var pt = e.getPoint(); rlm@46: rlm@46: rlm@46: var oldOvers = []; rlm@46: rlm@46: var outEvts = []; rlm@46: var overEvts = []; rlm@46: var dropEvts = []; rlm@46: var enterEvts = []; rlm@46: rlm@46: rlm@46: rlm@46: for (var i in this.dragOvers) { rlm@46: rlm@46: var ddo = this.dragOvers[i]; rlm@46: rlm@46: if (! this.isTypeOfDD(ddo)) { rlm@46: continue; rlm@46: } rlm@46: rlm@46: if (! this.isOverTarget(pt, ddo, this.mode)) { rlm@46: outEvts.push( ddo ); rlm@46: } rlm@46: rlm@46: oldOvers[i] = true; rlm@46: delete this.dragOvers[i]; rlm@46: } rlm@46: rlm@46: for (var sGroup in dc.groups) { rlm@46: rlm@46: if ("string" != typeof sGroup) { rlm@46: continue; rlm@46: } rlm@46: rlm@46: for (i in this.ids[sGroup]) { rlm@46: var oDD = this.ids[sGroup][i]; rlm@46: if (! this.isTypeOfDD(oDD)) { rlm@46: continue; rlm@46: } rlm@46: rlm@46: if (oDD.isTarget && !oDD.isLocked() && oDD != dc) { rlm@46: if (this.isOverTarget(pt, oDD, this.mode)) { rlm@46: rlm@46: if (isDrop) { rlm@46: dropEvts.push( oDD ); rlm@46: rlm@46: } else { rlm@46: rlm@46: rlm@46: if (!oldOvers[oDD.id]) { rlm@46: enterEvts.push( oDD ); rlm@46: rlm@46: } else { rlm@46: overEvts.push( oDD ); rlm@46: } rlm@46: rlm@46: this.dragOvers[oDD.id] = oDD; rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: if (this.mode) { rlm@46: if (outEvts.length) { rlm@46: dc.b4DragOut(e, outEvts); rlm@46: dc.onDragOut(e, outEvts); rlm@46: } rlm@46: rlm@46: if (enterEvts.length) { rlm@46: dc.onDragEnter(e, enterEvts); rlm@46: } rlm@46: rlm@46: if (overEvts.length) { rlm@46: dc.b4DragOver(e, overEvts); rlm@46: dc.onDragOver(e, overEvts); rlm@46: } rlm@46: rlm@46: if (dropEvts.length) { rlm@46: dc.b4DragDrop(e, dropEvts); rlm@46: dc.onDragDrop(e, dropEvts); rlm@46: } rlm@46: rlm@46: } else { rlm@46: rlm@46: var len = 0; rlm@46: for (i=0, len=outEvts.length; i 2000) { rlm@46: } else { rlm@46: setTimeout(DDM._addListeners, 10); rlm@46: if (document && document.body) { rlm@46: DDM._timeoutCount += 1; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: handleWasClicked: function(node, id) { rlm@46: if (this.isHandle(id, node.id)) { rlm@46: return true; rlm@46: } else { rlm@46: rlm@46: var p = node.parentNode; rlm@46: rlm@46: while (p) { rlm@46: if (this.isHandle(id, p.id)) { rlm@46: return true; rlm@46: } else { rlm@46: p = p.parentNode; rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: return false; rlm@46: } rlm@46: rlm@46: }; rlm@46: rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.dd.DDM = Ext.dd.DragDropMgr; rlm@46: Ext.dd.DDM._addListeners(); rlm@46: rlm@46: } rlm@46: rlm@46: rlm@46: Ext.dd.DD = function(id, sGroup, config) { rlm@46: if (id) { rlm@46: this.init(id, sGroup, config); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, { rlm@46: rlm@46: rlm@46: scroll: true, rlm@46: rlm@46: rlm@46: autoOffset: function(iPageX, iPageY) { rlm@46: var x = iPageX - this.startPageX; rlm@46: var y = iPageY - this.startPageY; rlm@46: this.setDelta(x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: setDelta: function(iDeltaX, iDeltaY) { rlm@46: this.deltaX = iDeltaX; rlm@46: this.deltaY = iDeltaY; rlm@46: }, rlm@46: rlm@46: rlm@46: setDragElPos: function(iPageX, iPageY) { rlm@46: rlm@46: rlm@46: rlm@46: var el = this.getDragEl(); rlm@46: this.alignElWithMouse(el, iPageX, iPageY); rlm@46: }, rlm@46: rlm@46: rlm@46: alignElWithMouse: function(el, iPageX, iPageY) { rlm@46: var oCoord = this.getTargetCoord(iPageX, iPageY); rlm@46: var fly = el.dom ? el : Ext.fly(el, '_dd'); rlm@46: if (!this.deltaSetXY) { rlm@46: var aCoord = [oCoord.x, oCoord.y]; rlm@46: fly.setXY(aCoord); rlm@46: var newLeft = fly.getLeft(true); rlm@46: var newTop = fly.getTop(true); rlm@46: this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ]; rlm@46: } else { rlm@46: fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]); rlm@46: } rlm@46: rlm@46: this.cachePosition(oCoord.x, oCoord.y); rlm@46: this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth); rlm@46: return oCoord; rlm@46: }, rlm@46: rlm@46: rlm@46: cachePosition: function(iPageX, iPageY) { rlm@46: if (iPageX) { rlm@46: this.lastPageX = iPageX; rlm@46: this.lastPageY = iPageY; rlm@46: } else { rlm@46: var aCoord = Ext.lib.Dom.getXY(this.getEl()); rlm@46: this.lastPageX = aCoord[0]; rlm@46: this.lastPageY = aCoord[1]; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: autoScroll: function(x, y, h, w) { rlm@46: rlm@46: if (this.scroll) { rlm@46: rlm@46: var clientH = Ext.lib.Dom.getViewHeight(); rlm@46: rlm@46: rlm@46: var clientW = Ext.lib.Dom.getViewWidth(); rlm@46: rlm@46: rlm@46: var st = this.DDM.getScrollTop(); rlm@46: rlm@46: rlm@46: var sl = this.DDM.getScrollLeft(); rlm@46: rlm@46: rlm@46: var bot = h + y; rlm@46: rlm@46: rlm@46: var right = w + x; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: var toBot = (clientH + st - y - this.deltaY); rlm@46: rlm@46: rlm@46: var toRight = (clientW + sl - x - this.deltaX); rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: var thresh = 40; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: var scrAmt = (document.all) ? 80 : 30; rlm@46: rlm@46: rlm@46: rlm@46: if ( bot > clientH && toBot < thresh ) { rlm@46: window.scrollTo(sl, st + scrAmt); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: if ( y < st && st > 0 && y - st < thresh ) { rlm@46: window.scrollTo(sl, st - scrAmt); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: if ( right > clientW && toRight < thresh ) { rlm@46: window.scrollTo(sl + scrAmt, st); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: if ( x < sl && sl > 0 && x - sl < thresh ) { rlm@46: window.scrollTo(sl - scrAmt, st); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTargetCoord: function(iPageX, iPageY) { rlm@46: rlm@46: rlm@46: var x = iPageX - this.deltaX; rlm@46: var y = iPageY - this.deltaY; rlm@46: rlm@46: if (this.constrainX) { rlm@46: if (x < this.minX) { x = this.minX; } rlm@46: if (x > this.maxX) { x = this.maxX; } rlm@46: } rlm@46: rlm@46: if (this.constrainY) { rlm@46: if (y < this.minY) { y = this.minY; } rlm@46: if (y > this.maxY) { y = this.maxY; } rlm@46: } rlm@46: rlm@46: x = this.getTick(x, this.xTicks); rlm@46: y = this.getTick(y, this.yTicks); rlm@46: rlm@46: rlm@46: return {x:x, y:y}; rlm@46: }, rlm@46: rlm@46: rlm@46: applyConfig: function() { rlm@46: Ext.dd.DD.superclass.applyConfig.call(this); rlm@46: this.scroll = (this.config.scroll !== false); rlm@46: }, rlm@46: rlm@46: rlm@46: b4MouseDown: function(e) { rlm@46: rlm@46: this.autoOffset(e.getPageX(), rlm@46: e.getPageY()); rlm@46: }, rlm@46: rlm@46: rlm@46: b4Drag: function(e) { rlm@46: this.setDragElPos(e.getPageX(), rlm@46: e.getPageY()); rlm@46: }, rlm@46: rlm@46: toString: function() { rlm@46: return ("DD " + this.id); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.dd.DDProxy = function(id, sGroup, config) { rlm@46: if (id) { rlm@46: this.init(id, sGroup, config); rlm@46: this.initFrame(); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.dd.DDProxy.dragElId = "ygddfdiv"; rlm@46: rlm@46: Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, { rlm@46: rlm@46: rlm@46: resizeFrame: true, rlm@46: rlm@46: rlm@46: centerFrame: false, rlm@46: rlm@46: rlm@46: createFrame: function() { rlm@46: var self = this; rlm@46: var body = document.body; rlm@46: rlm@46: if (!body || !body.firstChild) { rlm@46: setTimeout( function() { self.createFrame(); }, 50 ); rlm@46: return; rlm@46: } rlm@46: rlm@46: var div = this.getDragEl(); rlm@46: rlm@46: if (!div) { rlm@46: div = document.createElement("div"); rlm@46: div.id = this.dragElId; rlm@46: var s = div.style; rlm@46: rlm@46: s.position = "absolute"; rlm@46: s.visibility = "hidden"; rlm@46: s.cursor = "move"; rlm@46: s.border = "2px solid #aaa"; rlm@46: s.zIndex = 999; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: body.insertBefore(div, body.firstChild); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: initFrame: function() { rlm@46: this.createFrame(); rlm@46: }, rlm@46: rlm@46: applyConfig: function() { rlm@46: Ext.dd.DDProxy.superclass.applyConfig.call(this); rlm@46: rlm@46: this.resizeFrame = (this.config.resizeFrame !== false); rlm@46: this.centerFrame = (this.config.centerFrame); rlm@46: this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId); rlm@46: }, rlm@46: rlm@46: rlm@46: showFrame: function(iPageX, iPageY) { rlm@46: var el = this.getEl(); rlm@46: var dragEl = this.getDragEl(); rlm@46: var s = dragEl.style; rlm@46: rlm@46: this._resizeProxy(); rlm@46: rlm@46: if (this.centerFrame) { rlm@46: this.setDelta( Math.round(parseInt(s.width, 10)/2), rlm@46: Math.round(parseInt(s.height, 10)/2) ); rlm@46: } rlm@46: rlm@46: this.setDragElPos(iPageX, iPageY); rlm@46: rlm@46: Ext.fly(dragEl).show(); rlm@46: }, rlm@46: rlm@46: rlm@46: _resizeProxy: function() { rlm@46: if (this.resizeFrame) { rlm@46: var el = this.getEl(); rlm@46: Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: b4MouseDown: function(e) { rlm@46: var x = e.getPageX(); rlm@46: var y = e.getPageY(); rlm@46: this.autoOffset(x, y); rlm@46: this.setDragElPos(x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: b4StartDrag: function(x, y) { rlm@46: rlm@46: this.showFrame(x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: b4EndDrag: function(e) { rlm@46: Ext.fly(this.getDragEl()).hide(); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: endDrag: function(e) { rlm@46: rlm@46: var lel = this.getEl(); rlm@46: var del = this.getDragEl(); rlm@46: rlm@46: rlm@46: del.style.visibility = ""; rlm@46: rlm@46: this.beforeMove(); rlm@46: rlm@46: rlm@46: lel.style.visibility = "hidden"; rlm@46: Ext.dd.DDM.moveToEl(lel, del); rlm@46: del.style.visibility = "hidden"; rlm@46: lel.style.visibility = ""; rlm@46: rlm@46: this.afterDrag(); rlm@46: }, rlm@46: rlm@46: beforeMove : function(){ rlm@46: rlm@46: }, rlm@46: rlm@46: afterDrag : function(){ rlm@46: rlm@46: }, rlm@46: rlm@46: toString: function() { rlm@46: return ("DDProxy " + this.id); rlm@46: } rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.dd.DDTarget = function(id, sGroup, config) { rlm@46: if (id) { rlm@46: this.initTarget(id, sGroup, config); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, { rlm@46: toString: function() { rlm@46: return ("DDTarget " + this.id); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.dd.DragTracker = function(config){ rlm@46: Ext.apply(this, config); rlm@46: this.addEvents( rlm@46: 'mousedown', rlm@46: 'mouseup', rlm@46: 'mousemove', rlm@46: 'dragstart', rlm@46: 'dragend', rlm@46: 'drag' rlm@46: ); rlm@46: rlm@46: this.dragRegion = new Ext.lib.Region(0,0,0,0); rlm@46: rlm@46: if(this.el){ rlm@46: this.initEl(this.el); rlm@46: } rlm@46: } rlm@46: rlm@46: Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, { rlm@46: active: false, rlm@46: tolerance: 5, rlm@46: autoStart: false, rlm@46: rlm@46: initEl: function(el){ rlm@46: this.el = Ext.get(el); rlm@46: el.on('mousedown', this.onMouseDown, this, rlm@46: this.delegate ? {delegate: this.delegate} : undefined); rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: this.el.un('mousedown', this.onMouseDown, this); rlm@46: }, rlm@46: rlm@46: onMouseDown: function(e, target){ rlm@46: if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){ rlm@46: this.startXY = this.lastXY = e.getXY(); rlm@46: this.dragTarget = this.delegate ? target : this.el.dom; rlm@46: e.preventDefault(); rlm@46: var doc = Ext.getDoc(); rlm@46: doc.on('mouseup', this.onMouseUp, this); rlm@46: doc.on('mousemove', this.onMouseMove, this); rlm@46: doc.on('selectstart', this.stopSelect, this); rlm@46: if(this.autoStart){ rlm@46: this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onMouseMove: function(e, target){ rlm@46: e.preventDefault(); rlm@46: var xy = e.getXY(), s = this.startXY; rlm@46: this.lastXY = xy; rlm@46: if(!this.active){ rlm@46: if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){ rlm@46: this.triggerStart(); rlm@46: }else{ rlm@46: return; rlm@46: } rlm@46: } rlm@46: this.fireEvent('mousemove', this, e); rlm@46: this.onDrag(e); rlm@46: this.fireEvent('drag', this, e); rlm@46: }, rlm@46: rlm@46: onMouseUp: function(e){ rlm@46: var doc = Ext.getDoc(); rlm@46: doc.un('mousemove', this.onMouseMove, this); rlm@46: doc.un('mouseup', this.onMouseUp, this); rlm@46: doc.un('selectstart', this.stopSelect, this); rlm@46: e.preventDefault(); rlm@46: this.clearStart(); rlm@46: this.active = false; rlm@46: delete this.elRegion; rlm@46: this.fireEvent('mouseup', this, e); rlm@46: this.onEnd(e); rlm@46: this.fireEvent('dragend', this, e); rlm@46: }, rlm@46: rlm@46: triggerStart: function(isTimer){ rlm@46: this.clearStart(); rlm@46: this.active = true; rlm@46: this.onStart(this.startXY); rlm@46: this.fireEvent('dragstart', this, this.startXY); rlm@46: }, rlm@46: rlm@46: clearStart : function(){ rlm@46: if(this.timer){ rlm@46: clearTimeout(this.timer); rlm@46: delete this.timer; rlm@46: } rlm@46: }, rlm@46: rlm@46: stopSelect : function(e){ rlm@46: e.stopEvent(); rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onBeforeStart : function(e){ rlm@46: rlm@46: }, rlm@46: rlm@46: onStart : function(xy){ rlm@46: rlm@46: }, rlm@46: rlm@46: onDrag : function(e){ rlm@46: rlm@46: }, rlm@46: rlm@46: onEnd : function(e){ rlm@46: rlm@46: }, rlm@46: rlm@46: getDragTarget : function(){ rlm@46: return this.dragTarget; rlm@46: }, rlm@46: rlm@46: getDragCt : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: getXY : function(constrain){ rlm@46: return constrain ? rlm@46: this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY; rlm@46: }, rlm@46: rlm@46: getOffset : function(constrain){ rlm@46: var xy = this.getXY(constrain); rlm@46: var s = this.startXY; rlm@46: return [s[0]-xy[0], s[1]-xy[1]]; rlm@46: }, rlm@46: rlm@46: constrainModes: { rlm@46: 'point' : function(xy){ rlm@46: rlm@46: if(!this.elRegion){ rlm@46: this.elRegion = this.getDragCt().getRegion(); rlm@46: } rlm@46: rlm@46: var dr = this.dragRegion; rlm@46: rlm@46: dr.left = xy[0]; rlm@46: dr.top = xy[1]; rlm@46: dr.right = xy[0]; rlm@46: dr.bottom = xy[1]; rlm@46: rlm@46: dr.constrainTo(this.elRegion); rlm@46: rlm@46: return [dr.left, dr.top]; rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.dd.ScrollManager = function(){ rlm@46: var ddm = Ext.dd.DragDropMgr; rlm@46: var els = {}; rlm@46: var dragEl = null; rlm@46: var proc = {}; rlm@46: rlm@46: var onStop = function(e){ rlm@46: dragEl = null; rlm@46: clearProc(); rlm@46: }; rlm@46: rlm@46: var triggerRefresh = function(){ rlm@46: if(ddm.dragCurrent){ rlm@46: ddm.refreshCache(ddm.dragCurrent.groups); rlm@46: } rlm@46: }; rlm@46: rlm@46: var doScroll = function(){ rlm@46: if(ddm.dragCurrent){ rlm@46: var dds = Ext.dd.ScrollManager; rlm@46: var inc = proc.el.ddScrollConfig ? rlm@46: proc.el.ddScrollConfig.increment : dds.increment; rlm@46: if(!dds.animate){ rlm@46: if(proc.el.scroll(proc.dir, inc)){ rlm@46: triggerRefresh(); rlm@46: } rlm@46: }else{ rlm@46: proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: var clearProc = function(){ rlm@46: if(proc.id){ rlm@46: clearInterval(proc.id); rlm@46: } rlm@46: proc.id = 0; rlm@46: proc.el = null; rlm@46: proc.dir = ""; rlm@46: }; rlm@46: rlm@46: var startProc = function(el, dir){ rlm@46: clearProc(); rlm@46: proc.el = el; rlm@46: proc.dir = dir; rlm@46: proc.id = setInterval(doScroll, Ext.dd.ScrollManager.frequency); rlm@46: }; rlm@46: rlm@46: var onFire = function(e, isDrop){ rlm@46: if(isDrop || !ddm.dragCurrent){ return; } rlm@46: var dds = Ext.dd.ScrollManager; rlm@46: if(!dragEl || dragEl != ddm.dragCurrent){ rlm@46: dragEl = ddm.dragCurrent; rlm@46: rlm@46: dds.refreshCache(); rlm@46: } rlm@46: rlm@46: var xy = Ext.lib.Event.getXY(e); rlm@46: var pt = new Ext.lib.Point(xy[0], xy[1]); rlm@46: for(var id in els){ rlm@46: var el = els[id], r = el._region; rlm@46: var c = el.ddScrollConfig ? el.ddScrollConfig : dds; rlm@46: if(r && r.contains(pt) && el.isScrollable()){ rlm@46: if(r.bottom - pt.y <= c.vthresh){ rlm@46: if(proc.el != el){ rlm@46: startProc(el, "down"); rlm@46: } rlm@46: return; rlm@46: }else if(r.right - pt.x <= c.hthresh){ rlm@46: if(proc.el != el){ rlm@46: startProc(el, "left"); rlm@46: } rlm@46: return; rlm@46: }else if(pt.y - r.top <= c.vthresh){ rlm@46: if(proc.el != el){ rlm@46: startProc(el, "up"); rlm@46: } rlm@46: return; rlm@46: }else if(pt.x - r.left <= c.hthresh){ rlm@46: if(proc.el != el){ rlm@46: startProc(el, "right"); rlm@46: } rlm@46: return; rlm@46: } rlm@46: } rlm@46: } rlm@46: clearProc(); rlm@46: }; rlm@46: rlm@46: ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm); rlm@46: ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm); rlm@46: rlm@46: return { rlm@46: rlm@46: register : function(el){ rlm@46: if(Ext.isArray(el)){ rlm@46: for(var i = 0, len = el.length; i < len; i++) { rlm@46: this.register(el[i]); rlm@46: } rlm@46: }else{ rlm@46: el = Ext.get(el); rlm@46: els[el.id] = el; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(el){ rlm@46: if(Ext.isArray(el)){ rlm@46: for(var i = 0, len = el.length; i < len; i++) { rlm@46: this.unregister(el[i]); rlm@46: } rlm@46: }else{ rlm@46: el = Ext.get(el); rlm@46: delete els[el.id]; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: vthresh : 25, rlm@46: rlm@46: hthresh : 25, rlm@46: rlm@46: rlm@46: increment : 100, rlm@46: rlm@46: rlm@46: frequency : 500, rlm@46: rlm@46: rlm@46: animate: true, rlm@46: rlm@46: rlm@46: animDuration: .4, rlm@46: rlm@46: rlm@46: refreshCache : function(){ rlm@46: for(var id in els){ rlm@46: if(typeof els[id] == 'object'){ rlm@46: els[id]._region = els[id].getRegion(); rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.dd.Registry = function(){ rlm@46: var elements = {}; rlm@46: var handles = {}; rlm@46: var autoIdSeed = 0; rlm@46: rlm@46: var getId = function(el, autogen){ rlm@46: if(typeof el == "string"){ rlm@46: return el; rlm@46: } rlm@46: var id = el.id; rlm@46: if(!id && autogen !== false){ rlm@46: id = "extdd-" + (++autoIdSeed); rlm@46: el.id = id; rlm@46: } rlm@46: return id; rlm@46: }; rlm@46: rlm@46: return { rlm@46: rlm@46: register : function(el, data){ rlm@46: data = data || {}; rlm@46: if(typeof el == "string"){ rlm@46: el = document.getElementById(el); rlm@46: } rlm@46: data.ddel = el; rlm@46: elements[getId(el)] = data; rlm@46: if(data.isHandle !== false){ rlm@46: handles[data.ddel.id] = data; rlm@46: } rlm@46: if(data.handles){ rlm@46: var hs = data.handles; rlm@46: for(var i = 0, len = hs.length; i < len; i++){ rlm@46: handles[getId(hs[i])] = data; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(el){ rlm@46: var id = getId(el, false); rlm@46: var data = elements[id]; rlm@46: if(data){ rlm@46: delete elements[id]; rlm@46: if(data.handles){ rlm@46: var hs = data.handles; rlm@46: for(var i = 0, len = hs.length; i < len; i++){ rlm@46: delete handles[getId(hs[i], false)]; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getHandle : function(id){ rlm@46: if(typeof id != "string"){ rlm@46: id = id.id; rlm@46: } rlm@46: return handles[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: getHandleFromEvent : function(e){ rlm@46: var t = Ext.lib.Event.getTarget(e); rlm@46: return t ? handles[t.id] : null; rlm@46: }, rlm@46: rlm@46: rlm@46: getTarget : function(id){ rlm@46: if(typeof id != "string"){ rlm@46: id = id.id; rlm@46: } rlm@46: return elements[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: getTargetFromEvent : function(e){ rlm@46: var t = Ext.lib.Event.getTarget(e); rlm@46: return t ? elements[t.id] || handles[t.id] : null; rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.dd.StatusProxy = function(config){ rlm@46: Ext.apply(this, config); rlm@46: this.id = this.id || Ext.id(); rlm@46: this.el = new Ext.Layer({ rlm@46: dh: { rlm@46: id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [ rlm@46: {tag: "div", cls: "x-dd-drop-icon"}, rlm@46: {tag: "div", cls: "x-dd-drag-ghost"} rlm@46: ] rlm@46: }, rlm@46: shadow: !config || config.shadow !== false rlm@46: }); rlm@46: this.ghost = Ext.get(this.el.dom.childNodes[1]); rlm@46: this.dropStatus = this.dropNotAllowed; rlm@46: }; rlm@46: rlm@46: Ext.dd.StatusProxy.prototype = { rlm@46: rlm@46: dropAllowed : "x-dd-drop-ok", rlm@46: rlm@46: dropNotAllowed : "x-dd-drop-nodrop", rlm@46: rlm@46: rlm@46: setStatus : function(cssClass){ rlm@46: cssClass = cssClass || this.dropNotAllowed; rlm@46: if(this.dropStatus != cssClass){ rlm@46: this.el.replaceClass(this.dropStatus, cssClass); rlm@46: this.dropStatus = cssClass; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: reset : function(clearGhost){ rlm@46: this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed; rlm@46: this.dropStatus = this.dropNotAllowed; rlm@46: if(clearGhost){ rlm@46: this.ghost.update(""); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(html){ rlm@46: if(typeof html == "string"){ rlm@46: this.ghost.update(html); rlm@46: }else{ rlm@46: this.ghost.update(""); rlm@46: html.style.margin = "0"; rlm@46: this.ghost.dom.appendChild(html); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: getGhost : function(){ rlm@46: return this.ghost; rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(clear){ rlm@46: this.el.hide(); rlm@46: if(clear){ rlm@46: this.reset(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: stop : function(){ rlm@46: if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){ rlm@46: this.anim.stop(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(){ rlm@46: this.el.show(); rlm@46: }, rlm@46: rlm@46: rlm@46: sync : function(){ rlm@46: this.el.sync(); rlm@46: }, rlm@46: rlm@46: rlm@46: repair : function(xy, callback, scope){ rlm@46: this.callback = callback; rlm@46: this.scope = scope; rlm@46: if(xy && this.animRepair !== false){ rlm@46: this.el.addClass("x-dd-drag-repair"); rlm@46: this.el.hideUnders(true); rlm@46: this.anim = this.el.shift({ rlm@46: duration: this.repairDuration || .5, rlm@46: easing: 'easeOut', rlm@46: xy: xy, rlm@46: stopFx: true, rlm@46: callback: this.afterRepair, rlm@46: scope: this rlm@46: }); rlm@46: }else{ rlm@46: this.afterRepair(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: afterRepair : function(){ rlm@46: this.hide(true); rlm@46: if(typeof this.callback == "function"){ rlm@46: this.callback.call(this.scope || this); rlm@46: } rlm@46: this.callback = null; rlm@46: this.scope = null; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.dd.DragSource = function(el, config){ rlm@46: this.el = Ext.get(el); rlm@46: if(!this.dragData){ rlm@46: this.dragData = {}; rlm@46: } rlm@46: rlm@46: Ext.apply(this, config); rlm@46: rlm@46: if(!this.proxy){ rlm@46: this.proxy = new Ext.dd.StatusProxy(); rlm@46: } rlm@46: Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, rlm@46: {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true}); rlm@46: rlm@46: this.dragging = false; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, { rlm@46: rlm@46: rlm@46: dropAllowed : "x-dd-drop-ok", rlm@46: rlm@46: dropNotAllowed : "x-dd-drop-nodrop", rlm@46: rlm@46: rlm@46: getDragData : function(e){ rlm@46: return this.dragData; rlm@46: }, rlm@46: rlm@46: rlm@46: onDragEnter : function(e, id){ rlm@46: var target = Ext.dd.DragDropMgr.getDDById(id); rlm@46: this.cachedTarget = target; rlm@46: if(this.beforeDragEnter(target, e, id) !== false){ rlm@46: if(target.isNotifyTarget){ rlm@46: var status = target.notifyEnter(this, e, this.dragData); rlm@46: this.proxy.setStatus(status); rlm@46: }else{ rlm@46: this.proxy.setStatus(this.dropAllowed); rlm@46: } rlm@46: rlm@46: if(this.afterDragEnter){ rlm@46: rlm@46: this.afterDragEnter(target, e, id); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDragEnter : function(target, e, id){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: alignElWithMouse: function() { rlm@46: Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments); rlm@46: this.proxy.sync(); rlm@46: }, rlm@46: rlm@46: rlm@46: onDragOver : function(e, id){ rlm@46: var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); rlm@46: if(this.beforeDragOver(target, e, id) !== false){ rlm@46: if(target.isNotifyTarget){ rlm@46: var status = target.notifyOver(this, e, this.dragData); rlm@46: this.proxy.setStatus(status); rlm@46: } rlm@46: rlm@46: if(this.afterDragOver){ rlm@46: rlm@46: this.afterDragOver(target, e, id); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDragOver : function(target, e, id){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: onDragOut : function(e, id){ rlm@46: var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); rlm@46: if(this.beforeDragOut(target, e, id) !== false){ rlm@46: if(target.isNotifyTarget){ rlm@46: target.notifyOut(this, e, this.dragData); rlm@46: } rlm@46: this.proxy.reset(); rlm@46: if(this.afterDragOut){ rlm@46: rlm@46: this.afterDragOut(target, e, id); rlm@46: } rlm@46: } rlm@46: this.cachedTarget = null; rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDragOut : function(target, e, id){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: onDragDrop : function(e, id){ rlm@46: var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id); rlm@46: if(this.beforeDragDrop(target, e, id) !== false){ rlm@46: if(target.isNotifyTarget){ rlm@46: if(target.notifyDrop(this, e, this.dragData)){ rlm@46: this.onValidDrop(target, e, id); rlm@46: }else{ rlm@46: this.onInvalidDrop(target, e, id); rlm@46: } rlm@46: }else{ rlm@46: this.onValidDrop(target, e, id); rlm@46: } rlm@46: rlm@46: if(this.afterDragDrop){ rlm@46: rlm@46: this.afterDragDrop(target, e, id); rlm@46: } rlm@46: } rlm@46: delete this.cachedTarget; rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDragDrop : function(target, e, id){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: onValidDrop : function(target, e, id){ rlm@46: this.hideProxy(); rlm@46: if(this.afterValidDrop){ rlm@46: rlm@46: this.afterValidDrop(target, e, id); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getRepairXY : function(e, data){ rlm@46: return this.el.getXY(); rlm@46: }, rlm@46: rlm@46: rlm@46: onInvalidDrop : function(target, e, id){ rlm@46: this.beforeInvalidDrop(target, e, id); rlm@46: if(this.cachedTarget){ rlm@46: if(this.cachedTarget.isNotifyTarget){ rlm@46: this.cachedTarget.notifyOut(this, e, this.dragData); rlm@46: } rlm@46: this.cacheTarget = null; rlm@46: } rlm@46: this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this); rlm@46: rlm@46: if(this.afterInvalidDrop){ rlm@46: rlm@46: this.afterInvalidDrop(e, id); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: afterRepair : function(){ rlm@46: if(Ext.enableFx){ rlm@46: this.el.highlight(this.hlColor || "c3daf9"); rlm@46: } rlm@46: this.dragging = false; rlm@46: }, rlm@46: rlm@46: rlm@46: beforeInvalidDrop : function(target, e, id){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseDown : function(e){ rlm@46: if(this.dragging) { rlm@46: return; rlm@46: } rlm@46: var data = this.getDragData(e); rlm@46: if(data && this.onBeforeDrag(data, e) !== false){ rlm@46: this.dragData = data; rlm@46: this.proxy.stop(); rlm@46: Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onBeforeDrag : function(data, e){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: onStartDrag : Ext.emptyFn, rlm@46: rlm@46: rlm@46: startDrag : function(x, y){ rlm@46: this.proxy.reset(); rlm@46: this.dragging = true; rlm@46: this.proxy.update(""); rlm@46: this.onInitDrag(x, y); rlm@46: this.proxy.show(); rlm@46: }, rlm@46: rlm@46: rlm@46: onInitDrag : function(x, y){ rlm@46: var clone = this.el.dom.cloneNode(true); rlm@46: clone.id = Ext.id(); rlm@46: this.proxy.update(clone); rlm@46: this.onStartDrag(x, y); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: getProxy : function(){ rlm@46: return this.proxy; rlm@46: }, rlm@46: rlm@46: rlm@46: hideProxy : function(){ rlm@46: this.proxy.hide(); rlm@46: this.proxy.reset(true); rlm@46: this.dragging = false; rlm@46: }, rlm@46: rlm@46: rlm@46: triggerCacheRefresh : function(){ rlm@46: Ext.dd.DDM.refreshCache(this.groups); rlm@46: }, rlm@46: rlm@46: rlm@46: b4EndDrag: function(e) { rlm@46: }, rlm@46: rlm@46: rlm@46: endDrag : function(e){ rlm@46: this.onEndDrag(this.dragData, e); rlm@46: }, rlm@46: rlm@46: rlm@46: onEndDrag : function(data, e){ rlm@46: }, rlm@46: rlm@46: rlm@46: autoOffset : function(x, y) { rlm@46: this.setDelta(-12, -20); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.dd.DropTarget = function(el, config){ rlm@46: this.el = Ext.get(el); rlm@46: rlm@46: Ext.apply(this, config); rlm@46: rlm@46: if(this.containerScroll){ rlm@46: Ext.dd.ScrollManager.register(this.el); rlm@46: } rlm@46: rlm@46: Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, rlm@46: {isTarget: true}); rlm@46: rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, { rlm@46: rlm@46: rlm@46: rlm@46: dropAllowed : "x-dd-drop-ok", rlm@46: rlm@46: dropNotAllowed : "x-dd-drop-nodrop", rlm@46: rlm@46: rlm@46: isTarget : true, rlm@46: rlm@46: rlm@46: isNotifyTarget : true, rlm@46: rlm@46: rlm@46: notifyEnter : function(dd, e, data){ rlm@46: if(this.overClass){ rlm@46: this.el.addClass(this.overClass); rlm@46: } rlm@46: return this.dropAllowed; rlm@46: }, rlm@46: rlm@46: rlm@46: notifyOver : function(dd, e, data){ rlm@46: return this.dropAllowed; rlm@46: }, rlm@46: rlm@46: rlm@46: notifyOut : function(dd, e, data){ rlm@46: if(this.overClass){ rlm@46: this.el.removeClass(this.overClass); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: notifyDrop : function(dd, e, data){ rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.dd.DragZone = function(el, config){ rlm@46: Ext.dd.DragZone.superclass.constructor.call(this, el, config); rlm@46: if(this.containerScroll){ rlm@46: Ext.dd.ScrollManager.register(this.el); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: getDragData : function(e){ rlm@46: return Ext.dd.Registry.getHandleFromEvent(e); rlm@46: }, rlm@46: rlm@46: rlm@46: onInitDrag : function(x, y){ rlm@46: this.proxy.update(this.dragData.ddel.cloneNode(true)); rlm@46: this.onStartDrag(x, y); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: afterRepair : function(){ rlm@46: if(Ext.enableFx){ rlm@46: Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9"); rlm@46: } rlm@46: this.dragging = false; rlm@46: }, rlm@46: rlm@46: rlm@46: getRepairXY : function(e){ rlm@46: return Ext.Element.fly(this.dragData.ddel).getXY(); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.dd.DropZone = function(el, config){ rlm@46: Ext.dd.DropZone.superclass.constructor.call(this, el, config); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, { rlm@46: rlm@46: getTargetFromEvent : function(e){ rlm@46: return Ext.dd.Registry.getTargetFromEvent(e); rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeEnter : function(n, dd, e, data){ rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeOver : function(n, dd, e, data){ rlm@46: return this.dropAllowed; rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeOut : function(n, dd, e, data){ rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeDrop : function(n, dd, e, data){ rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: onContainerOver : function(dd, e, data){ rlm@46: return this.dropNotAllowed; rlm@46: }, rlm@46: rlm@46: rlm@46: onContainerDrop : function(dd, e, data){ rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: notifyEnter : function(dd, e, data){ rlm@46: return this.dropNotAllowed; rlm@46: }, rlm@46: rlm@46: rlm@46: notifyOver : function(dd, e, data){ rlm@46: var n = this.getTargetFromEvent(e); rlm@46: if(!n){ rlm@46: if(this.lastOverNode){ rlm@46: this.onNodeOut(this.lastOverNode, dd, e, data); rlm@46: this.lastOverNode = null; rlm@46: } rlm@46: return this.onContainerOver(dd, e, data); rlm@46: } rlm@46: if(this.lastOverNode != n){ rlm@46: if(this.lastOverNode){ rlm@46: this.onNodeOut(this.lastOverNode, dd, e, data); rlm@46: } rlm@46: this.onNodeEnter(n, dd, e, data); rlm@46: this.lastOverNode = n; rlm@46: } rlm@46: return this.onNodeOver(n, dd, e, data); rlm@46: }, rlm@46: rlm@46: rlm@46: notifyOut : function(dd, e, data){ rlm@46: if(this.lastOverNode){ rlm@46: this.onNodeOut(this.lastOverNode, dd, e, data); rlm@46: this.lastOverNode = null; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: notifyDrop : function(dd, e, data){ rlm@46: if(this.lastOverNode){ rlm@46: this.onNodeOut(this.lastOverNode, dd, e, data); rlm@46: this.lastOverNode = null; rlm@46: } rlm@46: var n = this.getTargetFromEvent(e); rlm@46: return n ? rlm@46: this.onNodeDrop(n, dd, e, data) : rlm@46: this.onContainerDrop(dd, e, data); rlm@46: }, rlm@46: rlm@46: rlm@46: triggerCacheRefresh : function(){ rlm@46: Ext.dd.DDM.refreshCache(this.groups); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.data.SortTypes = { rlm@46: rlm@46: none : function(s){ rlm@46: return s; rlm@46: }, rlm@46: rlm@46: rlm@46: stripTagsRE : /<\/?[^>]+>/gi, rlm@46: rlm@46: rlm@46: asText : function(s){ rlm@46: return String(s).replace(this.stripTagsRE, ""); rlm@46: }, rlm@46: rlm@46: rlm@46: asUCText : function(s){ rlm@46: return String(s).toUpperCase().replace(this.stripTagsRE, ""); rlm@46: }, rlm@46: rlm@46: rlm@46: asUCString : function(s) { rlm@46: return String(s).toUpperCase(); rlm@46: }, rlm@46: rlm@46: rlm@46: asDate : function(s) { rlm@46: if(!s){ rlm@46: return 0; rlm@46: } rlm@46: if(Ext.isDate(s)){ rlm@46: return s.getTime(); rlm@46: } rlm@46: return Date.parse(String(s)); rlm@46: }, rlm@46: rlm@46: rlm@46: asFloat : function(s) { rlm@46: var val = parseFloat(String(s).replace(/,/g, "")); rlm@46: if(isNaN(val)) val = 0; rlm@46: return val; rlm@46: }, rlm@46: rlm@46: rlm@46: asInt : function(s) { rlm@46: var val = parseInt(String(s).replace(/,/g, "")); rlm@46: if(isNaN(val)) val = 0; rlm@46: return val; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.data.Record = function(data, id){ rlm@46: this.id = (id || id === 0) ? id : ++Ext.data.Record.AUTO_ID; rlm@46: this.data = data; rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.data.Record.create = function(o){ rlm@46: var f = Ext.extend(Ext.data.Record, {}); rlm@46: var p = f.prototype; rlm@46: p.fields = new Ext.util.MixedCollection(false, function(field){ rlm@46: return field.name; rlm@46: }); rlm@46: for(var i = 0, len = o.length; i < len; i++){ rlm@46: p.fields.add(new Ext.data.Field(o[i])); rlm@46: } rlm@46: f.getField = function(name){ rlm@46: return p.fields.get(name); rlm@46: }; rlm@46: return f; rlm@46: }; rlm@46: rlm@46: Ext.data.Record.AUTO_ID = 1000; rlm@46: Ext.data.Record.EDIT = 'edit'; rlm@46: Ext.data.Record.REJECT = 'reject'; rlm@46: Ext.data.Record.COMMIT = 'commit'; rlm@46: rlm@46: Ext.data.Record.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: dirty : false, rlm@46: editing : false, rlm@46: error: null, rlm@46: rlm@46: modified: null, rlm@46: rlm@46: join : function(store){ rlm@46: this.store = store; rlm@46: }, rlm@46: rlm@46: rlm@46: set : function(name, value){ rlm@46: if(String(this.data[name]) == String(value)){ rlm@46: return; rlm@46: } rlm@46: this.dirty = true; rlm@46: if(!this.modified){ rlm@46: this.modified = {}; rlm@46: } rlm@46: if(typeof this.modified[name] == 'undefined'){ rlm@46: this.modified[name] = this.data[name]; rlm@46: } rlm@46: this.data[name] = value; rlm@46: if(!this.editing && this.store){ rlm@46: this.store.afterEdit(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: get : function(name){ rlm@46: return this.data[name]; rlm@46: }, rlm@46: rlm@46: rlm@46: beginEdit : function(){ rlm@46: this.editing = true; rlm@46: this.modified = {}; rlm@46: }, rlm@46: rlm@46: rlm@46: cancelEdit : function(){ rlm@46: this.editing = false; rlm@46: delete this.modified; rlm@46: }, rlm@46: rlm@46: rlm@46: endEdit : function(){ rlm@46: this.editing = false; rlm@46: if(this.dirty && this.store){ rlm@46: this.store.afterEdit(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: reject : function(silent){ rlm@46: var m = this.modified; rlm@46: for(var n in m){ rlm@46: if(typeof m[n] != "function"){ rlm@46: this.data[n] = m[n]; rlm@46: } rlm@46: } rlm@46: this.dirty = false; rlm@46: delete this.modified; rlm@46: this.editing = false; rlm@46: if(this.store && silent !== true){ rlm@46: this.store.afterReject(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: commit : function(silent){ rlm@46: this.dirty = false; rlm@46: delete this.modified; rlm@46: this.editing = false; rlm@46: if(this.store && silent !== true){ rlm@46: this.store.afterCommit(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getChanges : function(){ rlm@46: var m = this.modified, cs = {}; rlm@46: for(var n in m){ rlm@46: if(m.hasOwnProperty(n)){ rlm@46: cs[n] = this.data[n]; rlm@46: } rlm@46: } rlm@46: return cs; rlm@46: }, rlm@46: rlm@46: hasError : function(){ rlm@46: return this.error != null; rlm@46: }, rlm@46: rlm@46: clearError : function(){ rlm@46: this.error = null; rlm@46: }, rlm@46: rlm@46: rlm@46: copy : function(newId) { rlm@46: return new this.constructor(Ext.apply({}, this.data), newId || this.id); rlm@46: }, rlm@46: rlm@46: rlm@46: isModified : function(fieldName){ rlm@46: return this.modified && this.modified.hasOwnProperty(fieldName); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.StoreMgr = Ext.apply(new Ext.util.MixedCollection(), { rlm@46: rlm@46: rlm@46: rlm@46: register : function(){ rlm@46: for(var i = 0, s; s = arguments[i]; i++){ rlm@46: this.add(s); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(){ rlm@46: for(var i = 0, s; s = arguments[i]; i++){ rlm@46: this.remove(this.lookup(s)); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: lookup : function(id){ rlm@46: return typeof id == "object" ? id : this.get(id); rlm@46: }, rlm@46: rlm@46: getKey : function(o){ rlm@46: return o.storeId || o.id; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.Store = function(config){ rlm@46: this.data = new Ext.util.MixedCollection(false); rlm@46: this.data.getKey = function(o){ rlm@46: return o.id; rlm@46: }; rlm@46: rlm@46: this.baseParams = {}; rlm@46: this.paramNames = { rlm@46: "start" : "start", rlm@46: "limit" : "limit", rlm@46: "sort" : "sort", rlm@46: "dir" : "dir" rlm@46: }; rlm@46: rlm@46: if(config && config.data){ rlm@46: this.inlineData = config.data; rlm@46: delete config.data; rlm@46: } rlm@46: rlm@46: Ext.apply(this, config); rlm@46: rlm@46: if(this.url && !this.proxy){ rlm@46: this.proxy = new Ext.data.HttpProxy({url: this.url}); rlm@46: } rlm@46: rlm@46: if(this.reader){ if(!this.recordType){ rlm@46: this.recordType = this.reader.recordType; rlm@46: } rlm@46: if(this.reader.onMetaChange){ rlm@46: this.reader.onMetaChange = this.onMetaChange.createDelegate(this); rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.recordType){ rlm@46: this.fields = this.recordType.prototype.fields; rlm@46: } rlm@46: this.modified = []; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'datachanged', rlm@46: rlm@46: 'metachange', rlm@46: rlm@46: 'add', rlm@46: rlm@46: 'remove', rlm@46: rlm@46: 'update', rlm@46: rlm@46: 'clear', rlm@46: rlm@46: 'beforeload', rlm@46: rlm@46: 'load', rlm@46: rlm@46: 'loadexception' rlm@46: ); rlm@46: rlm@46: if(this.proxy){ rlm@46: this.relayEvents(this.proxy, ["loadexception"]); rlm@46: } rlm@46: rlm@46: this.sortToggle = {}; rlm@46: if(this.sortInfo){ rlm@46: this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction); rlm@46: } rlm@46: rlm@46: Ext.data.Store.superclass.constructor.call(this); rlm@46: rlm@46: if(this.storeId || this.id){ rlm@46: Ext.StoreMgr.register(this); rlm@46: } rlm@46: if(this.inlineData){ rlm@46: this.loadData(this.inlineData); rlm@46: delete this.inlineData; rlm@46: }else if(this.autoLoad){ rlm@46: this.load.defer(10, this, [ rlm@46: typeof this.autoLoad == 'object' ? rlm@46: this.autoLoad : undefined]); rlm@46: } rlm@46: }; rlm@46: Ext.extend(Ext.data.Store, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: remoteSort : false, rlm@46: rlm@46: rlm@46: pruneModifiedRecords : false, rlm@46: rlm@46: rlm@46: lastOptions : null, rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.id){ rlm@46: Ext.StoreMgr.unregister(this); rlm@46: } rlm@46: this.data = null; rlm@46: this.purgeListeners(); rlm@46: }, rlm@46: rlm@46: rlm@46: add : function(records){ rlm@46: records = [].concat(records); rlm@46: if(records.length < 1){ rlm@46: return; rlm@46: } rlm@46: for(var i = 0, len = records.length; i < len; i++){ rlm@46: records[i].join(this); rlm@46: } rlm@46: var index = this.data.length; rlm@46: this.data.addAll(records); rlm@46: if(this.snapshot){ rlm@46: this.snapshot.addAll(records); rlm@46: } rlm@46: this.fireEvent("add", this, records, index); rlm@46: }, rlm@46: rlm@46: rlm@46: addSorted : function(record){ rlm@46: var index = this.findInsertIndex(record); rlm@46: this.insert(index, record); rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(record){ rlm@46: var index = this.data.indexOf(record); rlm@46: this.data.removeAt(index); rlm@46: if(this.pruneModifiedRecords){ rlm@46: this.modified.remove(record); rlm@46: } rlm@46: if(this.snapshot){ rlm@46: this.snapshot.remove(record); rlm@46: } rlm@46: this.fireEvent("remove", this, record, index); rlm@46: }, rlm@46: rlm@46: rlm@46: removeAll : function(){ rlm@46: this.data.clear(); rlm@46: if(this.snapshot){ rlm@46: this.snapshot.clear(); rlm@46: } rlm@46: if(this.pruneModifiedRecords){ rlm@46: this.modified = []; rlm@46: } rlm@46: this.fireEvent("clear", this); rlm@46: }, rlm@46: rlm@46: rlm@46: insert : function(index, records){ rlm@46: records = [].concat(records); rlm@46: for(var i = 0, len = records.length; i < len; i++){ rlm@46: this.data.insert(index, records[i]); rlm@46: records[i].join(this); rlm@46: } rlm@46: this.fireEvent("add", this, records, index); rlm@46: }, rlm@46: rlm@46: rlm@46: indexOf : function(record){ rlm@46: return this.data.indexOf(record); rlm@46: }, rlm@46: rlm@46: rlm@46: indexOfId : function(id){ rlm@46: return this.data.indexOfKey(id); rlm@46: }, rlm@46: rlm@46: rlm@46: getById : function(id){ rlm@46: return this.data.key(id); rlm@46: }, rlm@46: rlm@46: rlm@46: getAt : function(index){ rlm@46: return this.data.itemAt(index); rlm@46: }, rlm@46: rlm@46: rlm@46: getRange : function(start, end){ rlm@46: return this.data.getRange(start, end); rlm@46: }, rlm@46: rlm@46: storeOptions : function(o){ rlm@46: o = Ext.apply({}, o); rlm@46: delete o.callback; rlm@46: delete o.scope; rlm@46: this.lastOptions = o; rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(options){ rlm@46: options = options || {}; rlm@46: if(this.fireEvent("beforeload", this, options) !== false){ rlm@46: this.storeOptions(options); rlm@46: var p = Ext.apply(options.params || {}, this.baseParams); rlm@46: if(this.sortInfo && this.remoteSort){ rlm@46: var pn = this.paramNames; rlm@46: p[pn["sort"]] = this.sortInfo.field; rlm@46: p[pn["dir"]] = this.sortInfo.direction; rlm@46: } rlm@46: this.proxy.load(p, this.reader, this.loadRecords, this, options); rlm@46: return true; rlm@46: } else { rlm@46: return false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: reload : function(options){ rlm@46: this.load(Ext.applyIf(options||{}, this.lastOptions)); rlm@46: }, rlm@46: rlm@46: loadRecords : function(o, options, success){ rlm@46: if(!o || success === false){ rlm@46: if(success !== false){ rlm@46: this.fireEvent("load", this, [], options); rlm@46: } rlm@46: if(options.callback){ rlm@46: options.callback.call(options.scope || this, [], options, false); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var r = o.records, t = o.totalRecords || r.length; rlm@46: if(!options || options.add !== true){ rlm@46: if(this.pruneModifiedRecords){ rlm@46: this.modified = []; rlm@46: } rlm@46: for(var i = 0, len = r.length; i < len; i++){ rlm@46: r[i].join(this); rlm@46: } rlm@46: if(this.snapshot){ rlm@46: this.data = this.snapshot; rlm@46: delete this.snapshot; rlm@46: } rlm@46: this.data.clear(); rlm@46: this.data.addAll(r); rlm@46: this.totalLength = t; rlm@46: this.applySort(); rlm@46: this.fireEvent("datachanged", this); rlm@46: }else{ rlm@46: this.totalLength = Math.max(t, this.data.length+r.length); rlm@46: this.add(r); rlm@46: } rlm@46: this.fireEvent("load", this, r, options); rlm@46: if(options.callback){ rlm@46: options.callback.call(options.scope || this, r, options, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: loadData : function(o, append){ rlm@46: var r = this.reader.readRecords(o); rlm@46: this.loadRecords(r, {add: append}, true); rlm@46: }, rlm@46: rlm@46: rlm@46: getCount : function(){ rlm@46: return this.data.length || 0; rlm@46: }, rlm@46: rlm@46: rlm@46: getTotalCount : function(){ rlm@46: return this.totalLength || 0; rlm@46: }, rlm@46: rlm@46: rlm@46: getSortState : function(){ rlm@46: return this.sortInfo; rlm@46: }, rlm@46: rlm@46: applySort : function(){ rlm@46: if(this.sortInfo && !this.remoteSort){ rlm@46: var s = this.sortInfo, f = s.field; rlm@46: this.sortData(f, s.direction); rlm@46: } rlm@46: }, rlm@46: rlm@46: sortData : function(f, direction){ rlm@46: direction = direction || 'ASC'; rlm@46: var st = this.fields.get(f).sortType; rlm@46: var fn = function(r1, r2){ rlm@46: var v1 = st(r1.data[f]), v2 = st(r2.data[f]); rlm@46: return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0); rlm@46: }; rlm@46: this.data.sort(direction, fn); rlm@46: if(this.snapshot && this.snapshot != this.data){ rlm@46: this.snapshot.sort(direction, fn); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setDefaultSort : function(field, dir){ rlm@46: dir = dir ? dir.toUpperCase() : "ASC"; rlm@46: this.sortInfo = {field: field, direction: dir}; rlm@46: this.sortToggle[field] = dir; rlm@46: }, rlm@46: rlm@46: rlm@46: sort : function(fieldName, dir){ rlm@46: var f = this.fields.get(fieldName); rlm@46: if(!f){ rlm@46: return false; rlm@46: } rlm@46: if(!dir){ rlm@46: if(this.sortInfo && this.sortInfo.field == f.name){ dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC"); rlm@46: }else{ rlm@46: dir = f.sortDir; rlm@46: } rlm@46: } rlm@46: var st = (this.sortToggle) ? this.sortToggle[f.name] : null; rlm@46: var si = (this.sortInfo) ? this.sortInfo : null; rlm@46: rlm@46: this.sortToggle[f.name] = dir; rlm@46: this.sortInfo = {field: f.name, direction: dir}; rlm@46: if(!this.remoteSort){ rlm@46: this.applySort(); rlm@46: this.fireEvent("datachanged", this); rlm@46: }else{ rlm@46: if (!this.load(this.lastOptions)) { rlm@46: if (st) { rlm@46: this.sortToggle[f.name] = st; rlm@46: } rlm@46: if (si) { rlm@46: this.sortInfo = si; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: this.data.each(fn, scope); rlm@46: }, rlm@46: rlm@46: rlm@46: getModifiedRecords : function(){ rlm@46: return this.modified; rlm@46: }, rlm@46: rlm@46: createFilterFn : function(property, value, anyMatch, caseSensitive){ rlm@46: if(Ext.isEmpty(value, false)){ rlm@46: return false; rlm@46: } rlm@46: value = this.data.createValueMatcher(value, anyMatch, caseSensitive); rlm@46: return function(r){ rlm@46: return value.test(r.data[property]); rlm@46: }; rlm@46: }, rlm@46: rlm@46: rlm@46: sum : function(property, start, end){ rlm@46: var rs = this.data.items, v = 0; rlm@46: start = start || 0; rlm@46: end = (end || end === 0) ? end : rs.length-1; rlm@46: rlm@46: for(var i = start; i <= end; i++){ rlm@46: v += (rs[i].data[property] || 0); rlm@46: } rlm@46: return v; rlm@46: }, rlm@46: rlm@46: rlm@46: filter : function(property, value, anyMatch, caseSensitive){ rlm@46: var fn = this.createFilterFn(property, value, anyMatch, caseSensitive); rlm@46: return fn ? this.filterBy(fn) : this.clearFilter(); rlm@46: }, rlm@46: rlm@46: rlm@46: filterBy : function(fn, scope){ rlm@46: this.snapshot = this.snapshot || this.data; rlm@46: this.data = this.queryBy(fn, scope||this); rlm@46: this.fireEvent("datachanged", this); rlm@46: }, rlm@46: rlm@46: rlm@46: query : function(property, value, anyMatch, caseSensitive){ rlm@46: var fn = this.createFilterFn(property, value, anyMatch, caseSensitive); rlm@46: return fn ? this.queryBy(fn) : this.data.clone(); rlm@46: }, rlm@46: rlm@46: rlm@46: queryBy : function(fn, scope){ rlm@46: var data = this.snapshot || this.data; rlm@46: return data.filterBy(fn, scope||this); rlm@46: }, rlm@46: rlm@46: rlm@46: find : function(property, value, start, anyMatch, caseSensitive){ rlm@46: var fn = this.createFilterFn(property, value, anyMatch, caseSensitive); rlm@46: return fn ? this.data.findIndexBy(fn, null, start) : -1; rlm@46: }, rlm@46: rlm@46: rlm@46: findBy : function(fn, scope, start){ rlm@46: return this.data.findIndexBy(fn, scope, start); rlm@46: }, rlm@46: rlm@46: rlm@46: collect : function(dataIndex, allowNull, bypassFilter){ rlm@46: var d = (bypassFilter === true && this.snapshot) ? rlm@46: this.snapshot.items : this.data.items; rlm@46: var v, sv, r = [], l = {}; rlm@46: for(var i = 0, len = d.length; i < len; i++){ rlm@46: v = d[i].data[dataIndex]; rlm@46: sv = String(v); rlm@46: if((allowNull || !Ext.isEmpty(v)) && !l[sv]){ rlm@46: l[sv] = true; rlm@46: r[r.length] = v; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: clearFilter : function(suppressEvent){ rlm@46: if(this.isFiltered()){ rlm@46: this.data = this.snapshot; rlm@46: delete this.snapshot; rlm@46: if(suppressEvent !== true){ rlm@46: this.fireEvent("datachanged", this); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isFiltered : function(){ rlm@46: return this.snapshot && this.snapshot != this.data; rlm@46: }, rlm@46: rlm@46: afterEdit : function(record){ rlm@46: if(this.modified.indexOf(record) == -1){ rlm@46: this.modified.push(record); rlm@46: } rlm@46: this.fireEvent("update", this, record, Ext.data.Record.EDIT); rlm@46: }, rlm@46: rlm@46: afterReject : function(record){ rlm@46: this.modified.remove(record); rlm@46: this.fireEvent("update", this, record, Ext.data.Record.REJECT); rlm@46: }, rlm@46: rlm@46: afterCommit : function(record){ rlm@46: this.modified.remove(record); rlm@46: this.fireEvent("update", this, record, Ext.data.Record.COMMIT); rlm@46: }, rlm@46: rlm@46: rlm@46: commitChanges : function(){ rlm@46: var m = this.modified.slice(0); rlm@46: this.modified = []; rlm@46: for(var i = 0, len = m.length; i < len; i++){ rlm@46: m[i].commit(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: rejectChanges : function(){ rlm@46: var m = this.modified.slice(0); rlm@46: this.modified = []; rlm@46: for(var i = 0, len = m.length; i < len; i++){ rlm@46: m[i].reject(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onMetaChange : function(meta, rtype, o){ rlm@46: this.recordType = rtype; rlm@46: this.fields = rtype.prototype.fields; rlm@46: delete this.snapshot; rlm@46: this.sortInfo = meta.sortInfo; rlm@46: this.modified = []; rlm@46: this.fireEvent('metachange', this, this.reader.meta); rlm@46: }, rlm@46: rlm@46: findInsertIndex : function(record){ rlm@46: this.suspendEvents(); rlm@46: var data = this.data.clone(); rlm@46: this.data.add(record); rlm@46: this.applySort(); rlm@46: var index = this.data.indexOf(record); rlm@46: this.data = data; rlm@46: this.resumeEvents(); rlm@46: return index; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.SimpleStore = function(config){ rlm@46: Ext.data.SimpleStore.superclass.constructor.call(this, Ext.apply(config, { rlm@46: reader: new Ext.data.ArrayReader({ rlm@46: id: config.id rlm@46: }, rlm@46: Ext.data.Record.create(config.fields) rlm@46: ) rlm@46: })); rlm@46: }; rlm@46: Ext.extend(Ext.data.SimpleStore, Ext.data.Store, { rlm@46: loadData : function(data, append){ rlm@46: if(this.expandData === true){ rlm@46: var r = []; rlm@46: for(var i = 0, len = data.length; i < len; i++){ rlm@46: r[r.length] = [data[i]]; rlm@46: } rlm@46: data = r; rlm@46: } rlm@46: Ext.data.SimpleStore.superclass.loadData.call(this, data, append); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.JsonStore = function(c){ rlm@46: Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(c, { rlm@46: proxy: !c.data ? new Ext.data.HttpProxy({url: c.url}) : undefined, rlm@46: reader: new Ext.data.JsonReader(c, c.fields) rlm@46: })); rlm@46: }; rlm@46: Ext.extend(Ext.data.JsonStore, Ext.data.Store); rlm@46: rlm@46: rlm@46: rlm@46: Ext.data.Field = function(config){ rlm@46: if(typeof config == "string"){ rlm@46: config = {name: config}; rlm@46: } rlm@46: Ext.apply(this, config); rlm@46: rlm@46: if(!this.type){ rlm@46: this.type = "auto"; rlm@46: } rlm@46: rlm@46: var st = Ext.data.SortTypes; rlm@46: rlm@46: if(typeof this.sortType == "string"){ rlm@46: this.sortType = st[this.sortType]; rlm@46: } rlm@46: rlm@46: rlm@46: if(!this.sortType){ rlm@46: switch(this.type){ rlm@46: case "string": rlm@46: this.sortType = st.asUCString; rlm@46: break; rlm@46: case "date": rlm@46: this.sortType = st.asDate; rlm@46: break; rlm@46: default: rlm@46: this.sortType = st.none; rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: var stripRe = /[\$,%]/g; rlm@46: rlm@46: rlm@46: rlm@46: if(!this.convert){ rlm@46: var cv, dateFormat = this.dateFormat; rlm@46: switch(this.type){ rlm@46: case "": rlm@46: case "auto": rlm@46: case undefined: rlm@46: cv = function(v){ return v; }; rlm@46: break; rlm@46: case "string": rlm@46: cv = function(v){ return (v === undefined || v === null) ? '' : String(v); }; rlm@46: break; rlm@46: case "int": rlm@46: cv = function(v){ rlm@46: return v !== undefined && v !== null && v !== '' ? rlm@46: parseInt(String(v).replace(stripRe, ""), 10) : ''; rlm@46: }; rlm@46: break; rlm@46: case "float": rlm@46: cv = function(v){ rlm@46: return v !== undefined && v !== null && v !== '' ? rlm@46: parseFloat(String(v).replace(stripRe, ""), 10) : ''; rlm@46: }; rlm@46: break; rlm@46: case "bool": rlm@46: case "boolean": rlm@46: cv = function(v){ return v === true || v === "true" || v == 1; }; rlm@46: break; rlm@46: case "date": rlm@46: cv = function(v){ rlm@46: if(!v){ rlm@46: return ''; rlm@46: } rlm@46: if(Ext.isDate(v)){ rlm@46: return v; rlm@46: } rlm@46: if(dateFormat){ rlm@46: if(dateFormat == "timestamp"){ rlm@46: return new Date(v*1000); rlm@46: } rlm@46: if(dateFormat == "time"){ rlm@46: return new Date(parseInt(v, 10)); rlm@46: } rlm@46: return Date.parseDate(v, dateFormat); rlm@46: } rlm@46: var parsed = Date.parse(v); rlm@46: return parsed ? new Date(parsed) : null; rlm@46: }; rlm@46: break; rlm@46: rlm@46: } rlm@46: this.convert = cv; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.data.Field.prototype = { rlm@46: dateFormat: null, rlm@46: defaultValue: "", rlm@46: mapping: null, rlm@46: sortType : null, rlm@46: sortDir : "ASC" rlm@46: }; rlm@46: rlm@46: Ext.data.DataReader = function(meta, recordType){ rlm@46: rlm@46: this.meta = meta; rlm@46: this.recordType = Ext.isArray(recordType) ? rlm@46: Ext.data.Record.create(recordType) : recordType; rlm@46: }; rlm@46: rlm@46: Ext.data.DataReader.prototype = { rlm@46: rlm@46: }; rlm@46: rlm@46: Ext.data.DataProxy = function(){ rlm@46: this.addEvents( rlm@46: rlm@46: 'beforeload', rlm@46: rlm@46: 'load' rlm@46: ); rlm@46: Ext.data.DataProxy.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.DataProxy, Ext.util.Observable); rlm@46: rlm@46: Ext.data.MemoryProxy = function(data){ rlm@46: Ext.data.MemoryProxy.superclass.constructor.call(this); rlm@46: this.data = data; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.MemoryProxy, Ext.data.DataProxy, { rlm@46: rlm@46: rlm@46: rlm@46: load : function(params, reader, callback, scope, arg){ rlm@46: params = params || {}; rlm@46: var result; rlm@46: try { rlm@46: result = reader.readRecords(this.data); rlm@46: }catch(e){ rlm@46: this.fireEvent("loadexception", this, arg, null, e); rlm@46: callback.call(scope, null, arg, false); rlm@46: return; rlm@46: } rlm@46: callback.call(scope, result, arg, true); rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(params, records){ rlm@46: rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.HttpProxy = function(conn){ rlm@46: Ext.data.HttpProxy.superclass.constructor.call(this); rlm@46: rlm@46: this.conn = conn; rlm@46: this.useAjax = !conn || !conn.events; rlm@46: rlm@46: rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.HttpProxy, Ext.data.DataProxy, { rlm@46: rlm@46: getConnection : function(){ rlm@46: return this.useAjax ? Ext.Ajax : this.conn; rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(params, reader, callback, scope, arg){ rlm@46: if(this.fireEvent("beforeload", this, params) !== false){ rlm@46: var o = { rlm@46: params : params || {}, rlm@46: request: { rlm@46: callback : callback, rlm@46: scope : scope, rlm@46: arg : arg rlm@46: }, rlm@46: reader: reader, rlm@46: callback : this.loadResponse, rlm@46: scope: this rlm@46: }; rlm@46: if(this.useAjax){ rlm@46: Ext.applyIf(o, this.conn); rlm@46: if(this.activeRequest){ rlm@46: Ext.Ajax.abort(this.activeRequest); rlm@46: } rlm@46: this.activeRequest = Ext.Ajax.request(o); rlm@46: }else{ rlm@46: this.conn.request(o); rlm@46: } rlm@46: }else{ rlm@46: callback.call(scope||this, null, arg, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: loadResponse : function(o, success, response){ rlm@46: delete this.activeRequest; rlm@46: if(!success){ rlm@46: this.fireEvent("loadexception", this, o, response); rlm@46: o.request.callback.call(o.request.scope, null, o.request.arg, false); rlm@46: return; rlm@46: } rlm@46: var result; rlm@46: try { rlm@46: result = o.reader.read(response); rlm@46: }catch(e){ rlm@46: this.fireEvent("loadexception", this, o, response, e); rlm@46: o.request.callback.call(o.request.scope, null, o.request.arg, false); rlm@46: return; rlm@46: } rlm@46: this.fireEvent("load", this, o, o.request.arg); rlm@46: o.request.callback.call(o.request.scope, result, o.request.arg, true); rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(dataSet){ rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: updateResponse : function(dataSet){ rlm@46: rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.ScriptTagProxy = function(config){ rlm@46: Ext.data.ScriptTagProxy.superclass.constructor.call(this); rlm@46: Ext.apply(this, config); rlm@46: this.head = document.getElementsByTagName("head")[0]; rlm@46: rlm@46: rlm@46: }; rlm@46: rlm@46: Ext.data.ScriptTagProxy.TRANS_ID = 1000; rlm@46: rlm@46: Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, { rlm@46: rlm@46: rlm@46: timeout : 30000, rlm@46: rlm@46: callbackParam : "callback", rlm@46: rlm@46: nocache : true, rlm@46: rlm@46: rlm@46: load : function(params, reader, callback, scope, arg){ rlm@46: if(this.fireEvent("beforeload", this, params) !== false){ rlm@46: rlm@46: var p = Ext.urlEncode(Ext.apply(params, this.extraParams)); rlm@46: rlm@46: var url = this.url; rlm@46: url += (url.indexOf("?") != -1 ? "&" : "?") + p; rlm@46: if(this.nocache){ rlm@46: url += "&_dc=" + (new Date().getTime()); rlm@46: } rlm@46: var transId = ++Ext.data.ScriptTagProxy.TRANS_ID; rlm@46: var trans = { rlm@46: id : transId, rlm@46: cb : "stcCallback"+transId, rlm@46: scriptId : "stcScript"+transId, rlm@46: params : params, rlm@46: arg : arg, rlm@46: url : url, rlm@46: callback : callback, rlm@46: scope : scope, rlm@46: reader : reader rlm@46: }; rlm@46: var conn = this; rlm@46: rlm@46: window[trans.cb] = function(o){ rlm@46: conn.handleResponse(o, trans); rlm@46: }; rlm@46: rlm@46: url += String.format("&{0}={1}", this.callbackParam, trans.cb); rlm@46: rlm@46: if(this.autoAbort !== false){ rlm@46: this.abort(); rlm@46: } rlm@46: rlm@46: trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]); rlm@46: rlm@46: var script = document.createElement("script"); rlm@46: script.setAttribute("src", url); rlm@46: script.setAttribute("type", "text/javascript"); rlm@46: script.setAttribute("id", trans.scriptId); rlm@46: this.head.appendChild(script); rlm@46: rlm@46: this.trans = trans; rlm@46: }else{ rlm@46: callback.call(scope||this, null, arg, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isLoading : function(){ rlm@46: return this.trans ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: abort : function(){ rlm@46: if(this.isLoading()){ rlm@46: this.destroyTrans(this.trans); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: destroyTrans : function(trans, isLoaded){ rlm@46: this.head.removeChild(document.getElementById(trans.scriptId)); rlm@46: clearTimeout(trans.timeoutId); rlm@46: if(isLoaded){ rlm@46: window[trans.cb] = undefined; rlm@46: try{ rlm@46: delete window[trans.cb]; rlm@46: }catch(e){} rlm@46: }else{ rlm@46: rlm@46: window[trans.cb] = function(){ rlm@46: window[trans.cb] = undefined; rlm@46: try{ rlm@46: delete window[trans.cb]; rlm@46: }catch(e){} rlm@46: }; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: handleResponse : function(o, trans){ rlm@46: this.trans = false; rlm@46: this.destroyTrans(trans, true); rlm@46: var result; rlm@46: try { rlm@46: result = trans.reader.readRecords(o); rlm@46: }catch(e){ rlm@46: this.fireEvent("loadexception", this, o, trans.arg, e); rlm@46: trans.callback.call(trans.scope||window, null, trans.arg, false); rlm@46: return; rlm@46: } rlm@46: this.fireEvent("load", this, o, trans.arg); rlm@46: trans.callback.call(trans.scope||window, result, trans.arg, true); rlm@46: }, rlm@46: rlm@46: rlm@46: handleFailure : function(trans){ rlm@46: this.trans = false; rlm@46: this.destroyTrans(trans, false); rlm@46: this.fireEvent("loadexception", this, null, trans.arg); rlm@46: trans.callback.call(trans.scope||window, null, trans.arg, false); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.JsonReader = function(meta, recordType){ rlm@46: meta = meta || {}; rlm@46: Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields); rlm@46: }; rlm@46: Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, { rlm@46: rlm@46: rlm@46: read : function(response){ rlm@46: var json = response.responseText; rlm@46: var o = eval("("+json+")"); rlm@46: if(!o) { rlm@46: throw {message: "JsonReader.read: Json object not found"}; rlm@46: } rlm@46: return this.readRecords(o); rlm@46: }, rlm@46: rlm@46: onMetaChange : function(meta, recordType, o){ rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: simpleAccess: function(obj, subsc) { rlm@46: return obj[subsc]; rlm@46: }, rlm@46: rlm@46: rlm@46: getJsonAccessor: function(){ rlm@46: var re = /[\[\.]/; rlm@46: return function(expr) { rlm@46: try { rlm@46: return(re.test(expr)) rlm@46: ? new Function("obj", "return obj." + expr) rlm@46: : function(obj){ rlm@46: return obj[expr]; rlm@46: }; rlm@46: } catch(e){} rlm@46: return Ext.emptyFn; rlm@46: }; rlm@46: }(), rlm@46: rlm@46: rlm@46: readRecords : function(o){ rlm@46: rlm@46: this.jsonData = o; rlm@46: if(o.metaData){ rlm@46: delete this.ef; rlm@46: this.meta = o.metaData; rlm@46: this.recordType = Ext.data.Record.create(o.metaData.fields); rlm@46: this.onMetaChange(this.meta, this.recordType, o); rlm@46: } rlm@46: var s = this.meta, Record = this.recordType, rlm@46: f = Record.prototype.fields, fi = f.items, fl = f.length; rlm@46: rlm@46: if (!this.ef) { rlm@46: if(s.totalProperty) { rlm@46: this.getTotal = this.getJsonAccessor(s.totalProperty); rlm@46: } rlm@46: if(s.successProperty) { rlm@46: this.getSuccess = this.getJsonAccessor(s.successProperty); rlm@46: } rlm@46: this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;}; rlm@46: if (s.id) { rlm@46: var g = this.getJsonAccessor(s.id); rlm@46: this.getId = function(rec) { rlm@46: var r = g(rec); rlm@46: return (r === undefined || r === "") ? null : r; rlm@46: }; rlm@46: } else { rlm@46: this.getId = function(){return null;}; rlm@46: } rlm@46: this.ef = []; rlm@46: for(var i = 0; i < fl; i++){ rlm@46: f = fi[i]; rlm@46: var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name; rlm@46: this.ef[i] = this.getJsonAccessor(map); rlm@46: } rlm@46: } rlm@46: rlm@46: var root = this.getRoot(o), c = root.length, totalRecords = c, success = true; rlm@46: if(s.totalProperty){ rlm@46: var v = parseInt(this.getTotal(o), 10); rlm@46: if(!isNaN(v)){ rlm@46: totalRecords = v; rlm@46: } rlm@46: } rlm@46: if(s.successProperty){ rlm@46: var v = this.getSuccess(o); rlm@46: if(v === false || v === 'false'){ rlm@46: success = false; rlm@46: } rlm@46: } rlm@46: var records = []; rlm@46: for(var i = 0; i < c; i++){ rlm@46: var n = root[i]; rlm@46: var values = {}; rlm@46: var id = this.getId(n); rlm@46: for(var j = 0; j < fl; j++){ rlm@46: f = fi[j]; rlm@46: var v = this.ef[j](n); rlm@46: values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, n); rlm@46: } rlm@46: var record = new Record(values, id); rlm@46: record.json = n; rlm@46: records[i] = record; rlm@46: } rlm@46: return { rlm@46: success : success, rlm@46: records : records, rlm@46: totalRecords : totalRecords rlm@46: }; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.XmlReader = function(meta, recordType){ rlm@46: meta = meta || {}; rlm@46: Ext.data.XmlReader.superclass.constructor.call(this, meta, recordType || meta.fields); rlm@46: }; rlm@46: Ext.extend(Ext.data.XmlReader, Ext.data.DataReader, { rlm@46: rlm@46: read : function(response){ rlm@46: var doc = response.responseXML; rlm@46: if(!doc) { rlm@46: throw {message: "XmlReader.read: XML Document not available"}; rlm@46: } rlm@46: return this.readRecords(doc); rlm@46: }, rlm@46: rlm@46: rlm@46: readRecords : function(doc){ rlm@46: rlm@46: this.xmlData = doc; rlm@46: var root = doc.documentElement || doc; rlm@46: var q = Ext.DomQuery; rlm@46: var recordType = this.recordType, fields = recordType.prototype.fields; rlm@46: var sid = this.meta.id; rlm@46: var totalRecords = 0, success = true; rlm@46: if(this.meta.totalRecords){ rlm@46: totalRecords = q.selectNumber(this.meta.totalRecords, root, 0); rlm@46: } rlm@46: rlm@46: if(this.meta.success){ rlm@46: var sv = q.selectValue(this.meta.success, root, true); rlm@46: success = sv !== false && sv !== 'false'; rlm@46: } rlm@46: var records = []; rlm@46: var ns = q.select(this.meta.record, root); rlm@46: for(var i = 0, len = ns.length; i < len; i++) { rlm@46: var n = ns[i]; rlm@46: var values = {}; rlm@46: var id = sid ? q.selectValue(sid, n) : undefined; rlm@46: for(var j = 0, jlen = fields.length; j < jlen; j++){ rlm@46: var f = fields.items[j]; rlm@46: var v = q.selectValue(f.mapping || f.name, n, f.defaultValue); rlm@46: v = f.convert(v, n); rlm@46: values[f.name] = v; rlm@46: } rlm@46: var record = new recordType(values, id); rlm@46: record.node = n; rlm@46: records[records.length] = record; rlm@46: } rlm@46: rlm@46: return { rlm@46: success : success, rlm@46: records : records, rlm@46: totalRecords : totalRecords || records.length rlm@46: }; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, { rlm@46: rlm@46: readRecords : function(o){ rlm@46: var sid = this.meta ? this.meta.id : null; rlm@46: var recordType = this.recordType, fields = recordType.prototype.fields; rlm@46: var records = []; rlm@46: var root = o; rlm@46: for(var i = 0; i < root.length; i++){ rlm@46: var n = root[i]; rlm@46: var values = {}; rlm@46: var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null); rlm@46: for(var j = 0, jlen = fields.length; j < jlen; j++){ rlm@46: var f = fields.items[j]; rlm@46: var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j; rlm@46: var v = n[k] !== undefined ? n[k] : f.defaultValue; rlm@46: v = f.convert(v, n); rlm@46: values[f.name] = v; rlm@46: } rlm@46: var record = new recordType(values, id); rlm@46: record.json = n; rlm@46: records[records.length] = record; rlm@46: } rlm@46: return { rlm@46: records : records, rlm@46: totalRecords : records.length rlm@46: }; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.Tree = function(root){ rlm@46: this.nodeHash = {}; rlm@46: rlm@46: this.root = null; rlm@46: if(root){ rlm@46: this.setRootNode(root); rlm@46: } rlm@46: this.addEvents( rlm@46: rlm@46: "append", rlm@46: rlm@46: "remove", rlm@46: rlm@46: "move", rlm@46: rlm@46: "insert", rlm@46: rlm@46: "beforeappend", rlm@46: rlm@46: "beforeremove", rlm@46: rlm@46: "beforemove", rlm@46: rlm@46: "beforeinsert" rlm@46: ); rlm@46: rlm@46: Ext.data.Tree.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.Tree, Ext.util.Observable, { rlm@46: rlm@46: pathSeparator: "/", rlm@46: rlm@46: rlm@46: proxyNodeEvent : function(){ rlm@46: return this.fireEvent.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: getRootNode : function(){ rlm@46: return this.root; rlm@46: }, rlm@46: rlm@46: rlm@46: setRootNode : function(node){ rlm@46: this.root = node; rlm@46: node.ownerTree = this; rlm@46: node.isRoot = true; rlm@46: this.registerNode(node); rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: getNodeById : function(id){ rlm@46: return this.nodeHash[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: registerNode : function(node){ rlm@46: this.nodeHash[node.id] = node; rlm@46: }, rlm@46: rlm@46: rlm@46: unregisterNode : function(node){ rlm@46: delete this.nodeHash[node.id]; rlm@46: }, rlm@46: rlm@46: toString : function(){ rlm@46: return "[Tree"+(this.id?" "+this.id:"")+"]"; rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.data.Node = function(attributes){ rlm@46: rlm@46: this.attributes = attributes || {}; rlm@46: this.leaf = this.attributes.leaf; rlm@46: rlm@46: this.id = this.attributes.id; rlm@46: if(!this.id){ rlm@46: this.id = Ext.id(null, "ynode-"); rlm@46: this.attributes.id = this.id; rlm@46: } rlm@46: rlm@46: this.childNodes = []; rlm@46: if(!this.childNodes.indexOf){ rlm@46: this.childNodes.indexOf = function(o){ rlm@46: for(var i = 0, len = this.length; i < len; i++){ rlm@46: if(this[i] == o) return i; rlm@46: } rlm@46: return -1; rlm@46: }; rlm@46: } rlm@46: rlm@46: this.parentNode = null; rlm@46: rlm@46: this.firstChild = null; rlm@46: rlm@46: this.lastChild = null; rlm@46: rlm@46: this.previousSibling = null; rlm@46: rlm@46: this.nextSibling = null; rlm@46: rlm@46: this.addEvents({ rlm@46: rlm@46: "append" : true, rlm@46: rlm@46: "remove" : true, rlm@46: rlm@46: "move" : true, rlm@46: rlm@46: "insert" : true, rlm@46: rlm@46: "beforeappend" : true, rlm@46: rlm@46: "beforeremove" : true, rlm@46: rlm@46: "beforemove" : true, rlm@46: rlm@46: "beforeinsert" : true rlm@46: }); rlm@46: this.listeners = this.attributes.listeners; rlm@46: Ext.data.Node.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.data.Node, Ext.util.Observable, { rlm@46: rlm@46: fireEvent : function(evtName){ rlm@46: rlm@46: if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: var ot = this.getOwnerTree(); rlm@46: if(ot){ rlm@46: if(ot.proxyNodeEvent.apply(ot, arguments) === false){ rlm@46: return false; rlm@46: } rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: isLeaf : function(){ rlm@46: return this.leaf === true; rlm@46: }, rlm@46: rlm@46: rlm@46: setFirstChild : function(node){ rlm@46: this.firstChild = node; rlm@46: }, rlm@46: rlm@46: rlm@46: setLastChild : function(node){ rlm@46: this.lastChild = node; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: isLast : function(){ rlm@46: return (!this.parentNode ? true : this.parentNode.lastChild == this); rlm@46: }, rlm@46: rlm@46: rlm@46: isFirst : function(){ rlm@46: return (!this.parentNode ? true : this.parentNode.firstChild == this); rlm@46: }, rlm@46: rlm@46: hasChildNodes : function(){ rlm@46: return !this.isLeaf() && this.childNodes.length > 0; rlm@46: }, rlm@46: rlm@46: rlm@46: appendChild : function(node){ rlm@46: var multi = false; rlm@46: if(Ext.isArray(node)){ rlm@46: multi = node; rlm@46: }else if(arguments.length > 1){ rlm@46: multi = arguments; rlm@46: } rlm@46: rlm@46: if(multi){ rlm@46: for(var i = 0, len = multi.length; i < len; i++) { rlm@46: this.appendChild(multi[i]); rlm@46: } rlm@46: }else{ rlm@46: if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){ rlm@46: return false; rlm@46: } rlm@46: var index = this.childNodes.length; rlm@46: var oldParent = node.parentNode; rlm@46: rlm@46: if(oldParent){ rlm@46: if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){ rlm@46: return false; rlm@46: } rlm@46: oldParent.removeChild(node); rlm@46: } rlm@46: index = this.childNodes.length; rlm@46: if(index == 0){ rlm@46: this.setFirstChild(node); rlm@46: } rlm@46: this.childNodes.push(node); rlm@46: node.parentNode = this; rlm@46: var ps = this.childNodes[index-1]; rlm@46: if(ps){ rlm@46: node.previousSibling = ps; rlm@46: ps.nextSibling = node; rlm@46: }else{ rlm@46: node.previousSibling = null; rlm@46: } rlm@46: node.nextSibling = null; rlm@46: this.setLastChild(node); rlm@46: node.setOwnerTree(this.getOwnerTree()); rlm@46: this.fireEvent("append", this.ownerTree, this, node, index); rlm@46: if(oldParent){ rlm@46: node.fireEvent("move", this.ownerTree, node, oldParent, this, index); rlm@46: } rlm@46: return node; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: removeChild : function(node){ rlm@46: var index = this.childNodes.indexOf(node); rlm@46: if(index == -1){ rlm@46: return false; rlm@46: } rlm@46: if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: rlm@46: this.childNodes.splice(index, 1); rlm@46: rlm@46: rlm@46: if(node.previousSibling){ rlm@46: node.previousSibling.nextSibling = node.nextSibling; rlm@46: } rlm@46: if(node.nextSibling){ rlm@46: node.nextSibling.previousSibling = node.previousSibling; rlm@46: } rlm@46: rlm@46: rlm@46: if(this.firstChild == node){ rlm@46: this.setFirstChild(node.nextSibling); rlm@46: } rlm@46: if(this.lastChild == node){ rlm@46: this.setLastChild(node.previousSibling); rlm@46: } rlm@46: rlm@46: node.setOwnerTree(null); rlm@46: rlm@46: node.parentNode = null; rlm@46: node.previousSibling = null; rlm@46: node.nextSibling = null; rlm@46: this.fireEvent("remove", this.ownerTree, this, node); rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: insertBefore : function(node, refNode){ rlm@46: if(!refNode){ rlm@46: return this.appendChild(node); rlm@46: } rlm@46: rlm@46: if(node == refNode){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){ rlm@46: return false; rlm@46: } rlm@46: var index = this.childNodes.indexOf(refNode); rlm@46: var oldParent = node.parentNode; rlm@46: var refIndex = index; rlm@46: rlm@46: rlm@46: if(oldParent == this && this.childNodes.indexOf(node) < index){ rlm@46: refIndex--; rlm@46: } rlm@46: rlm@46: rlm@46: if(oldParent){ rlm@46: if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){ rlm@46: return false; rlm@46: } rlm@46: oldParent.removeChild(node); rlm@46: } rlm@46: if(refIndex == 0){ rlm@46: this.setFirstChild(node); rlm@46: } rlm@46: this.childNodes.splice(refIndex, 0, node); rlm@46: node.parentNode = this; rlm@46: var ps = this.childNodes[refIndex-1]; rlm@46: if(ps){ rlm@46: node.previousSibling = ps; rlm@46: ps.nextSibling = node; rlm@46: }else{ rlm@46: node.previousSibling = null; rlm@46: } rlm@46: node.nextSibling = refNode; rlm@46: refNode.previousSibling = node; rlm@46: node.setOwnerTree(this.getOwnerTree()); rlm@46: this.fireEvent("insert", this.ownerTree, this, node, refNode); rlm@46: if(oldParent){ rlm@46: node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode); rlm@46: } rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(){ rlm@46: this.parentNode.removeChild(this); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: item : function(index){ rlm@46: return this.childNodes[index]; rlm@46: }, rlm@46: rlm@46: rlm@46: replaceChild : function(newChild, oldChild){ rlm@46: this.insertBefore(newChild, oldChild); rlm@46: this.removeChild(oldChild); rlm@46: return oldChild; rlm@46: }, rlm@46: rlm@46: rlm@46: indexOf : function(child){ rlm@46: return this.childNodes.indexOf(child); rlm@46: }, rlm@46: rlm@46: rlm@46: getOwnerTree : function(){ rlm@46: rlm@46: if(!this.ownerTree){ rlm@46: var p = this; rlm@46: while(p){ rlm@46: if(p.ownerTree){ rlm@46: this.ownerTree = p.ownerTree; rlm@46: break; rlm@46: } rlm@46: p = p.parentNode; rlm@46: } rlm@46: } rlm@46: return this.ownerTree; rlm@46: }, rlm@46: rlm@46: rlm@46: getDepth : function(){ rlm@46: var depth = 0; rlm@46: var p = this; rlm@46: while(p.parentNode){ rlm@46: ++depth; rlm@46: p = p.parentNode; rlm@46: } rlm@46: return depth; rlm@46: }, rlm@46: rlm@46: rlm@46: setOwnerTree : function(tree){ rlm@46: rlm@46: if(tree != this.ownerTree){ rlm@46: if(this.ownerTree){ rlm@46: this.ownerTree.unregisterNode(this); rlm@46: } rlm@46: this.ownerTree = tree; rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: cs[i].setOwnerTree(tree); rlm@46: } rlm@46: if(tree){ rlm@46: tree.registerNode(this); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getPath : function(attr){ rlm@46: attr = attr || "id"; rlm@46: var p = this.parentNode; rlm@46: var b = [this.attributes[attr]]; rlm@46: while(p){ rlm@46: b.unshift(p.attributes[attr]); rlm@46: p = p.parentNode; rlm@46: } rlm@46: var sep = this.getOwnerTree().pathSeparator; rlm@46: return sep + b.join(sep); rlm@46: }, rlm@46: rlm@46: rlm@46: bubble : function(fn, scope, args){ rlm@46: var p = this; rlm@46: while(p){ rlm@46: if(fn.apply(scope || p, args || [p]) === false){ rlm@46: break; rlm@46: } rlm@46: p = p.parentNode; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: cascade : function(fn, scope, args){ rlm@46: if(fn.apply(scope || this, args || [this]) !== false){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: cs[i].cascade(fn, scope, args); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: eachChild : function(fn, scope, args){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: if(fn.apply(scope || this, args || [cs[i]]) === false){ rlm@46: break; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: findChild : function(attribute, value){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: if(cs[i].attributes[attribute] == value){ rlm@46: return cs[i]; rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: findChildBy : function(fn, scope){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: if(fn.call(scope||cs[i], cs[i]) === true){ rlm@46: return cs[i]; rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: sort : function(fn, scope){ rlm@46: var cs = this.childNodes; rlm@46: var len = cs.length; rlm@46: if(len > 0){ rlm@46: var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn; rlm@46: cs.sort(sortFn); rlm@46: for(var i = 0; i < len; i++){ rlm@46: var n = cs[i]; rlm@46: n.previousSibling = cs[i-1]; rlm@46: n.nextSibling = cs[i+1]; rlm@46: if(i == 0){ rlm@46: this.setFirstChild(n); rlm@46: } rlm@46: if(i == len-1){ rlm@46: this.setLastChild(n); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: contains : function(node){ rlm@46: return node.isAncestor(this); rlm@46: }, rlm@46: rlm@46: rlm@46: isAncestor : function(node){ rlm@46: var p = this.parentNode; rlm@46: while(p){ rlm@46: if(p == node){ rlm@46: return true; rlm@46: } rlm@46: p = p.parentNode; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: toString : function(){ rlm@46: return "[Node"+(this.id?" "+this.id:"")+"]"; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.data.GroupingStore = Ext.extend(Ext.data.Store, { rlm@46: rlm@46: rlm@46: remoteGroup : false, rlm@46: rlm@46: groupOnSort:false, rlm@46: rlm@46: rlm@46: clearGrouping : function(){ rlm@46: this.groupField = false; rlm@46: if(this.remoteGroup){ rlm@46: if(this.baseParams){ rlm@46: delete this.baseParams.groupBy; rlm@46: } rlm@46: this.reload(); rlm@46: }else{ rlm@46: this.applySort(); rlm@46: this.fireEvent('datachanged', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: groupBy : function(field, forceRegroup){ rlm@46: if(this.groupField == field && !forceRegroup){ rlm@46: return; rlm@46: } rlm@46: this.groupField = field; rlm@46: if(this.remoteGroup){ rlm@46: if(!this.baseParams){ rlm@46: this.baseParams = {}; rlm@46: } rlm@46: this.baseParams['groupBy'] = field; rlm@46: } rlm@46: if(this.groupOnSort){ rlm@46: this.sort(field); rlm@46: return; rlm@46: } rlm@46: if(this.remoteGroup){ rlm@46: this.reload(); rlm@46: }else{ rlm@46: var si = this.sortInfo || {}; rlm@46: if(si.field != field){ rlm@46: this.applySort(); rlm@46: }else{ rlm@46: this.sortData(field); rlm@46: } rlm@46: this.fireEvent('datachanged', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: applySort : function(){ rlm@46: Ext.data.GroupingStore.superclass.applySort.call(this); rlm@46: if(!this.groupOnSort && !this.remoteGroup){ rlm@46: var gs = this.getGroupState(); rlm@46: if(gs && gs != this.sortInfo.field){ rlm@46: this.sortData(this.groupField); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: applyGrouping : function(alwaysFireChange){ rlm@46: if(this.groupField !== false){ rlm@46: this.groupBy(this.groupField, true); rlm@46: return true; rlm@46: }else{ rlm@46: if(alwaysFireChange === true){ rlm@46: this.fireEvent('datachanged', this); rlm@46: } rlm@46: return false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getGroupState : function(){ rlm@46: return this.groupOnSort && this.groupField !== false ? rlm@46: (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.ComponentMgr = function(){ rlm@46: var all = new Ext.util.MixedCollection(); rlm@46: var types = {}; rlm@46: rlm@46: return { rlm@46: rlm@46: register : function(c){ rlm@46: all.add(c); rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(c){ rlm@46: all.remove(c); rlm@46: }, rlm@46: rlm@46: rlm@46: get : function(id){ rlm@46: return all.get(id); rlm@46: }, rlm@46: rlm@46: rlm@46: onAvailable : function(id, fn, scope){ rlm@46: all.on("add", function(index, o){ rlm@46: if(o.id == id){ rlm@46: fn.call(scope || o, o); rlm@46: all.un("add", fn, scope); rlm@46: } rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: all : all, rlm@46: rlm@46: rlm@46: registerType : function(xtype, cls){ rlm@46: types[xtype] = cls; rlm@46: cls.xtype = xtype; rlm@46: }, rlm@46: rlm@46: create : function(config, defaultType){ rlm@46: return new types[config.xtype || defaultType](config); rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down rlm@46: rlm@46: Ext.Component = function(config){ rlm@46: config = config || {}; rlm@46: if(config.initialConfig){ rlm@46: if(config.isAction){ this.baseAction = config; rlm@46: } rlm@46: config = config.initialConfig; }else if(config.tagName || config.dom || typeof config == "string"){ config = {applyTo: config, id: config.id || config}; rlm@46: } rlm@46: rlm@46: rlm@46: this.initialConfig = config; rlm@46: rlm@46: Ext.apply(this, config); rlm@46: this.addEvents( rlm@46: rlm@46: 'disable', rlm@46: rlm@46: 'enable', rlm@46: rlm@46: 'beforeshow', rlm@46: rlm@46: 'show', rlm@46: rlm@46: 'beforehide', rlm@46: rlm@46: 'hide', rlm@46: rlm@46: 'beforerender', rlm@46: rlm@46: 'render', rlm@46: rlm@46: 'beforedestroy', rlm@46: rlm@46: 'destroy', rlm@46: rlm@46: 'beforestaterestore', rlm@46: rlm@46: 'staterestore', rlm@46: rlm@46: 'beforestatesave', rlm@46: rlm@46: 'statesave' rlm@46: ); rlm@46: this.getId(); rlm@46: Ext.ComponentMgr.register(this); rlm@46: Ext.Component.superclass.constructor.call(this); rlm@46: rlm@46: if(this.baseAction){ rlm@46: this.baseAction.addComponent(this); rlm@46: } rlm@46: rlm@46: this.initComponent(); rlm@46: rlm@46: if(this.plugins){ rlm@46: if(Ext.isArray(this.plugins)){ rlm@46: for(var i = 0, len = this.plugins.length; i < len; i++){ rlm@46: this.plugins[i].init(this); rlm@46: } rlm@46: }else{ rlm@46: this.plugins.init(this); rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.stateful !== false){ rlm@46: this.initState(config); rlm@46: } rlm@46: rlm@46: if(this.applyTo){ rlm@46: this.applyToMarkup(this.applyTo); rlm@46: delete this.applyTo; rlm@46: }else if(this.renderTo){ rlm@46: this.render(this.renderTo); rlm@46: delete this.renderTo; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.Component.AUTO_ID = 1000; rlm@46: rlm@46: Ext.extend(Ext.Component, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: disabledClass : "x-item-disabled", rlm@46: rlm@46: allowDomMove : true, rlm@46: rlm@46: autoShow : false, rlm@46: rlm@46: hideMode: 'display', rlm@46: rlm@46: hideParent: false, rlm@46: rlm@46: rlm@46: rlm@46: hidden : false, rlm@46: rlm@46: disabled : false, rlm@46: rlm@46: rendered : false, rlm@46: rlm@46: ctype : "Ext.Component", rlm@46: rlm@46: actionMode : "el", rlm@46: rlm@46: getActionEl : function(){ rlm@46: return this[this.actionMode]; rlm@46: }, rlm@46: rlm@46: rlm@46: initComponent : Ext.emptyFn, rlm@46: rlm@46: rlm@46: render : function(container, position){ rlm@46: if(!this.rendered && this.fireEvent("beforerender", this) !== false){ rlm@46: if(!container && this.el){ rlm@46: this.el = Ext.get(this.el); rlm@46: container = this.el.dom.parentNode; rlm@46: this.allowDomMove = false; rlm@46: } rlm@46: this.container = Ext.get(container); rlm@46: if(this.ctCls){ rlm@46: this.container.addClass(this.ctCls); rlm@46: } rlm@46: this.rendered = true; rlm@46: if(position !== undefined){ rlm@46: if(typeof position == 'number'){ rlm@46: position = this.container.dom.childNodes[position]; rlm@46: }else{ rlm@46: position = Ext.getDom(position); rlm@46: } rlm@46: } rlm@46: this.onRender(this.container, position || null); rlm@46: if(this.autoShow){ rlm@46: this.el.removeClass(['x-hidden','x-hide-' + this.hideMode]); rlm@46: } rlm@46: if(this.cls){ rlm@46: this.el.addClass(this.cls); rlm@46: delete this.cls; rlm@46: } rlm@46: if(this.style){ rlm@46: this.el.applyStyles(this.style); rlm@46: delete this.style; rlm@46: } rlm@46: this.fireEvent("render", this); rlm@46: this.afterRender(this.container); rlm@46: if(this.hidden){ rlm@46: this.hide(); rlm@46: } rlm@46: if(this.disabled){ rlm@46: this.disable(); rlm@46: } rlm@46: rlm@46: this.initStateEvents(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: initState : function(config){ rlm@46: if(Ext.state.Manager){ rlm@46: var state = Ext.state.Manager.get(this.stateId || this.id); rlm@46: if(state){ rlm@46: if(this.fireEvent('beforestaterestore', this, state) !== false){ rlm@46: this.applyState(state); rlm@46: this.fireEvent('staterestore', this, state); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: initStateEvents : function(){ rlm@46: if(this.stateEvents){ rlm@46: for(var i = 0, e; e = this.stateEvents[i]; i++){ rlm@46: this.on(e, this.saveState, this, {delay:100}); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: applyState : function(state, config){ rlm@46: if(state){ rlm@46: Ext.apply(this, state); rlm@46: } rlm@46: }, rlm@46: rlm@46: getState : function(){ rlm@46: return null; rlm@46: }, rlm@46: rlm@46: saveState : function(){ rlm@46: if(Ext.state.Manager){ rlm@46: var state = this.getState(); rlm@46: if(this.fireEvent('beforestatesave', this, state) !== false){ rlm@46: Ext.state.Manager.set(this.stateId || this.id, state); rlm@46: this.fireEvent('statesave', this, state); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: applyToMarkup : function(el){ rlm@46: this.allowDomMove = false; rlm@46: this.el = Ext.get(el); rlm@46: this.render(this.el.dom.parentNode); rlm@46: }, rlm@46: rlm@46: rlm@46: addClass : function(cls){ rlm@46: if(this.el){ rlm@46: this.el.addClass(cls); rlm@46: }else{ rlm@46: this.cls = this.cls ? this.cls + ' ' + cls : cls; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: removeClass : function(cls){ rlm@46: if(this.el){ rlm@46: this.el.removeClass(cls); rlm@46: }else if(this.cls){ rlm@46: this.cls = this.cls.split(' ').remove(cls).join(' '); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: if(this.autoEl){ rlm@46: if(typeof this.autoEl == 'string'){ rlm@46: this.el = document.createElement(this.autoEl); rlm@46: }else{ rlm@46: var div = document.createElement('div'); rlm@46: Ext.DomHelper.overwrite(div, this.autoEl); rlm@46: this.el = div.firstChild; rlm@46: } rlm@46: if (!this.el.id) { rlm@46: this.el.id = this.getId(); rlm@46: } rlm@46: } rlm@46: if(this.el){ rlm@46: this.el = Ext.get(this.el); rlm@46: if(this.allowDomMove !== false){ rlm@46: ct.dom.insertBefore(this.el.dom, position); rlm@46: } rlm@46: if(this.overCls) { rlm@46: this.el.addClassOnOver(this.overCls); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: getAutoCreate : function(){ rlm@46: var cfg = typeof this.autoCreate == "object" ? rlm@46: this.autoCreate : Ext.apply({}, this.defaultAutoCreate); rlm@46: if(this.id && !cfg.id){ rlm@46: cfg.id = this.id; rlm@46: } rlm@46: return cfg; rlm@46: }, rlm@46: rlm@46: afterRender : Ext.emptyFn, rlm@46: rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.fireEvent("beforedestroy", this) !== false){ rlm@46: this.beforeDestroy(); rlm@46: if(this.rendered){ rlm@46: this.el.removeAllListeners(); rlm@46: this.el.remove(); rlm@46: if(this.actionMode == "container"){ rlm@46: this.container.remove(); rlm@46: } rlm@46: } rlm@46: this.onDestroy(); rlm@46: Ext.ComponentMgr.unregister(this); rlm@46: this.fireEvent("destroy", this); rlm@46: this.purgeListeners(); rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeDestroy : Ext.emptyFn, rlm@46: rlm@46: onDestroy : Ext.emptyFn, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: getId : function(){ rlm@46: return this.id || (this.id = "ext-comp-" + (++Ext.Component.AUTO_ID)); rlm@46: }, rlm@46: rlm@46: rlm@46: getItemId : function(){ rlm@46: return this.itemId || this.getId(); rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(selectText, delay){ rlm@46: if(delay){ rlm@46: this.focus.defer(typeof delay == 'number' ? delay : 10, this, [selectText, false]); rlm@46: return; rlm@46: } rlm@46: if(this.rendered){ rlm@46: this.el.focus(); rlm@46: if(selectText === true){ rlm@46: this.el.dom.select(); rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: blur : function(){ rlm@46: if(this.rendered){ rlm@46: this.el.blur(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: if(this.rendered){ rlm@46: this.onDisable(); rlm@46: } rlm@46: this.disabled = true; rlm@46: this.fireEvent("disable", this); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onDisable : function(){ rlm@46: this.getActionEl().addClass(this.disabledClass); rlm@46: this.el.dom.disabled = true; rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: if(this.rendered){ rlm@46: this.onEnable(); rlm@46: } rlm@46: this.disabled = false; rlm@46: this.fireEvent("enable", this); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onEnable : function(){ rlm@46: this.getActionEl().removeClass(this.disabledClass); rlm@46: this.el.dom.disabled = false; rlm@46: }, rlm@46: rlm@46: rlm@46: setDisabled : function(disabled){ rlm@46: this[disabled ? "disable" : "enable"](); rlm@46: }, rlm@46: rlm@46: rlm@46: show: function(){ rlm@46: if(this.fireEvent("beforeshow", this) !== false){ rlm@46: this.hidden = false; rlm@46: if(this.autoRender){ rlm@46: this.render(typeof this.autoRender == 'boolean' ? Ext.getBody() : this.autoRender); rlm@46: } rlm@46: if(this.rendered){ rlm@46: this.onShow(); rlm@46: } rlm@46: this.fireEvent("show", this); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onShow : function(){ rlm@46: if(this.hideParent){ rlm@46: this.container.removeClass('x-hide-' + this.hideMode); rlm@46: }else{ rlm@46: this.getActionEl().removeClass('x-hide-' + this.hideMode); rlm@46: } rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: hide: function(){ rlm@46: if(this.fireEvent("beforehide", this) !== false){ rlm@46: this.hidden = true; rlm@46: if(this.rendered){ rlm@46: this.onHide(); rlm@46: } rlm@46: this.fireEvent("hide", this); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: if(this.hideParent){ rlm@46: this.container.addClass('x-hide-' + this.hideMode); rlm@46: }else{ rlm@46: this.getActionEl().addClass('x-hide-' + this.hideMode); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setVisible: function(visible){ rlm@46: if(visible) { rlm@46: this.show(); rlm@46: }else{ rlm@46: this.hide(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(){ rlm@46: return this.rendered && this.getActionEl().isVisible(); rlm@46: }, rlm@46: rlm@46: rlm@46: cloneConfig : function(overrides){ rlm@46: overrides = overrides || {}; rlm@46: var id = overrides.id || Ext.id(); rlm@46: var cfg = Ext.applyIf(overrides, this.initialConfig); rlm@46: cfg.id = id; return new this.constructor(cfg); rlm@46: }, rlm@46: rlm@46: rlm@46: getXType : function(){ rlm@46: return this.constructor.xtype; rlm@46: }, rlm@46: rlm@46: rlm@46: isXType : function(xtype, shallow){ rlm@46: return !shallow ? rlm@46: ('/' + this.getXTypes() + '/').indexOf('/' + xtype + '/') != -1 : rlm@46: this.constructor.xtype == xtype; rlm@46: }, rlm@46: rlm@46: rlm@46: getXTypes : function(){ rlm@46: var tc = this.constructor; rlm@46: if(!tc.xtypes){ rlm@46: var c = [], sc = this; rlm@46: while(sc && sc.constructor.xtype){ rlm@46: c.unshift(sc.constructor.xtype); rlm@46: sc = sc.constructor.superclass; rlm@46: } rlm@46: tc.xtypeChain = c; rlm@46: tc.xtypes = c.join('/'); rlm@46: } rlm@46: return tc.xtypes; rlm@46: }, rlm@46: rlm@46: rlm@46: findParentBy: function(fn) { rlm@46: for (var p = this.ownerCt; (p != null) && !fn(p, this); p = p.ownerCt); rlm@46: return p || null; rlm@46: }, rlm@46: rlm@46: rlm@46: findParentByType: function(xtype) { rlm@46: return typeof xtype == 'function' ? rlm@46: this.findParentBy(function(p){ rlm@46: return p.constructor === xtype; rlm@46: }) : rlm@46: this.findParentBy(function(p){ rlm@46: return p.constructor.xtype === xtype; rlm@46: }); rlm@46: }, rlm@46: rlm@46: mon : function(item, ename, fn, scope, opt){ rlm@46: if(!this.mons){ rlm@46: this.mons = []; rlm@46: this.on('beforedestroy', function(){ rlm@46: for(var i= 0, len = this.mons.length; i < len; i++){ rlm@46: var m = this.mons[i]; rlm@46: m.item.un(m.ename, m.fn, m.scope); rlm@46: } rlm@46: }, this); rlm@46: } rlm@46: this.mons.push({ rlm@46: item: item, ename: ename, fn: fn, scope: scope rlm@46: }); rlm@46: item.on(ename, fn, scope, opt); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.reg('component', Ext.Component); rlm@46: rlm@46: rlm@46: Ext.Action = function(config){ rlm@46: this.initialConfig = config; rlm@46: this.items = []; rlm@46: } rlm@46: rlm@46: Ext.Action.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: isAction : true, rlm@46: rlm@46: rlm@46: setText : function(text){ rlm@46: this.initialConfig.text = text; rlm@46: this.callEach('setText', [text]); rlm@46: }, rlm@46: rlm@46: rlm@46: getText : function(){ rlm@46: return this.initialConfig.text; rlm@46: }, rlm@46: rlm@46: rlm@46: setIconClass : function(cls){ rlm@46: this.initialConfig.iconCls = cls; rlm@46: this.callEach('setIconClass', [cls]); rlm@46: }, rlm@46: rlm@46: rlm@46: getIconClass : function(){ rlm@46: return this.initialConfig.iconCls; rlm@46: }, rlm@46: rlm@46: rlm@46: setDisabled : function(v){ rlm@46: this.initialConfig.disabled = v; rlm@46: this.callEach('setDisabled', [v]); rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: this.setDisabled(false); rlm@46: }, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: this.setDisabled(true); rlm@46: }, rlm@46: rlm@46: rlm@46: isDisabled : function(){ rlm@46: return this.initialConfig.disabled; rlm@46: }, rlm@46: rlm@46: rlm@46: setHidden : function(v){ rlm@46: this.initialConfig.hidden = v; rlm@46: this.callEach('setVisible', [!v]); rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(){ rlm@46: this.setHidden(false); rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(){ rlm@46: this.setHidden(true); rlm@46: }, rlm@46: rlm@46: rlm@46: isHidden : function(){ rlm@46: return this.initialConfig.hidden; rlm@46: }, rlm@46: rlm@46: rlm@46: setHandler : function(fn, scope){ rlm@46: this.initialConfig.handler = fn; rlm@46: this.initialConfig.scope = scope; rlm@46: this.callEach('setHandler', [fn, scope]); rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: Ext.each(this.items, fn, scope); rlm@46: }, rlm@46: rlm@46: rlm@46: callEach : function(fnName, args){ rlm@46: var cs = this.items; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: cs[i][fnName].apply(cs[i], args); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: addComponent : function(comp){ rlm@46: this.items.push(comp); rlm@46: comp.on('destroy', this.removeComponent, this); rlm@46: }, rlm@46: rlm@46: rlm@46: removeComponent : function(comp){ rlm@46: this.items.remove(comp); rlm@46: }, rlm@46: rlm@46: rlm@46: execute : function(){ rlm@46: this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments); rlm@46: } rlm@46: }; rlm@46: rlm@46: (function(){ rlm@46: Ext.Layer = function(config, existingEl){ rlm@46: config = config || {}; rlm@46: var dh = Ext.DomHelper; rlm@46: var cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body; rlm@46: if(existingEl){ rlm@46: this.dom = Ext.getDom(existingEl); rlm@46: } rlm@46: if(!this.dom){ rlm@46: var o = config.dh || {tag: "div", cls: "x-layer"}; rlm@46: this.dom = dh.append(pel, o); rlm@46: } rlm@46: if(config.cls){ rlm@46: this.addClass(config.cls); rlm@46: } rlm@46: this.constrain = config.constrain !== false; rlm@46: this.visibilityMode = Ext.Element.VISIBILITY; rlm@46: if(config.id){ rlm@46: this.id = this.dom.id = config.id; rlm@46: }else{ rlm@46: this.id = Ext.id(this.dom); rlm@46: } rlm@46: this.zindex = config.zindex || this.getZIndex(); rlm@46: this.position("absolute", this.zindex); rlm@46: if(config.shadow){ rlm@46: this.shadowOffset = config.shadowOffset || 4; rlm@46: this.shadow = new Ext.Shadow({ rlm@46: offset : this.shadowOffset, rlm@46: mode : config.shadow rlm@46: }); rlm@46: }else{ rlm@46: this.shadowOffset = 0; rlm@46: } rlm@46: this.useShim = config.shim !== false && Ext.useShims; rlm@46: this.useDisplay = config.useDisplay; rlm@46: this.hide(); rlm@46: }; rlm@46: rlm@46: var supr = Ext.Element.prototype; rlm@46: rlm@46: rlm@46: var shims = []; rlm@46: rlm@46: Ext.extend(Ext.Layer, Ext.Element, { rlm@46: rlm@46: getZIndex : function(){ rlm@46: return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000; rlm@46: }, rlm@46: rlm@46: getShim : function(){ rlm@46: if(!this.useShim){ rlm@46: return null; rlm@46: } rlm@46: if(this.shim){ rlm@46: return this.shim; rlm@46: } rlm@46: var shim = shims.shift(); rlm@46: if(!shim){ rlm@46: shim = this.createShim(); rlm@46: shim.enableDisplayMode('block'); rlm@46: shim.dom.style.display = 'none'; rlm@46: shim.dom.style.visibility = 'visible'; rlm@46: } rlm@46: var pn = this.dom.parentNode; rlm@46: if(shim.dom.parentNode != pn){ rlm@46: pn.insertBefore(shim.dom, this.dom); rlm@46: } rlm@46: shim.setStyle('z-index', this.getZIndex()-2); rlm@46: this.shim = shim; rlm@46: return shim; rlm@46: }, rlm@46: rlm@46: hideShim : function(){ rlm@46: if(this.shim){ rlm@46: this.shim.setDisplayed(false); rlm@46: shims.push(this.shim); rlm@46: delete this.shim; rlm@46: } rlm@46: }, rlm@46: rlm@46: disableShadow : function(){ rlm@46: if(this.shadow){ rlm@46: this.shadowDisabled = true; rlm@46: this.shadow.hide(); rlm@46: this.lastShadowOffset = this.shadowOffset; rlm@46: this.shadowOffset = 0; rlm@46: } rlm@46: }, rlm@46: rlm@46: enableShadow : function(show){ rlm@46: if(this.shadow){ rlm@46: this.shadowDisabled = false; rlm@46: this.shadowOffset = this.lastShadowOffset; rlm@46: delete this.lastShadowOffset; rlm@46: if(show){ rlm@46: this.sync(true); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: sync : function(doShow){ rlm@46: var sw = this.shadow; rlm@46: if(!this.updating && this.isVisible() && (sw || this.useShim)){ rlm@46: var sh = this.getShim(); rlm@46: rlm@46: var w = this.getWidth(), rlm@46: h = this.getHeight(); rlm@46: rlm@46: var l = this.getLeft(true), rlm@46: t = this.getTop(true); rlm@46: rlm@46: if(sw && !this.shadowDisabled){ rlm@46: if(doShow && !sw.isVisible()){ rlm@46: sw.show(this); rlm@46: }else{ rlm@46: sw.realign(l, t, w, h); rlm@46: } rlm@46: if(sh){ rlm@46: if(doShow){ rlm@46: sh.show(); rlm@46: } rlm@46: rlm@46: var a = sw.adjusts, s = sh.dom.style; rlm@46: s.left = (Math.min(l, l+a.l))+"px"; rlm@46: s.top = (Math.min(t, t+a.t))+"px"; rlm@46: s.width = (w+a.w)+"px"; rlm@46: s.height = (h+a.h)+"px"; rlm@46: } rlm@46: }else if(sh){ rlm@46: if(doShow){ rlm@46: sh.show(); rlm@46: } rlm@46: sh.setSize(w, h); rlm@46: sh.setLeftTop(l, t); rlm@46: } rlm@46: rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: destroy : function(){ rlm@46: this.hideShim(); rlm@46: if(this.shadow){ rlm@46: this.shadow.hide(); rlm@46: } rlm@46: this.removeAllListeners(); rlm@46: Ext.removeNode(this.dom); rlm@46: Ext.Element.uncache(this.id); rlm@46: }, rlm@46: rlm@46: remove : function(){ rlm@46: this.destroy(); rlm@46: }, rlm@46: rlm@46: rlm@46: beginUpdate : function(){ rlm@46: this.updating = true; rlm@46: }, rlm@46: rlm@46: rlm@46: endUpdate : function(){ rlm@46: this.updating = false; rlm@46: this.sync(true); rlm@46: }, rlm@46: rlm@46: rlm@46: hideUnders : function(negOffset){ rlm@46: if(this.shadow){ rlm@46: this.shadow.hide(); rlm@46: } rlm@46: this.hideShim(); rlm@46: }, rlm@46: rlm@46: rlm@46: constrainXY : function(){ rlm@46: if(this.constrain){ rlm@46: var vw = Ext.lib.Dom.getViewWidth(), rlm@46: vh = Ext.lib.Dom.getViewHeight(); rlm@46: var s = Ext.getDoc().getScroll(); rlm@46: rlm@46: var xy = this.getXY(); rlm@46: var x = xy[0], y = xy[1]; rlm@46: var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset; rlm@46: rlm@46: var moved = false; rlm@46: rlm@46: if((x + w) > vw+s.left){ rlm@46: x = vw - w - this.shadowOffset; rlm@46: moved = true; rlm@46: } rlm@46: if((y + h) > vh+s.top){ rlm@46: y = vh - h - this.shadowOffset; rlm@46: moved = true; rlm@46: } rlm@46: rlm@46: if(x < s.left){ rlm@46: x = s.left; rlm@46: moved = true; rlm@46: } rlm@46: if(y < s.top){ rlm@46: y = s.top; rlm@46: moved = true; rlm@46: } rlm@46: if(moved){ rlm@46: if(this.avoidY){ rlm@46: var ay = this.avoidY; rlm@46: if(y <= ay && (y+h) >= ay){ rlm@46: y = ay-h-5; rlm@46: } rlm@46: } rlm@46: xy = [x, y]; rlm@46: this.storeXY(xy); rlm@46: supr.setXY.call(this, xy); rlm@46: this.sync(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: isVisible : function(){ rlm@46: return this.visible; rlm@46: }, rlm@46: rlm@46: rlm@46: showAction : function(){ rlm@46: this.visible = true; rlm@46: if(this.useDisplay === true){ rlm@46: this.setDisplayed(""); rlm@46: }else if(this.lastXY){ rlm@46: supr.setXY.call(this, this.lastXY); rlm@46: }else if(this.lastLT){ rlm@46: supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hideAction : function(){ rlm@46: this.visible = false; rlm@46: if(this.useDisplay === true){ rlm@46: this.setDisplayed(false); rlm@46: }else{ rlm@46: this.setLeftTop(-10000,-10000); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setVisible : function(v, a, d, c, e){ rlm@46: if(v){ rlm@46: this.showAction(); rlm@46: } rlm@46: if(a && v){ rlm@46: var cb = function(){ rlm@46: this.sync(true); rlm@46: if(c){ rlm@46: c(); rlm@46: } rlm@46: }.createDelegate(this); rlm@46: supr.setVisible.call(this, true, true, d, cb, e); rlm@46: }else{ rlm@46: if(!v){ rlm@46: this.hideUnders(true); rlm@46: } rlm@46: var cb = c; rlm@46: if(a){ rlm@46: cb = function(){ rlm@46: this.hideAction(); rlm@46: if(c){ rlm@46: c(); rlm@46: } rlm@46: }.createDelegate(this); rlm@46: } rlm@46: supr.setVisible.call(this, v, a, d, cb, e); rlm@46: if(v){ rlm@46: this.sync(true); rlm@46: }else if(!a){ rlm@46: this.hideAction(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: storeXY : function(xy){ rlm@46: delete this.lastLT; rlm@46: this.lastXY = xy; rlm@46: }, rlm@46: rlm@46: storeLeftTop : function(left, top){ rlm@46: delete this.lastXY; rlm@46: this.lastLT = [left, top]; rlm@46: }, rlm@46: rlm@46: rlm@46: beforeFx : function(){ rlm@46: this.beforeAction(); rlm@46: return Ext.Layer.superclass.beforeFx.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: afterFx : function(){ rlm@46: Ext.Layer.superclass.afterFx.apply(this, arguments); rlm@46: this.sync(this.isVisible()); rlm@46: }, rlm@46: rlm@46: rlm@46: beforeAction : function(){ rlm@46: if(!this.updating && this.shadow){ rlm@46: this.shadow.hide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setLeft : function(left){ rlm@46: this.storeLeftTop(left, this.getTop(true)); rlm@46: supr.setLeft.apply(this, arguments); rlm@46: this.sync(); rlm@46: }, rlm@46: rlm@46: setTop : function(top){ rlm@46: this.storeLeftTop(this.getLeft(true), top); rlm@46: supr.setTop.apply(this, arguments); rlm@46: this.sync(); rlm@46: }, rlm@46: rlm@46: setLeftTop : function(left, top){ rlm@46: this.storeLeftTop(left, top); rlm@46: supr.setLeftTop.apply(this, arguments); rlm@46: this.sync(); rlm@46: }, rlm@46: rlm@46: setXY : function(xy, a, d, c, e){ rlm@46: this.fixDisplay(); rlm@46: this.beforeAction(); rlm@46: this.storeXY(xy); rlm@46: var cb = this.createCB(c); rlm@46: supr.setXY.call(this, xy, a, d, cb, e); rlm@46: if(!a){ rlm@46: cb(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: createCB : function(c){ rlm@46: var el = this; rlm@46: return function(){ rlm@46: el.constrainXY(); rlm@46: el.sync(true); rlm@46: if(c){ rlm@46: c(); rlm@46: } rlm@46: }; rlm@46: }, rlm@46: rlm@46: rlm@46: setX : function(x, a, d, c, e){ rlm@46: this.setXY([x, this.getY()], a, d, c, e); rlm@46: }, rlm@46: rlm@46: rlm@46: setY : function(y, a, d, c, e){ rlm@46: this.setXY([this.getX(), y], a, d, c, e); rlm@46: }, rlm@46: rlm@46: rlm@46: setSize : function(w, h, a, d, c, e){ rlm@46: this.beforeAction(); rlm@46: var cb = this.createCB(c); rlm@46: supr.setSize.call(this, w, h, a, d, cb, e); rlm@46: if(!a){ rlm@46: cb(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setWidth : function(w, a, d, c, e){ rlm@46: this.beforeAction(); rlm@46: var cb = this.createCB(c); rlm@46: supr.setWidth.call(this, w, a, d, cb, e); rlm@46: if(!a){ rlm@46: cb(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setHeight : function(h, a, d, c, e){ rlm@46: this.beforeAction(); rlm@46: var cb = this.createCB(c); rlm@46: supr.setHeight.call(this, h, a, d, cb, e); rlm@46: if(!a){ rlm@46: cb(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setBounds : function(x, y, w, h, a, d, c, e){ rlm@46: this.beforeAction(); rlm@46: var cb = this.createCB(c); rlm@46: if(!a){ rlm@46: this.storeXY([x, y]); rlm@46: supr.setXY.call(this, [x, y]); rlm@46: supr.setSize.call(this, w, h, a, d, cb, e); rlm@46: cb(); rlm@46: }else{ rlm@46: supr.setBounds.call(this, x, y, w, h, a, d, cb, e); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setZIndex : function(zindex){ rlm@46: this.zindex = zindex; rlm@46: this.setStyle("z-index", zindex + 2); rlm@46: if(this.shadow){ rlm@46: this.shadow.setZIndex(zindex + 1); rlm@46: } rlm@46: if(this.shim){ rlm@46: this.shim.setStyle("z-index", zindex); rlm@46: } rlm@46: } rlm@46: }); rlm@46: })(); rlm@46: rlm@46: Ext.Shadow = function(config){ rlm@46: Ext.apply(this, config); rlm@46: if(typeof this.mode != "string"){ rlm@46: this.mode = this.defaultMode; rlm@46: } rlm@46: var o = this.offset, a = {h: 0}; rlm@46: var rad = Math.floor(this.offset/2); rlm@46: switch(this.mode.toLowerCase()){ case "drop": rlm@46: a.w = 0; rlm@46: a.l = a.t = o; rlm@46: a.t -= 1; rlm@46: if(Ext.isIE){ rlm@46: a.l -= this.offset + rad; rlm@46: a.t -= this.offset + rad; rlm@46: a.w -= rad; rlm@46: a.h -= rad; rlm@46: a.t += 1; rlm@46: } rlm@46: break; rlm@46: case "sides": rlm@46: a.w = (o*2); rlm@46: a.l = -o; rlm@46: a.t = o-1; rlm@46: if(Ext.isIE){ rlm@46: a.l -= (this.offset - rad); rlm@46: a.t -= this.offset + rad; rlm@46: a.l += 1; rlm@46: a.w -= (this.offset - rad)*2; rlm@46: a.w -= rad + 1; rlm@46: a.h -= 1; rlm@46: } rlm@46: break; rlm@46: case "frame": rlm@46: a.w = a.h = (o*2); rlm@46: a.l = a.t = -o; rlm@46: a.t += 1; rlm@46: a.h -= 2; rlm@46: if(Ext.isIE){ rlm@46: a.l -= (this.offset - rad); rlm@46: a.t -= (this.offset - rad); rlm@46: a.l += 1; rlm@46: a.w -= (this.offset + rad + 1); rlm@46: a.h -= (this.offset + rad); rlm@46: a.h += 1; rlm@46: } rlm@46: break; rlm@46: }; rlm@46: rlm@46: this.adjusts = a; rlm@46: }; rlm@46: rlm@46: Ext.Shadow.prototype = { rlm@46: rlm@46: rlm@46: offset: 4, rlm@46: rlm@46: defaultMode: "drop", rlm@46: rlm@46: rlm@46: show : function(target){ rlm@46: target = Ext.get(target); rlm@46: if(!this.el){ rlm@46: this.el = Ext.Shadow.Pool.pull(); rlm@46: if(this.el.dom.nextSibling != target.dom){ rlm@46: this.el.insertBefore(target); rlm@46: } rlm@46: } rlm@46: this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1); rlm@46: if(Ext.isIE){ rlm@46: this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")"; rlm@46: } rlm@46: this.realign( rlm@46: target.getLeft(true), rlm@46: target.getTop(true), rlm@46: target.getWidth(), rlm@46: target.getHeight() rlm@46: ); rlm@46: this.el.dom.style.display = "block"; rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(){ rlm@46: return this.el ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: realign : function(l, t, w, h){ rlm@46: if(!this.el){ rlm@46: return; rlm@46: } rlm@46: var a = this.adjusts, d = this.el.dom, s = d.style; rlm@46: var iea = 0; rlm@46: s.left = (l+a.l)+"px"; rlm@46: s.top = (t+a.t)+"px"; rlm@46: var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px"; rlm@46: if(s.width != sws || s.height != shs){ rlm@46: s.width = sws; rlm@46: s.height = shs; rlm@46: if(!Ext.isIE){ rlm@46: var cn = d.childNodes; rlm@46: var sww = Math.max(0, (sw-12))+"px"; rlm@46: cn[0].childNodes[1].style.width = sww; rlm@46: cn[1].childNodes[1].style.width = sww; rlm@46: cn[2].childNodes[1].style.width = sww; rlm@46: cn[1].style.height = Math.max(0, (sh-12))+"px"; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(){ rlm@46: if(this.el){ rlm@46: this.el.dom.style.display = "none"; rlm@46: Ext.Shadow.Pool.push(this.el); rlm@46: delete this.el; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setZIndex : function(z){ rlm@46: this.zIndex = z; rlm@46: if(this.el){ rlm@46: this.el.setStyle("z-index", z); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.Shadow.Pool = function(){ rlm@46: var p = []; rlm@46: var markup = Ext.isIE ? rlm@46: '
' : rlm@46: '
'; rlm@46: return { rlm@46: pull : function(){ rlm@46: var sh = p.shift(); rlm@46: if(!sh){ rlm@46: sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup)); rlm@46: sh.autoBoxAdjust = false; rlm@46: } rlm@46: return sh; rlm@46: }, rlm@46: rlm@46: push : function(sh){ rlm@46: p.push(sh); rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.BoxComponent = Ext.extend(Ext.Component, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.BoxComponent.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'resize', rlm@46: rlm@46: 'move' rlm@46: ); rlm@46: }, rlm@46: rlm@46: boxReady : false, rlm@46: deferHeight: false, rlm@46: rlm@46: rlm@46: setSize : function(w, h){ rlm@46: if(typeof w == 'object'){ rlm@46: h = w.height; rlm@46: w = w.width; rlm@46: } rlm@46: if(!this.boxReady){ rlm@46: this.width = w; rlm@46: this.height = h; rlm@46: return this; rlm@46: } rlm@46: rlm@46: if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){ rlm@46: return this; rlm@46: } rlm@46: this.lastSize = {width: w, height: h}; rlm@46: var adj = this.adjustSize(w, h); rlm@46: var aw = adj.width, ah = adj.height; rlm@46: if(aw !== undefined || ah !== undefined){ var rz = this.getResizeEl(); rlm@46: if(!this.deferHeight && aw !== undefined && ah !== undefined){ rlm@46: rz.setSize(aw, ah); rlm@46: }else if(!this.deferHeight && ah !== undefined){ rlm@46: rz.setHeight(ah); rlm@46: }else if(aw !== undefined){ rlm@46: rz.setWidth(aw); rlm@46: } rlm@46: this.onResize(aw, ah, w, h); rlm@46: this.fireEvent('resize', this, aw, ah, w, h); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setWidth : function(width){ rlm@46: return this.setSize(width); rlm@46: }, rlm@46: rlm@46: rlm@46: setHeight : function(height){ rlm@46: return this.setSize(undefined, height); rlm@46: }, rlm@46: rlm@46: rlm@46: getSize : function(){ rlm@46: return this.el.getSize(); rlm@46: }, rlm@46: rlm@46: rlm@46: getPosition : function(local){ rlm@46: if(local === true){ rlm@46: return [this.el.getLeft(true), this.el.getTop(true)]; rlm@46: } rlm@46: return this.xy || this.el.getXY(); rlm@46: }, rlm@46: rlm@46: rlm@46: getBox : function(local){ rlm@46: var s = this.el.getSize(); rlm@46: if(local === true){ rlm@46: s.x = this.el.getLeft(true); rlm@46: s.y = this.el.getTop(true); rlm@46: }else{ rlm@46: var xy = this.xy || this.el.getXY(); rlm@46: s.x = xy[0]; rlm@46: s.y = xy[1]; rlm@46: } rlm@46: return s; rlm@46: }, rlm@46: rlm@46: rlm@46: updateBox : function(box){ rlm@46: this.setSize(box.width, box.height); rlm@46: this.setPagePosition(box.x, box.y); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: getResizeEl : function(){ rlm@46: return this.resizeEl || this.el; rlm@46: }, rlm@46: rlm@46: getPositionEl : function(){ rlm@46: return this.positionEl || this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: setPosition : function(x, y){ rlm@46: if(x && typeof x[1] == 'number'){ rlm@46: y = x[1]; rlm@46: x = x[0]; rlm@46: } rlm@46: this.x = x; rlm@46: this.y = y; rlm@46: if(!this.boxReady){ rlm@46: return this; rlm@46: } rlm@46: var adj = this.adjustPosition(x, y); rlm@46: var ax = adj.x, ay = adj.y; rlm@46: rlm@46: var el = this.getPositionEl(); rlm@46: if(ax !== undefined || ay !== undefined){ rlm@46: if(ax !== undefined && ay !== undefined){ rlm@46: el.setLeftTop(ax, ay); rlm@46: }else if(ax !== undefined){ rlm@46: el.setLeft(ax); rlm@46: }else if(ay !== undefined){ rlm@46: el.setTop(ay); rlm@46: } rlm@46: this.onPosition(ax, ay); rlm@46: this.fireEvent('move', this, ax, ay); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setPagePosition : function(x, y){ rlm@46: if(x && typeof x[1] == 'number'){ rlm@46: y = x[1]; rlm@46: x = x[0]; rlm@46: } rlm@46: this.pageX = x; rlm@46: this.pageY = y; rlm@46: if(!this.boxReady){ rlm@46: return; rlm@46: } rlm@46: if(x === undefined || y === undefined){ return; rlm@46: } rlm@46: var p = this.el.translatePoints(x, y); rlm@46: this.setPosition(p.left, p.top); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.BoxComponent.superclass.onRender.call(this, ct, position); rlm@46: if(this.resizeEl){ rlm@46: this.resizeEl = Ext.get(this.resizeEl); rlm@46: } rlm@46: if(this.positionEl){ rlm@46: this.positionEl = Ext.get(this.positionEl); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.BoxComponent.superclass.afterRender.call(this); rlm@46: this.boxReady = true; rlm@46: this.setSize(this.width, this.height); rlm@46: if(this.x || this.y){ rlm@46: this.setPosition(this.x, this.y); rlm@46: }else if(this.pageX || this.pageY){ rlm@46: this.setPagePosition(this.pageX, this.pageY); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: syncSize : function(){ rlm@46: delete this.lastSize; rlm@46: this.setSize(this.autoWidth ? undefined : this.el.getWidth(), this.autoHeight ? undefined : this.el.getHeight()); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){ rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: onPosition : function(x, y){ rlm@46: rlm@46: }, rlm@46: rlm@46: adjustSize : function(w, h){ rlm@46: if(this.autoWidth){ rlm@46: w = 'auto'; rlm@46: } rlm@46: if(this.autoHeight){ rlm@46: h = 'auto'; rlm@46: } rlm@46: return {width : w, height: h}; rlm@46: }, rlm@46: rlm@46: adjustPosition : function(x, y){ rlm@46: return {x : x, y: y}; rlm@46: } rlm@46: }); rlm@46: Ext.reg('box', Ext.BoxComponent); rlm@46: rlm@46: Ext.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){ rlm@46: rlm@46: rlm@46: this.el = Ext.get(dragElement, true); rlm@46: this.el.dom.unselectable = "on"; rlm@46: rlm@46: this.resizingEl = Ext.get(resizingElement, true); rlm@46: rlm@46: rlm@46: this.orientation = orientation || Ext.SplitBar.HORIZONTAL; rlm@46: rlm@46: rlm@46: this.minSize = 0; rlm@46: rlm@46: rlm@46: this.maxSize = 2000; rlm@46: rlm@46: rlm@46: this.animate = false; rlm@46: rlm@46: rlm@46: this.useShim = false; rlm@46: rlm@46: rlm@46: this.shim = null; rlm@46: rlm@46: if(!existingProxy){ rlm@46: rlm@46: this.proxy = Ext.SplitBar.createProxy(this.orientation); rlm@46: }else{ rlm@46: this.proxy = Ext.get(existingProxy).dom; rlm@46: } rlm@46: rlm@46: this.dd = new Ext.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id}); rlm@46: rlm@46: rlm@46: this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this); rlm@46: rlm@46: rlm@46: this.dd.endDrag = this.onEndProxyDrag.createDelegate(this); rlm@46: rlm@46: rlm@46: this.dragSpecs = {}; rlm@46: rlm@46: rlm@46: this.adapter = new Ext.SplitBar.BasicLayoutAdapter(); rlm@46: this.adapter.init(this); rlm@46: rlm@46: if(this.orientation == Ext.SplitBar.HORIZONTAL){ rlm@46: rlm@46: this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Ext.SplitBar.LEFT : Ext.SplitBar.RIGHT); rlm@46: this.el.addClass("x-splitbar-h"); rlm@46: }else{ rlm@46: rlm@46: this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Ext.SplitBar.TOP : Ext.SplitBar.BOTTOM); rlm@46: this.el.addClass("x-splitbar-v"); rlm@46: } rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "resize", rlm@46: rlm@46: "moved", rlm@46: rlm@46: "beforeresize", rlm@46: rlm@46: "beforeapply" rlm@46: ); rlm@46: rlm@46: Ext.SplitBar.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.SplitBar, Ext.util.Observable, { rlm@46: onStartProxyDrag : function(x, y){ rlm@46: this.fireEvent("beforeresize", this); rlm@46: this.overlay = Ext.DomHelper.append(document.body, {cls: "x-drag-overlay", html: " "}, true); rlm@46: this.overlay.unselectable(); rlm@46: this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true)); rlm@46: this.overlay.show(); rlm@46: Ext.get(this.proxy).setDisplayed("block"); rlm@46: var size = this.adapter.getElementSize(this); rlm@46: this.activeMinSize = this.getMinimumSize();; rlm@46: this.activeMaxSize = this.getMaximumSize();; rlm@46: var c1 = size - this.activeMinSize; rlm@46: var c2 = Math.max(this.activeMaxSize - size, 0); rlm@46: if(this.orientation == Ext.SplitBar.HORIZONTAL){ rlm@46: this.dd.resetConstraints(); rlm@46: this.dd.setXConstraint( rlm@46: this.placement == Ext.SplitBar.LEFT ? c1 : c2, rlm@46: this.placement == Ext.SplitBar.LEFT ? c2 : c1 rlm@46: ); rlm@46: this.dd.setYConstraint(0, 0); rlm@46: }else{ rlm@46: this.dd.resetConstraints(); rlm@46: this.dd.setXConstraint(0, 0); rlm@46: this.dd.setYConstraint( rlm@46: this.placement == Ext.SplitBar.TOP ? c1 : c2, rlm@46: this.placement == Ext.SplitBar.TOP ? c2 : c1 rlm@46: ); rlm@46: } rlm@46: this.dragSpecs.startSize = size; rlm@46: this.dragSpecs.startPoint = [x, y]; rlm@46: Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: onEndProxyDrag : function(e){ rlm@46: Ext.get(this.proxy).setDisplayed(false); rlm@46: var endPoint = Ext.lib.Event.getXY(e); rlm@46: if(this.overlay){ rlm@46: this.overlay.remove(); rlm@46: delete this.overlay; rlm@46: } rlm@46: var newSize; rlm@46: if(this.orientation == Ext.SplitBar.HORIZONTAL){ rlm@46: newSize = this.dragSpecs.startSize + rlm@46: (this.placement == Ext.SplitBar.LEFT ? rlm@46: endPoint[0] - this.dragSpecs.startPoint[0] : rlm@46: this.dragSpecs.startPoint[0] - endPoint[0] rlm@46: ); rlm@46: }else{ rlm@46: newSize = this.dragSpecs.startSize + rlm@46: (this.placement == Ext.SplitBar.TOP ? rlm@46: endPoint[1] - this.dragSpecs.startPoint[1] : rlm@46: this.dragSpecs.startPoint[1] - endPoint[1] rlm@46: ); rlm@46: } rlm@46: newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize); rlm@46: if(newSize != this.dragSpecs.startSize){ rlm@46: if(this.fireEvent('beforeapply', this, newSize) !== false){ rlm@46: this.adapter.setElementSize(this, newSize); rlm@46: this.fireEvent("moved", this, newSize); rlm@46: this.fireEvent("resize", this, newSize); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getAdapter : function(){ rlm@46: return this.adapter; rlm@46: }, rlm@46: rlm@46: rlm@46: setAdapter : function(adapter){ rlm@46: this.adapter = adapter; rlm@46: this.adapter.init(this); rlm@46: }, rlm@46: rlm@46: rlm@46: getMinimumSize : function(){ rlm@46: return this.minSize; rlm@46: }, rlm@46: rlm@46: rlm@46: setMinimumSize : function(minSize){ rlm@46: this.minSize = minSize; rlm@46: }, rlm@46: rlm@46: rlm@46: getMaximumSize : function(){ rlm@46: return this.maxSize; rlm@46: }, rlm@46: rlm@46: rlm@46: setMaximumSize : function(maxSize){ rlm@46: this.maxSize = maxSize; rlm@46: }, rlm@46: rlm@46: rlm@46: setCurrentSize : function(size){ rlm@46: var oldAnimate = this.animate; rlm@46: this.animate = false; rlm@46: this.adapter.setElementSize(this, size); rlm@46: this.animate = oldAnimate; rlm@46: }, rlm@46: rlm@46: rlm@46: destroy : function(removeEl){ rlm@46: if(this.shim){ rlm@46: this.shim.remove(); rlm@46: } rlm@46: this.dd.unreg(); rlm@46: Ext.removeNode(this.proxy); rlm@46: if(removeEl){ rlm@46: this.el.remove(); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.SplitBar.createProxy = function(dir){ rlm@46: var proxy = new Ext.Element(document.createElement("div")); rlm@46: proxy.unselectable(); rlm@46: var cls = 'x-splitbar-proxy'; rlm@46: proxy.addClass(cls + ' ' + (dir == Ext.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v')); rlm@46: document.body.appendChild(proxy.dom); rlm@46: return proxy.dom; rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.SplitBar.BasicLayoutAdapter = function(){ rlm@46: }; rlm@46: rlm@46: Ext.SplitBar.BasicLayoutAdapter.prototype = { rlm@46: rlm@46: init : function(s){ rlm@46: rlm@46: }, rlm@46: rlm@46: getElementSize : function(s){ rlm@46: if(s.orientation == Ext.SplitBar.HORIZONTAL){ rlm@46: return s.resizingEl.getWidth(); rlm@46: }else{ rlm@46: return s.resizingEl.getHeight(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setElementSize : function(s, newSize, onComplete){ rlm@46: if(s.orientation == Ext.SplitBar.HORIZONTAL){ rlm@46: if(!s.animate){ rlm@46: s.resizingEl.setWidth(newSize); rlm@46: if(onComplete){ rlm@46: onComplete(s, newSize); rlm@46: } rlm@46: }else{ rlm@46: s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut'); rlm@46: } rlm@46: }else{ rlm@46: rlm@46: if(!s.animate){ rlm@46: s.resizingEl.setHeight(newSize); rlm@46: if(onComplete){ rlm@46: onComplete(s, newSize); rlm@46: } rlm@46: }else{ rlm@46: s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut'); rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.SplitBar.AbsoluteLayoutAdapter = function(container){ rlm@46: this.basic = new Ext.SplitBar.BasicLayoutAdapter(); rlm@46: this.container = Ext.get(container); rlm@46: }; rlm@46: rlm@46: Ext.SplitBar.AbsoluteLayoutAdapter.prototype = { rlm@46: init : function(s){ rlm@46: this.basic.init(s); rlm@46: }, rlm@46: rlm@46: getElementSize : function(s){ rlm@46: return this.basic.getElementSize(s); rlm@46: }, rlm@46: rlm@46: setElementSize : function(s, newSize, onComplete){ rlm@46: this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s])); rlm@46: }, rlm@46: rlm@46: moveSplitter : function(s){ rlm@46: var yes = Ext.SplitBar; rlm@46: switch(s.placement){ rlm@46: case yes.LEFT: rlm@46: s.el.setX(s.resizingEl.getRight()); rlm@46: break; rlm@46: case yes.RIGHT: rlm@46: s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px"); rlm@46: break; rlm@46: case yes.TOP: rlm@46: s.el.setY(s.resizingEl.getBottom()); rlm@46: break; rlm@46: case yes.BOTTOM: rlm@46: s.el.setY(s.resizingEl.getTop() - s.el.getHeight()); rlm@46: break; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.SplitBar.VERTICAL = 1; rlm@46: rlm@46: rlm@46: Ext.SplitBar.HORIZONTAL = 2; rlm@46: rlm@46: rlm@46: Ext.SplitBar.LEFT = 1; rlm@46: rlm@46: rlm@46: Ext.SplitBar.RIGHT = 2; rlm@46: rlm@46: rlm@46: Ext.SplitBar.TOP = 3; rlm@46: rlm@46: rlm@46: Ext.SplitBar.BOTTOM = 4; rlm@46: rlm@46: rlm@46: Ext.Container = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: autoDestroy: true, rlm@46: rlm@46: rlm@46: defaultType: 'panel', rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Container.superclass.initComponent.call(this); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'afterlayout', rlm@46: rlm@46: 'beforeadd', rlm@46: rlm@46: 'beforeremove', rlm@46: rlm@46: 'add', rlm@46: rlm@46: 'remove' rlm@46: ); rlm@46: rlm@46: rlm@46: var items = this.items; rlm@46: if(items){ rlm@46: delete this.items; rlm@46: if(Ext.isArray(items)){ rlm@46: this.add.apply(this, items); rlm@46: }else{ rlm@46: this.add(items); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: initItems : function(){ rlm@46: if(!this.items){ rlm@46: this.items = new Ext.util.MixedCollection(false, this.getComponentId); rlm@46: this.getLayout(); } rlm@46: }, rlm@46: rlm@46: setLayout : function(layout){ rlm@46: if(this.layout && this.layout != layout){ rlm@46: this.layout.setContainer(null); rlm@46: } rlm@46: this.initItems(); rlm@46: this.layout = layout; rlm@46: layout.setContainer(this); rlm@46: }, rlm@46: rlm@46: render : function(){ rlm@46: Ext.Container.superclass.render.apply(this, arguments); rlm@46: if(this.layout){ rlm@46: if(typeof this.layout == 'string'){ rlm@46: this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig); rlm@46: } rlm@46: this.setLayout(this.layout); rlm@46: rlm@46: if(this.activeItem !== undefined){ rlm@46: var item = this.activeItem; rlm@46: delete this.activeItem; rlm@46: this.layout.setActiveItem(item); rlm@46: return; rlm@46: } rlm@46: } rlm@46: if(!this.ownerCt){ rlm@46: this.doLayout(); rlm@46: } rlm@46: if(this.monitorResize === true){ rlm@46: Ext.EventManager.onWindowResize(this.doLayout, this, [false]); rlm@46: } rlm@46: }, rlm@46: rlm@46: getLayoutTarget : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: getComponentId : function(comp){ rlm@46: return comp.itemId || comp.id; rlm@46: }, rlm@46: rlm@46: rlm@46: add : function(comp){ rlm@46: if(!this.items){ rlm@46: this.initItems(); rlm@46: } rlm@46: var a = arguments, len = a.length; rlm@46: if(len > 1){ rlm@46: for(var i = 0; i < len; i++) { rlm@46: this.add(a[i]); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var c = this.lookupComponent(this.applyDefaults(comp)); rlm@46: var pos = this.items.length; rlm@46: if(this.fireEvent('beforeadd', this, c, pos) !== false && this.onBeforeAdd(c) !== false){ rlm@46: this.items.add(c); rlm@46: c.ownerCt = this; rlm@46: this.fireEvent('add', this, c, pos); rlm@46: } rlm@46: return c; rlm@46: }, rlm@46: rlm@46: rlm@46: insert : function(index, comp){ rlm@46: if(!this.items){ rlm@46: this.initItems(); rlm@46: } rlm@46: var a = arguments, len = a.length; rlm@46: if(len > 2){ rlm@46: for(var i = len-1; i >= 1; --i) { rlm@46: this.insert(index, a[i]); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var c = this.lookupComponent(this.applyDefaults(comp)); rlm@46: rlm@46: if(c.ownerCt == this && this.items.indexOf(c) < index){ rlm@46: --index; rlm@46: } rlm@46: rlm@46: if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){ rlm@46: this.items.insert(index, c); rlm@46: c.ownerCt = this; rlm@46: this.fireEvent('add', this, c, index); rlm@46: } rlm@46: return c; rlm@46: }, rlm@46: rlm@46: applyDefaults : function(c){ rlm@46: if(this.defaults){ rlm@46: if(typeof c == 'string'){ rlm@46: c = Ext.ComponentMgr.get(c); rlm@46: Ext.apply(c, this.defaults); rlm@46: }else if(!c.events){ rlm@46: Ext.applyIf(c, this.defaults); rlm@46: }else{ rlm@46: Ext.apply(c, this.defaults); rlm@46: } rlm@46: } rlm@46: return c; rlm@46: }, rlm@46: rlm@46: onBeforeAdd : function(item){ rlm@46: if(item.ownerCt){ rlm@46: item.ownerCt.remove(item, false); rlm@46: } rlm@46: if(this.hideBorders === true){ rlm@46: item.border = (item.border === true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(comp, autoDestroy){ rlm@46: var c = this.getComponent(comp); rlm@46: if(c && this.fireEvent('beforeremove', this, c) !== false){ rlm@46: this.items.remove(c); rlm@46: delete c.ownerCt; rlm@46: if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){ rlm@46: c.destroy(); rlm@46: } rlm@46: if(this.layout && this.layout.activeItem == c){ rlm@46: delete this.layout.activeItem; rlm@46: } rlm@46: this.fireEvent('remove', this, c); rlm@46: } rlm@46: return c; rlm@46: }, rlm@46: rlm@46: rlm@46: getComponent : function(comp){ rlm@46: if(typeof comp == 'object'){ rlm@46: return comp; rlm@46: } rlm@46: return this.items.get(comp); rlm@46: }, rlm@46: rlm@46: lookupComponent : function(comp){ rlm@46: if(typeof comp == 'string'){ rlm@46: return Ext.ComponentMgr.get(comp); rlm@46: }else if(!comp.events){ rlm@46: return this.createComponent(comp); rlm@46: } rlm@46: return comp; rlm@46: }, rlm@46: rlm@46: createComponent : function(config){ rlm@46: return Ext.ComponentMgr.create(config, this.defaultType); rlm@46: }, rlm@46: rlm@46: rlm@46: doLayout : function(shallow){ rlm@46: if(this.rendered && this.layout){ rlm@46: this.layout.layout(); rlm@46: } rlm@46: if(shallow !== false && this.items){ rlm@46: var cs = this.items.items; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: var c = cs[i]; rlm@46: if(c.doLayout){ rlm@46: c.doLayout(); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getLayout : function(){ rlm@46: if(!this.layout){ rlm@46: var layout = new Ext.layout.ContainerLayout(this.layoutConfig); rlm@46: this.setLayout(layout); rlm@46: } rlm@46: return this.layout; rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.items){ rlm@46: var cs = this.items.items; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: Ext.destroy(cs[i]); rlm@46: } rlm@46: } rlm@46: if(this.monitorResize){ rlm@46: Ext.EventManager.removeResizeListener(this.doLayout, this); rlm@46: } rlm@46: Ext.Container.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: rlm@46: bubble : function(fn, scope, args){ rlm@46: var p = this; rlm@46: while(p){ rlm@46: if(fn.apply(scope || p, args || [p]) === false){ rlm@46: break; rlm@46: } rlm@46: p = p.ownerCt; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: cascade : function(fn, scope, args){ rlm@46: if(fn.apply(scope || this, args || [this]) !== false){ rlm@46: if(this.items){ rlm@46: var cs = this.items.items; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: if(cs[i].cascade){ rlm@46: cs[i].cascade(fn, scope, args); rlm@46: }else{ rlm@46: fn.apply(scope || this, args || [cs[i]]); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: findById : function(id){ rlm@46: var m, ct = this; rlm@46: this.cascade(function(c){ rlm@46: if(ct != c && c.id === id){ rlm@46: m = c; rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: return m || null; rlm@46: }, rlm@46: rlm@46: rlm@46: findByType : function(xtype){ rlm@46: return typeof xtype == 'function' ? rlm@46: this.findBy(function(c){ rlm@46: return c.constructor === xtype; rlm@46: }) : rlm@46: this.findBy(function(c){ rlm@46: return c.constructor.xtype === xtype; rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: find : function(prop, value){ rlm@46: return this.findBy(function(c){ rlm@46: return c[prop] === value; rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: findBy : function(fn, scope){ rlm@46: var m = [], ct = this; rlm@46: this.cascade(function(c){ rlm@46: if(ct != c && fn.call(scope || c, c, ct) === true){ rlm@46: m.push(c); rlm@46: } rlm@46: }); rlm@46: return m; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.Container.LAYOUTS = {}; rlm@46: Ext.reg('container', Ext.Container); rlm@46: rlm@46: Ext.layout.ContainerLayout = function(config){ rlm@46: Ext.apply(this, config); rlm@46: }; rlm@46: rlm@46: Ext.layout.ContainerLayout.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: monitorResize:false, rlm@46: activeItem : null, rlm@46: rlm@46: layout : function(){ rlm@46: var target = this.container.getLayoutTarget(); rlm@46: this.onLayout(this.container, target); rlm@46: this.container.fireEvent('afterlayout', this.container, this); rlm@46: }, rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: this.renderAll(ct, target); rlm@46: }, rlm@46: rlm@46: isValidParent : function(c, target){ rlm@46: var el = c.getPositionEl ? c.getPositionEl() : c.getEl(); rlm@46: return el.dom.parentNode == target.dom; rlm@46: }, rlm@46: rlm@46: renderAll : function(ct, target){ rlm@46: var items = ct.items.items; rlm@46: for(var i = 0, len = items.length; i < len; i++) { rlm@46: var c = items[i]; rlm@46: if(c && (!c.rendered || !this.isValidParent(c, target))){ rlm@46: this.renderItem(c, i, target); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: renderItem : function(c, position, target){ rlm@46: if(c && !c.rendered){ rlm@46: c.render(target, position); rlm@46: if(this.extraCls){ rlm@46: var t = c.getPositionEl ? c.getPositionEl() : c; rlm@46: t.addClass(this.extraCls); rlm@46: } rlm@46: if (this.renderHidden && c != this.activeItem) { rlm@46: c.hide(); rlm@46: } rlm@46: }else if(c && !this.isValidParent(c, target)){ rlm@46: if(this.extraCls){ rlm@46: c.addClass(this.extraCls); rlm@46: } rlm@46: if(typeof position == 'number'){ rlm@46: position = target.dom.childNodes[position]; rlm@46: } rlm@46: target.dom.insertBefore(c.getEl().dom, position || null); rlm@46: if (this.renderHidden && c != this.activeItem) { rlm@46: c.hide(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onResize: function(){ rlm@46: if(this.container.collapsed){ rlm@46: return; rlm@46: } rlm@46: var b = this.container.bufferResize; rlm@46: if(b){ rlm@46: if(!this.resizeTask){ rlm@46: this.resizeTask = new Ext.util.DelayedTask(this.layout, this); rlm@46: this.resizeBuffer = typeof b == 'number' ? b : 100; rlm@46: } rlm@46: this.resizeTask.delay(this.resizeBuffer); rlm@46: }else{ rlm@46: this.layout(); rlm@46: } rlm@46: }, rlm@46: rlm@46: setContainer : function(ct){ rlm@46: if(this.monitorResize && ct != this.container){ rlm@46: if(this.container){ rlm@46: this.container.un('resize', this.onResize, this); rlm@46: } rlm@46: if(ct){ rlm@46: ct.on('resize', this.onResize, this); rlm@46: } rlm@46: } rlm@46: this.container = ct; rlm@46: }, rlm@46: rlm@46: parseMargins : function(v){ rlm@46: var ms = v.split(' '); rlm@46: var len = ms.length; rlm@46: if(len == 1){ rlm@46: ms[1] = ms[0]; rlm@46: ms[2] = ms[0]; rlm@46: ms[3] = ms[0]; rlm@46: } rlm@46: if(len == 2){ rlm@46: ms[2] = ms[0]; rlm@46: ms[3] = ms[1]; rlm@46: } rlm@46: return { rlm@46: top:parseInt(ms[0], 10) || 0, rlm@46: right:parseInt(ms[1], 10) || 0, rlm@46: bottom:parseInt(ms[2], 10) || 0, rlm@46: left:parseInt(ms[3], 10) || 0 rlm@46: }; rlm@46: } rlm@46: }; rlm@46: Ext.Container.LAYOUTS['auto'] = Ext.layout.ContainerLayout; rlm@46: rlm@46: Ext.layout.FitLayout = Ext.extend(Ext.layout.ContainerLayout, { rlm@46: rlm@46: monitorResize:true, rlm@46: rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: Ext.layout.FitLayout.superclass.onLayout.call(this, ct, target); rlm@46: if(!this.container.collapsed){ rlm@46: this.setItemSize(this.activeItem || ct.items.itemAt(0), target.getStyleSize()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setItemSize : function(item, size){ rlm@46: if(item && size.height > 0){ rlm@46: item.setSize(size); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.Container.LAYOUTS['fit'] = Ext.layout.FitLayout; rlm@46: rlm@46: Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, { rlm@46: rlm@46: deferredRender : false, rlm@46: rlm@46: rlm@46: renderHidden : true, rlm@46: rlm@46: rlm@46: setActiveItem : function(item){ rlm@46: item = this.container.getComponent(item); rlm@46: if(this.activeItem != item){ rlm@46: if(this.activeItem){ rlm@46: this.activeItem.hide(); rlm@46: } rlm@46: this.activeItem = item; rlm@46: item.show(); rlm@46: this.layout(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: renderAll : function(ct, target){ rlm@46: if(this.deferredRender){ rlm@46: this.renderItem(this.activeItem, undefined, target); rlm@46: }else{ rlm@46: Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout; rlm@46: rlm@46: Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, { rlm@46: rlm@46: monitorResize:true, rlm@46: rlm@46: rlm@46: getAnchorViewSize : function(ct, target){ rlm@46: return target.dom == document.body ? rlm@46: target.getViewSize() : target.getStyleSize(); rlm@46: }, rlm@46: rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: Ext.layout.AnchorLayout.superclass.onLayout.call(this, ct, target); rlm@46: rlm@46: var size = this.getAnchorViewSize(ct, target); rlm@46: rlm@46: var w = size.width, h = size.height; rlm@46: rlm@46: if(w < 20 || h < 20){ rlm@46: return; rlm@46: } rlm@46: rlm@46: rlm@46: var aw, ah; rlm@46: if(ct.anchorSize){ rlm@46: if(typeof ct.anchorSize == 'number'){ rlm@46: aw = ct.anchorSize; rlm@46: }else{ rlm@46: aw = ct.anchorSize.width; rlm@46: ah = ct.anchorSize.height; rlm@46: } rlm@46: }else{ rlm@46: aw = ct.initialConfig.width; rlm@46: ah = ct.initialConfig.height; rlm@46: } rlm@46: rlm@46: var cs = ct.items.items, len = cs.length, i, c, a, cw, ch; rlm@46: for(i = 0; i < len; i++){ rlm@46: c = cs[i]; rlm@46: if(c.anchor){ rlm@46: a = c.anchorSpec; rlm@46: if(!a){ rlm@46: var vs = c.anchor.split(' '); rlm@46: c.anchorSpec = a = { rlm@46: right: this.parseAnchor(vs[0], c.initialConfig.width, aw), rlm@46: bottom: this.parseAnchor(vs[1], c.initialConfig.height, ah) rlm@46: }; rlm@46: } rlm@46: cw = a.right ? this.adjustWidthAnchor(a.right(w), c) : undefined; rlm@46: ch = a.bottom ? this.adjustHeightAnchor(a.bottom(h), c) : undefined; rlm@46: rlm@46: if(cw || ch){ rlm@46: c.setSize(cw || undefined, ch || undefined); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: parseAnchor : function(a, start, cstart){ rlm@46: if(a && a != 'none'){ rlm@46: var last; rlm@46: if(/^(r|right|b|bottom)$/i.test(a)){ rlm@46: var diff = cstart - start; rlm@46: return function(v){ rlm@46: if(v !== last){ rlm@46: last = v; rlm@46: return v - diff; rlm@46: } rlm@46: } rlm@46: }else if(a.indexOf('%') != -1){ rlm@46: var ratio = parseFloat(a.replace('%', ''))*.01; rlm@46: return function(v){ rlm@46: if(v !== last){ rlm@46: last = v; rlm@46: return Math.floor(v*ratio); rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: a = parseInt(a, 10); rlm@46: if(!isNaN(a)){ rlm@46: return function(v){ rlm@46: if(v !== last){ rlm@46: last = v; rlm@46: return v + a; rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: adjustWidthAnchor : function(value, comp){ rlm@46: return value; rlm@46: }, rlm@46: rlm@46: rlm@46: adjustHeightAnchor : function(value, comp){ rlm@46: return value; rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout; rlm@46: rlm@46: Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, { rlm@46: rlm@46: monitorResize:true, rlm@46: rlm@46: extraCls: 'x-column', rlm@46: rlm@46: scrollOffset : 0, rlm@46: rlm@46: rlm@46: isValidParent : function(c, target){ rlm@46: return c.getEl().dom.parentNode == this.innerCt.dom; rlm@46: }, rlm@46: rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: var cs = ct.items.items, len = cs.length, c, i; rlm@46: rlm@46: if(!this.innerCt){ rlm@46: target.addClass('x-column-layout-ct'); rlm@46: rlm@46: rlm@46: rlm@46: this.innerCt = target.createChild({cls:'x-column-inner'}); rlm@46: this.innerCt.createChild({cls:'x-clear'}); rlm@46: } rlm@46: this.renderAll(ct, this.innerCt); rlm@46: rlm@46: var size = target.getViewSize(); rlm@46: rlm@46: if(size.width < 1 && size.height < 1){ rlm@46: return; rlm@46: } rlm@46: rlm@46: var w = size.width - target.getPadding('lr') - this.scrollOffset, rlm@46: h = size.height - target.getPadding('tb'), rlm@46: pw = w; rlm@46: rlm@46: this.innerCt.setWidth(w); rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: for(i = 0; i < len; i++){ rlm@46: c = cs[i]; rlm@46: if(!c.columnWidth){ rlm@46: pw -= (c.getSize().width + c.getEl().getMargins('lr')); rlm@46: } rlm@46: } rlm@46: rlm@46: pw = pw < 0 ? 0 : pw; rlm@46: rlm@46: for(i = 0; i < len; i++){ rlm@46: c = cs[i]; rlm@46: if(c.columnWidth){ rlm@46: c.setSize(Math.floor(c.columnWidth*pw) - c.getEl().getMargins('lr')); rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout; rlm@46: rlm@46: Ext.layout.BorderLayout = Ext.extend(Ext.layout.ContainerLayout, { rlm@46: monitorResize:true, rlm@46: rendered : false, rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: var collapsed; rlm@46: if(!this.rendered){ rlm@46: target.position(); rlm@46: target.addClass('x-border-layout-ct'); rlm@46: var items = ct.items.items; rlm@46: collapsed = []; rlm@46: for(var i = 0, len = items.length; i < len; i++) { rlm@46: var c = items[i]; rlm@46: var pos = c.region; rlm@46: if(c.collapsed){ rlm@46: collapsed.push(c); rlm@46: } rlm@46: c.collapsed = false; rlm@46: if(!c.rendered){ rlm@46: c.cls = c.cls ? c.cls +' x-border-panel' : 'x-border-panel'; rlm@46: c.render(target, i); rlm@46: } rlm@46: this[pos] = pos != 'center' && c.split ? rlm@46: new Ext.layout.BorderLayout.SplitRegion(this, c.initialConfig, pos) : rlm@46: new Ext.layout.BorderLayout.Region(this, c.initialConfig, pos); rlm@46: this[pos].render(target, c); rlm@46: } rlm@46: this.rendered = true; rlm@46: } rlm@46: rlm@46: var size = target.getViewSize(); rlm@46: if(size.width < 20 || size.height < 20){ if(collapsed){ rlm@46: this.restoreCollapsed = collapsed; rlm@46: } rlm@46: return; rlm@46: }else if(this.restoreCollapsed){ rlm@46: collapsed = this.restoreCollapsed; rlm@46: delete this.restoreCollapsed; rlm@46: } rlm@46: rlm@46: var w = size.width, h = size.height; rlm@46: var centerW = w, centerH = h, centerY = 0, centerX = 0; rlm@46: rlm@46: var n = this.north, s = this.south, west = this.west, e = this.east, c = this.center; rlm@46: if(!c){ rlm@46: throw 'No center region defined in BorderLayout ' + ct.id; rlm@46: } rlm@46: rlm@46: if(n && n.isVisible()){ rlm@46: var b = n.getSize(); rlm@46: var m = n.getMargins(); rlm@46: b.width = w - (m.left+m.right); rlm@46: b.x = m.left; rlm@46: b.y = m.top; rlm@46: centerY = b.height + b.y + m.bottom; rlm@46: centerH -= centerY; rlm@46: n.applyLayout(b); rlm@46: } rlm@46: if(s && s.isVisible()){ rlm@46: var b = s.getSize(); rlm@46: var m = s.getMargins(); rlm@46: b.width = w - (m.left+m.right); rlm@46: b.x = m.left; rlm@46: var totalHeight = (b.height + m.top + m.bottom); rlm@46: b.y = h - totalHeight + m.top; rlm@46: centerH -= totalHeight; rlm@46: s.applyLayout(b); rlm@46: } rlm@46: if(west && west.isVisible()){ rlm@46: var b = west.getSize(); rlm@46: var m = west.getMargins(); rlm@46: b.height = centerH - (m.top+m.bottom); rlm@46: b.x = m.left; rlm@46: b.y = centerY + m.top; rlm@46: var totalWidth = (b.width + m.left + m.right); rlm@46: centerX += totalWidth; rlm@46: centerW -= totalWidth; rlm@46: west.applyLayout(b); rlm@46: } rlm@46: if(e && e.isVisible()){ rlm@46: var b = e.getSize(); rlm@46: var m = e.getMargins(); rlm@46: b.height = centerH - (m.top+m.bottom); rlm@46: var totalWidth = (b.width + m.left + m.right); rlm@46: b.x = w - totalWidth + m.left; rlm@46: b.y = centerY + m.top; rlm@46: centerW -= totalWidth; rlm@46: e.applyLayout(b); rlm@46: } rlm@46: rlm@46: var m = c.getMargins(); rlm@46: var centerBox = { rlm@46: x: centerX + m.left, rlm@46: y: centerY + m.top, rlm@46: width: centerW - (m.left+m.right), rlm@46: height: centerH - (m.top+m.bottom) rlm@46: }; rlm@46: c.applyLayout(centerBox); rlm@46: rlm@46: if(collapsed){ rlm@46: for(var i = 0, len = collapsed.length; i < len; i++){ rlm@46: collapsed[i].collapse(false); rlm@46: } rlm@46: } rlm@46: rlm@46: if(Ext.isIE && Ext.isStrict){ target.repaint(); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.layout.BorderLayout.Region = function(layout, config, pos){ rlm@46: Ext.apply(this, config); rlm@46: this.layout = layout; rlm@46: this.position = pos; rlm@46: this.state = {}; rlm@46: if(typeof this.margins == 'string'){ rlm@46: this.margins = this.layout.parseMargins(this.margins); rlm@46: } rlm@46: this.margins = Ext.applyIf(this.margins || {}, this.defaultMargins); rlm@46: if(this.collapsible){ rlm@46: if(typeof this.cmargins == 'string'){ rlm@46: this.cmargins = this.layout.parseMargins(this.cmargins); rlm@46: } rlm@46: if(this.collapseMode == 'mini' && !this.cmargins){ rlm@46: this.cmargins = {left:0,top:0,right:0,bottom:0}; rlm@46: }else{ rlm@46: this.cmargins = Ext.applyIf(this.cmargins || {}, rlm@46: pos == 'north' || pos == 'south' ? this.defaultNSCMargins : this.defaultEWCMargins); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.layout.BorderLayout.Region.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: collapsible : false, rlm@46: rlm@46: split:false, rlm@46: rlm@46: floatable: true, rlm@46: rlm@46: minWidth:50, rlm@46: rlm@46: minHeight:50, rlm@46: rlm@46: defaultMargins : {left:0,top:0,right:0,bottom:0}, rlm@46: defaultNSCMargins : {left:5,top:5,right:5,bottom:5}, rlm@46: defaultEWCMargins : {left:5,top:0,right:5,bottom:0}, rlm@46: rlm@46: rlm@46: isCollapsed : false, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: render : function(ct, p){ rlm@46: this.panel = p; rlm@46: p.el.enableDisplayMode(); rlm@46: this.targetEl = ct; rlm@46: this.el = p.el; rlm@46: rlm@46: var gs = p.getState, ps = this.position; rlm@46: p.getState = function(){ rlm@46: return Ext.apply(gs.call(p) || {}, this.state); rlm@46: }.createDelegate(this); rlm@46: rlm@46: if(ps != 'center'){ rlm@46: p.allowQueuedExpand = false; rlm@46: p.on({ rlm@46: beforecollapse: this.beforeCollapse, rlm@46: collapse: this.onCollapse, rlm@46: beforeexpand: this.beforeExpand, rlm@46: expand: this.onExpand, rlm@46: hide: this.onHide, rlm@46: show: this.onShow, rlm@46: scope: this rlm@46: }); rlm@46: if(this.collapsible){ rlm@46: p.collapseEl = 'el'; rlm@46: p.slideAnchor = this.getSlideAnchor(); rlm@46: } rlm@46: if(p.tools && p.tools.toggle){ rlm@46: p.tools.toggle.addClass('x-tool-collapse-'+ps); rlm@46: p.tools.toggle.addClassOnOver('x-tool-collapse-'+ps+'-over'); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: getCollapsedEl : function(){ rlm@46: if(!this.collapsedEl){ rlm@46: if(!this.toolTemplate){ rlm@46: var tt = new Ext.Template( rlm@46: '
 
' rlm@46: ); rlm@46: tt.disableFormats = true; rlm@46: tt.compile(); rlm@46: Ext.layout.BorderLayout.Region.prototype.toolTemplate = tt; rlm@46: } rlm@46: this.collapsedEl = this.targetEl.createChild({ rlm@46: cls: "x-layout-collapsed x-layout-collapsed-"+this.position, rlm@46: id: this.panel.id + '-xcollapsed' rlm@46: }); rlm@46: this.collapsedEl.enableDisplayMode('block'); rlm@46: rlm@46: if(this.collapseMode == 'mini'){ rlm@46: this.collapsedEl.addClass('x-layout-cmini-'+this.position); rlm@46: this.miniCollapsedEl = this.collapsedEl.createChild({ rlm@46: cls: "x-layout-mini x-layout-mini-"+this.position, html: " " rlm@46: }); rlm@46: this.miniCollapsedEl.addClassOnOver('x-layout-mini-over'); rlm@46: this.collapsedEl.addClassOnOver("x-layout-collapsed-over"); rlm@46: this.collapsedEl.on('click', this.onExpandClick, this, {stopEvent:true}); rlm@46: }else { rlm@46: var t = this.toolTemplate.append( rlm@46: this.collapsedEl.dom, rlm@46: {id:'expand-'+this.position}, true); rlm@46: t.addClassOnOver('x-tool-expand-'+this.position+'-over'); rlm@46: t.on('click', this.onExpandClick, this, {stopEvent:true}); rlm@46: rlm@46: if(this.floatable !== false){ rlm@46: this.collapsedEl.addClassOnOver("x-layout-collapsed-over"); rlm@46: this.collapsedEl.on("click", this.collapseClick, this); rlm@46: } rlm@46: } rlm@46: } rlm@46: return this.collapsedEl; rlm@46: }, rlm@46: rlm@46: onExpandClick : function(e){ rlm@46: if(this.isSlid){ rlm@46: this.afterSlideIn(); rlm@46: this.panel.expand(false); rlm@46: }else{ rlm@46: this.panel.expand(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onCollapseClick : function(e){ rlm@46: this.panel.collapse(); rlm@46: }, rlm@46: rlm@46: beforeCollapse : function(p, animate){ rlm@46: this.lastAnim = animate; rlm@46: if(this.splitEl){ rlm@46: this.splitEl.hide(); rlm@46: } rlm@46: this.getCollapsedEl().show(); rlm@46: this.panel.el.setStyle('z-index', 100); rlm@46: this.isCollapsed = true; rlm@46: this.layout.layout(); rlm@46: }, rlm@46: rlm@46: onCollapse : function(animate){ rlm@46: this.panel.el.setStyle('z-index', 1); rlm@46: if(this.lastAnim === false || this.panel.animCollapse === false){ rlm@46: this.getCollapsedEl().dom.style.visibility = 'visible'; rlm@46: }else{ rlm@46: this.getCollapsedEl().slideIn(this.panel.slideAnchor, {duration:.2}); rlm@46: } rlm@46: this.state.collapsed = true; rlm@46: this.panel.saveState(); rlm@46: }, rlm@46: rlm@46: beforeExpand : function(animate){ rlm@46: var c = this.getCollapsedEl(); rlm@46: this.el.show(); rlm@46: if(this.position == 'east' || this.position == 'west'){ rlm@46: this.panel.setSize(undefined, c.getHeight()); rlm@46: }else{ rlm@46: this.panel.setSize(c.getWidth(), undefined); rlm@46: } rlm@46: c.hide(); rlm@46: c.dom.style.visibility = 'hidden'; rlm@46: this.panel.el.setStyle('z-index', 100); rlm@46: }, rlm@46: rlm@46: onExpand : function(){ rlm@46: this.isCollapsed = false; rlm@46: if(this.splitEl){ rlm@46: this.splitEl.show(); rlm@46: } rlm@46: this.layout.layout(); rlm@46: this.panel.el.setStyle('z-index', 1); rlm@46: this.state.collapsed = false; rlm@46: this.panel.saveState(); rlm@46: }, rlm@46: rlm@46: collapseClick : function(e){ rlm@46: if(this.isSlid){ rlm@46: e.stopPropagation(); rlm@46: this.slideIn(); rlm@46: }else{ rlm@46: e.stopPropagation(); rlm@46: this.slideOut(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: if(this.isCollapsed){ rlm@46: this.getCollapsedEl().hide(); rlm@46: }else if(this.splitEl){ rlm@46: this.splitEl.hide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onShow : function(){ rlm@46: if(this.isCollapsed){ rlm@46: this.getCollapsedEl().show(); rlm@46: }else if(this.splitEl){ rlm@46: this.splitEl.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(){ rlm@46: return !this.panel.hidden; rlm@46: }, rlm@46: rlm@46: rlm@46: getMargins : function(){ rlm@46: return this.isCollapsed && this.cmargins ? this.cmargins : this.margins; rlm@46: }, rlm@46: rlm@46: rlm@46: getSize : function(){ rlm@46: return this.isCollapsed ? this.getCollapsedEl().getSize() : this.panel.getSize(); rlm@46: }, rlm@46: rlm@46: rlm@46: setPanel : function(panel){ rlm@46: this.panel = panel; rlm@46: }, rlm@46: rlm@46: rlm@46: getMinWidth: function(){ rlm@46: return this.minWidth; rlm@46: }, rlm@46: rlm@46: rlm@46: getMinHeight: function(){ rlm@46: return this.minHeight; rlm@46: }, rlm@46: rlm@46: applyLayoutCollapsed : function(box){ rlm@46: var ce = this.getCollapsedEl(); rlm@46: ce.setLeftTop(box.x, box.y); rlm@46: ce.setSize(box.width, box.height); rlm@46: }, rlm@46: rlm@46: applyLayout : function(box){ rlm@46: if(this.isCollapsed){ rlm@46: this.applyLayoutCollapsed(box); rlm@46: }else{ rlm@46: this.panel.setPosition(box.x, box.y); rlm@46: this.panel.setSize(box.width, box.height); rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeSlide: function(){ rlm@46: this.panel.beforeEffect(); rlm@46: }, rlm@46: rlm@46: afterSlide : function(){ rlm@46: this.panel.afterEffect(); rlm@46: }, rlm@46: rlm@46: initAutoHide : function(){ rlm@46: if(this.autoHide !== false){ rlm@46: if(!this.autoHideHd){ rlm@46: var st = new Ext.util.DelayedTask(this.slideIn, this); rlm@46: this.autoHideHd = { rlm@46: "mouseout": function(e){ rlm@46: if(!e.within(this.el, true)){ rlm@46: st.delay(500); rlm@46: } rlm@46: }, rlm@46: "mouseover" : function(e){ rlm@46: st.cancel(); rlm@46: }, rlm@46: scope : this rlm@46: }; rlm@46: } rlm@46: this.el.on(this.autoHideHd); rlm@46: } rlm@46: }, rlm@46: rlm@46: clearAutoHide : function(){ rlm@46: if(this.autoHide !== false){ rlm@46: this.el.un("mouseout", this.autoHideHd.mouseout); rlm@46: this.el.un("mouseover", this.autoHideHd.mouseover); rlm@46: } rlm@46: }, rlm@46: rlm@46: clearMonitor : function(){ rlm@46: Ext.getDoc().un("click", this.slideInIf, this); rlm@46: }, rlm@46: rlm@46: slideOut : function(){ rlm@46: if(this.isSlid || this.el.hasActiveFx()){ rlm@46: return; rlm@46: } rlm@46: this.isSlid = true; rlm@46: var ts = this.panel.tools; rlm@46: if(ts && ts.toggle){ rlm@46: ts.toggle.hide(); rlm@46: } rlm@46: this.el.show(); rlm@46: if(this.position == 'east' || this.position == 'west'){ rlm@46: this.panel.setSize(undefined, this.collapsedEl.getHeight()); rlm@46: }else{ rlm@46: this.panel.setSize(this.collapsedEl.getWidth(), undefined); rlm@46: } rlm@46: this.restoreLT = [this.el.dom.style.left, this.el.dom.style.top]; rlm@46: this.el.alignTo(this.collapsedEl, this.getCollapseAnchor()); rlm@46: this.el.setStyle("z-index", 102); rlm@46: if(this.animFloat !== false){ rlm@46: this.beforeSlide(); rlm@46: this.el.slideIn(this.getSlideAnchor(), { rlm@46: callback: function(){ rlm@46: this.afterSlide(); rlm@46: this.initAutoHide(); rlm@46: Ext.getDoc().on("click", this.slideInIf, this); rlm@46: }, rlm@46: scope: this, rlm@46: block: true rlm@46: }); rlm@46: }else{ rlm@46: this.initAutoHide(); rlm@46: Ext.getDoc().on("click", this.slideInIf, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterSlideIn : function(){ rlm@46: this.clearAutoHide(); rlm@46: this.isSlid = false; rlm@46: this.clearMonitor(); rlm@46: this.el.setStyle("z-index", ""); rlm@46: this.el.dom.style.left = this.restoreLT[0]; rlm@46: this.el.dom.style.top = this.restoreLT[1]; rlm@46: rlm@46: var ts = this.panel.tools; rlm@46: if(ts && ts.toggle){ rlm@46: ts.toggle.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: slideIn : function(cb){ rlm@46: if(!this.isSlid || this.el.hasActiveFx()){ rlm@46: Ext.callback(cb); rlm@46: return; rlm@46: } rlm@46: this.isSlid = false; rlm@46: if(this.animFloat !== false){ rlm@46: this.beforeSlide(); rlm@46: this.el.slideOut(this.getSlideAnchor(), { rlm@46: callback: function(){ rlm@46: this.el.hide(); rlm@46: this.afterSlide(); rlm@46: this.afterSlideIn(); rlm@46: Ext.callback(cb); rlm@46: }, rlm@46: scope: this, rlm@46: block: true rlm@46: }); rlm@46: }else{ rlm@46: this.el.hide(); rlm@46: this.afterSlideIn(); rlm@46: } rlm@46: }, rlm@46: rlm@46: slideInIf : function(e){ rlm@46: if(!e.within(this.el)){ rlm@46: this.slideIn(); rlm@46: } rlm@46: }, rlm@46: rlm@46: anchors : { rlm@46: "west" : "left", rlm@46: "east" : "right", rlm@46: "north" : "top", rlm@46: "south" : "bottom" rlm@46: }, rlm@46: rlm@46: sanchors : { rlm@46: "west" : "l", rlm@46: "east" : "r", rlm@46: "north" : "t", rlm@46: "south" : "b" rlm@46: }, rlm@46: rlm@46: canchors : { rlm@46: "west" : "tl-tr", rlm@46: "east" : "tr-tl", rlm@46: "north" : "tl-bl", rlm@46: "south" : "bl-tl" rlm@46: }, rlm@46: rlm@46: getAnchor : function(){ rlm@46: return this.anchors[this.position]; rlm@46: }, rlm@46: rlm@46: getCollapseAnchor : function(){ rlm@46: return this.canchors[this.position]; rlm@46: }, rlm@46: rlm@46: getSlideAnchor : function(){ rlm@46: return this.sanchors[this.position]; rlm@46: }, rlm@46: rlm@46: getAlignAdj : function(){ rlm@46: var cm = this.cmargins; rlm@46: switch(this.position){ rlm@46: case "west": rlm@46: return [0, 0]; rlm@46: break; rlm@46: case "east": rlm@46: return [0, 0]; rlm@46: break; rlm@46: case "north": rlm@46: return [0, 0]; rlm@46: break; rlm@46: case "south": rlm@46: return [0, 0]; rlm@46: break; rlm@46: } rlm@46: }, rlm@46: rlm@46: getExpandAdj : function(){ rlm@46: var c = this.collapsedEl, cm = this.cmargins; rlm@46: switch(this.position){ rlm@46: case "west": rlm@46: return [-(cm.right+c.getWidth()+cm.left), 0]; rlm@46: break; rlm@46: case "east": rlm@46: return [cm.right+c.getWidth()+cm.left, 0]; rlm@46: break; rlm@46: case "north": rlm@46: return [0, -(cm.top+cm.bottom+c.getHeight())]; rlm@46: break; rlm@46: case "south": rlm@46: return [0, cm.top+cm.bottom+c.getHeight()]; rlm@46: break; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.layout.BorderLayout.SplitRegion = function(layout, config, pos){ rlm@46: Ext.layout.BorderLayout.SplitRegion.superclass.constructor.call(this, layout, config, pos); rlm@46: this.applyLayout = this.applyFns[pos]; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.layout.BorderLayout.SplitRegion, Ext.layout.BorderLayout.Region, { rlm@46: rlm@46: splitTip : "Drag to resize.", rlm@46: rlm@46: collapsibleSplitTip : "Drag to resize. Double click to hide.", rlm@46: rlm@46: useSplitTips : false, rlm@46: rlm@46: splitSettings : { rlm@46: north : { rlm@46: orientation: Ext.SplitBar.VERTICAL, rlm@46: placement: Ext.SplitBar.TOP, rlm@46: maxFn : 'getVMaxSize', rlm@46: minProp: 'minHeight', rlm@46: maxProp: 'maxHeight' rlm@46: }, rlm@46: south : { rlm@46: orientation: Ext.SplitBar.VERTICAL, rlm@46: placement: Ext.SplitBar.BOTTOM, rlm@46: maxFn : 'getVMaxSize', rlm@46: minProp: 'minHeight', rlm@46: maxProp: 'maxHeight' rlm@46: }, rlm@46: east : { rlm@46: orientation: Ext.SplitBar.HORIZONTAL, rlm@46: placement: Ext.SplitBar.RIGHT, rlm@46: maxFn : 'getHMaxSize', rlm@46: minProp: 'minWidth', rlm@46: maxProp: 'maxWidth' rlm@46: }, rlm@46: west : { rlm@46: orientation: Ext.SplitBar.HORIZONTAL, rlm@46: placement: Ext.SplitBar.LEFT, rlm@46: maxFn : 'getHMaxSize', rlm@46: minProp: 'minWidth', rlm@46: maxProp: 'maxWidth' rlm@46: } rlm@46: }, rlm@46: rlm@46: applyFns : { rlm@46: west : function(box){ rlm@46: if(this.isCollapsed){ rlm@46: return this.applyLayoutCollapsed(box); rlm@46: } rlm@46: var sd = this.splitEl.dom, s = sd.style; rlm@46: this.panel.setPosition(box.x, box.y); rlm@46: var sw = sd.offsetWidth; rlm@46: s.left = (box.x+box.width-sw)+'px'; rlm@46: s.top = (box.y)+'px'; rlm@46: s.height = Math.max(0, box.height)+'px'; rlm@46: this.panel.setSize(box.width-sw, box.height); rlm@46: }, rlm@46: east : function(box){ rlm@46: if(this.isCollapsed){ rlm@46: return this.applyLayoutCollapsed(box); rlm@46: } rlm@46: var sd = this.splitEl.dom, s = sd.style; rlm@46: var sw = sd.offsetWidth; rlm@46: this.panel.setPosition(box.x+sw, box.y); rlm@46: s.left = (box.x)+'px'; rlm@46: s.top = (box.y)+'px'; rlm@46: s.height = Math.max(0, box.height)+'px'; rlm@46: this.panel.setSize(box.width-sw, box.height); rlm@46: }, rlm@46: north : function(box){ rlm@46: if(this.isCollapsed){ rlm@46: return this.applyLayoutCollapsed(box); rlm@46: } rlm@46: var sd = this.splitEl.dom, s = sd.style; rlm@46: var sh = sd.offsetHeight; rlm@46: this.panel.setPosition(box.x, box.y); rlm@46: s.left = (box.x)+'px'; rlm@46: s.top = (box.y+box.height-sh)+'px'; rlm@46: s.width = Math.max(0, box.width)+'px'; rlm@46: this.panel.setSize(box.width, box.height-sh); rlm@46: }, rlm@46: south : function(box){ rlm@46: if(this.isCollapsed){ rlm@46: return this.applyLayoutCollapsed(box); rlm@46: } rlm@46: var sd = this.splitEl.dom, s = sd.style; rlm@46: var sh = sd.offsetHeight; rlm@46: this.panel.setPosition(box.x, box.y+sh); rlm@46: s.left = (box.x)+'px'; rlm@46: s.top = (box.y)+'px'; rlm@46: s.width = Math.max(0, box.width)+'px'; rlm@46: this.panel.setSize(box.width, box.height-sh); rlm@46: } rlm@46: }, rlm@46: rlm@46: render : function(ct, p){ rlm@46: Ext.layout.BorderLayout.SplitRegion.superclass.render.call(this, ct, p); rlm@46: rlm@46: var ps = this.position; rlm@46: rlm@46: this.splitEl = ct.createChild({ rlm@46: cls: "x-layout-split x-layout-split-"+ps, html: " ", rlm@46: id: this.panel.id + '-xsplit' rlm@46: }); rlm@46: rlm@46: if(this.collapseMode == 'mini'){ rlm@46: this.miniSplitEl = this.splitEl.createChild({ rlm@46: cls: "x-layout-mini x-layout-mini-"+ps, html: " " rlm@46: }); rlm@46: this.miniSplitEl.addClassOnOver('x-layout-mini-over'); rlm@46: this.miniSplitEl.on('click', this.onCollapseClick, this, {stopEvent:true}); rlm@46: } rlm@46: rlm@46: var s = this.splitSettings[ps]; rlm@46: rlm@46: this.split = new Ext.SplitBar(this.splitEl.dom, p.el, s.orientation); rlm@46: this.split.placement = s.placement; rlm@46: this.split.getMaximumSize = this[s.maxFn].createDelegate(this); rlm@46: this.split.minSize = this.minSize || this[s.minProp]; rlm@46: this.split.on("beforeapply", this.onSplitMove, this); rlm@46: this.split.useShim = this.useShim === true; rlm@46: this.maxSize = this.maxSize || this[s.maxProp]; rlm@46: rlm@46: if(p.hidden){ rlm@46: this.splitEl.hide(); rlm@46: } rlm@46: rlm@46: if(this.useSplitTips){ rlm@46: this.splitEl.dom.title = this.collapsible ? this.collapsibleSplitTip : this.splitTip; rlm@46: } rlm@46: if(this.collapsible){ rlm@46: this.splitEl.on("dblclick", this.onCollapseClick, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: getSize : function(){ rlm@46: if(this.isCollapsed){ rlm@46: return this.collapsedEl.getSize(); rlm@46: } rlm@46: var s = this.panel.getSize(); rlm@46: if(this.position == 'north' || this.position == 'south'){ rlm@46: s.height += this.splitEl.dom.offsetHeight; rlm@46: }else{ rlm@46: s.width += this.splitEl.dom.offsetWidth; rlm@46: } rlm@46: return s; rlm@46: }, rlm@46: rlm@46: getHMaxSize : function(){ rlm@46: var cmax = this.maxSize || 10000; rlm@46: var center = this.layout.center; rlm@46: return Math.min(cmax, (this.el.getWidth()+center.el.getWidth())-center.getMinWidth()); rlm@46: }, rlm@46: rlm@46: getVMaxSize : function(){ rlm@46: var cmax = this.maxSize || 10000; rlm@46: var center = this.layout.center; rlm@46: return Math.min(cmax, (this.el.getHeight()+center.el.getHeight())-center.getMinHeight()); rlm@46: }, rlm@46: rlm@46: onSplitMove : function(split, newSize){ rlm@46: var s = this.panel.getSize(); rlm@46: this.lastSplitSize = newSize; rlm@46: if(this.position == 'north' || this.position == 'south'){ rlm@46: this.panel.setSize(s.width, newSize); rlm@46: this.state.height = newSize; rlm@46: }else{ rlm@46: this.panel.setSize(newSize, s.height); rlm@46: this.state.width = newSize; rlm@46: } rlm@46: this.layout.layout(); rlm@46: this.panel.saveState(); rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: getSplitBar : function(){ rlm@46: return this.split; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.Container.LAYOUTS['border'] = Ext.layout.BorderLayout; rlm@46: rlm@46: Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, { rlm@46: rlm@46: rlm@46: rlm@46: labelSeparator : ':', rlm@46: rlm@46: getAnchorViewSize : function(ct, target){ rlm@46: return ct.body.getStyleSize(); rlm@46: }, rlm@46: rlm@46: setContainer : function(ct){ rlm@46: Ext.layout.FormLayout.superclass.setContainer.call(this, ct); rlm@46: rlm@46: if(ct.labelAlign){ rlm@46: ct.addClass('x-form-label-'+ct.labelAlign); rlm@46: } rlm@46: rlm@46: if(ct.hideLabels){ rlm@46: this.labelStyle = "display:none"; rlm@46: this.elementStyle = "padding-left:0;"; rlm@46: this.labelAdjust = 0; rlm@46: }else{ rlm@46: this.labelSeparator = ct.labelSeparator || this.labelSeparator; rlm@46: ct.labelWidth = ct.labelWidth || 100; rlm@46: if(typeof ct.labelWidth == 'number'){ rlm@46: var pad = (typeof ct.labelPad == 'number' ? ct.labelPad : 5); rlm@46: this.labelAdjust = ct.labelWidth+pad; rlm@46: this.labelStyle = "width:"+ct.labelWidth+"px;"; rlm@46: this.elementStyle = "padding-left:"+(ct.labelWidth+pad)+'px'; rlm@46: } rlm@46: if(ct.labelAlign == 'top'){ rlm@46: this.labelStyle = "width:auto;"; rlm@46: this.labelAdjust = 0; rlm@46: this.elementStyle = "padding-left:0;"; rlm@46: } rlm@46: } rlm@46: rlm@46: if(!this.fieldTpl){ rlm@46: var t = new Ext.Template( rlm@46: '
', rlm@46: '', rlm@46: '
', rlm@46: '
', rlm@46: '
' rlm@46: ); rlm@46: t.disableFormats = true; rlm@46: t.compile(); rlm@46: Ext.layout.FormLayout.prototype.fieldTpl = t; rlm@46: } rlm@46: }, rlm@46: rlm@46: renderItem : function(c, position, target){ rlm@46: if(c && !c.rendered && c.isFormField && c.inputType != 'hidden'){ rlm@46: var args = [ rlm@46: c.id, c.fieldLabel, rlm@46: c.labelStyle||this.labelStyle||'', rlm@46: this.elementStyle||'', rlm@46: typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator, rlm@46: (c.itemCls||this.container.itemCls||'') + (c.hideLabel ? ' x-hide-label' : ''), rlm@46: c.clearCls || 'x-form-clear-left' rlm@46: ]; rlm@46: if(typeof position == 'number'){ rlm@46: position = target.dom.childNodes[position] || null; rlm@46: } rlm@46: if(position){ rlm@46: this.fieldTpl.insertBefore(position, args); rlm@46: }else{ rlm@46: this.fieldTpl.append(target, args); rlm@46: } rlm@46: c.render('x-form-el-'+c.id); rlm@46: }else { rlm@46: Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments); rlm@46: } rlm@46: }, rlm@46: rlm@46: adjustWidthAnchor : function(value, comp){ rlm@46: return value - (comp.isFormField ? (comp.hideLabel ? 0 : this.labelAdjust) : 0); rlm@46: }, rlm@46: rlm@46: isValidParent : function(c, target){ rlm@46: return true; rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.Container.LAYOUTS['form'] = Ext.layout.FormLayout; rlm@46: rlm@46: Ext.layout.Accordion = Ext.extend(Ext.layout.FitLayout, { rlm@46: rlm@46: fill : true, rlm@46: rlm@46: autoWidth : true, rlm@46: rlm@46: titleCollapse : true, rlm@46: rlm@46: hideCollapseTool : false, rlm@46: rlm@46: collapseFirst : false, rlm@46: rlm@46: animate : false, rlm@46: rlm@46: sequence : false, rlm@46: rlm@46: activeOnTop : false, rlm@46: rlm@46: renderItem : function(c){ rlm@46: if(this.animate === false){ rlm@46: c.animCollapse = false; rlm@46: } rlm@46: c.collapsible = true; rlm@46: if(this.autoWidth){ rlm@46: c.autoWidth = true; rlm@46: } rlm@46: if(this.titleCollapse){ rlm@46: c.titleCollapse = true; rlm@46: } rlm@46: if(this.hideCollapseTool){ rlm@46: c.hideCollapseTool = true; rlm@46: } rlm@46: if(this.collapseFirst !== undefined){ rlm@46: c.collapseFirst = this.collapseFirst; rlm@46: } rlm@46: if(!this.activeItem && !c.collapsed){ rlm@46: this.activeItem = c; rlm@46: }else if(this.activeItem){ rlm@46: c.collapsed = true; rlm@46: } rlm@46: Ext.layout.Accordion.superclass.renderItem.apply(this, arguments); rlm@46: c.header.addClass('x-accordion-hd'); rlm@46: c.on('beforeexpand', this.beforeExpand, this); rlm@46: }, rlm@46: rlm@46: rlm@46: beforeExpand : function(p, anim){ rlm@46: var ai = this.activeItem; rlm@46: if(ai){ rlm@46: if(this.sequence){ rlm@46: delete this.activeItem; rlm@46: if (!ai.collapsed){ rlm@46: ai.collapse({callback:function(){ rlm@46: p.expand(anim || true); rlm@46: }, scope: this}); rlm@46: return false; rlm@46: } rlm@46: }else{ rlm@46: ai.collapse(this.animate); rlm@46: } rlm@46: } rlm@46: this.activeItem = p; rlm@46: if(this.activeOnTop){ rlm@46: p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild); rlm@46: } rlm@46: this.layout(); rlm@46: }, rlm@46: rlm@46: rlm@46: setItemSize : function(item, size){ rlm@46: if(this.fill && item){ rlm@46: var items = this.container.items.items; rlm@46: var hh = 0; rlm@46: for(var i = 0, len = items.length; i < len; i++){ rlm@46: var p = items[i]; rlm@46: if(p != item){ rlm@46: hh += (p.getSize().height - p.bwrap.getHeight()); rlm@46: } rlm@46: } rlm@46: size.height -= hh; rlm@46: item.setSize(size); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.Container.LAYOUTS['accordion'] = Ext.layout.Accordion; rlm@46: rlm@46: Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, { rlm@46: rlm@46: rlm@46: rlm@46: monitorResize:false, rlm@46: rlm@46: rlm@46: setContainer : function(ct){ rlm@46: Ext.layout.TableLayout.superclass.setContainer.call(this, ct); rlm@46: rlm@46: this.currentRow = 0; rlm@46: this.currentColumn = 0; rlm@46: this.cells = []; rlm@46: }, rlm@46: rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: var cs = ct.items.items, len = cs.length, c, i; rlm@46: rlm@46: if(!this.table){ rlm@46: target.addClass('x-table-layout-ct'); rlm@46: rlm@46: this.table = target.createChild( rlm@46: {tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, null, true); rlm@46: rlm@46: this.renderAll(ct, target); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getRow : function(index){ rlm@46: var row = this.table.tBodies[0].childNodes[index]; rlm@46: if(!row){ rlm@46: row = document.createElement('tr'); rlm@46: this.table.tBodies[0].appendChild(row); rlm@46: } rlm@46: return row; rlm@46: }, rlm@46: rlm@46: rlm@46: getNextCell : function(c){ rlm@46: var cell = this.getNextNonSpan(this.currentColumn, this.currentRow); rlm@46: var curCol = this.currentColumn = cell[0], curRow = this.currentRow = cell[1]; rlm@46: for(var rowIndex = curRow; rowIndex < curRow + (c.rowspan || 1); rowIndex++){ rlm@46: if(!this.cells[rowIndex]){ rlm@46: this.cells[rowIndex] = []; rlm@46: } rlm@46: for(var colIndex = curCol; colIndex < curCol + (c.colspan || 1); colIndex++){ rlm@46: this.cells[rowIndex][colIndex] = true; rlm@46: } rlm@46: } rlm@46: var td = document.createElement('td'); rlm@46: if(c.cellId){ rlm@46: td.id = c.cellId; rlm@46: } rlm@46: var cls = 'x-table-layout-cell'; rlm@46: if(c.cellCls){ rlm@46: cls += ' ' + c.cellCls; rlm@46: } rlm@46: td.className = cls; rlm@46: if(c.colspan){ rlm@46: td.colSpan = c.colspan; rlm@46: } rlm@46: if(c.rowspan){ rlm@46: td.rowSpan = c.rowspan; rlm@46: } rlm@46: this.getRow(curRow).appendChild(td); rlm@46: return td; rlm@46: }, rlm@46: rlm@46: rlm@46: getNextNonSpan: function(colIndex, rowIndex){ rlm@46: var cols = this.columns; rlm@46: while((cols && colIndex >= cols) || (this.cells[rowIndex] && this.cells[rowIndex][colIndex])) { rlm@46: if(cols && colIndex >= cols){ rlm@46: rowIndex++; rlm@46: colIndex = 0; rlm@46: }else{ rlm@46: colIndex++; rlm@46: } rlm@46: } rlm@46: return [colIndex, rowIndex]; rlm@46: }, rlm@46: rlm@46: rlm@46: renderItem : function(c, position, target){ rlm@46: if(c && !c.rendered){ rlm@46: c.render(this.getNextCell(c)); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isValidParent : function(c, target){ rlm@46: return true; rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.Container.LAYOUTS['table'] = Ext.layout.TableLayout; rlm@46: rlm@46: Ext.layout.AbsoluteLayout = Ext.extend(Ext.layout.AnchorLayout, { rlm@46: extraCls: 'x-abs-layout-item', rlm@46: isForm: false, rlm@46: rlm@46: setContainer : function(ct){ rlm@46: Ext.layout.AbsoluteLayout.superclass.setContainer.call(this, ct); rlm@46: if(ct.isXType('form')){ rlm@46: this.isForm = true; rlm@46: } rlm@46: }, rlm@46: rlm@46: onLayout : function(ct, target){ rlm@46: if(this.isForm){ ct.body.position(); } else { target.position(); } rlm@46: Ext.layout.AbsoluteLayout.superclass.onLayout.call(this, ct, target); rlm@46: }, rlm@46: rlm@46: rlm@46: getAnchorViewSize : function(ct, target){ rlm@46: return this.isForm ? ct.body.getStyleSize() : Ext.layout.AbsoluteLayout.superclass.getAnchorViewSize.call(this, ct, target); rlm@46: }, rlm@46: rlm@46: rlm@46: isValidParent : function(c, target){ rlm@46: return this.isForm ? true : Ext.layout.AbsoluteLayout.superclass.isValidParent.call(this, c, target); rlm@46: }, rlm@46: rlm@46: rlm@46: adjustWidthAnchor : function(value, comp){ rlm@46: return value ? value - comp.getPosition(true)[0] : value; rlm@46: }, rlm@46: rlm@46: rlm@46: adjustHeightAnchor : function(value, comp){ rlm@46: return value ? value - comp.getPosition(true)[1] : value; rlm@46: } rlm@46: rlm@46: }); rlm@46: Ext.Container.LAYOUTS['absolute'] = Ext.layout.AbsoluteLayout; rlm@46: rlm@46: Ext.Viewport = Ext.extend(Ext.Container, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: initComponent : function() { rlm@46: Ext.Viewport.superclass.initComponent.call(this); rlm@46: document.getElementsByTagName('html')[0].className += ' x-viewport'; rlm@46: this.el = Ext.getBody(); rlm@46: this.el.setHeight = Ext.emptyFn; rlm@46: this.el.setWidth = Ext.emptyFn; rlm@46: this.el.setSize = Ext.emptyFn; rlm@46: this.el.dom.scroll = 'no'; rlm@46: this.allowDomMove = false; rlm@46: this.autoWidth = true; rlm@46: this.autoHeight = true; rlm@46: Ext.EventManager.onWindowResize(this.fireResize, this); rlm@46: this.renderTo = this.el; rlm@46: }, rlm@46: rlm@46: fireResize : function(w, h){ rlm@46: this.fireEvent('resize', this, w, h, w, h); rlm@46: } rlm@46: }); rlm@46: Ext.reg('viewport', Ext.Viewport); rlm@46: rlm@46: Ext.Panel = Ext.extend(Ext.Container, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: baseCls : 'x-panel', rlm@46: rlm@46: collapsedCls : 'x-panel-collapsed', rlm@46: rlm@46: maskDisabled: true, rlm@46: rlm@46: animCollapse: Ext.enableFx, rlm@46: rlm@46: headerAsText: true, rlm@46: rlm@46: buttonAlign: 'right', rlm@46: rlm@46: collapsed : false, rlm@46: rlm@46: collapseFirst: true, rlm@46: rlm@46: minButtonWidth:75, rlm@46: rlm@46: elements : 'body', rlm@46: rlm@46: toolTarget : 'header', rlm@46: collapseEl : 'bwrap', rlm@46: slideAnchor : 't', rlm@46: rlm@46: deferHeight: true, rlm@46: expandDefaults: { rlm@46: duration:.25 rlm@46: }, rlm@46: collapseDefaults: { rlm@46: duration:.25 rlm@46: }, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Panel.superclass.initComponent.call(this); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'bodyresize', rlm@46: rlm@46: 'titlechange', rlm@46: rlm@46: 'collapse', rlm@46: rlm@46: 'expand', rlm@46: rlm@46: 'beforecollapse', rlm@46: rlm@46: 'beforeexpand', rlm@46: rlm@46: 'beforeclose', rlm@46: rlm@46: 'close', rlm@46: rlm@46: 'activate', rlm@46: rlm@46: 'deactivate' rlm@46: ); rlm@46: rlm@46: if(this.tbar){ rlm@46: this.elements += ',tbar'; rlm@46: if(typeof this.tbar == 'object'){ rlm@46: this.topToolbar = this.tbar; rlm@46: } rlm@46: delete this.tbar; rlm@46: } rlm@46: if(this.bbar){ rlm@46: this.elements += ',bbar'; rlm@46: if(typeof this.bbar == 'object'){ rlm@46: this.bottomToolbar = this.bbar; rlm@46: } rlm@46: delete this.bbar; rlm@46: } rlm@46: rlm@46: if(this.header === true){ rlm@46: this.elements += ',header'; rlm@46: delete this.header; rlm@46: }else if(this.title && this.header !== false){ rlm@46: this.elements += ',header'; rlm@46: } rlm@46: rlm@46: if(this.footer === true){ rlm@46: this.elements += ',footer'; rlm@46: delete this.footer; rlm@46: } rlm@46: rlm@46: if(this.buttons){ rlm@46: var btns = this.buttons; rlm@46: rlm@46: this.buttons = []; rlm@46: for(var i = 0, len = btns.length; i < len; i++) { rlm@46: if(btns[i].render){ this.buttons.push(btns[i]); rlm@46: }else{ rlm@46: this.addButton(btns[i]); rlm@46: } rlm@46: } rlm@46: } rlm@46: if(this.autoLoad){ rlm@46: this.on('render', this.doAutoLoad, this, {delay:10}); rlm@46: } rlm@46: }, rlm@46: rlm@46: createElement : function(name, pnode){ rlm@46: if(this[name]){ rlm@46: pnode.appendChild(this[name].dom); rlm@46: return; rlm@46: } rlm@46: rlm@46: if(name === 'bwrap' || this.elements.indexOf(name) != -1){ rlm@46: if(this[name+'Cfg']){ rlm@46: this[name] = Ext.fly(pnode).createChild(this[name+'Cfg']); rlm@46: }else{ rlm@46: var el = document.createElement('div'); rlm@46: el.className = this[name+'Cls']; rlm@46: this[name] = Ext.get(pnode.appendChild(el)); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.Panel.superclass.onRender.call(this, ct, position); rlm@46: rlm@46: this.createClasses(); rlm@46: rlm@46: if(this.el){ this.el.addClass(this.baseCls); rlm@46: this.header = this.el.down('.'+this.headerCls); rlm@46: this.bwrap = this.el.down('.'+this.bwrapCls); rlm@46: var cp = this.bwrap ? this.bwrap : this.el; rlm@46: this.tbar = cp.down('.'+this.tbarCls); rlm@46: this.body = cp.down('.'+this.bodyCls); rlm@46: this.bbar = cp.down('.'+this.bbarCls); rlm@46: this.footer = cp.down('.'+this.footerCls); rlm@46: this.fromMarkup = true; rlm@46: }else{ rlm@46: this.el = ct.createChild({ rlm@46: id: this.id, rlm@46: cls: this.baseCls rlm@46: }, position); rlm@46: } rlm@46: var el = this.el, d = el.dom; rlm@46: rlm@46: if(this.cls){ rlm@46: this.el.addClass(this.cls); rlm@46: } rlm@46: rlm@46: if(this.buttons){ rlm@46: this.elements += ',footer'; rlm@46: } rlm@46: rlm@46: rlm@46: if(this.frame){ rlm@46: el.insertHtml('afterBegin', String.format(Ext.Element.boxMarkup, this.baseCls)); rlm@46: rlm@46: this.createElement('header', d.firstChild.firstChild.firstChild); rlm@46: this.createElement('bwrap', d); rlm@46: rlm@46: var bw = this.bwrap.dom; rlm@46: var ml = d.childNodes[1], bl = d.childNodes[2]; rlm@46: bw.appendChild(ml); rlm@46: bw.appendChild(bl); rlm@46: rlm@46: var mc = bw.firstChild.firstChild.firstChild; rlm@46: this.createElement('tbar', mc); rlm@46: this.createElement('body', mc); rlm@46: this.createElement('bbar', mc); rlm@46: this.createElement('footer', bw.lastChild.firstChild.firstChild); rlm@46: rlm@46: if(!this.footer){ rlm@46: this.bwrap.dom.lastChild.className += ' x-panel-nofooter'; rlm@46: } rlm@46: }else{ rlm@46: this.createElement('header', d); rlm@46: this.createElement('bwrap', d); rlm@46: rlm@46: var bw = this.bwrap.dom; rlm@46: this.createElement('tbar', bw); rlm@46: this.createElement('body', bw); rlm@46: this.createElement('bbar', bw); rlm@46: this.createElement('footer', bw); rlm@46: rlm@46: if(!this.header){ rlm@46: this.body.addClass(this.bodyCls + '-noheader'); rlm@46: if(this.tbar){ rlm@46: this.tbar.addClass(this.tbarCls + '-noheader'); rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.border === false){ rlm@46: this.el.addClass(this.baseCls + '-noborder'); rlm@46: this.body.addClass(this.bodyCls + '-noborder'); rlm@46: if(this.header){ rlm@46: this.header.addClass(this.headerCls + '-noborder'); rlm@46: } rlm@46: if(this.footer){ rlm@46: this.footer.addClass(this.footerCls + '-noborder'); rlm@46: } rlm@46: if(this.tbar){ rlm@46: this.tbar.addClass(this.tbarCls + '-noborder'); rlm@46: } rlm@46: if(this.bbar){ rlm@46: this.bbar.addClass(this.bbarCls + '-noborder'); rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.bodyBorder === false){ rlm@46: this.body.addClass(this.bodyCls + '-noborder'); rlm@46: } rlm@46: rlm@46: if(this.bodyStyle){ rlm@46: this.body.applyStyles(this.bodyStyle); rlm@46: } rlm@46: rlm@46: this.bwrap.enableDisplayMode('block'); rlm@46: rlm@46: if(this.header){ rlm@46: this.header.unselectable(); rlm@46: rlm@46: if(this.headerAsText){ rlm@46: this.header.dom.innerHTML = rlm@46: ''+this.header.dom.innerHTML+''; rlm@46: rlm@46: if(this.iconCls){ rlm@46: this.setIconClass(this.iconCls); rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.floating){ rlm@46: this.makeFloating(this.floating); rlm@46: } rlm@46: rlm@46: if(this.collapsible){ rlm@46: this.tools = this.tools ? this.tools.slice(0) : []; rlm@46: if(!this.hideCollapseTool){ rlm@46: this.tools[this.collapseFirst?'unshift':'push']({ rlm@46: id: 'toggle', rlm@46: handler : this.toggleCollapse, rlm@46: scope: this rlm@46: }); rlm@46: } rlm@46: if(this.titleCollapse && this.header){ rlm@46: this.header.on('click', this.toggleCollapse, this); rlm@46: this.header.setStyle('cursor', 'pointer'); rlm@46: } rlm@46: } rlm@46: if(this.tools){ rlm@46: var ts = this.tools; rlm@46: this.tools = {}; rlm@46: this.addTool.apply(this, ts); rlm@46: }else{ rlm@46: this.tools = {}; rlm@46: } rlm@46: rlm@46: if(this.buttons && this.buttons.length > 0){ rlm@46: var tb = this.footer.createChild({cls:'x-panel-btns-ct', cn: { rlm@46: cls:"x-panel-btns x-panel-btns-"+this.buttonAlign, rlm@46: html:'
' rlm@46: }}, null, true); rlm@46: var tr = tb.getElementsByTagName('tr')[0]; rlm@46: for(var i = 0, len = this.buttons.length; i < len; i++) { rlm@46: var b = this.buttons[i]; rlm@46: var td = document.createElement('td'); rlm@46: td.className = 'x-panel-btn-td'; rlm@46: b.render(tr.appendChild(td)); rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.tbar && this.topToolbar){ rlm@46: if(Ext.isArray(this.topToolbar)){ rlm@46: this.topToolbar = new Ext.Toolbar(this.topToolbar); rlm@46: } rlm@46: this.topToolbar.render(this.tbar); rlm@46: this.topToolbar.ownerCt = this; rlm@46: } rlm@46: if(this.bbar && this.bottomToolbar){ rlm@46: if(Ext.isArray(this.bottomToolbar)){ rlm@46: this.bottomToolbar = new Ext.Toolbar(this.bottomToolbar); rlm@46: } rlm@46: this.bottomToolbar.render(this.bbar); rlm@46: this.bottomToolbar.ownerCt = this; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setIconClass : function(cls){ rlm@46: var old = this.iconCls; rlm@46: this.iconCls = cls; rlm@46: if(this.rendered && this.header){ rlm@46: if(this.frame){ rlm@46: this.header.addClass('x-panel-icon'); rlm@46: this.header.replaceClass(old, this.iconCls); rlm@46: }else{ rlm@46: var hd = this.header.dom; rlm@46: var img = hd.firstChild && String(hd.firstChild.tagName).toLowerCase() == 'img' ? hd.firstChild : null; rlm@46: if(img){ rlm@46: Ext.fly(img).replaceClass(old, this.iconCls); rlm@46: }else{ rlm@46: Ext.DomHelper.insertBefore(hd.firstChild, { rlm@46: tag:'img', src: Ext.BLANK_IMAGE_URL, cls:'x-panel-inline-icon '+this.iconCls rlm@46: }); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: makeFloating : function(cfg){ rlm@46: this.floating = true; rlm@46: this.el = new Ext.Layer( rlm@46: typeof cfg == 'object' ? cfg : { rlm@46: shadow: this.shadow !== undefined ? this.shadow : 'sides', rlm@46: shadowOffset: this.shadowOffset, rlm@46: constrain:false, rlm@46: shim: this.shim === false ? false : undefined rlm@46: }, this.el rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: getTopToolbar : function(){ rlm@46: return this.topToolbar; rlm@46: }, rlm@46: rlm@46: rlm@46: getBottomToolbar : function(){ rlm@46: return this.bottomToolbar; rlm@46: }, rlm@46: rlm@46: rlm@46: addButton : function(config, handler, scope){ rlm@46: var bc = { rlm@46: handler: handler, rlm@46: scope: scope, rlm@46: minWidth: this.minButtonWidth, rlm@46: hideParent:true rlm@46: }; rlm@46: if(typeof config == "string"){ rlm@46: bc.text = config; rlm@46: }else{ rlm@46: Ext.apply(bc, config); rlm@46: } rlm@46: var btn = new Ext.Button(bc); rlm@46: btn.ownerCt = this; rlm@46: if(!this.buttons){ rlm@46: this.buttons = []; rlm@46: } rlm@46: this.buttons.push(btn); rlm@46: return btn; rlm@46: }, rlm@46: rlm@46: addTool : function(){ rlm@46: if(!this[this.toolTarget]) { return; rlm@46: } rlm@46: if(!this.toolTemplate){ rlm@46: var tt = new Ext.Template( rlm@46: '
 
' rlm@46: ); rlm@46: tt.disableFormats = true; rlm@46: tt.compile(); rlm@46: Ext.Panel.prototype.toolTemplate = tt; rlm@46: } rlm@46: for(var i = 0, a = arguments, len = a.length; i < len; i++) { rlm@46: var tc = a[i], overCls = 'x-tool-'+tc.id+'-over'; rlm@46: var t = this.toolTemplate.insertFirst((tc.align !== 'left') ? this[this.toolTarget] : this[this.toolTarget].child('span'), tc, true); rlm@46: this.tools[tc.id] = t; rlm@46: t.enableDisplayMode('block'); rlm@46: t.on('click', this.createToolHandler(t, tc, overCls, this)); rlm@46: if(tc.on){ rlm@46: t.on(tc.on); rlm@46: } rlm@46: if(tc.hidden){ rlm@46: t.hide(); rlm@46: } rlm@46: if(tc.qtip){ rlm@46: if(typeof tc.qtip == 'object'){ rlm@46: Ext.QuickTips.register(Ext.apply({ rlm@46: target: t.id rlm@46: }, tc.qtip)); rlm@46: } else { rlm@46: t.dom.qtip = tc.qtip; rlm@46: } rlm@46: } rlm@46: t.addClassOnOver(overCls); rlm@46: } rlm@46: }, rlm@46: rlm@46: onShow : function(){ rlm@46: if(this.floating){ rlm@46: return this.el.show(); rlm@46: } rlm@46: Ext.Panel.superclass.onShow.call(this); rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: if(this.floating){ rlm@46: return this.el.hide(); rlm@46: } rlm@46: Ext.Panel.superclass.onHide.call(this); rlm@46: }, rlm@46: rlm@46: createToolHandler : function(t, tc, overCls, panel){ rlm@46: return function(e){ rlm@46: t.removeClass(overCls); rlm@46: e.stopEvent(); rlm@46: if(tc.handler){ rlm@46: tc.handler.call(tc.scope || t, e, t, panel); rlm@46: } rlm@46: }; rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: if(this.fromMarkup && this.height === undefined && !this.autoHeight){ rlm@46: this.height = this.el.getHeight(); rlm@46: } rlm@46: if(this.floating && !this.hidden && !this.initHidden){ rlm@46: this.el.show(); rlm@46: } rlm@46: if(this.title){ rlm@46: this.setTitle(this.title); rlm@46: } rlm@46: this.setAutoScroll(); rlm@46: if(this.html){ rlm@46: this.body.update(typeof this.html == 'object' ? rlm@46: Ext.DomHelper.markup(this.html) : rlm@46: this.html); rlm@46: delete this.html; rlm@46: } rlm@46: if(this.contentEl){ rlm@46: var ce = Ext.getDom(this.contentEl); rlm@46: Ext.fly(ce).removeClass(['x-hidden', 'x-hide-display']); rlm@46: this.body.dom.appendChild(ce); rlm@46: } rlm@46: if(this.collapsed){ rlm@46: this.collapsed = false; rlm@46: this.collapse(false); rlm@46: } rlm@46: Ext.Panel.superclass.afterRender.call(this); this.initEvents(); rlm@46: }, rlm@46: rlm@46: setAutoScroll : function(){ rlm@46: if(this.rendered && this.autoScroll){ rlm@46: this.body.setOverflow('auto'); rlm@46: } rlm@46: }, rlm@46: rlm@46: getKeyMap : function(){ rlm@46: if(!this.keyMap){ rlm@46: this.keyMap = new Ext.KeyMap(this.el, this.keys); rlm@46: } rlm@46: return this.keyMap; rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: if(this.keys){ rlm@46: this.getKeyMap(); rlm@46: } rlm@46: if(this.draggable){ rlm@46: this.initDraggable(); rlm@46: } rlm@46: }, rlm@46: rlm@46: initDraggable : function(){ rlm@46: rlm@46: this.dd = new Ext.Panel.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable); rlm@46: }, rlm@46: rlm@46: beforeEffect : function(){ rlm@46: if(this.floating){ rlm@46: this.el.beforeAction(); rlm@46: } rlm@46: this.el.addClass('x-panel-animated'); rlm@46: }, rlm@46: rlm@46: afterEffect : function(){ rlm@46: this.syncShadow(); rlm@46: this.el.removeClass('x-panel-animated'); rlm@46: }, rlm@46: rlm@46: createEffect : function(a, cb, scope){ rlm@46: var o = { rlm@46: scope:scope, rlm@46: block:true rlm@46: }; rlm@46: if(a === true){ rlm@46: o.callback = cb; rlm@46: return o; rlm@46: }else if(!a.callback){ rlm@46: o.callback = cb; rlm@46: }else { o.callback = function(){ rlm@46: cb.call(scope); rlm@46: Ext.callback(a.callback, a.scope); rlm@46: }; rlm@46: } rlm@46: return Ext.applyIf(o, a); rlm@46: }, rlm@46: rlm@46: rlm@46: collapse : function(animate){ rlm@46: if(this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforecollapse', this, animate) === false){ rlm@46: return; rlm@46: } rlm@46: var doAnim = animate === true || (animate !== false && this.animCollapse); rlm@46: this.beforeEffect(); rlm@46: this.onCollapse(doAnim, animate); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onCollapse : function(doAnim, animArg){ rlm@46: if(doAnim){ rlm@46: this[this.collapseEl].slideOut(this.slideAnchor, rlm@46: Ext.apply(this.createEffect(animArg||true, this.afterCollapse, this), rlm@46: this.collapseDefaults)); rlm@46: }else{ rlm@46: this[this.collapseEl].hide(); rlm@46: this.afterCollapse(); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterCollapse : function(){ rlm@46: this.collapsed = true; rlm@46: this.el.addClass(this.collapsedCls); rlm@46: this.afterEffect(); rlm@46: this.fireEvent('collapse', this); rlm@46: }, rlm@46: rlm@46: rlm@46: expand : function(animate){ rlm@46: if(!this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforeexpand', this, animate) === false){ rlm@46: return; rlm@46: } rlm@46: var doAnim = animate === true || (animate !== false && this.animCollapse); rlm@46: this.el.removeClass(this.collapsedCls); rlm@46: this.beforeEffect(); rlm@46: this.onExpand(doAnim, animate); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onExpand : function(doAnim, animArg){ rlm@46: if(doAnim){ rlm@46: this[this.collapseEl].slideIn(this.slideAnchor, rlm@46: Ext.apply(this.createEffect(animArg||true, this.afterExpand, this), rlm@46: this.expandDefaults)); rlm@46: }else{ rlm@46: this[this.collapseEl].show(); rlm@46: this.afterExpand(); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterExpand : function(){ rlm@46: this.collapsed = false; rlm@46: this.afterEffect(); rlm@46: this.fireEvent('expand', this); rlm@46: }, rlm@46: rlm@46: rlm@46: toggleCollapse : function(animate){ rlm@46: this[this.collapsed ? 'expand' : 'collapse'](animate); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: onDisable : function(){ rlm@46: if(this.rendered && this.maskDisabled){ rlm@46: this.el.mask(); rlm@46: } rlm@46: Ext.Panel.superclass.onDisable.call(this); rlm@46: }, rlm@46: rlm@46: onEnable : function(){ rlm@46: if(this.rendered && this.maskDisabled){ rlm@46: this.el.unmask(); rlm@46: } rlm@46: Ext.Panel.superclass.onEnable.call(this); rlm@46: }, rlm@46: rlm@46: onResize : function(w, h){ rlm@46: if(w !== undefined || h !== undefined){ rlm@46: if(!this.collapsed){ rlm@46: if(typeof w == 'number'){ rlm@46: this.body.setWidth( rlm@46: this.adjustBodyWidth(w - this.getFrameWidth())); rlm@46: }else if(w == 'auto'){ rlm@46: this.body.setWidth(w); rlm@46: } rlm@46: rlm@46: if(typeof h == 'number'){ rlm@46: this.body.setHeight( rlm@46: this.adjustBodyHeight(h - this.getFrameHeight())); rlm@46: }else if(h == 'auto'){ rlm@46: this.body.setHeight(h); rlm@46: } rlm@46: }else{ rlm@46: this.queuedBodySize = {width: w, height: h}; rlm@46: if(!this.queuedExpand && this.allowQueuedExpand !== false){ rlm@46: this.queuedExpand = true; rlm@46: this.on('expand', function(){ rlm@46: delete this.queuedExpand; rlm@46: this.onResize(this.queuedBodySize.width, this.queuedBodySize.height); rlm@46: this.doLayout(); rlm@46: }, this, {single:true}); rlm@46: } rlm@46: } rlm@46: this.fireEvent('bodyresize', this, w, h); rlm@46: } rlm@46: this.syncShadow(); rlm@46: }, rlm@46: rlm@46: adjustBodyHeight : function(h){ rlm@46: return h; rlm@46: }, rlm@46: rlm@46: adjustBodyWidth : function(w){ rlm@46: return w; rlm@46: }, rlm@46: rlm@46: onPosition : function(){ rlm@46: this.syncShadow(); rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.tools){ rlm@46: for(var k in this.tools){ rlm@46: Ext.destroy(this.tools[k]); rlm@46: } rlm@46: } rlm@46: if(this.buttons){ rlm@46: for(var b in this.buttons){ rlm@46: Ext.destroy(this.buttons[b]); rlm@46: } rlm@46: } rlm@46: Ext.destroy( rlm@46: this.topToolbar, rlm@46: this.bottomToolbar rlm@46: ); rlm@46: Ext.Panel.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: rlm@46: getFrameWidth : function(){ rlm@46: var w = this.el.getFrameWidth('lr'); rlm@46: rlm@46: if(this.frame){ rlm@46: var l = this.bwrap.dom.firstChild; rlm@46: w += (Ext.fly(l).getFrameWidth('l') + Ext.fly(l.firstChild).getFrameWidth('r')); rlm@46: var mc = this.bwrap.dom.firstChild.firstChild.firstChild; rlm@46: w += Ext.fly(mc).getFrameWidth('lr'); rlm@46: } rlm@46: return w; rlm@46: }, rlm@46: rlm@46: rlm@46: getFrameHeight : function(){ rlm@46: var h = this.el.getFrameWidth('tb'); rlm@46: h += (this.tbar ? this.tbar.getHeight() : 0) + rlm@46: (this.bbar ? this.bbar.getHeight() : 0); rlm@46: rlm@46: if(this.frame){ rlm@46: var hd = this.el.dom.firstChild; rlm@46: var ft = this.bwrap.dom.lastChild; rlm@46: h += (hd.offsetHeight + ft.offsetHeight); rlm@46: var mc = this.bwrap.dom.firstChild.firstChild.firstChild; rlm@46: h += Ext.fly(mc).getFrameWidth('tb'); rlm@46: }else{ rlm@46: h += (this.header ? this.header.getHeight() : 0) + rlm@46: (this.footer ? this.footer.getHeight() : 0); rlm@46: } rlm@46: return h; rlm@46: }, rlm@46: rlm@46: rlm@46: getInnerWidth : function(){ rlm@46: return this.getSize().width - this.getFrameWidth(); rlm@46: }, rlm@46: rlm@46: rlm@46: getInnerHeight : function(){ rlm@46: return this.getSize().height - this.getFrameHeight(); rlm@46: }, rlm@46: rlm@46: syncShadow : function(){ rlm@46: if(this.floating){ rlm@46: this.el.sync(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: getLayoutTarget : function(){ rlm@46: return this.body; rlm@46: }, rlm@46: rlm@46: rlm@46: setTitle : function(title, iconCls){ rlm@46: this.title = title; rlm@46: if(this.header && this.headerAsText){ rlm@46: this.header.child('span').update(title); rlm@46: } rlm@46: if(iconCls){ rlm@46: this.setIconClass(iconCls); rlm@46: } rlm@46: this.fireEvent('titlechange', this, title); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getUpdater : function(){ rlm@46: return this.body.getUpdater(); rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(){ rlm@46: var um = this.body.getUpdater(); rlm@46: um.update.apply(um, arguments); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: beforeDestroy : function(){ rlm@46: Ext.Element.uncache( rlm@46: this.header, rlm@46: this.tbar, rlm@46: this.bbar, rlm@46: this.footer, rlm@46: this.body rlm@46: ); rlm@46: }, rlm@46: rlm@46: createClasses : function(){ rlm@46: this.headerCls = this.baseCls + '-header'; rlm@46: this.headerTextCls = this.baseCls + '-header-text'; rlm@46: this.bwrapCls = this.baseCls + '-bwrap'; rlm@46: this.tbarCls = this.baseCls + '-tbar'; rlm@46: this.bodyCls = this.baseCls + '-body'; rlm@46: this.bbarCls = this.baseCls + '-bbar'; rlm@46: this.footerCls = this.baseCls + '-footer'; rlm@46: }, rlm@46: rlm@46: createGhost : function(cls, useShim, appendTo){ rlm@46: var el = document.createElement('div'); rlm@46: el.className = 'x-panel-ghost ' + (cls ? cls : ''); rlm@46: if(this.header){ rlm@46: el.appendChild(this.el.dom.firstChild.cloneNode(true)); rlm@46: } rlm@46: Ext.fly(el.appendChild(document.createElement('ul'))).setHeight(this.bwrap.getHeight()); rlm@46: el.style.width = this.el.dom.offsetWidth + 'px';; rlm@46: if(!appendTo){ rlm@46: this.container.dom.appendChild(el); rlm@46: }else{ rlm@46: Ext.getDom(appendTo).appendChild(el); rlm@46: } rlm@46: if(useShim !== false && this.el.useShim !== false){ rlm@46: var layer = new Ext.Layer({shadow:false, useDisplay:true, constrain:false}, el); rlm@46: layer.show(); rlm@46: return layer; rlm@46: }else{ rlm@46: return new Ext.Element(el); rlm@46: } rlm@46: }, rlm@46: rlm@46: doAutoLoad : function(){ rlm@46: this.body.load( rlm@46: typeof this.autoLoad == 'object' ? rlm@46: this.autoLoad : {url: this.autoLoad}); rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('panel', Ext.Panel); rlm@46: rlm@46: rlm@46: Ext.Window = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: baseCls : 'x-window', rlm@46: rlm@46: resizable:true, rlm@46: rlm@46: draggable:true, rlm@46: rlm@46: closable : true, rlm@46: rlm@46: constrain:false, rlm@46: rlm@46: constrainHeader:false, rlm@46: rlm@46: plain:false, rlm@46: rlm@46: minimizable : false, rlm@46: rlm@46: maximizable : false, rlm@46: rlm@46: minHeight: 100, rlm@46: rlm@46: minWidth: 200, rlm@46: rlm@46: expandOnShow: true, rlm@46: rlm@46: closeAction: 'close', rlm@46: rlm@46: elements: 'header,body', rlm@46: rlm@46: collapsible:false, rlm@46: rlm@46: initHidden : true, rlm@46: rlm@46: monitorResize : true, rlm@46: rlm@46: frame:true, rlm@46: rlm@46: floating:true, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Window.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: rlm@46: rlm@46: 'resize', rlm@46: rlm@46: 'maximize', rlm@46: rlm@46: 'minimize', rlm@46: rlm@46: 'restore' rlm@46: ); rlm@46: }, rlm@46: rlm@46: getState : function(){ rlm@46: return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox()); rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.Window.superclass.onRender.call(this, ct, position); rlm@46: rlm@46: if(this.plain){ rlm@46: this.el.addClass('x-window-plain'); rlm@46: } rlm@46: rlm@46: this.focusEl = this.el.createChild({ rlm@46: tag: "a", href:"#", cls:"x-dlg-focus", rlm@46: tabIndex:"-1", html: " "}); rlm@46: this.focusEl.swallowEvent('click', true); rlm@46: rlm@46: this.proxy = this.el.createProxy("x-window-proxy"); rlm@46: this.proxy.enableDisplayMode('block'); rlm@46: rlm@46: if(this.modal){ rlm@46: this.mask = this.container.createChild({cls:"ext-el-mask"}, this.el.dom); rlm@46: this.mask.enableDisplayMode("block"); rlm@46: this.mask.hide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.Window.superclass.initEvents.call(this); rlm@46: if(this.animateTarget){ rlm@46: this.setAnimateTarget(this.animateTarget); rlm@46: } rlm@46: rlm@46: if(this.resizable){ rlm@46: this.resizer = new Ext.Resizable(this.el, { rlm@46: minWidth: this.minWidth, rlm@46: minHeight:this.minHeight, rlm@46: handles: this.resizeHandles || "all", rlm@46: pinned: true, rlm@46: resizeElement : this.resizerAction rlm@46: }); rlm@46: this.resizer.window = this; rlm@46: this.resizer.on("beforeresize", this.beforeResize, this); rlm@46: } rlm@46: rlm@46: if(this.draggable){ rlm@46: this.header.addClass("x-window-draggable"); rlm@46: } rlm@46: this.initTools(); rlm@46: rlm@46: this.el.on("mousedown", this.toFront, this); rlm@46: this.manager = this.manager || Ext.WindowMgr; rlm@46: this.manager.register(this); rlm@46: this.hidden = true; rlm@46: if(this.maximized){ rlm@46: this.maximized = false; rlm@46: this.maximize(); rlm@46: } rlm@46: if(this.closable){ rlm@46: var km = this.getKeyMap(); rlm@46: km.on(27, this.onEsc, this); rlm@46: km.disable(); rlm@46: } rlm@46: }, rlm@46: rlm@46: initDraggable : function(){ rlm@46: rlm@46: this.dd = new Ext.Window.DD(this); rlm@46: }, rlm@46: rlm@46: onEsc : function(){ rlm@46: this[this.closeAction](); rlm@46: }, rlm@46: rlm@46: beforeDestroy : function(){ rlm@46: Ext.destroy( rlm@46: this.resizer, rlm@46: this.dd, rlm@46: this.proxy, rlm@46: this.mask rlm@46: ); rlm@46: Ext.Window.superclass.beforeDestroy.call(this); rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.manager){ rlm@46: this.manager.unregister(this); rlm@46: } rlm@46: Ext.Window.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: initTools : function(){ rlm@46: if(this.minimizable){ rlm@46: this.addTool({ rlm@46: id: 'minimize', rlm@46: handler: this.minimize.createDelegate(this, []) rlm@46: }); rlm@46: } rlm@46: if(this.maximizable){ rlm@46: this.addTool({ rlm@46: id: 'maximize', rlm@46: handler: this.maximize.createDelegate(this, []) rlm@46: }); rlm@46: this.addTool({ rlm@46: id: 'restore', rlm@46: handler: this.restore.createDelegate(this, []), rlm@46: hidden:true rlm@46: }); rlm@46: this.header.on('dblclick', this.toggleMaximize, this); rlm@46: } rlm@46: if(this.closable){ rlm@46: this.addTool({ rlm@46: id: 'close', rlm@46: handler: this[this.closeAction].createDelegate(this, []) rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: resizerAction : function(){ rlm@46: var box = this.proxy.getBox(); rlm@46: this.proxy.hide(); rlm@46: this.window.handleResize(box); rlm@46: return box; rlm@46: }, rlm@46: rlm@46: beforeResize : function(){ rlm@46: this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40); rlm@46: this.resizeBox = this.el.getBox(); rlm@46: }, rlm@46: rlm@46: updateHandles : function(){ rlm@46: if(Ext.isIE && this.resizer){ rlm@46: this.resizer.syncHandleHeight(); rlm@46: this.el.repaint(); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleResize : function(box){ rlm@46: var rz = this.resizeBox; rlm@46: if(rz.x != box.x || rz.y != box.y){ rlm@46: this.updateBox(box); rlm@46: }else{ rlm@46: this.setSize(box); rlm@46: } rlm@46: this.focus(); rlm@46: this.updateHandles(); rlm@46: this.saveState(); rlm@46: this.fireEvent("resize", this, box.width, box.height); rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: var f = this.focusEl, db = this.defaultButton, t = typeof db; rlm@46: if(t != 'undefined'){ rlm@46: if(t == 'number'){ rlm@46: f = this.buttons[db]; rlm@46: }else if(t == 'string'){ rlm@46: f = Ext.getCmp(db); rlm@46: }else{ rlm@46: f = db; rlm@46: } rlm@46: } rlm@46: f.focus.defer(10, f); rlm@46: }, rlm@46: rlm@46: rlm@46: setAnimateTarget : function(el){ rlm@46: el = Ext.get(el); rlm@46: this.animateTarget = el; rlm@46: }, rlm@46: rlm@46: beforeShow : function(){ rlm@46: delete this.el.lastXY; rlm@46: delete this.el.lastLT; rlm@46: if(this.x === undefined || this.y === undefined){ rlm@46: var xy = this.el.getAlignToXY(this.container, 'c-c'); rlm@46: var pos = this.el.translatePoints(xy[0], xy[1]); rlm@46: this.x = this.x === undefined? pos.left : this.x; rlm@46: this.y = this.y === undefined? pos.top : this.y; rlm@46: } rlm@46: this.el.setLeftTop(this.x, this.y); rlm@46: rlm@46: if(this.expandOnShow){ rlm@46: this.expand(false); rlm@46: } rlm@46: rlm@46: if(this.modal){ rlm@46: Ext.getBody().addClass("x-body-masked"); rlm@46: this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true)); rlm@46: this.mask.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(animateTarget, cb, scope){ rlm@46: if(!this.rendered){ rlm@46: this.render(Ext.getBody()); rlm@46: } rlm@46: if(this.hidden === false){ rlm@46: this.toFront(); rlm@46: return; rlm@46: } rlm@46: if(this.fireEvent("beforeshow", this) === false){ rlm@46: return; rlm@46: } rlm@46: if(cb){ rlm@46: this.on('show', cb, scope, {single:true}); rlm@46: } rlm@46: this.hidden = false; rlm@46: if(animateTarget !== undefined){ rlm@46: this.setAnimateTarget(animateTarget); rlm@46: } rlm@46: this.beforeShow(); rlm@46: if(this.animateTarget){ rlm@46: this.animShow(); rlm@46: }else{ rlm@46: this.afterShow(); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterShow : function(){ rlm@46: this.proxy.hide(); rlm@46: this.el.setStyle('display', 'block'); rlm@46: this.el.show(); rlm@46: if(this.maximized){ rlm@46: this.fitContainer(); rlm@46: } rlm@46: if(Ext.isMac && Ext.isGecko){ this.cascade(this.setAutoScroll); rlm@46: } rlm@46: rlm@46: if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){ rlm@46: Ext.EventManager.onWindowResize(this.onWindowResize, this); rlm@46: } rlm@46: this.doConstrain(); rlm@46: if(this.layout){ rlm@46: this.doLayout(); rlm@46: } rlm@46: if(this.keyMap){ rlm@46: this.keyMap.enable(); rlm@46: } rlm@46: this.toFront(); rlm@46: this.updateHandles(); rlm@46: this.fireEvent("show", this); rlm@46: }, rlm@46: rlm@46: animShow : function(){ rlm@46: this.proxy.show(); rlm@46: this.proxy.setBox(this.animateTarget.getBox()); rlm@46: this.proxy.setOpacity(0); rlm@46: var b = this.getBox(false); rlm@46: b.callback = this.afterShow; rlm@46: b.scope = this; rlm@46: b.duration = .25; rlm@46: b.easing = 'easeNone'; rlm@46: b.opacity = .5; rlm@46: b.block = true; rlm@46: this.el.setStyle('display', 'none'); rlm@46: this.proxy.shift(b); rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(animateTarget, cb, scope){ rlm@46: if(this.hidden || this.fireEvent("beforehide", this) === false){ rlm@46: return; rlm@46: } rlm@46: if(cb){ rlm@46: this.on('hide', cb, scope, {single:true}); rlm@46: } rlm@46: this.hidden = true; rlm@46: if(animateTarget !== undefined){ rlm@46: this.setAnimateTarget(animateTarget); rlm@46: } rlm@46: if(this.animateTarget){ rlm@46: this.animHide(); rlm@46: }else{ rlm@46: this.el.hide(); rlm@46: this.afterHide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterHide : function(){ rlm@46: this.proxy.hide(); rlm@46: if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){ rlm@46: Ext.EventManager.removeResizeListener(this.onWindowResize, this); rlm@46: } rlm@46: if(this.modal){ rlm@46: this.mask.hide(); rlm@46: Ext.getBody().removeClass("x-body-masked"); rlm@46: } rlm@46: if(this.keyMap){ rlm@46: this.keyMap.disable(); rlm@46: } rlm@46: this.fireEvent("hide", this); rlm@46: }, rlm@46: rlm@46: animHide : function(){ rlm@46: this.proxy.setOpacity(.5); rlm@46: this.proxy.show(); rlm@46: var tb = this.getBox(false); rlm@46: this.proxy.setBox(tb); rlm@46: this.el.hide(); rlm@46: var b = this.animateTarget.getBox(); rlm@46: b.callback = this.afterHide; rlm@46: b.scope = this; rlm@46: b.duration = .25; rlm@46: b.easing = 'easeNone'; rlm@46: b.block = true; rlm@46: b.opacity = 0; rlm@46: this.proxy.shift(b); rlm@46: }, rlm@46: rlm@46: onWindowResize : function(){ rlm@46: if(this.maximized){ rlm@46: this.fitContainer(); rlm@46: } rlm@46: if(this.modal){ rlm@46: this.mask.setSize('100%', '100%'); rlm@46: var force = this.mask.dom.offsetHeight; rlm@46: this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true)); rlm@46: } rlm@46: this.doConstrain(); rlm@46: }, rlm@46: rlm@46: doConstrain : function(){ rlm@46: if(this.constrain || this.constrainHeader){ rlm@46: var offsets; rlm@46: if(this.constrain){ rlm@46: offsets = { rlm@46: right:this.el.shadowOffset, rlm@46: left:this.el.shadowOffset, rlm@46: bottom:this.el.shadowOffset rlm@46: }; rlm@46: }else { rlm@46: var s = this.getSize(); rlm@46: offsets = { rlm@46: right:-(s.width - 100), rlm@46: bottom:-(s.height - 25) rlm@46: }; rlm@46: } rlm@46: rlm@46: var xy = this.el.getConstrainToXY(this.container, true, offsets); rlm@46: if(xy){ rlm@46: this.setPosition(xy[0], xy[1]); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: ghost : function(cls){ rlm@46: var ghost = this.createGhost(cls); rlm@46: var box = this.getBox(true); rlm@46: ghost.setLeftTop(box.x, box.y); rlm@46: ghost.setWidth(box.width); rlm@46: this.el.hide(); rlm@46: this.activeGhost = ghost; rlm@46: return ghost; rlm@46: }, rlm@46: rlm@46: unghost : function(show, matchPosition){ rlm@46: if(show !== false){ rlm@46: this.el.show(); rlm@46: this.focus(); rlm@46: if(Ext.isMac && Ext.isGecko){ this.cascade(this.setAutoScroll); rlm@46: } rlm@46: } rlm@46: if(matchPosition !== false){ rlm@46: this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true)); rlm@46: } rlm@46: this.activeGhost.hide(); rlm@46: this.activeGhost.remove(); rlm@46: delete this.activeGhost; rlm@46: }, rlm@46: rlm@46: rlm@46: minimize : function(){ rlm@46: this.fireEvent('minimize', this); rlm@46: }, rlm@46: rlm@46: rlm@46: close : function(){ rlm@46: if(this.fireEvent("beforeclose", this) !== false){ rlm@46: this.hide(null, function(){ rlm@46: this.fireEvent('close', this); rlm@46: this.destroy(); rlm@46: }, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: maximize : function(){ rlm@46: if(!this.maximized){ rlm@46: this.expand(false); rlm@46: this.restoreSize = this.getSize(); rlm@46: this.restorePos = this.getPosition(true); rlm@46: if (this.maximizable){ rlm@46: this.tools.maximize.hide(); rlm@46: this.tools.restore.show(); rlm@46: } rlm@46: this.maximized = true; rlm@46: this.el.disableShadow(); rlm@46: rlm@46: if(this.dd){ rlm@46: this.dd.lock(); rlm@46: } rlm@46: if(this.collapsible){ rlm@46: this.tools.toggle.hide(); rlm@46: } rlm@46: this.el.addClass('x-window-maximized'); rlm@46: this.container.addClass('x-window-maximized-ct'); rlm@46: rlm@46: this.setPosition(0, 0); rlm@46: this.fitContainer(); rlm@46: this.fireEvent('maximize', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: restore : function(){ rlm@46: if(this.maximized){ rlm@46: this.el.removeClass('x-window-maximized'); rlm@46: this.tools.restore.hide(); rlm@46: this.tools.maximize.show(); rlm@46: this.setPosition(this.restorePos[0], this.restorePos[1]); rlm@46: this.setSize(this.restoreSize.width, this.restoreSize.height); rlm@46: delete this.restorePos; rlm@46: delete this.restoreSize; rlm@46: this.maximized = false; rlm@46: this.el.enableShadow(true); rlm@46: rlm@46: if(this.dd){ rlm@46: this.dd.unlock(); rlm@46: } rlm@46: if(this.collapsible){ rlm@46: this.tools.toggle.show(); rlm@46: } rlm@46: this.container.removeClass('x-window-maximized-ct'); rlm@46: rlm@46: this.doConstrain(); rlm@46: this.fireEvent('restore', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toggleMaximize : function(){ rlm@46: this[this.maximized ? 'restore' : 'maximize'](); rlm@46: }, rlm@46: rlm@46: fitContainer : function(){ rlm@46: var vs = this.container.getViewSize(); rlm@46: this.setSize(vs.width, vs.height); rlm@46: }, rlm@46: rlm@46: setZIndex : function(index){ rlm@46: if(this.modal){ rlm@46: this.mask.setStyle("z-index", index); rlm@46: } rlm@46: this.el.setZIndex(++index); rlm@46: index += 5; rlm@46: rlm@46: if(this.resizer){ rlm@46: this.resizer.proxy.setStyle("z-index", ++index); rlm@46: } rlm@46: rlm@46: this.lastZIndex = index; rlm@46: }, rlm@46: rlm@46: rlm@46: alignTo : function(element, position, offsets){ rlm@46: var xy = this.el.getAlignToXY(element, position, offsets); rlm@46: this.setPagePosition(xy[0], xy[1]); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: anchorTo : function(el, alignment, offsets, monitorScroll, _pname){ rlm@46: var action = function(){ rlm@46: this.alignTo(el, alignment, offsets); rlm@46: }; rlm@46: Ext.EventManager.onWindowResize(action, this); rlm@46: var tm = typeof monitorScroll; rlm@46: if(tm != 'undefined'){ rlm@46: Ext.EventManager.on(window, 'scroll', action, this, rlm@46: {buffer: tm == 'number' ? monitorScroll : 50}); rlm@46: } rlm@46: action.call(this); rlm@46: this[_pname] = action; rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: toFront : function(){ rlm@46: if(this.manager.bringToFront(this)){ rlm@46: this.focus(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setActive : function(active){ rlm@46: if(active){ rlm@46: if(!this.maximized){ rlm@46: this.el.enableShadow(true); rlm@46: } rlm@46: this.fireEvent('activate', this); rlm@46: }else{ rlm@46: this.el.disableShadow(); rlm@46: this.fireEvent('deactivate', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toBack : function(){ rlm@46: this.manager.sendToBack(this); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: center : function(){ rlm@46: var xy = this.el.getAlignToXY(this.container, 'c-c'); rlm@46: this.setPagePosition(xy[0], xy[1]); rlm@46: return this; rlm@46: } rlm@46: }); rlm@46: Ext.reg('window', Ext.Window); rlm@46: rlm@46: Ext.Window.DD = function(win){ rlm@46: this.win = win; rlm@46: Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id); rlm@46: this.setHandleElId(win.header.id); rlm@46: this.scroll = false; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Window.DD, Ext.dd.DD, { rlm@46: moveOnly:true, rlm@46: headerOffsets:[100, 25], rlm@46: startDrag : function(){ rlm@46: var w = this.win; rlm@46: this.proxy = w.ghost(); rlm@46: if(w.constrain !== false){ rlm@46: var so = w.el.shadowOffset; rlm@46: this.constrainTo(w.container, {right: so, left: so, bottom: so}); rlm@46: }else if(w.constrainHeader !== false){ rlm@46: var s = this.proxy.getSize(); rlm@46: this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])}); rlm@46: } rlm@46: }, rlm@46: b4Drag : Ext.emptyFn, rlm@46: rlm@46: onDrag : function(e){ rlm@46: this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY()); rlm@46: }, rlm@46: rlm@46: endDrag : function(e){ rlm@46: this.win.unghost(); rlm@46: this.win.saveState(); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.WindowGroup = function(){ rlm@46: var list = {}; rlm@46: var accessList = []; rlm@46: var front = null; rlm@46: rlm@46: var sortWindows = function(d1, d2){ rlm@46: return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1; rlm@46: }; rlm@46: rlm@46: var orderWindows = function(){ rlm@46: var a = accessList, len = a.length; rlm@46: if(len > 0){ rlm@46: a.sort(sortWindows); rlm@46: var seed = a[0].manager.zseed; rlm@46: for(var i = 0; i < len; i++){ rlm@46: var win = a[i]; rlm@46: if(win && !win.hidden){ rlm@46: win.setZIndex(seed + (i*10)); rlm@46: } rlm@46: } rlm@46: } rlm@46: activateLast(); rlm@46: }; rlm@46: rlm@46: var setActiveWin = function(win){ rlm@46: if(win != front){ rlm@46: if(front){ rlm@46: front.setActive(false); rlm@46: } rlm@46: front = win; rlm@46: if(win){ rlm@46: win.setActive(true); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: var activateLast = function(){ rlm@46: for(var i = accessList.length-1; i >=0; --i) { rlm@46: if(!accessList[i].hidden){ rlm@46: setActiveWin(accessList[i]); rlm@46: return; rlm@46: } rlm@46: } rlm@46: setActiveWin(null); rlm@46: }; rlm@46: rlm@46: return { rlm@46: rlm@46: zseed : 9000, rlm@46: rlm@46: register : function(win){ rlm@46: list[win.id] = win; rlm@46: accessList.push(win); rlm@46: win.on('hide', activateLast); rlm@46: }, rlm@46: rlm@46: unregister : function(win){ rlm@46: delete list[win.id]; rlm@46: win.un('hide', activateLast); rlm@46: accessList.remove(win); rlm@46: }, rlm@46: rlm@46: rlm@46: get : function(id){ rlm@46: return typeof id == "object" ? id : list[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: bringToFront : function(win){ rlm@46: win = this.get(win); rlm@46: if(win != front){ rlm@46: win._lastAccess = new Date().getTime(); rlm@46: orderWindows(); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: sendToBack : function(win){ rlm@46: win = this.get(win); rlm@46: win._lastAccess = -(new Date().getTime()); rlm@46: orderWindows(); rlm@46: return win; rlm@46: }, rlm@46: rlm@46: rlm@46: hideAll : function(){ rlm@46: for(var id in list){ rlm@46: if(list[id] && typeof list[id] != "function" && list[id].isVisible()){ rlm@46: list[id].hide(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getActive : function(){ rlm@46: return front; rlm@46: }, rlm@46: rlm@46: rlm@46: getBy : function(fn, scope){ rlm@46: var r = []; rlm@46: for(var i = accessList.length-1; i >=0; --i) { rlm@46: var win = accessList[i]; rlm@46: if(fn.call(scope||win, win) !== false){ rlm@46: r.push(win); rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: for(var id in list){ rlm@46: if(list[id] && typeof list[id] != "function"){ rlm@46: if(fn.call(scope || list[id], list[id]) === false){ rlm@46: return; rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: Ext.WindowMgr = new Ext.WindowGroup(); rlm@46: rlm@46: Ext.dd.PanelProxy = function(panel, config){ rlm@46: this.panel = panel; rlm@46: this.id = this.panel.id +'-ddproxy'; rlm@46: Ext.apply(this, config); rlm@46: }; rlm@46: rlm@46: Ext.dd.PanelProxy.prototype = { rlm@46: rlm@46: insertProxy : true, rlm@46: rlm@46: rlm@46: setStatus : Ext.emptyFn, rlm@46: reset : Ext.emptyFn, rlm@46: update : Ext.emptyFn, rlm@46: stop : Ext.emptyFn, rlm@46: sync: Ext.emptyFn, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.ghost; rlm@46: }, rlm@46: rlm@46: rlm@46: getGhost : function(){ rlm@46: return this.ghost; rlm@46: }, rlm@46: rlm@46: rlm@46: getProxy : function(){ rlm@46: return this.proxy; rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(){ rlm@46: if(this.ghost){ rlm@46: if(this.proxy){ rlm@46: this.proxy.remove(); rlm@46: delete this.proxy; rlm@46: } rlm@46: this.panel.el.dom.style.display = ''; rlm@46: this.ghost.remove(); rlm@46: delete this.ghost; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(){ rlm@46: if(!this.ghost){ rlm@46: this.ghost = this.panel.createGhost(undefined, undefined, Ext.getBody()); rlm@46: this.ghost.setXY(this.panel.el.getXY()) rlm@46: if(this.insertProxy){ rlm@46: this.proxy = this.panel.el.insertSibling({cls:'x-panel-dd-spacer'}); rlm@46: this.proxy.setSize(this.panel.getSize()); rlm@46: } rlm@46: this.panel.el.dom.style.display = 'none'; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: repair : function(xy, callback, scope){ rlm@46: this.hide(); rlm@46: if(typeof callback == "function"){ rlm@46: callback.call(scope || this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: moveProxy : function(parentNode, before){ rlm@46: if(this.proxy){ rlm@46: parentNode.insertBefore(this.proxy.dom, before); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.Panel.DD = function(panel, cfg){ rlm@46: this.panel = panel; rlm@46: this.dragData = {panel: panel}; rlm@46: this.proxy = new Ext.dd.PanelProxy(panel, cfg); rlm@46: Ext.Panel.DD.superclass.constructor.call(this, panel.el, cfg); rlm@46: var h = panel.header; rlm@46: if(h){ rlm@46: this.setHandleElId(h.id); rlm@46: } rlm@46: (h ? h : this.panel.body).setStyle('cursor', 'move'); rlm@46: this.scroll = false; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Panel.DD, Ext.dd.DragSource, { rlm@46: showFrame: Ext.emptyFn, rlm@46: startDrag: Ext.emptyFn, rlm@46: b4StartDrag: function(x, y) { rlm@46: this.proxy.show(); rlm@46: }, rlm@46: b4MouseDown: function(e) { rlm@46: var x = e.getPageX(); rlm@46: var y = e.getPageY(); rlm@46: this.autoOffset(x, y); rlm@46: }, rlm@46: onInitDrag : function(x, y){ rlm@46: this.onStartDrag(x, y); rlm@46: return true; rlm@46: }, rlm@46: createFrame : Ext.emptyFn, rlm@46: getDragEl : function(e){ rlm@46: return this.proxy.ghost.dom; rlm@46: }, rlm@46: endDrag : function(e){ rlm@46: this.proxy.hide(); rlm@46: this.panel.saveState(); rlm@46: }, rlm@46: rlm@46: autoOffset : function(x, y) { rlm@46: x -= this.startPageX; rlm@46: y -= this.startPageY; rlm@46: this.setDelta(x, y); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.state.Provider = function(){ rlm@46: rlm@46: this.addEvents("statechange"); rlm@46: this.state = {}; rlm@46: Ext.state.Provider.superclass.constructor.call(this); rlm@46: }; rlm@46: Ext.extend(Ext.state.Provider, Ext.util.Observable, { rlm@46: rlm@46: get : function(name, defaultValue){ rlm@46: return typeof this.state[name] == "undefined" ? rlm@46: defaultValue : this.state[name]; rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(name){ rlm@46: delete this.state[name]; rlm@46: this.fireEvent("statechange", this, name, null); rlm@46: }, rlm@46: rlm@46: rlm@46: set : function(name, value){ rlm@46: this.state[name] = value; rlm@46: this.fireEvent("statechange", this, name, value); rlm@46: }, rlm@46: rlm@46: rlm@46: decodeValue : function(cookie){ rlm@46: var re = /^(a|n|d|b|s|o)\:(.*)$/; rlm@46: var matches = re.exec(unescape(cookie)); rlm@46: if(!matches || !matches[1]) return; rlm@46: var type = matches[1]; rlm@46: var v = matches[2]; rlm@46: switch(type){ rlm@46: case "n": rlm@46: return parseFloat(v); rlm@46: case "d": rlm@46: return new Date(Date.parse(v)); rlm@46: case "b": rlm@46: return (v == "1"); rlm@46: case "a": rlm@46: var all = []; rlm@46: var values = v.split("^"); rlm@46: for(var i = 0, len = values.length; i < len; i++){ rlm@46: all.push(this.decodeValue(values[i])); rlm@46: } rlm@46: return all; rlm@46: case "o": rlm@46: var all = {}; rlm@46: var values = v.split("^"); rlm@46: for(var i = 0, len = values.length; i < len; i++){ rlm@46: var kv = values[i].split("="); rlm@46: all[kv[0]] = this.decodeValue(kv[1]); rlm@46: } rlm@46: return all; rlm@46: default: rlm@46: return v; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: encodeValue : function(v){ rlm@46: var enc; rlm@46: if(typeof v == "number"){ rlm@46: enc = "n:" + v; rlm@46: }else if(typeof v == "boolean"){ rlm@46: enc = "b:" + (v ? "1" : "0"); rlm@46: }else if(Ext.isDate(v)){ rlm@46: enc = "d:" + v.toGMTString(); rlm@46: }else if(Ext.isArray(v)){ rlm@46: var flat = ""; rlm@46: for(var i = 0, len = v.length; i < len; i++){ rlm@46: flat += this.encodeValue(v[i]); rlm@46: if(i != len-1) flat += "^"; rlm@46: } rlm@46: enc = "a:" + flat; rlm@46: }else if(typeof v == "object"){ rlm@46: var flat = ""; rlm@46: for(var key in v){ rlm@46: if(typeof v[key] != "function" && v[key] !== undefined){ rlm@46: flat += key + "=" + this.encodeValue(v[key]) + "^"; rlm@46: } rlm@46: } rlm@46: enc = "o:" + flat.substring(0, flat.length-1); rlm@46: }else{ rlm@46: enc = "s:" + v; rlm@46: } rlm@46: return escape(enc); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.state.Manager = function(){ rlm@46: var provider = new Ext.state.Provider(); rlm@46: rlm@46: return { rlm@46: rlm@46: setProvider : function(stateProvider){ rlm@46: provider = stateProvider; rlm@46: }, rlm@46: rlm@46: rlm@46: get : function(key, defaultValue){ rlm@46: return provider.get(key, defaultValue); rlm@46: }, rlm@46: rlm@46: rlm@46: set : function(key, value){ rlm@46: provider.set(key, value); rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(key){ rlm@46: provider.clear(key); rlm@46: }, rlm@46: rlm@46: rlm@46: getProvider : function(){ rlm@46: return provider; rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.state.CookieProvider = function(config){ rlm@46: Ext.state.CookieProvider.superclass.constructor.call(this); rlm@46: this.path = "/"; rlm@46: this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); rlm@46: this.domain = null; rlm@46: this.secure = false; rlm@46: Ext.apply(this, config); rlm@46: this.state = this.readCookies(); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.state.CookieProvider, Ext.state.Provider, { rlm@46: rlm@46: set : function(name, value){ rlm@46: if(typeof value == "undefined" || value === null){ rlm@46: this.clear(name); rlm@46: return; rlm@46: } rlm@46: this.setCookie(name, value); rlm@46: Ext.state.CookieProvider.superclass.set.call(this, name, value); rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(name){ rlm@46: this.clearCookie(name); rlm@46: Ext.state.CookieProvider.superclass.clear.call(this, name); rlm@46: }, rlm@46: rlm@46: rlm@46: readCookies : function(){ rlm@46: var cookies = {}; rlm@46: var c = document.cookie + ";"; rlm@46: var re = /\s?(.*?)=(.*?);/g; rlm@46: var matches; rlm@46: while((matches = re.exec(c)) != null){ rlm@46: var name = matches[1]; rlm@46: var value = matches[2]; rlm@46: if(name && name.substring(0,3) == "ys-"){ rlm@46: cookies[name.substr(3)] = this.decodeValue(value); rlm@46: } rlm@46: } rlm@46: return cookies; rlm@46: }, rlm@46: rlm@46: rlm@46: setCookie : function(name, value){ rlm@46: document.cookie = "ys-"+ name + "=" + this.encodeValue(value) + rlm@46: ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) + rlm@46: ((this.path == null) ? "" : ("; path=" + this.path)) + rlm@46: ((this.domain == null) ? "" : ("; domain=" + this.domain)) + rlm@46: ((this.secure == true) ? "; secure" : ""); rlm@46: }, rlm@46: rlm@46: rlm@46: clearCookie : function(name){ rlm@46: document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" + rlm@46: ((this.path == null) ? "" : ("; path=" + this.path)) + rlm@46: ((this.domain == null) ? "" : ("; domain=" + this.domain)) + rlm@46: ((this.secure == true) ? "; secure" : ""); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.DataView = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: selectedClass : "x-view-selected", rlm@46: rlm@46: emptyText : "", rlm@46: rlm@46: rlm@46: deferEmptyText: true, rlm@46: rlm@46: last: false, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.DataView.superclass.initComponent.call(this); rlm@46: if(typeof this.tpl == "string"){ rlm@46: this.tpl = new Ext.XTemplate(this.tpl); rlm@46: } rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "beforeclick", rlm@46: rlm@46: "click", rlm@46: rlm@46: "containerclick", rlm@46: rlm@46: "dblclick", rlm@46: rlm@46: "contextmenu", rlm@46: rlm@46: "selectionchange", rlm@46: rlm@46: rlm@46: "beforeselect" rlm@46: ); rlm@46: rlm@46: this.all = new Ext.CompositeElementLite(); rlm@46: this.selected = new Ext.CompositeElementLite(); rlm@46: }, rlm@46: rlm@46: onRender : function(){ rlm@46: if(!this.el){ rlm@46: this.el = document.createElement('div'); rlm@46: this.el.id = this.id; rlm@46: } rlm@46: Ext.DataView.superclass.onRender.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.DataView.superclass.afterRender.call(this); rlm@46: rlm@46: this.el.on({ rlm@46: "click": this.onClick, rlm@46: "dblclick": this.onDblClick, rlm@46: "contextmenu": this.onContextMenu, rlm@46: scope:this rlm@46: }); rlm@46: rlm@46: if(this.overClass){ rlm@46: this.el.on({ rlm@46: "mouseover": this.onMouseOver, rlm@46: "mouseout": this.onMouseOut, rlm@46: scope:this rlm@46: }); rlm@46: } rlm@46: rlm@46: if(this.store){ rlm@46: this.setStore(this.store, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: refresh : function(){ rlm@46: this.clearSelections(false, true); rlm@46: this.el.update(""); rlm@46: var html = []; rlm@46: var records = this.store.getRange(); rlm@46: if(records.length < 1){ rlm@46: if(!this.deferEmptyText || this.hasSkippedEmptyText){ rlm@46: this.el.update(this.emptyText); rlm@46: } rlm@46: this.hasSkippedEmptyText = true; rlm@46: this.all.clear(); rlm@46: return; rlm@46: } rlm@46: this.tpl.overwrite(this.el, this.collectData(records, 0)); rlm@46: this.all.fill(Ext.query(this.itemSelector, this.el.dom)); rlm@46: this.updateIndexes(0); rlm@46: }, rlm@46: rlm@46: rlm@46: prepareData : function(data){ rlm@46: return data; rlm@46: }, rlm@46: rlm@46: collectData : function(records, startIndex){ rlm@46: var r = []; rlm@46: for(var i = 0, len = records.length; i < len; i++){ rlm@46: r[r.length] = this.prepareData(records[i].data, startIndex+i, records[i]); rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: bufferRender : function(records){ rlm@46: var div = document.createElement('div'); rlm@46: this.tpl.overwrite(div, this.collectData(records)); rlm@46: return Ext.query(this.itemSelector, div); rlm@46: }, rlm@46: rlm@46: onUpdate : function(ds, record){ rlm@46: var index = this.store.indexOf(record); rlm@46: var sel = this.isSelected(index); rlm@46: var original = this.all.elements[index]; rlm@46: var node = this.bufferRender([record], index)[0]; rlm@46: rlm@46: this.all.replaceElement(index, node, true); rlm@46: if(sel){ rlm@46: this.selected.replaceElement(original, node); rlm@46: this.all.item(index).addClass(this.selectedClass); rlm@46: } rlm@46: this.updateIndexes(index, index); rlm@46: }, rlm@46: rlm@46: onAdd : function(ds, records, index){ rlm@46: if(this.all.getCount() == 0){ rlm@46: this.refresh(); rlm@46: return; rlm@46: } rlm@46: var nodes = this.bufferRender(records, index), n, a = this.all.elements; rlm@46: if(index < this.all.getCount()){ rlm@46: n = this.all.item(index).insertSibling(nodes, 'before', true); rlm@46: a.splice.apply(a, [index, 0].concat(nodes)); rlm@46: }else{ rlm@46: n = this.all.last().insertSibling(nodes, 'after', true); rlm@46: a.push.apply(a, nodes); rlm@46: } rlm@46: this.updateIndexes(index); rlm@46: }, rlm@46: rlm@46: onRemove : function(ds, record, index){ rlm@46: this.deselect(index); rlm@46: this.all.removeElement(index, true); rlm@46: this.updateIndexes(index); rlm@46: }, rlm@46: rlm@46: rlm@46: refreshNode : function(index){ rlm@46: this.onUpdate(this.store, this.store.getAt(index)); rlm@46: }, rlm@46: rlm@46: updateIndexes : function(startIndex, endIndex){ rlm@46: var ns = this.all.elements; rlm@46: startIndex = startIndex || 0; rlm@46: endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1)); rlm@46: for(var i = startIndex; i <= endIndex; i++){ rlm@46: ns[i].viewIndex = i; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setStore : function(store, initial){ rlm@46: if(!initial && this.store){ rlm@46: this.store.un("beforeload", this.onBeforeLoad, this); rlm@46: this.store.un("datachanged", this.refresh, this); rlm@46: this.store.un("add", this.onAdd, this); rlm@46: this.store.un("remove", this.onRemove, this); rlm@46: this.store.un("update", this.onUpdate, this); rlm@46: this.store.un("clear", this.refresh, this); rlm@46: } rlm@46: if(store){ rlm@46: store = Ext.StoreMgr.lookup(store); rlm@46: store.on("beforeload", this.onBeforeLoad, this); rlm@46: store.on("datachanged", this.refresh, this); rlm@46: store.on("add", this.onAdd, this); rlm@46: store.on("remove", this.onRemove, this); rlm@46: store.on("update", this.onUpdate, this); rlm@46: store.on("clear", this.refresh, this); rlm@46: } rlm@46: this.store = store; rlm@46: if(store){ rlm@46: this.refresh(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: findItemFromChild : function(node){ rlm@46: return Ext.fly(node).findParent(this.itemSelector, this.el); rlm@46: }, rlm@46: rlm@46: onClick : function(e){ rlm@46: var item = e.getTarget(this.itemSelector, this.el); rlm@46: if(item){ rlm@46: var index = this.indexOf(item); rlm@46: if(this.onItemClick(item, index, e) !== false){ rlm@46: this.fireEvent("click", this, index, item, e); rlm@46: } rlm@46: }else{ rlm@46: if(this.fireEvent("containerclick", this, e) !== false){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onContextMenu : function(e){ rlm@46: var item = e.getTarget(this.itemSelector, this.el); rlm@46: if(item){ rlm@46: this.fireEvent("contextmenu", this, this.indexOf(item), item, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDblClick : function(e){ rlm@46: var item = e.getTarget(this.itemSelector, this.el); rlm@46: if(item){ rlm@46: this.fireEvent("dblclick", this, this.indexOf(item), item, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onMouseOver : function(e){ rlm@46: var item = e.getTarget(this.itemSelector, this.el); rlm@46: if(item && item !== this.lastItem){ rlm@46: this.lastItem = item; rlm@46: Ext.fly(item).addClass(this.overClass); rlm@46: } rlm@46: }, rlm@46: rlm@46: onMouseOut : function(e){ rlm@46: if(this.lastItem){ rlm@46: if(!e.within(this.lastItem, true)){ rlm@46: Ext.fly(this.lastItem).removeClass(this.overClass); rlm@46: delete this.lastItem; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onItemClick : function(item, index, e){ rlm@46: if(this.fireEvent("beforeclick", this, index, item, e) === false){ rlm@46: return false; rlm@46: } rlm@46: if(this.multiSelect){ rlm@46: this.doMultiSelection(item, index, e); rlm@46: e.preventDefault(); rlm@46: }else if(this.singleSelect){ rlm@46: this.doSingleSelection(item, index, e); rlm@46: e.preventDefault(); rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: doSingleSelection : function(item, index, e){ rlm@46: if(e.ctrlKey && this.isSelected(index)){ rlm@46: this.deselect(index); rlm@46: }else{ rlm@46: this.select(index, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: doMultiSelection : function(item, index, e){ rlm@46: if(e.shiftKey && this.last !== false){ rlm@46: var last = this.last; rlm@46: this.selectRange(last, index, e.ctrlKey); rlm@46: this.last = last; }else{ rlm@46: if((e.ctrlKey||this.simpleSelect) && this.isSelected(index)){ rlm@46: this.deselect(index); rlm@46: }else{ rlm@46: this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectionCount : function(){ rlm@46: return this.selected.getCount() rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedNodes : function(){ rlm@46: return this.selected.elements; rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedIndexes : function(){ rlm@46: var indexes = [], s = this.selected.elements; rlm@46: for(var i = 0, len = s.length; i < len; i++){ rlm@46: indexes.push(s[i].viewIndex); rlm@46: } rlm@46: return indexes; rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedRecords : function(){ rlm@46: var r = [], s = this.selected.elements; rlm@46: for(var i = 0, len = s.length; i < len; i++){ rlm@46: r[r.length] = this.store.getAt(s[i].viewIndex); rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: getRecords : function(nodes){ rlm@46: var r = [], s = nodes; rlm@46: for(var i = 0, len = s.length; i < len; i++){ rlm@46: r[r.length] = this.store.getAt(s[i].viewIndex); rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: getRecord : function(node){ rlm@46: return this.store.getAt(node.viewIndex); rlm@46: }, rlm@46: rlm@46: rlm@46: clearSelections : function(suppressEvent, skipUpdate){ rlm@46: if((this.multiSelect || this.singleSelect) && this.selected.getCount() > 0){ rlm@46: if(!skipUpdate){ rlm@46: this.selected.removeClass(this.selectedClass); rlm@46: } rlm@46: this.selected.clear(); rlm@46: this.last = false; rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent("selectionchange", this, this.selected.elements); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isSelected : function(node){ rlm@46: return this.selected.contains(this.getNode(node)); rlm@46: }, rlm@46: rlm@46: rlm@46: deselect : function(node){ rlm@46: if(this.isSelected(node)){ rlm@46: var node = this.getNode(node); rlm@46: this.selected.removeElement(node); rlm@46: if(this.last == node.viewIndex){ rlm@46: this.last = false; rlm@46: } rlm@46: Ext.fly(node).removeClass(this.selectedClass); rlm@46: this.fireEvent("selectionchange", this, this.selected.elements); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(nodeInfo, keepExisting, suppressEvent){ rlm@46: if(Ext.isArray(nodeInfo)){ rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(true); rlm@46: } rlm@46: for(var i = 0, len = nodeInfo.length; i < len; i++){ rlm@46: this.select(nodeInfo[i], true, true); rlm@46: } rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent("selectionchange", this, this.selected.elements); rlm@46: } rlm@46: } else{ rlm@46: var node = this.getNode(nodeInfo); rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(true); rlm@46: } rlm@46: if(node && !this.isSelected(node)){ rlm@46: if(this.fireEvent("beforeselect", this, node, this.selected.elements) !== false){ rlm@46: Ext.fly(node).addClass(this.selectedClass); rlm@46: this.selected.add(node); rlm@46: this.last = node.viewIndex; rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent("selectionchange", this, this.selected.elements); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectRange : function(start, end, keepExisting){ rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(true); rlm@46: } rlm@46: this.select(this.getNodes(start, end), true); rlm@46: }, rlm@46: rlm@46: rlm@46: getNode : function(nodeInfo){ rlm@46: if(typeof nodeInfo == "string"){ rlm@46: return document.getElementById(nodeInfo); rlm@46: }else if(typeof nodeInfo == "number"){ rlm@46: return this.all.elements[nodeInfo]; rlm@46: } rlm@46: return nodeInfo; rlm@46: }, rlm@46: rlm@46: rlm@46: getNodes : function(start, end){ rlm@46: var ns = this.all.elements; rlm@46: start = start || 0; rlm@46: end = typeof end == "undefined" ? ns.length - 1 : end; rlm@46: var nodes = [], i; rlm@46: if(start <= end){ rlm@46: for(i = start; i <= end; i++){ rlm@46: nodes.push(ns[i]); rlm@46: } rlm@46: } else{ rlm@46: for(i = start; i >= end; i--){ rlm@46: nodes.push(ns[i]); rlm@46: } rlm@46: } rlm@46: return nodes; rlm@46: }, rlm@46: rlm@46: rlm@46: indexOf : function(node){ rlm@46: node = this.getNode(node); rlm@46: if(typeof node.viewIndex == "number"){ rlm@46: return node.viewIndex; rlm@46: } rlm@46: return this.all.indexOf(node); rlm@46: }, rlm@46: rlm@46: onBeforeLoad : function(){ rlm@46: if(this.loadingText){ rlm@46: this.clearSelections(false, true); rlm@46: this.el.update('
'+this.loadingText+'
'); rlm@46: this.all.clear(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: Ext.DataView.superclass.onDestroy.call(this); rlm@46: this.setStore(null); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.reg('dataview', Ext.DataView); rlm@46: rlm@46: Ext.ColorPalette = function(config){ rlm@46: Ext.ColorPalette.superclass.constructor.call(this, config); rlm@46: this.addEvents( rlm@46: rlm@46: 'select' rlm@46: ); rlm@46: rlm@46: if(this.handler){ rlm@46: this.on("select", this.handler, this.scope, true); rlm@46: } rlm@46: }; rlm@46: Ext.extend(Ext.ColorPalette, Ext.Component, { rlm@46: rlm@46: rlm@46: itemCls : "x-color-palette", rlm@46: rlm@46: value : null, rlm@46: clickEvent:'click', rlm@46: ctype: "Ext.ColorPalette", rlm@46: rlm@46: rlm@46: allowReselect : false, rlm@46: rlm@46: rlm@46: colors : [ rlm@46: "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333", rlm@46: "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080", rlm@46: "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696", rlm@46: "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0", rlm@46: "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF" rlm@46: ], rlm@46: rlm@46: onRender : function(container, position){ rlm@46: var t = this.tpl || new Ext.XTemplate( rlm@46: ' ' rlm@46: ); rlm@46: var el = document.createElement("div"); rlm@46: el.className = this.itemCls; rlm@46: t.overwrite(el, this.colors); rlm@46: container.dom.insertBefore(el, position); rlm@46: this.el = Ext.get(el); rlm@46: this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"}); rlm@46: if(this.clickEvent != 'click'){ rlm@46: this.el.on('click', Ext.emptyFn, this, {delegate: "a", preventDefault:true}); rlm@46: } rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.ColorPalette.superclass.afterRender.call(this); rlm@46: if(this.value){ rlm@46: var s = this.value; rlm@46: this.value = null; rlm@46: this.select(s); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleClick : function(e, t){ rlm@46: e.preventDefault(); rlm@46: if(!this.disabled){ rlm@46: var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1]; rlm@46: this.select(c.toUpperCase()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(color){ rlm@46: color = color.replace("#", ""); rlm@46: if(color != this.value || this.allowReselect){ rlm@46: var el = this.el; rlm@46: if(this.value){ rlm@46: el.child("a.color-"+this.value).removeClass("x-color-palette-sel"); rlm@46: } rlm@46: el.child("a.color-"+color).addClass("x-color-palette-sel"); rlm@46: this.value = color; rlm@46: this.fireEvent("select", this, color); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('colorpalette', Ext.ColorPalette); rlm@46: rlm@46: Ext.DatePicker = Ext.extend(Ext.Component, { rlm@46: rlm@46: todayText : "Today", rlm@46: rlm@46: okText : " OK ", rlm@46: rlm@46: cancelText : "Cancel", rlm@46: rlm@46: todayTip : "{0} (Spacebar)", rlm@46: rlm@46: minDate : null, rlm@46: rlm@46: maxDate : null, rlm@46: rlm@46: minText : "This date is before the minimum date", rlm@46: rlm@46: maxText : "This date is after the maximum date", rlm@46: rlm@46: format : "m/d/y", rlm@46: rlm@46: disabledDays : null, rlm@46: rlm@46: disabledDaysText : "", rlm@46: rlm@46: disabledDatesRE : null, rlm@46: rlm@46: disabledDatesText : "", rlm@46: rlm@46: constrainToViewport : true, rlm@46: rlm@46: monthNames : Date.monthNames, rlm@46: rlm@46: dayNames : Date.dayNames, rlm@46: rlm@46: nextText: 'Next Month (Control+Right)', rlm@46: rlm@46: prevText: 'Previous Month (Control+Left)', rlm@46: rlm@46: monthYearText: 'Choose a month (Control+Up/Down to move years)', rlm@46: rlm@46: startDay : 0, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.DatePicker.superclass.initComponent.call(this); rlm@46: rlm@46: this.value = this.value ? rlm@46: this.value.clearTime() : new Date().clearTime(); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'select' rlm@46: ); rlm@46: rlm@46: if(this.handler){ rlm@46: this.on("select", this.handler, this.scope || this); rlm@46: } rlm@46: rlm@46: this.initDisabledDays(); rlm@46: }, rlm@46: rlm@46: rlm@46: initDisabledDays : function(){ rlm@46: if(!this.disabledDatesRE && this.disabledDates){ rlm@46: var dd = this.disabledDates; rlm@46: var re = "(?:"; rlm@46: for(var i = 0; i < dd.length; i++){ rlm@46: re += dd[i]; rlm@46: if(i != dd.length-1) re += "|"; rlm@46: } rlm@46: this.disabledDatesRE = new RegExp(re + ")"); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(value){ rlm@46: var old = this.value; rlm@46: this.value = value.clearTime(true); rlm@46: if(this.el){ rlm@46: this.update(this.value); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: return this.value; rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: if(this.el){ rlm@46: this.update(this.activeDate); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(container, position){ rlm@46: var m = [ rlm@46: '', rlm@46: '', rlm@46: '
  
']; rlm@46: var dn = this.dayNames; rlm@46: for(var i = 0; i < 7; i++){ rlm@46: var d = this.startDay+i; rlm@46: if(d > 6){ rlm@46: d = d-7; rlm@46: } rlm@46: m.push(""); rlm@46: } rlm@46: m[m.length] = ""; rlm@46: for(var i = 0; i < 42; i++) { rlm@46: if(i % 7 == 0 && i != 0){ rlm@46: m[m.length] = ""; rlm@46: } rlm@46: m[m.length] = ''; rlm@46: } rlm@46: m[m.length] = '
", dn[d].substr(0,1), "
'; rlm@46: rlm@46: var el = document.createElement("div"); rlm@46: el.className = "x-date-picker"; rlm@46: el.innerHTML = m.join(""); rlm@46: rlm@46: container.dom.insertBefore(el, position); rlm@46: rlm@46: this.el = Ext.get(el); rlm@46: this.eventEl = Ext.get(el.firstChild); rlm@46: rlm@46: new Ext.util.ClickRepeater(this.el.child("td.x-date-left a"), { rlm@46: handler: this.showPrevMonth, rlm@46: scope: this, rlm@46: preventDefault:true, rlm@46: stopDefault:true rlm@46: }); rlm@46: rlm@46: new Ext.util.ClickRepeater(this.el.child("td.x-date-right a"), { rlm@46: handler: this.showNextMonth, rlm@46: scope: this, rlm@46: preventDefault:true, rlm@46: stopDefault:true rlm@46: }); rlm@46: rlm@46: this.eventEl.on("mousewheel", this.handleMouseWheel, this); rlm@46: rlm@46: this.monthPicker = this.el.down('div.x-date-mp'); rlm@46: this.monthPicker.enableDisplayMode('block'); rlm@46: rlm@46: var kn = new Ext.KeyNav(this.eventEl, { rlm@46: "left" : function(e){ rlm@46: e.ctrlKey ? rlm@46: this.showPrevMonth() : rlm@46: this.update(this.activeDate.add("d", -1)); rlm@46: }, rlm@46: rlm@46: "right" : function(e){ rlm@46: e.ctrlKey ? rlm@46: this.showNextMonth() : rlm@46: this.update(this.activeDate.add("d", 1)); rlm@46: }, rlm@46: rlm@46: "up" : function(e){ rlm@46: e.ctrlKey ? rlm@46: this.showNextYear() : rlm@46: this.update(this.activeDate.add("d", -7)); rlm@46: }, rlm@46: rlm@46: "down" : function(e){ rlm@46: e.ctrlKey ? rlm@46: this.showPrevYear() : rlm@46: this.update(this.activeDate.add("d", 7)); rlm@46: }, rlm@46: rlm@46: "pageUp" : function(e){ rlm@46: this.showNextMonth(); rlm@46: }, rlm@46: rlm@46: "pageDown" : function(e){ rlm@46: this.showPrevMonth(); rlm@46: }, rlm@46: rlm@46: "enter" : function(e){ rlm@46: e.stopPropagation(); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: scope : this rlm@46: }); rlm@46: rlm@46: this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"}); rlm@46: rlm@46: this.eventEl.addKeyListener(Ext.EventObject.SPACE, this.selectToday, this); rlm@46: rlm@46: this.el.unselectable(); rlm@46: rlm@46: this.cells = this.el.select("table.x-date-inner tbody td"); rlm@46: this.textNodes = this.el.query("table.x-date-inner tbody span"); rlm@46: rlm@46: this.mbtn = new Ext.Button({ rlm@46: text: " ", rlm@46: tooltip: this.monthYearText, rlm@46: renderTo: this.el.child("td.x-date-middle", true) rlm@46: }); rlm@46: rlm@46: this.mbtn.on('click', this.showMonthPicker, this); rlm@46: this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu"); rlm@46: rlm@46: rlm@46: var today = (new Date()).dateFormat(this.format); rlm@46: this.todayBtn = new Ext.Button({ rlm@46: renderTo: this.el.child("td.x-date-bottom", true), rlm@46: text: String.format(this.todayText, today), rlm@46: tooltip: String.format(this.todayTip, today), rlm@46: handler: this.selectToday, rlm@46: scope: this rlm@46: }); rlm@46: rlm@46: if(Ext.isIE){ rlm@46: this.el.repaint(); rlm@46: } rlm@46: this.update(this.value); rlm@46: }, rlm@46: rlm@46: createMonthPicker : function(){ rlm@46: if(!this.monthPicker.dom.firstChild){ rlm@46: var buf = ['']; rlm@46: for(var i = 0; i < 6; i++){ rlm@46: buf.push( rlm@46: '', rlm@46: '', rlm@46: i == 0 ? rlm@46: '' : rlm@46: '' rlm@46: ); rlm@46: } rlm@46: buf.push( rlm@46: '', rlm@46: '
', this.monthNames[i].substr(0, 3), '', this.monthNames[i+6].substr(0, 3), '
' rlm@46: ); rlm@46: this.monthPicker.update(buf.join('')); rlm@46: this.monthPicker.on('click', this.onMonthClick, this); rlm@46: this.monthPicker.on('dblclick', this.onMonthDblClick, this); rlm@46: rlm@46: this.mpMonths = this.monthPicker.select('td.x-date-mp-month'); rlm@46: this.mpYears = this.monthPicker.select('td.x-date-mp-year'); rlm@46: rlm@46: this.mpMonths.each(function(m, a, i){ rlm@46: i += 1; rlm@46: if((i%2) == 0){ rlm@46: m.dom.xmonth = 5 + Math.round(i * .5); rlm@46: }else{ rlm@46: m.dom.xmonth = Math.round((i-1) * .5); rlm@46: } rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: showMonthPicker : function(){ rlm@46: this.createMonthPicker(); rlm@46: var size = this.el.getSize(); rlm@46: this.monthPicker.setSize(size); rlm@46: this.monthPicker.child('table').setSize(size); rlm@46: rlm@46: this.mpSelMonth = (this.activeDate || this.value).getMonth(); rlm@46: this.updateMPMonth(this.mpSelMonth); rlm@46: this.mpSelYear = (this.activeDate || this.value).getFullYear(); rlm@46: this.updateMPYear(this.mpSelYear); rlm@46: rlm@46: this.monthPicker.slideIn('t', {duration:.2}); rlm@46: }, rlm@46: rlm@46: updateMPYear : function(y){ rlm@46: this.mpyear = y; rlm@46: var ys = this.mpYears.elements; rlm@46: for(var i = 1; i <= 10; i++){ rlm@46: var td = ys[i-1], y2; rlm@46: if((i%2) == 0){ rlm@46: y2 = y + Math.round(i * .5); rlm@46: td.firstChild.innerHTML = y2; rlm@46: td.xyear = y2; rlm@46: }else{ rlm@46: y2 = y - (5-Math.round(i * .5)); rlm@46: td.firstChild.innerHTML = y2; rlm@46: td.xyear = y2; rlm@46: } rlm@46: this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel'); rlm@46: } rlm@46: }, rlm@46: rlm@46: updateMPMonth : function(sm){ rlm@46: this.mpMonths.each(function(m, a, i){ rlm@46: m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel'); rlm@46: }); rlm@46: }, rlm@46: rlm@46: selectMPMonth: function(m){ rlm@46: rlm@46: }, rlm@46: rlm@46: onMonthClick : function(e, t){ rlm@46: e.stopEvent(); rlm@46: var el = new Ext.Element(t), pn; rlm@46: if(el.is('button.x-date-mp-cancel')){ rlm@46: this.hideMonthPicker(); rlm@46: } rlm@46: else if(el.is('button.x-date-mp-ok')){ rlm@46: var d = new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()); rlm@46: if(d.getMonth() != this.mpSelMonth){ rlm@46: rlm@46: d = new Date(this.mpSelYear, this.mpSelMonth, 1).getLastDateOfMonth(); rlm@46: } rlm@46: this.update(d); rlm@46: this.hideMonthPicker(); rlm@46: } rlm@46: else if(pn = el.up('td.x-date-mp-month', 2)){ rlm@46: this.mpMonths.removeClass('x-date-mp-sel'); rlm@46: pn.addClass('x-date-mp-sel'); rlm@46: this.mpSelMonth = pn.dom.xmonth; rlm@46: } rlm@46: else if(pn = el.up('td.x-date-mp-year', 2)){ rlm@46: this.mpYears.removeClass('x-date-mp-sel'); rlm@46: pn.addClass('x-date-mp-sel'); rlm@46: this.mpSelYear = pn.dom.xyear; rlm@46: } rlm@46: else if(el.is('a.x-date-mp-prev')){ rlm@46: this.updateMPYear(this.mpyear-10); rlm@46: } rlm@46: else if(el.is('a.x-date-mp-next')){ rlm@46: this.updateMPYear(this.mpyear+10); rlm@46: } rlm@46: }, rlm@46: rlm@46: onMonthDblClick : function(e, t){ rlm@46: e.stopEvent(); rlm@46: var el = new Ext.Element(t), pn; rlm@46: if(pn = el.up('td.x-date-mp-month', 2)){ rlm@46: this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate())); rlm@46: this.hideMonthPicker(); rlm@46: } rlm@46: else if(pn = el.up('td.x-date-mp-year', 2)){ rlm@46: this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate())); rlm@46: this.hideMonthPicker(); rlm@46: } rlm@46: }, rlm@46: rlm@46: hideMonthPicker : function(disableAnim){ rlm@46: if(this.monthPicker){ rlm@46: if(disableAnim === true){ rlm@46: this.monthPicker.hide(); rlm@46: }else{ rlm@46: this.monthPicker.slideOut('t', {duration:.2}); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: showPrevMonth : function(e){ rlm@46: this.update(this.activeDate.add("mo", -1)); rlm@46: }, rlm@46: rlm@46: rlm@46: showNextMonth : function(e){ rlm@46: this.update(this.activeDate.add("mo", 1)); rlm@46: }, rlm@46: rlm@46: rlm@46: showPrevYear : function(){ rlm@46: this.update(this.activeDate.add("y", -1)); rlm@46: }, rlm@46: rlm@46: rlm@46: showNextYear : function(){ rlm@46: this.update(this.activeDate.add("y", 1)); rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseWheel : function(e){ rlm@46: var delta = e.getWheelDelta(); rlm@46: if(delta > 0){ rlm@46: this.showPrevMonth(); rlm@46: e.stopEvent(); rlm@46: } else if(delta < 0){ rlm@46: this.showNextMonth(); rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: handleDateClick : function(e, t){ rlm@46: e.stopEvent(); rlm@46: if(t.dateValue && !Ext.fly(t.parentNode).hasClass("x-date-disabled")){ rlm@46: this.setValue(new Date(t.dateValue)); rlm@46: this.fireEvent("select", this, this.value); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectToday : function(){ rlm@46: this.setValue(new Date().clearTime()); rlm@46: this.fireEvent("select", this, this.value); rlm@46: }, rlm@46: rlm@46: rlm@46: update : function(date){ rlm@46: var vd = this.activeDate; rlm@46: this.activeDate = date; rlm@46: if(vd && this.el){ rlm@46: var t = date.getTime(); rlm@46: if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){ rlm@46: this.cells.removeClass("x-date-selected"); rlm@46: this.cells.each(function(c){ rlm@46: if(c.dom.firstChild.dateValue == t){ rlm@46: c.addClass("x-date-selected"); rlm@46: setTimeout(function(){ rlm@46: try{c.dom.firstChild.focus();}catch(e){} rlm@46: }, 50); rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: return; rlm@46: } rlm@46: } rlm@46: var days = date.getDaysInMonth(); rlm@46: var firstOfMonth = date.getFirstDateOfMonth(); rlm@46: var startingPos = firstOfMonth.getDay()-this.startDay; rlm@46: rlm@46: if(startingPos <= this.startDay){ rlm@46: startingPos += 7; rlm@46: } rlm@46: rlm@46: var pm = date.add("mo", -1); rlm@46: var prevStart = pm.getDaysInMonth()-startingPos; rlm@46: rlm@46: var cells = this.cells.elements; rlm@46: var textEls = this.textNodes; rlm@46: days += startingPos; rlm@46: rlm@46: rlm@46: var day = 86400000; rlm@46: var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime(); rlm@46: var today = new Date().clearTime().getTime(); rlm@46: var sel = date.clearTime().getTime(); rlm@46: var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY; rlm@46: var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY; rlm@46: var ddMatch = this.disabledDatesRE; rlm@46: var ddText = this.disabledDatesText; rlm@46: var ddays = this.disabledDays ? this.disabledDays.join("") : false; rlm@46: var ddaysText = this.disabledDaysText; rlm@46: var format = this.format; rlm@46: rlm@46: var setCellClass = function(cal, cell){ rlm@46: cell.title = ""; rlm@46: var t = d.getTime(); rlm@46: cell.firstChild.dateValue = t; rlm@46: if(t == today){ rlm@46: cell.className += " x-date-today"; rlm@46: cell.title = cal.todayText; rlm@46: } rlm@46: if(t == sel){ rlm@46: cell.className += " x-date-selected"; rlm@46: setTimeout(function(){ rlm@46: try{cell.firstChild.focus();}catch(e){} rlm@46: }, 50); rlm@46: } rlm@46: rlm@46: if(t < min) { rlm@46: cell.className = " x-date-disabled"; rlm@46: cell.title = cal.minText; rlm@46: return; rlm@46: } rlm@46: if(t > max) { rlm@46: cell.className = " x-date-disabled"; rlm@46: cell.title = cal.maxText; rlm@46: return; rlm@46: } rlm@46: if(ddays){ rlm@46: if(ddays.indexOf(d.getDay()) != -1){ rlm@46: cell.title = ddaysText; rlm@46: cell.className = " x-date-disabled"; rlm@46: } rlm@46: } rlm@46: if(ddMatch && format){ rlm@46: var fvalue = d.dateFormat(format); rlm@46: if(ddMatch.test(fvalue)){ rlm@46: cell.title = ddText.replace("%0", fvalue); rlm@46: cell.className = " x-date-disabled"; rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: var i = 0; rlm@46: for(; i < startingPos; i++) { rlm@46: textEls[i].innerHTML = (++prevStart); rlm@46: d.setDate(d.getDate()+1); rlm@46: cells[i].className = "x-date-prevday"; rlm@46: setCellClass(this, cells[i]); rlm@46: } rlm@46: for(; i < days; i++){ rlm@46: intDay = i - startingPos + 1; rlm@46: textEls[i].innerHTML = (intDay); rlm@46: d.setDate(d.getDate()+1); rlm@46: cells[i].className = "x-date-active"; rlm@46: setCellClass(this, cells[i]); rlm@46: } rlm@46: var extraDays = 0; rlm@46: for(; i < 42; i++) { rlm@46: textEls[i].innerHTML = (++extraDays); rlm@46: d.setDate(d.getDate()+1); rlm@46: cells[i].className = "x-date-nextday"; rlm@46: setCellClass(this, cells[i]); rlm@46: } rlm@46: rlm@46: this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear()); rlm@46: rlm@46: if(!this.internalRender){ rlm@46: var main = this.el.dom.firstChild; rlm@46: var w = main.offsetWidth; rlm@46: this.el.setWidth(w + this.el.getBorderWidth("lr")); rlm@46: Ext.fly(main).setWidth(w); rlm@46: this.internalRender = true; rlm@46: rlm@46: rlm@46: rlm@46: if(Ext.isOpera && !this.secondPass){ rlm@46: main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px"; rlm@46: this.secondPass = true; rlm@46: this.update.defer(10, this, [date]); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDestroy : function() { rlm@46: if(this.rendered){ rlm@46: this.mbtn.destroy(); rlm@46: this.todayBtn.destroy(); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('datepicker', Ext.DatePicker); rlm@46: rlm@46: Ext.TabPanel = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: monitorResize : true, rlm@46: rlm@46: deferredRender : true, rlm@46: rlm@46: tabWidth: 120, rlm@46: rlm@46: minTabWidth: 30, rlm@46: rlm@46: resizeTabs:false, rlm@46: rlm@46: enableTabScroll: false, rlm@46: rlm@46: scrollIncrement : 0, rlm@46: rlm@46: scrollRepeatInterval : 400, rlm@46: rlm@46: scrollDuration : .35, rlm@46: rlm@46: animScroll : true, rlm@46: rlm@46: tabPosition: 'top', rlm@46: rlm@46: baseCls: 'x-tab-panel', rlm@46: rlm@46: autoTabs : false, rlm@46: rlm@46: autoTabSelector:'div.x-tab', rlm@46: rlm@46: activeTab : null, rlm@46: rlm@46: tabMargin : 2, rlm@46: rlm@46: plain: false, rlm@46: rlm@46: wheelIncrement : 20, rlm@46: rlm@46: rlm@46: idDelimiter : '__', rlm@46: rlm@46: itemCls : 'x-tab-item', rlm@46: rlm@46: elements: 'body', rlm@46: headerAsText: false, rlm@46: frame: false, rlm@46: hideBorders:true, rlm@46: rlm@46: initComponent : function(){ rlm@46: this.frame = false; rlm@46: Ext.TabPanel.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'beforetabchange', rlm@46: rlm@46: 'tabchange', rlm@46: rlm@46: 'contextmenu' rlm@46: ); rlm@46: this.setLayout(new Ext.layout.CardLayout({ rlm@46: deferredRender: this.deferredRender rlm@46: })); rlm@46: if(this.tabPosition == 'top'){ rlm@46: this.elements += ',header'; rlm@46: this.stripTarget = 'header'; rlm@46: }else { rlm@46: this.elements += ',footer'; rlm@46: this.stripTarget = 'footer'; rlm@46: } rlm@46: if(!this.stack){ rlm@46: this.stack = Ext.TabPanel.AccessStack(); rlm@46: } rlm@46: this.initItems(); rlm@46: }, rlm@46: rlm@46: render : function(){ rlm@46: Ext.TabPanel.superclass.render.apply(this, arguments); rlm@46: if(this.activeTab !== undefined){ rlm@46: var item = this.activeTab; rlm@46: delete this.activeTab; rlm@46: this.setActiveTab(item); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.TabPanel.superclass.onRender.call(this, ct, position); rlm@46: rlm@46: if(this.plain){ rlm@46: var pos = this.tabPosition == 'top' ? 'header' : 'footer'; rlm@46: this[pos].addClass('x-tab-panel-'+pos+'-plain'); rlm@46: } rlm@46: rlm@46: var st = this[this.stripTarget]; rlm@46: rlm@46: this.stripWrap = st.createChild({cls:'x-tab-strip-wrap', cn:{ rlm@46: tag:'ul', cls:'x-tab-strip x-tab-strip-'+this.tabPosition}}); rlm@46: this.stripSpacer = st.createChild({cls:'x-tab-strip-spacer'}); rlm@46: this.strip = new Ext.Element(this.stripWrap.dom.firstChild); rlm@46: rlm@46: this.edge = this.strip.createChild({tag:'li', cls:'x-tab-edge'}); rlm@46: this.strip.createChild({cls:'x-clear'}); rlm@46: rlm@46: this.body.addClass('x-tab-panel-body-'+this.tabPosition); rlm@46: rlm@46: if(!this.itemTpl){ rlm@46: var tt = new Ext.Template( rlm@46: '
  • ', rlm@46: '', rlm@46: '{text}', rlm@46: '
  • ' rlm@46: ); rlm@46: tt.disableFormats = true; rlm@46: tt.compile(); rlm@46: Ext.TabPanel.prototype.itemTpl = tt; rlm@46: } rlm@46: rlm@46: this.items.each(this.initTab, this); rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.TabPanel.superclass.afterRender.call(this); rlm@46: if(this.autoTabs){ rlm@46: this.readTabs(false); rlm@46: } rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.TabPanel.superclass.initEvents.call(this); rlm@46: this.on('add', this.onAdd, this); rlm@46: this.on('remove', this.onRemove, this); rlm@46: rlm@46: this.strip.on('mousedown', this.onStripMouseDown, this); rlm@46: this.strip.on('click', this.onStripClick, this); rlm@46: this.strip.on('contextmenu', this.onStripContextMenu, this); rlm@46: if(this.enableTabScroll){ rlm@46: this.strip.on('mousewheel', this.onWheel, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: findTargets : function(e){ rlm@46: var item = null; rlm@46: var itemEl = e.getTarget('li', this.strip); rlm@46: if(itemEl){ rlm@46: item = this.getComponent(itemEl.id.split(this.idDelimiter)[1]); rlm@46: if(item.disabled){ rlm@46: return { rlm@46: close : null, rlm@46: item : null, rlm@46: el : null rlm@46: }; rlm@46: } rlm@46: } rlm@46: return { rlm@46: close : e.getTarget('.x-tab-strip-close', this.strip), rlm@46: item : item, rlm@46: el : itemEl rlm@46: }; rlm@46: }, rlm@46: rlm@46: onStripMouseDown : function(e){ rlm@46: e.preventDefault(); rlm@46: if(e.button != 0){ rlm@46: return; rlm@46: } rlm@46: var t = this.findTargets(e); rlm@46: if(t.close){ rlm@46: this.remove(t.item); rlm@46: return; rlm@46: } rlm@46: if(t.item && t.item != this.activeTab){ rlm@46: this.setActiveTab(t.item); rlm@46: } rlm@46: }, rlm@46: rlm@46: onStripClick : function(e){ rlm@46: var t = this.findTargets(e); rlm@46: if(!t.close && t.item && t.item != this.activeTab){ rlm@46: this.setActiveTab(t.item); rlm@46: } rlm@46: }, rlm@46: rlm@46: onStripContextMenu : function(e){ rlm@46: e.preventDefault(); rlm@46: var t = this.findTargets(e); rlm@46: if(t.item){ rlm@46: this.fireEvent('contextmenu', this, t.item, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: readTabs : function(removeExisting){ rlm@46: if(removeExisting === true){ rlm@46: this.items.each(function(item){ rlm@46: this.remove(item); rlm@46: }, this); rlm@46: } rlm@46: var tabs = this.el.query(this.autoTabSelector); rlm@46: for(var i = 0, len = tabs.length; i < len; i++){ rlm@46: var tab = tabs[i]; rlm@46: var title = tab.getAttribute('title'); rlm@46: tab.removeAttribute('title'); rlm@46: this.add({ rlm@46: title: title, rlm@46: el: tab rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: initTab : function(item, index){ rlm@46: var before = this.strip.dom.childNodes[index]; rlm@46: var cls = item.closable ? 'x-tab-strip-closable' : ''; rlm@46: if(item.disabled){ rlm@46: cls += ' x-item-disabled'; rlm@46: } rlm@46: if(item.iconCls){ rlm@46: cls += ' x-tab-with-icon'; rlm@46: } rlm@46: if(item.tabCls){ rlm@46: cls += ' ' + item.tabCls; rlm@46: } rlm@46: rlm@46: var p = { rlm@46: id: this.id + this.idDelimiter + item.getItemId(), rlm@46: text: item.title, rlm@46: cls: cls, rlm@46: iconCls: item.iconCls || '' rlm@46: }; rlm@46: var el = before ? rlm@46: this.itemTpl.insertBefore(before, p) : rlm@46: this.itemTpl.append(this.strip, p); rlm@46: rlm@46: Ext.fly(el).addClassOnOver('x-tab-strip-over'); rlm@46: rlm@46: if(item.tabTip){ rlm@46: Ext.fly(el).child('span.x-tab-strip-text', true).qtip = item.tabTip; rlm@46: } rlm@46: item.on('disable', this.onItemDisabled, this); rlm@46: item.on('enable', this.onItemEnabled, this); rlm@46: item.on('titlechange', this.onItemTitleChanged, this); rlm@46: item.on('beforeshow', this.onBeforeShowItem, this); rlm@46: }, rlm@46: rlm@46: onAdd : function(tp, item, index){ rlm@46: this.initTab(item, index); rlm@46: if(this.items.getCount() == 1){ rlm@46: this.syncSize(); rlm@46: } rlm@46: this.delegateUpdates(); rlm@46: }, rlm@46: rlm@46: onBeforeAdd : function(item){ rlm@46: var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item); rlm@46: if(existing){ rlm@46: this.setActiveTab(item); rlm@46: return false; rlm@46: } rlm@46: Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments); rlm@46: var es = item.elements; rlm@46: item.elements = es ? es.replace(',header', '') : es; rlm@46: item.border = (item.border === true); rlm@46: }, rlm@46: rlm@46: onRemove : function(tp, item){ rlm@46: Ext.removeNode(this.getTabEl(item)); rlm@46: this.stack.remove(item); rlm@46: item.un('disable', this.onItemDisabled, this); rlm@46: item.un('enable', this.onItemEnabled, this); rlm@46: item.un('titlechange', this.onItemTitleChanged, this); rlm@46: item.un('beforeshow', this.onBeforeShowItem, this); rlm@46: if(item == this.activeTab){ rlm@46: var next = this.stack.next(); rlm@46: if(next){ rlm@46: this.setActiveTab(next); rlm@46: }else{ rlm@46: this.setActiveTab(0); rlm@46: } rlm@46: } rlm@46: this.delegateUpdates(); rlm@46: }, rlm@46: rlm@46: onBeforeShowItem : function(item){ rlm@46: if(item != this.activeTab){ rlm@46: this.setActiveTab(item); rlm@46: return false; rlm@46: } rlm@46: }, rlm@46: rlm@46: onItemDisabled : function(item){ rlm@46: var el = this.getTabEl(item); rlm@46: if(el){ rlm@46: Ext.fly(el).addClass('x-item-disabled'); rlm@46: } rlm@46: this.stack.remove(item); rlm@46: }, rlm@46: rlm@46: onItemEnabled : function(item){ rlm@46: var el = this.getTabEl(item); rlm@46: if(el){ rlm@46: Ext.fly(el).removeClass('x-item-disabled'); rlm@46: } rlm@46: }, rlm@46: rlm@46: onItemTitleChanged : function(item){ rlm@46: var el = this.getTabEl(item); rlm@46: if(el){ rlm@46: Ext.fly(el).child('span.x-tab-strip-text', true).innerHTML = item.title; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTabEl : function(item){ rlm@46: var itemId = (typeof item === 'number')?this.items.items[item].getItemId() : item.getItemId(); rlm@46: return document.getElementById(this.id+this.idDelimiter+itemId); rlm@46: }, rlm@46: rlm@46: onResize : function(){ rlm@46: Ext.TabPanel.superclass.onResize.apply(this, arguments); rlm@46: this.delegateUpdates(); rlm@46: }, rlm@46: rlm@46: rlm@46: beginUpdate : function(){ rlm@46: this.suspendUpdates = true; rlm@46: }, rlm@46: rlm@46: rlm@46: endUpdate : function(){ rlm@46: this.suspendUpdates = false; rlm@46: this.delegateUpdates(); rlm@46: }, rlm@46: rlm@46: rlm@46: hideTabStripItem : function(item){ rlm@46: item = this.getComponent(item); rlm@46: var el = this.getTabEl(item); rlm@46: if(el){ rlm@46: el.style.display = 'none'; rlm@46: this.delegateUpdates(); rlm@46: } rlm@46: this.stack.remove(item); rlm@46: }, rlm@46: rlm@46: rlm@46: unhideTabStripItem : function(item){ rlm@46: item = this.getComponent(item); rlm@46: var el = this.getTabEl(item); rlm@46: if(el){ rlm@46: el.style.display = ''; rlm@46: this.delegateUpdates(); rlm@46: } rlm@46: }, rlm@46: rlm@46: delegateUpdates : function(){ rlm@46: if(this.suspendUpdates){ rlm@46: return; rlm@46: } rlm@46: if(this.resizeTabs && this.rendered){ rlm@46: this.autoSizeTabs(); rlm@46: } rlm@46: if(this.enableTabScroll && this.rendered){ rlm@46: this.autoScrollTabs(); rlm@46: } rlm@46: }, rlm@46: rlm@46: autoSizeTabs : function(){ rlm@46: var count = this.items.length; rlm@46: var ce = this.tabPosition != 'bottom' ? 'header' : 'footer'; rlm@46: var ow = this[ce].dom.offsetWidth; rlm@46: var aw = this[ce].dom.clientWidth; rlm@46: rlm@46: if(!this.resizeTabs || count < 1 || !aw){ return; rlm@46: } rlm@46: rlm@46: var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.tabMargin, this.tabWidth), this.minTabWidth); this.lastTabWidth = each; rlm@46: var lis = this.stripWrap.dom.getElementsByTagName('li'); rlm@46: for(var i = 0, len = lis.length-1; i < len; i++) { var li = lis[i]; rlm@46: var inner = li.childNodes[1].firstChild.firstChild; rlm@46: var tw = li.offsetWidth; rlm@46: var iw = inner.offsetWidth; rlm@46: inner.style.width = (each - (tw-iw)) + 'px'; rlm@46: } rlm@46: }, rlm@46: rlm@46: adjustBodyWidth : function(w){ rlm@46: if(this.header){ rlm@46: this.header.setWidth(w); rlm@46: } rlm@46: if(this.footer){ rlm@46: this.footer.setWidth(w); rlm@46: } rlm@46: return w; rlm@46: }, rlm@46: rlm@46: rlm@46: setActiveTab : function(item){ rlm@46: item = this.getComponent(item); rlm@46: if(!item || this.fireEvent('beforetabchange', this, item, this.activeTab) === false){ rlm@46: return; rlm@46: } rlm@46: if(!this.rendered){ rlm@46: this.activeTab = item; rlm@46: return; rlm@46: } rlm@46: if(this.activeTab != item){ rlm@46: if(this.activeTab){ rlm@46: var oldEl = this.getTabEl(this.activeTab); rlm@46: if(oldEl){ rlm@46: Ext.fly(oldEl).removeClass('x-tab-strip-active'); rlm@46: } rlm@46: this.activeTab.fireEvent('deactivate', this.activeTab); rlm@46: } rlm@46: var el = this.getTabEl(item); rlm@46: Ext.fly(el).addClass('x-tab-strip-active'); rlm@46: this.activeTab = item; rlm@46: this.stack.add(item); rlm@46: rlm@46: this.layout.setActiveItem(item); rlm@46: if(this.layoutOnTabChange && item.doLayout){ rlm@46: item.doLayout(); rlm@46: } rlm@46: if(this.scrolling){ rlm@46: this.scrollToTab(item, this.animScroll); rlm@46: } rlm@46: rlm@46: item.fireEvent('activate', item); rlm@46: this.fireEvent('tabchange', this, item); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getActiveTab : function(){ rlm@46: return this.activeTab || null; rlm@46: }, rlm@46: rlm@46: rlm@46: getItem : function(item){ rlm@46: return this.getComponent(item); rlm@46: }, rlm@46: rlm@46: autoScrollTabs : function(){ rlm@46: var count = this.items.length; rlm@46: var ow = this.header.dom.offsetWidth; rlm@46: var tw = this.header.dom.clientWidth; rlm@46: rlm@46: var wrap = this.stripWrap; rlm@46: var wd = wrap.dom; rlm@46: var cw = wd.offsetWidth; rlm@46: var pos = this.getScrollPos(); rlm@46: var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos; rlm@46: rlm@46: if(!this.enableTabScroll || count < 1 || cw < 20){ return; rlm@46: } rlm@46: if(l <= tw){ rlm@46: wd.scrollLeft = 0; rlm@46: wrap.setWidth(tw); rlm@46: if(this.scrolling){ rlm@46: this.scrolling = false; rlm@46: this.header.removeClass('x-tab-scrolling'); rlm@46: this.scrollLeft.hide(); rlm@46: this.scrollRight.hide(); rlm@46: if(Ext.isAir){ rlm@46: wd.style.marginLeft = ''; rlm@46: wd.style.marginRight = ''; rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: if(!this.scrolling){ rlm@46: this.header.addClass('x-tab-scrolling'); rlm@46: if(Ext.isAir){ rlm@46: wd.style.marginLeft = '18px'; rlm@46: wd.style.marginRight = '18px'; rlm@46: } rlm@46: } rlm@46: tw -= wrap.getMargins('lr'); rlm@46: wrap.setWidth(tw > 20 ? tw : 20); rlm@46: if(!this.scrolling){ rlm@46: if(!this.scrollLeft){ rlm@46: this.createScrollers(); rlm@46: }else{ rlm@46: this.scrollLeft.show(); rlm@46: this.scrollRight.show(); rlm@46: } rlm@46: } rlm@46: this.scrolling = true; rlm@46: if(pos > (l-tw)){ wd.scrollLeft = l-tw; rlm@46: }else{ this.scrollToTab(this.activeTab, false); rlm@46: } rlm@46: this.updateScrollButtons(); rlm@46: } rlm@46: }, rlm@46: rlm@46: createScrollers : function(){ rlm@46: var h = this.stripWrap.dom.offsetHeight; rlm@46: rlm@46: var sl = this.header.insertFirst({ rlm@46: cls:'x-tab-scroller-left' rlm@46: }); rlm@46: sl.setHeight(h); rlm@46: sl.addClassOnOver('x-tab-scroller-left-over'); rlm@46: this.leftRepeater = new Ext.util.ClickRepeater(sl, { rlm@46: interval : this.scrollRepeatInterval, rlm@46: handler: this.onScrollLeft, rlm@46: scope: this rlm@46: }); rlm@46: this.scrollLeft = sl; rlm@46: rlm@46: var sr = this.header.insertFirst({ rlm@46: cls:'x-tab-scroller-right' rlm@46: }); rlm@46: sr.setHeight(h); rlm@46: sr.addClassOnOver('x-tab-scroller-right-over'); rlm@46: this.rightRepeater = new Ext.util.ClickRepeater(sr, { rlm@46: interval : this.scrollRepeatInterval, rlm@46: handler: this.onScrollRight, rlm@46: scope: this rlm@46: }); rlm@46: this.scrollRight = sr; rlm@46: }, rlm@46: rlm@46: getScrollWidth : function(){ rlm@46: return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos(); rlm@46: }, rlm@46: rlm@46: getScrollPos : function(){ rlm@46: return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0; rlm@46: }, rlm@46: rlm@46: getScrollArea : function(){ rlm@46: return parseInt(this.stripWrap.dom.clientWidth, 10) || 0; rlm@46: }, rlm@46: rlm@46: getScrollAnim : function(){ rlm@46: return {duration:this.scrollDuration, callback: this.updateScrollButtons, scope: this}; rlm@46: }, rlm@46: rlm@46: getScrollIncrement : function(){ rlm@46: return this.scrollIncrement || (this.resizeTabs ? this.lastTabWidth+2 : 100); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: scrollToTab : function(item, animate){ rlm@46: if(!item){ return; } rlm@46: var el = this.getTabEl(item); rlm@46: var pos = this.getScrollPos(), area = this.getScrollArea(); rlm@46: var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos; rlm@46: var right = left + el.offsetWidth; rlm@46: if(left < pos){ rlm@46: this.scrollTo(left, animate); rlm@46: }else if(right > (pos + area)){ rlm@46: this.scrollTo(right - area, animate); rlm@46: } rlm@46: }, rlm@46: rlm@46: scrollTo : function(pos, animate){ rlm@46: this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false); rlm@46: if(!animate){ rlm@46: this.updateScrollButtons(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onWheel : function(e){ rlm@46: var d = e.getWheelDelta()*this.wheelIncrement*-1; rlm@46: e.stopEvent(); rlm@46: rlm@46: var pos = this.getScrollPos(); rlm@46: var newpos = pos + d; rlm@46: var sw = this.getScrollWidth()-this.getScrollArea(); rlm@46: rlm@46: var s = Math.max(0, Math.min(sw, newpos)); rlm@46: if(s != pos){ rlm@46: this.scrollTo(s, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: onScrollRight : function(){ rlm@46: var sw = this.getScrollWidth()-this.getScrollArea(); rlm@46: var pos = this.getScrollPos(); rlm@46: var s = Math.min(sw, pos + this.getScrollIncrement()); rlm@46: if(s != pos){ rlm@46: this.scrollTo(s, this.animScroll); rlm@46: } rlm@46: }, rlm@46: rlm@46: onScrollLeft : function(){ rlm@46: var pos = this.getScrollPos(); rlm@46: var s = Math.max(0, pos - this.getScrollIncrement()); rlm@46: if(s != pos){ rlm@46: this.scrollTo(s, this.animScroll); rlm@46: } rlm@46: }, rlm@46: rlm@46: updateScrollButtons : function(){ rlm@46: var pos = this.getScrollPos(); rlm@46: this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('x-tab-scroller-left-disabled'); rlm@46: this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('x-tab-scroller-right-disabled'); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('tabpanel', Ext.TabPanel); rlm@46: rlm@46: rlm@46: Ext.TabPanel.prototype.activate = Ext.TabPanel.prototype.setActiveTab; rlm@46: rlm@46: Ext.TabPanel.AccessStack = function(){ rlm@46: var items = []; rlm@46: return { rlm@46: add : function(item){ rlm@46: items.push(item); rlm@46: if(items.length > 10){ rlm@46: items.shift(); rlm@46: } rlm@46: }, rlm@46: rlm@46: remove : function(item){ rlm@46: var s = []; rlm@46: for(var i = 0, len = items.length; i < len; i++) { rlm@46: if(items[i] != item){ rlm@46: s.push(items[i]); rlm@46: } rlm@46: } rlm@46: items = s; rlm@46: }, rlm@46: rlm@46: next : function(){ rlm@46: return items.pop(); rlm@46: } rlm@46: }; rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: Ext.Button = Ext.extend(Ext.Component, { rlm@46: rlm@46: hidden : false, rlm@46: rlm@46: disabled : false, rlm@46: rlm@46: pressed : false, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: enableToggle: false, rlm@46: rlm@46: rlm@46: rlm@46: menuAlign : "tl-bl?", rlm@46: rlm@46: rlm@46: rlm@46: type : 'button', rlm@46: rlm@46: menuClassTarget: 'tr', rlm@46: rlm@46: rlm@46: clickEvent : 'click', rlm@46: rlm@46: rlm@46: handleMouseEvents : true, rlm@46: rlm@46: rlm@46: tooltipType : 'qtip', rlm@46: rlm@46: buttonSelector : "button:first", rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Button.superclass.initComponent.call(this); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "click", rlm@46: rlm@46: "toggle", rlm@46: rlm@46: 'mouseover', rlm@46: rlm@46: 'mouseout', rlm@46: rlm@46: 'menushow', rlm@46: rlm@46: 'menuhide', rlm@46: rlm@46: 'menutriggerover', rlm@46: rlm@46: 'menutriggerout' rlm@46: ); rlm@46: if(this.menu){ rlm@46: this.menu = Ext.menu.MenuMgr.get(this.menu); rlm@46: } rlm@46: if(typeof this.toggleGroup === 'string'){ rlm@46: this.enableToggle = true; rlm@46: } rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: if(!this.template){ rlm@46: if(!Ext.Button.buttonTemplate){ rlm@46: Ext.Button.buttonTemplate = new Ext.Template( rlm@46: '', rlm@46: '', rlm@46: "
      
    "); rlm@46: } rlm@46: this.template = Ext.Button.buttonTemplate; rlm@46: } rlm@46: var btn, targs = [this.text || ' ', this.type]; rlm@46: rlm@46: if(position){ rlm@46: btn = this.template.insertBefore(position, targs, true); rlm@46: }else{ rlm@46: btn = this.template.append(ct, targs, true); rlm@46: } rlm@46: var btnEl = btn.child(this.buttonSelector); rlm@46: btnEl.on('focus', this.onFocus, this); rlm@46: btnEl.on('blur', this.onBlur, this); rlm@46: rlm@46: this.initButtonEl(btn, btnEl); rlm@46: rlm@46: if(this.menu){ rlm@46: this.el.child(this.menuClassTarget).addClass("x-btn-with-menu"); rlm@46: } rlm@46: Ext.ButtonToggleMgr.register(this); rlm@46: }, rlm@46: rlm@46: initButtonEl : function(btn, btnEl){ rlm@46: rlm@46: this.el = btn; rlm@46: btn.addClass("x-btn"); rlm@46: rlm@46: if(this.icon){ rlm@46: btnEl.setStyle('background-image', 'url(' +this.icon +')'); rlm@46: } rlm@46: if(this.iconCls){ rlm@46: btnEl.addClass(this.iconCls); rlm@46: if(!this.cls){ rlm@46: btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon'); rlm@46: } rlm@46: } rlm@46: if(this.tabIndex !== undefined){ rlm@46: btnEl.dom.tabIndex = this.tabIndex; rlm@46: } rlm@46: if(this.tooltip){ rlm@46: if(typeof this.tooltip == 'object'){ rlm@46: Ext.QuickTips.register(Ext.apply({ rlm@46: target: btnEl.id rlm@46: }, this.tooltip)); rlm@46: } else { rlm@46: btnEl.dom[this.tooltipType] = this.tooltip; rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.pressed){ rlm@46: this.el.addClass("x-btn-pressed"); rlm@46: } rlm@46: rlm@46: if(this.handleMouseEvents){ rlm@46: btn.on("mouseover", this.onMouseOver, this); rlm@46: btn.on("mousedown", this.onMouseDown, this); rlm@46: } rlm@46: rlm@46: if(this.menu){ rlm@46: this.menu.on("show", this.onMenuShow, this); rlm@46: this.menu.on("hide", this.onMenuHide, this); rlm@46: } rlm@46: rlm@46: if(this.id){ rlm@46: this.el.dom.id = this.el.id = this.id; rlm@46: } rlm@46: rlm@46: if(this.repeat){ rlm@46: var repeater = new Ext.util.ClickRepeater(btn, rlm@46: typeof this.repeat == "object" ? this.repeat : {} rlm@46: ); rlm@46: repeater.on("click", this.onClick, this); rlm@46: } rlm@46: rlm@46: btn.on(this.clickEvent, this.onClick, this); rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.Button.superclass.afterRender.call(this); rlm@46: if(Ext.isIE6){ rlm@46: this.autoWidth.defer(1, this); rlm@46: }else{ rlm@46: this.autoWidth(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setIconClass : function(cls){ rlm@46: if(this.el){ rlm@46: this.el.child(this.buttonSelector).replaceClass(this.iconCls, cls); rlm@46: } rlm@46: this.iconCls = cls; rlm@46: }, rlm@46: rlm@46: beforeDestroy: function(){ rlm@46: if(this.rendered){ rlm@46: var btn = this.el.child(this.buttonSelector); rlm@46: if(btn){ rlm@46: btn.removeAllListeners(); rlm@46: } rlm@46: } rlm@46: if(this.menu){ rlm@46: Ext.destroy(this.menu); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.rendered){ rlm@46: Ext.ButtonToggleMgr.unregister(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: autoWidth : function(){ rlm@46: if(this.el){ rlm@46: this.el.setWidth("auto"); rlm@46: if(Ext.isIE7 && Ext.isStrict){ rlm@46: var ib = this.el.child(this.buttonSelector); rlm@46: if(ib && ib.getWidth() > 20){ rlm@46: ib.clip(); rlm@46: ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr')); rlm@46: } rlm@46: } rlm@46: if(this.minWidth){ rlm@46: if(this.el.getWidth() < this.minWidth){ rlm@46: this.el.setWidth(this.minWidth); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setHandler : function(handler, scope){ rlm@46: this.handler = handler; rlm@46: this.scope = scope; rlm@46: }, rlm@46: rlm@46: rlm@46: setText : function(text){ rlm@46: this.text = text; rlm@46: if(this.el){ rlm@46: this.el.child("td.x-btn-center " + this.buttonSelector).update(text); rlm@46: } rlm@46: this.autoWidth(); rlm@46: }, rlm@46: rlm@46: rlm@46: getText : function(){ rlm@46: return this.text; rlm@46: }, rlm@46: rlm@46: rlm@46: toggle : function(state){ rlm@46: state = state === undefined ? !this.pressed : state; rlm@46: if(state != this.pressed){ rlm@46: if(state){ rlm@46: this.el.addClass("x-btn-pressed"); rlm@46: this.pressed = true; rlm@46: this.fireEvent("toggle", this, true); rlm@46: }else{ rlm@46: this.el.removeClass("x-btn-pressed"); rlm@46: this.pressed = false; rlm@46: this.fireEvent("toggle", this, false); rlm@46: } rlm@46: if(this.toggleHandler){ rlm@46: this.toggleHandler.call(this.scope || this, this, state); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: this.el.child(this.buttonSelector).focus(); rlm@46: }, rlm@46: rlm@46: onDisable : function(){ rlm@46: if(this.el){ rlm@46: if(!Ext.isIE6 || !this.text){ rlm@46: this.el.addClass(this.disabledClass); rlm@46: } rlm@46: this.el.dom.disabled = true; rlm@46: } rlm@46: this.disabled = true; rlm@46: }, rlm@46: rlm@46: onEnable : function(){ rlm@46: if(this.el){ rlm@46: if(!Ext.isIE6 || !this.text){ rlm@46: this.el.removeClass(this.disabledClass); rlm@46: } rlm@46: this.el.dom.disabled = false; rlm@46: } rlm@46: this.disabled = false; rlm@46: }, rlm@46: rlm@46: rlm@46: showMenu : function(){ rlm@46: if(this.menu){ rlm@46: this.menu.show(this.el, this.menuAlign); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: hideMenu : function(){ rlm@46: if(this.menu){ rlm@46: this.menu.hide(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: hasVisibleMenu : function(){ rlm@46: return this.menu && this.menu.isVisible(); rlm@46: }, rlm@46: rlm@46: onClick : function(e){ rlm@46: if(e){ rlm@46: e.preventDefault(); rlm@46: } rlm@46: if(e.button != 0){ rlm@46: return; rlm@46: } rlm@46: if(!this.disabled){ rlm@46: if(this.enableToggle && (this.allowDepress !== false || !this.pressed)){ rlm@46: this.toggle(); rlm@46: } rlm@46: if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){ rlm@46: this.showMenu(); rlm@46: } rlm@46: this.fireEvent("click", this, e); rlm@46: if(this.handler){ rlm@46: this.handler.call(this.scope || this, this, e); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: isMenuTriggerOver : function(e, internal){ rlm@46: return this.menu && !internal; rlm@46: }, rlm@46: rlm@46: isMenuTriggerOut : function(e, internal){ rlm@46: return this.menu && !internal; rlm@46: }, rlm@46: rlm@46: onMouseOver : function(e){ rlm@46: if(!this.disabled){ rlm@46: var internal = e.within(this.el, true); rlm@46: if(!internal){ rlm@46: this.el.addClass("x-btn-over"); rlm@46: Ext.getDoc().on('mouseover', this.monitorMouseOver, this); rlm@46: this.fireEvent('mouseover', this, e); rlm@46: } rlm@46: if(this.isMenuTriggerOver(e, internal)){ rlm@46: this.fireEvent('menutriggerover', this, this.menu, e); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: monitorMouseOver : function(e){ rlm@46: if(e.target != this.el.dom && !e.within(this.el)){ rlm@46: Ext.getDoc().un('mouseover', this.monitorMouseOver, this); rlm@46: this.onMouseOut(e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onMouseOut : function(e){ rlm@46: var internal = e.within(this.el) && e.target != this.el.dom; rlm@46: this.el.removeClass("x-btn-over"); rlm@46: this.fireEvent('mouseout', this, e); rlm@46: if(this.isMenuTriggerOut(e, internal)){ rlm@46: this.fireEvent('menutriggerout', this, this.menu, e); rlm@46: } rlm@46: }, rlm@46: onFocus : function(e){ rlm@46: if(!this.disabled){ rlm@46: this.el.addClass("x-btn-focus"); rlm@46: } rlm@46: }, rlm@46: onBlur : function(e){ rlm@46: this.el.removeClass("x-btn-focus"); rlm@46: }, rlm@46: rlm@46: getClickEl : function(e, isUp){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: onMouseDown : function(e){ rlm@46: if(!this.disabled && e.button == 0){ rlm@46: this.getClickEl(e).addClass("x-btn-click"); rlm@46: Ext.getDoc().on('mouseup', this.onMouseUp, this); rlm@46: } rlm@46: }, rlm@46: onMouseUp : function(e){ rlm@46: if(e.button == 0){ rlm@46: this.getClickEl(e, true).removeClass("x-btn-click"); rlm@46: Ext.getDoc().un('mouseup', this.onMouseUp, this); rlm@46: } rlm@46: }, rlm@46: onMenuShow : function(e){ rlm@46: this.ignoreNextClick = 0; rlm@46: this.el.addClass("x-btn-menu-active"); rlm@46: this.fireEvent('menushow', this, this.menu); rlm@46: }, rlm@46: onMenuHide : function(e){ rlm@46: this.el.removeClass("x-btn-menu-active"); rlm@46: this.ignoreNextClick = this.restoreClick.defer(250, this); rlm@46: this.fireEvent('menuhide', this, this.menu); rlm@46: }, rlm@46: rlm@46: restoreClick : function(){ rlm@46: this.ignoreNextClick = 0; rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('button', Ext.Button); rlm@46: rlm@46: Ext.ButtonToggleMgr = function(){ rlm@46: var groups = {}; rlm@46: rlm@46: function toggleGroup(btn, state){ rlm@46: if(state){ rlm@46: var g = groups[btn.toggleGroup]; rlm@46: for(var i = 0, l = g.length; i < l; i++){ rlm@46: if(g[i] != btn){ rlm@46: g[i].toggle(false); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: return { rlm@46: register : function(btn){ rlm@46: if(!btn.toggleGroup){ rlm@46: return; rlm@46: } rlm@46: var g = groups[btn.toggleGroup]; rlm@46: if(!g){ rlm@46: g = groups[btn.toggleGroup] = []; rlm@46: } rlm@46: g.push(btn); rlm@46: btn.on("toggle", toggleGroup); rlm@46: }, rlm@46: rlm@46: unregister : function(btn){ rlm@46: if(!btn.toggleGroup){ rlm@46: return; rlm@46: } rlm@46: var g = groups[btn.toggleGroup]; rlm@46: if(g){ rlm@46: g.remove(btn); rlm@46: btn.un("toggle", toggleGroup); rlm@46: } rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.SplitButton = Ext.extend(Ext.Button, { rlm@46: rlm@46: arrowSelector : 'button:last', rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.SplitButton.superclass.initComponent.call(this); rlm@46: rlm@46: this.addEvents("arrowclick"); rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: rlm@46: var tpl = new Ext.Template( rlm@46: '
    ', rlm@46: '', rlm@46: '', rlm@46: "
     
    ", rlm@46: '', rlm@46: '', rlm@46: "
     
    " rlm@46: ); rlm@46: var btn, targs = [this.text || ' ', this.type]; rlm@46: if(position){ rlm@46: btn = tpl.insertBefore(position, targs, true); rlm@46: }else{ rlm@46: btn = tpl.append(ct, targs, true); rlm@46: } rlm@46: var btnEl = btn.child(this.buttonSelector); rlm@46: rlm@46: this.initButtonEl(btn, btnEl); rlm@46: this.arrowBtnTable = btn.child("table:last"); rlm@46: if(this.arrowTooltip){ rlm@46: btn.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: autoWidth : function(){ rlm@46: if(this.el){ rlm@46: var tbl = this.el.child("table:first"); rlm@46: var tbl2 = this.el.child("table:last"); rlm@46: this.el.setWidth("auto"); rlm@46: tbl.setWidth("auto"); rlm@46: if(Ext.isIE7 && Ext.isStrict){ rlm@46: var ib = this.el.child(this.buttonSelector); rlm@46: if(ib && ib.getWidth() > 20){ rlm@46: ib.clip(); rlm@46: ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr')); rlm@46: } rlm@46: } rlm@46: if(this.minWidth){ rlm@46: if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){ rlm@46: tbl.setWidth(this.minWidth-tbl2.getWidth()); rlm@46: } rlm@46: } rlm@46: this.el.setWidth(tbl.getWidth()+tbl2.getWidth()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setArrowHandler : function(handler, scope){ rlm@46: this.arrowHandler = handler; rlm@46: this.scope = scope; rlm@46: }, rlm@46: rlm@46: rlm@46: onClick : function(e){ rlm@46: e.preventDefault(); rlm@46: if(!this.disabled){ rlm@46: if(e.getTarget(".x-btn-menu-arrow-wrap")){ rlm@46: if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){ rlm@46: this.showMenu(); rlm@46: } rlm@46: this.fireEvent("arrowclick", this, e); rlm@46: if(this.arrowHandler){ rlm@46: this.arrowHandler.call(this.scope || this, this, e); rlm@46: } rlm@46: }else{ rlm@46: if(this.enableToggle){ rlm@46: this.toggle(); rlm@46: } rlm@46: this.fireEvent("click", this, e); rlm@46: if(this.handler){ rlm@46: this.handler.call(this.scope || this, this, e); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getClickEl : function(e, isUp){ rlm@46: if(!isUp){ rlm@46: return (this.lastClickEl = e.getTarget("table", 10, true)); rlm@46: } rlm@46: return this.lastClickEl; rlm@46: }, rlm@46: rlm@46: rlm@46: onDisable : function(){ rlm@46: if(this.el){ rlm@46: if(!Ext.isIE6){ rlm@46: this.el.addClass("x-item-disabled"); rlm@46: } rlm@46: this.el.child(this.buttonSelector).dom.disabled = true; rlm@46: this.el.child(this.arrowSelector).dom.disabled = true; rlm@46: } rlm@46: this.disabled = true; rlm@46: }, rlm@46: rlm@46: rlm@46: onEnable : function(){ rlm@46: if(this.el){ rlm@46: if(!Ext.isIE6){ rlm@46: this.el.removeClass("x-item-disabled"); rlm@46: } rlm@46: this.el.child(this.buttonSelector).dom.disabled = false; rlm@46: this.el.child(this.arrowSelector).dom.disabled = false; rlm@46: } rlm@46: this.disabled = false; rlm@46: }, rlm@46: rlm@46: rlm@46: isMenuTriggerOver : function(e){ rlm@46: return this.menu && e.within(this.arrowBtnTable) && !e.within(this.arrowBtnTable, true); rlm@46: }, rlm@46: rlm@46: rlm@46: isMenuTriggerOut : function(e, internal){ rlm@46: return this.menu && !e.within(this.arrowBtnTable); rlm@46: }, rlm@46: rlm@46: rlm@46: onDestroy : function(){ rlm@46: Ext.destroy(this.arrowBtnTable); rlm@46: Ext.SplitButton.superclass.onDestroy.call(this); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.MenuButton = Ext.SplitButton; rlm@46: rlm@46: rlm@46: Ext.reg('splitbutton', Ext.SplitButton); rlm@46: rlm@46: Ext.CycleButton = Ext.extend(Ext.SplitButton, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: getItemText : function(item){ rlm@46: if(item && this.showText === true){ rlm@46: var text = ''; rlm@46: if(this.prependText){ rlm@46: text += this.prependText; rlm@46: } rlm@46: text += item.text; rlm@46: return text; rlm@46: } rlm@46: return undefined; rlm@46: }, rlm@46: rlm@46: rlm@46: setActiveItem : function(item, suppressEvent){ rlm@46: if(typeof item != 'object'){ rlm@46: item = this.menu.items.get(item); rlm@46: } rlm@46: if(item){ rlm@46: if(!this.rendered){ rlm@46: this.text = this.getItemText(item); rlm@46: this.iconCls = item.iconCls; rlm@46: }else{ rlm@46: var t = this.getItemText(item); rlm@46: if(t){ rlm@46: this.setText(t); rlm@46: } rlm@46: this.setIconClass(item.iconCls); rlm@46: } rlm@46: this.activeItem = item; rlm@46: if(!item.checked){ rlm@46: item.setChecked(true, true); rlm@46: } rlm@46: if(this.forceIcon){ rlm@46: this.setIconClass(this.forceIcon); rlm@46: } rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent('change', this, item); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getActiveItem : function(){ rlm@46: return this.activeItem; rlm@46: }, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: this.addEvents( rlm@46: rlm@46: "change" rlm@46: ); rlm@46: rlm@46: if(this.changeHandler){ rlm@46: this.on('change', this.changeHandler, this.scope||this); rlm@46: delete this.changeHandler; rlm@46: } rlm@46: rlm@46: this.itemCount = this.items.length; rlm@46: rlm@46: this.menu = {cls:'x-cycle-menu', items:[]}; rlm@46: var checked; rlm@46: for(var i = 0, len = this.itemCount; i < len; i++){ rlm@46: var item = this.items[i]; rlm@46: item.group = item.group || this.id; rlm@46: item.itemIndex = i; rlm@46: item.checkHandler = this.checkHandler; rlm@46: item.scope = this; rlm@46: item.checked = item.checked || false; rlm@46: this.menu.items.push(item); rlm@46: if(item.checked){ rlm@46: checked = item; rlm@46: } rlm@46: } rlm@46: this.setActiveItem(checked, true); rlm@46: Ext.CycleButton.superclass.initComponent.call(this); rlm@46: rlm@46: this.on('click', this.toggleSelected, this); rlm@46: }, rlm@46: rlm@46: rlm@46: checkHandler : function(item, pressed){ rlm@46: if(pressed){ rlm@46: this.setActiveItem(item); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toggleSelected : function(){ rlm@46: this.menu.render(); rlm@46: rlm@46: var nextIdx, checkItem; rlm@46: for (var i = 1; i < this.itemCount; i++) { rlm@46: nextIdx = (this.activeItem.itemIndex + i) % this.itemCount; rlm@46: rlm@46: checkItem = this.menu.items.itemAt(nextIdx); rlm@46: rlm@46: if (!checkItem.disabled) { rlm@46: checkItem.setChecked(true); rlm@46: break; rlm@46: } rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.reg('cycle', Ext.CycleButton); rlm@46: rlm@46: Ext.Toolbar = function(config){ rlm@46: if(Ext.isArray(config)){ rlm@46: config = {buttons:config}; rlm@46: } rlm@46: Ext.Toolbar.superclass.constructor.call(this, config); rlm@46: }; rlm@46: rlm@46: (function(){ rlm@46: rlm@46: var T = Ext.Toolbar; rlm@46: rlm@46: Ext.extend(T, Ext.BoxComponent, { rlm@46: rlm@46: trackMenus : true, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: T.superclass.initComponent.call(this); rlm@46: rlm@46: if(this.items){ rlm@46: this.buttons = this.items; rlm@46: } rlm@46: rlm@46: this.items = new Ext.util.MixedCollection(false, function(o){ rlm@46: return o.itemId || o.id || Ext.id(); rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: autoCreate: { rlm@46: cls:'x-toolbar x-small-editor', rlm@46: html:'
    ' rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position); rlm@46: this.tr = this.el.child("tr", true); rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: T.superclass.afterRender.call(this); rlm@46: if(this.buttons){ rlm@46: this.add.apply(this, this.buttons); rlm@46: delete this.buttons; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: add : function(){ rlm@46: var a = arguments, l = a.length; rlm@46: for(var i = 0; i < l; i++){ rlm@46: var el = a[i]; rlm@46: if(el.isFormField){ rlm@46: this.addField(el); rlm@46: }else if(el.render){ rlm@46: this.addItem(el); rlm@46: }else if(typeof el == "string"){ rlm@46: if(el == "separator" || el == "-"){ rlm@46: this.addSeparator(); rlm@46: }else if(el == " "){ rlm@46: this.addSpacer(); rlm@46: }else if(el == "->"){ rlm@46: this.addFill(); rlm@46: }else{ rlm@46: this.addText(el); rlm@46: } rlm@46: }else if(el.tagName){ rlm@46: this.addElement(el); rlm@46: }else if(typeof el == "object"){ rlm@46: if(el.xtype){ rlm@46: this.addField(Ext.ComponentMgr.create(el, 'button')); rlm@46: }else{ rlm@46: this.addButton(el); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: addSeparator : function(){ rlm@46: return this.addItem(new T.Separator()); rlm@46: }, rlm@46: rlm@46: rlm@46: addSpacer : function(){ rlm@46: return this.addItem(new T.Spacer()); rlm@46: }, rlm@46: rlm@46: rlm@46: addFill : function(){ rlm@46: return this.addItem(new T.Fill()); rlm@46: }, rlm@46: rlm@46: rlm@46: addElement : function(el){ rlm@46: return this.addItem(new T.Item(el)); rlm@46: }, rlm@46: rlm@46: rlm@46: addItem : function(item){ rlm@46: var td = this.nextBlock(); rlm@46: this.initMenuTracking(item); rlm@46: item.render(td); rlm@46: this.items.add(item); rlm@46: return item; rlm@46: }, rlm@46: rlm@46: rlm@46: addButton : function(config){ rlm@46: if(Ext.isArray(config)){ rlm@46: var buttons = []; rlm@46: for(var i = 0, len = config.length; i < len; i++) { rlm@46: buttons.push(this.addButton(config[i])); rlm@46: } rlm@46: return buttons; rlm@46: } rlm@46: var b = config; rlm@46: if(!(config instanceof T.Button)){ rlm@46: b = config.split ? rlm@46: new T.SplitButton(config) : rlm@46: new T.Button(config); rlm@46: } rlm@46: var td = this.nextBlock(); rlm@46: this.initMenuTracking(b); rlm@46: b.render(td); rlm@46: this.items.add(b); rlm@46: return b; rlm@46: }, rlm@46: rlm@46: rlm@46: initMenuTracking : function(item){ rlm@46: if(this.trackMenus && item.menu){ rlm@46: item.on({ rlm@46: 'menutriggerover' : this.onButtonTriggerOver, rlm@46: 'menushow' : this.onButtonMenuShow, rlm@46: 'menuhide' : this.onButtonMenuHide, rlm@46: scope: this rlm@46: }) rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: addText : function(text){ rlm@46: return this.addItem(new T.TextItem(text)); rlm@46: }, rlm@46: rlm@46: rlm@46: insertButton : function(index, item){ rlm@46: if(Ext.isArray(item)){ rlm@46: var buttons = []; rlm@46: for(var i = 0, len = item.length; i < len; i++) { rlm@46: buttons.push(this.insertButton(index + i, item[i])); rlm@46: } rlm@46: return buttons; rlm@46: } rlm@46: if (!(item instanceof T.Button)){ rlm@46: item = new T.Button(item); rlm@46: } rlm@46: var td = document.createElement("td"); rlm@46: this.tr.insertBefore(td, this.tr.childNodes[index]); rlm@46: this.initMenuTracking(item); rlm@46: item.render(td); rlm@46: this.items.insert(index, item); rlm@46: return item; rlm@46: }, rlm@46: rlm@46: rlm@46: addDom : function(config, returnEl){ rlm@46: var td = this.nextBlock(); rlm@46: Ext.DomHelper.overwrite(td, config); rlm@46: var ti = new T.Item(td.firstChild); rlm@46: ti.render(td); rlm@46: this.items.add(ti); rlm@46: return ti; rlm@46: }, rlm@46: rlm@46: rlm@46: addField : function(field){ rlm@46: var td = this.nextBlock(); rlm@46: field.render(td); rlm@46: var ti = new T.Item(td.firstChild); rlm@46: ti.render(td); rlm@46: this.items.add(ti); rlm@46: return ti; rlm@46: }, rlm@46: rlm@46: rlm@46: nextBlock : function(){ rlm@46: var td = document.createElement("td"); rlm@46: this.tr.appendChild(td); rlm@46: return td; rlm@46: }, rlm@46: rlm@46: rlm@46: onDestroy : function(){ rlm@46: Ext.Toolbar.superclass.onDestroy.call(this); rlm@46: if(this.rendered){ rlm@46: if(this.items){ rlm@46: Ext.destroy.apply(Ext, this.items.items); rlm@46: } rlm@46: Ext.Element.uncache(this.tr); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onDisable : function(){ rlm@46: this.items.each(function(item){ rlm@46: if(item.disable){ rlm@46: item.disable(); rlm@46: } rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: onEnable : function(){ rlm@46: this.items.each(function(item){ rlm@46: if(item.enable){ rlm@46: item.enable(); rlm@46: } rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: onButtonTriggerOver : function(btn){ rlm@46: if(this.activeMenuBtn && this.activeMenuBtn != btn){ rlm@46: this.activeMenuBtn.hideMenu(); rlm@46: btn.showMenu(); rlm@46: this.activeMenuBtn = btn; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onButtonMenuShow : function(btn){ rlm@46: this.activeMenuBtn = btn; rlm@46: }, rlm@46: rlm@46: rlm@46: onButtonMenuHide : function(btn){ rlm@46: delete this.activeMenuBtn; rlm@46: } rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('toolbar', Ext.Toolbar); rlm@46: rlm@46: rlm@46: T.Item = function(el){ rlm@46: this.el = Ext.getDom(el); rlm@46: this.id = Ext.id(this.el); rlm@46: this.hidden = false; rlm@46: }; rlm@46: rlm@46: T.Item.prototype = { rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: render : function(td){ rlm@46: this.td = td; rlm@46: td.appendChild(this.el); rlm@46: }, rlm@46: rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.td && this.td.parentNode){ rlm@46: this.td.parentNode.removeChild(this.td); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show: function(){ rlm@46: this.hidden = false; rlm@46: this.td.style.display = ""; rlm@46: }, rlm@46: rlm@46: rlm@46: hide: function(){ rlm@46: this.hidden = true; rlm@46: this.td.style.display = "none"; rlm@46: }, rlm@46: rlm@46: rlm@46: setVisible: function(visible){ rlm@46: if(visible) { rlm@46: this.show(); rlm@46: }else{ rlm@46: this.hide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: Ext.fly(this.el).focus(); rlm@46: }, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: Ext.fly(this.td).addClass("x-item-disabled"); rlm@46: this.disabled = true; rlm@46: this.el.disabled = true; rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: Ext.fly(this.td).removeClass("x-item-disabled"); rlm@46: this.disabled = false; rlm@46: this.el.disabled = false; rlm@46: } rlm@46: }; rlm@46: Ext.reg('tbitem', T.Item); rlm@46: rlm@46: rlm@46: rlm@46: T.Separator = function(){ rlm@46: var s = document.createElement("span"); rlm@46: s.className = "ytb-sep"; rlm@46: T.Separator.superclass.constructor.call(this, s); rlm@46: }; rlm@46: Ext.extend(T.Separator, T.Item, { rlm@46: enable:Ext.emptyFn, rlm@46: disable:Ext.emptyFn, rlm@46: focus:Ext.emptyFn rlm@46: }); rlm@46: Ext.reg('tbseparator', T.Separator); rlm@46: rlm@46: rlm@46: T.Spacer = function(){ rlm@46: var s = document.createElement("div"); rlm@46: s.className = "ytb-spacer"; rlm@46: T.Spacer.superclass.constructor.call(this, s); rlm@46: }; rlm@46: Ext.extend(T.Spacer, T.Item, { rlm@46: enable:Ext.emptyFn, rlm@46: disable:Ext.emptyFn, rlm@46: focus:Ext.emptyFn rlm@46: }); rlm@46: rlm@46: Ext.reg('tbspacer', T.Spacer); rlm@46: rlm@46: rlm@46: T.Fill = Ext.extend(T.Spacer, { rlm@46: rlm@46: render : function(td){ rlm@46: td.style.width = '100%'; rlm@46: T.Fill.superclass.render.call(this, td); rlm@46: } rlm@46: }); rlm@46: Ext.reg('tbfill', T.Fill); rlm@46: rlm@46: rlm@46: T.TextItem = function(t){ rlm@46: var s = document.createElement("span"); rlm@46: s.className = "ytb-text"; rlm@46: s.innerHTML = t.text ? t.text : t; rlm@46: T.TextItem.superclass.constructor.call(this, s); rlm@46: }; rlm@46: Ext.extend(T.TextItem, T.Item, { rlm@46: enable:Ext.emptyFn, rlm@46: disable:Ext.emptyFn, rlm@46: focus:Ext.emptyFn rlm@46: }); rlm@46: Ext.reg('tbtext', T.TextItem); rlm@46: rlm@46: rlm@46: rlm@46: T.Button = Ext.extend(Ext.Button, { rlm@46: hideParent : true, rlm@46: rlm@46: onDestroy : function(){ rlm@46: T.Button.superclass.onDestroy.call(this); rlm@46: if(this.container){ rlm@46: this.container.remove(); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.reg('tbbutton', T.Button); rlm@46: rlm@46: rlm@46: T.SplitButton = Ext.extend(Ext.SplitButton, { rlm@46: hideParent : true, rlm@46: rlm@46: onDestroy : function(){ rlm@46: T.SplitButton.superclass.onDestroy.call(this); rlm@46: if(this.container){ rlm@46: this.container.remove(); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.reg('tbsplit', T.SplitButton); rlm@46: rlm@46: T.MenuButton = T.SplitButton; rlm@46: rlm@46: })(); rlm@46: rlm@46: rlm@46: Ext.PagingToolbar = Ext.extend(Ext.Toolbar, { rlm@46: rlm@46: rlm@46: rlm@46: pageSize: 20, rlm@46: rlm@46: displayMsg : 'Displaying {0} - {1} of {2}', rlm@46: rlm@46: emptyMsg : 'No data to display', rlm@46: rlm@46: beforePageText : "Page", rlm@46: rlm@46: afterPageText : "of {0}", rlm@46: rlm@46: firstText : "First Page", rlm@46: rlm@46: prevText : "Previous Page", rlm@46: rlm@46: nextText : "Next Page", rlm@46: rlm@46: lastText : "Last Page", rlm@46: rlm@46: refreshText : "Refresh", rlm@46: rlm@46: rlm@46: paramNames : {start: 'start', limit: 'limit'}, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.PagingToolbar.superclass.initComponent.call(this); rlm@46: this.cursor = 0; rlm@46: this.bind(this.store); rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.PagingToolbar.superclass.onRender.call(this, ct, position); rlm@46: this.first = this.addButton({ rlm@46: tooltip: this.firstText, rlm@46: iconCls: "x-tbar-page-first", rlm@46: disabled: true, rlm@46: handler: this.onClick.createDelegate(this, ["first"]) rlm@46: }); rlm@46: this.prev = this.addButton({ rlm@46: tooltip: this.prevText, rlm@46: iconCls: "x-tbar-page-prev", rlm@46: disabled: true, rlm@46: handler: this.onClick.createDelegate(this, ["prev"]) rlm@46: }); rlm@46: this.addSeparator(); rlm@46: this.add(this.beforePageText); rlm@46: this.field = Ext.get(this.addDom({ rlm@46: tag: "input", rlm@46: type: "text", rlm@46: size: "3", rlm@46: value: "1", rlm@46: cls: "x-tbar-page-number" rlm@46: }).el); rlm@46: this.field.on("keydown", this.onPagingKeydown, this); rlm@46: this.field.on("focus", function(){this.dom.select();}); rlm@46: this.afterTextEl = this.addText(String.format(this.afterPageText, 1)); rlm@46: this.field.setHeight(18); rlm@46: this.addSeparator(); rlm@46: this.next = this.addButton({ rlm@46: tooltip: this.nextText, rlm@46: iconCls: "x-tbar-page-next", rlm@46: disabled: true, rlm@46: handler: this.onClick.createDelegate(this, ["next"]) rlm@46: }); rlm@46: this.last = this.addButton({ rlm@46: tooltip: this.lastText, rlm@46: iconCls: "x-tbar-page-last", rlm@46: disabled: true, rlm@46: handler: this.onClick.createDelegate(this, ["last"]) rlm@46: }); rlm@46: this.addSeparator(); rlm@46: this.loading = this.addButton({ rlm@46: tooltip: this.refreshText, rlm@46: iconCls: "x-tbar-loading", rlm@46: handler: this.onClick.createDelegate(this, ["refresh"]) rlm@46: }); rlm@46: rlm@46: if(this.displayInfo){ rlm@46: this.displayEl = Ext.fly(this.el.dom).createChild({cls:'x-paging-info'}); rlm@46: } rlm@46: if(this.dsLoaded){ rlm@46: this.onLoad.apply(this, this.dsLoaded); rlm@46: } rlm@46: }, rlm@46: rlm@46: updateInfo : function(){ rlm@46: if(this.displayEl){ rlm@46: var count = this.store.getCount(); rlm@46: var msg = count == 0 ? rlm@46: this.emptyMsg : rlm@46: String.format( rlm@46: this.displayMsg, rlm@46: this.cursor+1, this.cursor+count, this.store.getTotalCount() rlm@46: ); rlm@46: this.displayEl.update(msg); rlm@46: } rlm@46: }, rlm@46: rlm@46: onLoad : function(store, r, o){ rlm@46: if(!this.rendered){ rlm@46: this.dsLoaded = [store, r, o]; rlm@46: return; rlm@46: } rlm@46: this.cursor = o.params ? o.params[this.paramNames.start] : 0; rlm@46: var d = this.getPageData(), ap = d.activePage, ps = d.pages; rlm@46: rlm@46: this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages); rlm@46: this.field.dom.value = ap; rlm@46: this.first.setDisabled(ap == 1); rlm@46: this.prev.setDisabled(ap == 1); rlm@46: this.next.setDisabled(ap == ps); rlm@46: this.last.setDisabled(ap == ps); rlm@46: this.loading.enable(); rlm@46: this.updateInfo(); rlm@46: }, rlm@46: rlm@46: getPageData : function(){ rlm@46: var total = this.store.getTotalCount(); rlm@46: return { rlm@46: total : total, rlm@46: activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize), rlm@46: pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize) rlm@46: }; rlm@46: }, rlm@46: rlm@46: onLoadError : function(){ rlm@46: if(!this.rendered){ rlm@46: return; rlm@46: } rlm@46: this.loading.enable(); rlm@46: }, rlm@46: rlm@46: readPage : function(d){ rlm@46: var v = this.field.dom.value, pageNum; rlm@46: if (!v || isNaN(pageNum = parseInt(v, 10))) { rlm@46: this.field.dom.value = d.activePage; rlm@46: return false; rlm@46: } rlm@46: return pageNum; rlm@46: }, rlm@46: rlm@46: onPagingKeydown : function(e){ rlm@46: var k = e.getKey(), d = this.getPageData(), pageNum; rlm@46: if (k == e.RETURN) { rlm@46: e.stopEvent(); rlm@46: if(pageNum = this.readPage(d)){ rlm@46: pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1; rlm@46: this.doLoad(pageNum * this.pageSize); rlm@46: } rlm@46: }else if (k == e.HOME || k == e.END){ rlm@46: e.stopEvent(); rlm@46: pageNum = k == e.HOME ? 1 : d.pages; rlm@46: this.field.dom.value = pageNum; rlm@46: }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){ rlm@46: e.stopEvent(); rlm@46: if(pageNum = this.readPage(d)){ rlm@46: var increment = e.shiftKey ? 10 : 1; rlm@46: if(k == e.DOWN || k == e.PAGEDOWN){ rlm@46: increment *= -1; rlm@46: } rlm@46: pageNum += increment; rlm@46: if(pageNum >= 1 & pageNum <= d.pages){ rlm@46: this.field.dom.value = pageNum; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeLoad : function(){ rlm@46: if(this.rendered && this.loading){ rlm@46: this.loading.disable(); rlm@46: } rlm@46: }, rlm@46: rlm@46: doLoad : function(start){ rlm@46: var o = {}, pn = this.paramNames; rlm@46: o[pn.start] = start; rlm@46: o[pn.limit] = this.pageSize; rlm@46: this.store.load({params:o}); rlm@46: }, rlm@46: rlm@46: onClick : function(which){ rlm@46: var store = this.store; rlm@46: switch(which){ rlm@46: case "first": rlm@46: this.doLoad(0); rlm@46: break; rlm@46: case "prev": rlm@46: this.doLoad(Math.max(0, this.cursor-this.pageSize)); rlm@46: break; rlm@46: case "next": rlm@46: this.doLoad(this.cursor+this.pageSize); rlm@46: break; rlm@46: case "last": rlm@46: var total = store.getTotalCount(); rlm@46: var extra = total % this.pageSize; rlm@46: var lastStart = extra ? (total - extra) : total-this.pageSize; rlm@46: this.doLoad(lastStart); rlm@46: break; rlm@46: case "refresh": rlm@46: this.doLoad(this.cursor); rlm@46: break; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: unbind : function(store){ rlm@46: store = Ext.StoreMgr.lookup(store); rlm@46: store.un("beforeload", this.beforeLoad, this); rlm@46: store.un("load", this.onLoad, this); rlm@46: store.un("loadexception", this.onLoadError, this); rlm@46: this.store = undefined; rlm@46: }, rlm@46: rlm@46: rlm@46: bind : function(store){ rlm@46: store = Ext.StoreMgr.lookup(store); rlm@46: store.on("beforeload", this.beforeLoad, this); rlm@46: store.on("load", this.onLoad, this); rlm@46: store.on("loadexception", this.onLoadError, this); rlm@46: this.store = store; rlm@46: } rlm@46: }); rlm@46: Ext.reg('paging', Ext.PagingToolbar); rlm@46: rlm@46: Ext.Resizable = function(el, config){ rlm@46: this.el = Ext.get(el); rlm@46: rlm@46: if(config && config.wrap){ rlm@46: config.resizeChild = this.el; rlm@46: this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"}); rlm@46: this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap"; rlm@46: this.el.setStyle("overflow", "hidden"); rlm@46: this.el.setPositioning(config.resizeChild.getPositioning()); rlm@46: config.resizeChild.clearPositioning(); rlm@46: if(!config.width || !config.height){ rlm@46: var csize = config.resizeChild.getSize(); rlm@46: this.el.setSize(csize.width, csize.height); rlm@46: } rlm@46: if(config.pinned && !config.adjustments){ rlm@46: config.adjustments = "auto"; rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"}); rlm@46: this.proxy.unselectable(); rlm@46: this.proxy.enableDisplayMode('block'); rlm@46: rlm@46: Ext.apply(this, config); rlm@46: rlm@46: if(this.pinned){ rlm@46: this.disableTrackOver = true; rlm@46: this.el.addClass("x-resizable-pinned"); rlm@46: } rlm@46: rlm@46: var position = this.el.getStyle("position"); rlm@46: if(position != "absolute" && position != "fixed"){ rlm@46: this.el.setStyle("position", "relative"); rlm@46: } rlm@46: if(!this.handles){ rlm@46: this.handles = 's,e,se'; rlm@46: if(this.multiDirectional){ rlm@46: this.handles += ',n,w'; rlm@46: } rlm@46: } rlm@46: if(this.handles == "all"){ rlm@46: this.handles = "n s e w ne nw se sw"; rlm@46: } rlm@46: var hs = this.handles.split(/\s*?[,;]\s*?| /); rlm@46: var ps = Ext.Resizable.positions; rlm@46: for(var i = 0, len = hs.length; i < len; i++){ rlm@46: if(hs[i] && ps[hs[i]]){ rlm@46: var pos = ps[hs[i]]; rlm@46: this[pos] = new Ext.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent); rlm@46: } rlm@46: } rlm@46: rlm@46: this.corner = this.southeast; rlm@46: rlm@46: if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1){ rlm@46: this.updateBox = true; rlm@46: } rlm@46: rlm@46: this.activeHandle = null; rlm@46: rlm@46: if(this.resizeChild){ rlm@46: if(typeof this.resizeChild == "boolean"){ rlm@46: this.resizeChild = Ext.get(this.el.dom.firstChild, true); rlm@46: }else{ rlm@46: this.resizeChild = Ext.get(this.resizeChild, true); rlm@46: } rlm@46: } rlm@46: rlm@46: if(this.adjustments == "auto"){ rlm@46: var rc = this.resizeChild; rlm@46: var hw = this.west, he = this.east, hn = this.north, hs = this.south; rlm@46: if(rc && (hw || hn)){ rlm@46: rc.position("relative"); rlm@46: rc.setLeft(hw ? hw.el.getWidth() : 0); rlm@46: rc.setTop(hn ? hn.el.getHeight() : 0); rlm@46: } rlm@46: this.adjustments = [ rlm@46: (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0), rlm@46: (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1 rlm@46: ]; rlm@46: } rlm@46: rlm@46: if(this.draggable){ rlm@46: this.dd = this.dynamic ? rlm@46: this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id}); rlm@46: this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id); rlm@46: } rlm@46: rlm@46: rlm@46: this.addEvents( rlm@46: "beforeresize", rlm@46: "resize" rlm@46: ); rlm@46: rlm@46: if(this.width !== null && this.height !== null){ rlm@46: this.resizeTo(this.width, this.height); rlm@46: }else{ rlm@46: this.updateChildSize(); rlm@46: } rlm@46: if(Ext.isIE){ rlm@46: this.el.dom.style.zoom = 1; rlm@46: } rlm@46: Ext.Resizable.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Resizable, Ext.util.Observable, { rlm@46: resizeChild : false, rlm@46: adjustments : [0, 0], rlm@46: minWidth : 5, rlm@46: minHeight : 5, rlm@46: maxWidth : 10000, rlm@46: maxHeight : 10000, rlm@46: enabled : true, rlm@46: animate : false, rlm@46: duration : .35, rlm@46: dynamic : false, rlm@46: handles : false, rlm@46: multiDirectional : false, rlm@46: disableTrackOver : false, rlm@46: easing : 'easeOutStrong', rlm@46: widthIncrement : 0, rlm@46: heightIncrement : 0, rlm@46: pinned : false, rlm@46: width : null, rlm@46: height : null, rlm@46: preserveRatio : false, rlm@46: transparent: false, rlm@46: minX: 0, rlm@46: minY: 0, rlm@46: draggable: false, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: resizeTo : function(width, height){ rlm@46: this.el.setSize(width, height); rlm@46: this.updateChildSize(); rlm@46: this.fireEvent("resize", this, width, height, null); rlm@46: }, rlm@46: rlm@46: rlm@46: startSizing : function(e, handle){ rlm@46: this.fireEvent("beforeresize", this, e); rlm@46: if(this.enabled){ rlm@46: rlm@46: if(!this.overlay){ rlm@46: this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "}, Ext.getBody()); rlm@46: this.overlay.unselectable(); rlm@46: this.overlay.enableDisplayMode("block"); rlm@46: this.overlay.on("mousemove", this.onMouseMove, this); rlm@46: this.overlay.on("mouseup", this.onMouseUp, this); rlm@46: } rlm@46: this.overlay.setStyle("cursor", handle.el.getStyle("cursor")); rlm@46: rlm@46: this.resizing = true; rlm@46: this.startBox = this.el.getBox(); rlm@46: this.startPoint = e.getXY(); rlm@46: this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0], rlm@46: (this.startBox.y + this.startBox.height) - this.startPoint[1]]; rlm@46: rlm@46: this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true)); rlm@46: this.overlay.show(); rlm@46: rlm@46: if(this.constrainTo) { rlm@46: var ct = Ext.get(this.constrainTo); rlm@46: this.resizeRegion = ct.getRegion().adjust( rlm@46: ct.getFrameWidth('t'), rlm@46: ct.getFrameWidth('l'), rlm@46: -ct.getFrameWidth('b'), rlm@46: -ct.getFrameWidth('r') rlm@46: ); rlm@46: } rlm@46: rlm@46: this.proxy.setStyle('visibility', 'hidden'); rlm@46: this.proxy.show(); rlm@46: this.proxy.setBox(this.startBox); rlm@46: if(!this.dynamic){ rlm@46: this.proxy.setStyle('visibility', 'visible'); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseDown : function(handle, e){ rlm@46: if(this.enabled){ rlm@46: e.stopEvent(); rlm@46: this.activeHandle = handle; rlm@46: this.startSizing(e, handle); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseUp : function(e){ rlm@46: var size = this.resizeElement(); rlm@46: this.resizing = false; rlm@46: this.handleOut(); rlm@46: this.overlay.hide(); rlm@46: this.proxy.hide(); rlm@46: this.fireEvent("resize", this, size.width, size.height, e); rlm@46: }, rlm@46: rlm@46: rlm@46: updateChildSize : function(){ rlm@46: if(this.resizeChild){ rlm@46: var el = this.el; rlm@46: var child = this.resizeChild; rlm@46: var adj = this.adjustments; rlm@46: if(el.dom.offsetWidth){ rlm@46: var b = el.getSize(true); rlm@46: child.setSize(b.width+adj[0], b.height+adj[1]); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: if(Ext.isIE){ rlm@46: setTimeout(function(){ rlm@46: if(el.dom.offsetWidth){ rlm@46: var b = el.getSize(true); rlm@46: child.setSize(b.width+adj[0], b.height+adj[1]); rlm@46: } rlm@46: }, 10); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: snap : function(value, inc, min){ rlm@46: if(!inc || !value) return value; rlm@46: var newValue = value; rlm@46: var m = value % inc; rlm@46: if(m > 0){ rlm@46: if(m > (inc/2)){ rlm@46: newValue = value + (inc-m); rlm@46: }else{ rlm@46: newValue = value - m; rlm@46: } rlm@46: } rlm@46: return Math.max(min, newValue); rlm@46: }, rlm@46: rlm@46: rlm@46: resizeElement : function(){ rlm@46: var box = this.proxy.getBox(); rlm@46: if(this.updateBox){ rlm@46: this.el.setBox(box, false, this.animate, this.duration, null, this.easing); rlm@46: }else{ rlm@46: this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing); rlm@46: } rlm@46: this.updateChildSize(); rlm@46: if(!this.dynamic){ rlm@46: this.proxy.hide(); rlm@46: } rlm@46: return box; rlm@46: }, rlm@46: rlm@46: rlm@46: constrain : function(v, diff, m, mx){ rlm@46: if(v - diff < m){ rlm@46: diff = v - m; rlm@46: }else if(v - diff > mx){ rlm@46: diff = mx - v; rlm@46: } rlm@46: return diff; rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseMove : function(e){ rlm@46: if(this.enabled){ rlm@46: try{ rlm@46: rlm@46: if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) { rlm@46: return; rlm@46: } rlm@46: rlm@46: rlm@46: var curSize = this.curSize || this.startBox; rlm@46: var x = this.startBox.x, y = this.startBox.y; rlm@46: var ox = x, oy = y; rlm@46: var w = curSize.width, h = curSize.height; rlm@46: var ow = w, oh = h; rlm@46: var mw = this.minWidth, mh = this.minHeight; rlm@46: var mxw = this.maxWidth, mxh = this.maxHeight; rlm@46: var wi = this.widthIncrement; rlm@46: var hi = this.heightIncrement; rlm@46: rlm@46: var eventXY = e.getXY(); rlm@46: var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0])); rlm@46: var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1])); rlm@46: rlm@46: var pos = this.activeHandle.position; rlm@46: rlm@46: switch(pos){ rlm@46: case "east": rlm@46: w += diffX; rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: break; rlm@46: case "south": rlm@46: h += diffY; rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: break; rlm@46: case "southeast": rlm@46: w += diffX; rlm@46: h += diffY; rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: break; rlm@46: case "north": rlm@46: diffY = this.constrain(h, diffY, mh, mxh); rlm@46: y += diffY; rlm@46: h -= diffY; rlm@46: break; rlm@46: case "west": rlm@46: diffX = this.constrain(w, diffX, mw, mxw); rlm@46: x += diffX; rlm@46: w -= diffX; rlm@46: break; rlm@46: case "northeast": rlm@46: w += diffX; rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: diffY = this.constrain(h, diffY, mh, mxh); rlm@46: y += diffY; rlm@46: h -= diffY; rlm@46: break; rlm@46: case "northwest": rlm@46: diffX = this.constrain(w, diffX, mw, mxw); rlm@46: diffY = this.constrain(h, diffY, mh, mxh); rlm@46: y += diffY; rlm@46: h -= diffY; rlm@46: x += diffX; rlm@46: w -= diffX; rlm@46: break; rlm@46: case "southwest": rlm@46: diffX = this.constrain(w, diffX, mw, mxw); rlm@46: h += diffY; rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: x += diffX; rlm@46: w -= diffX; rlm@46: break; rlm@46: } rlm@46: rlm@46: var sw = this.snap(w, wi, mw); rlm@46: var sh = this.snap(h, hi, mh); rlm@46: if(sw != w || sh != h){ rlm@46: switch(pos){ rlm@46: case "northeast": rlm@46: y -= sh - h; rlm@46: break; rlm@46: case "north": rlm@46: y -= sh - h; rlm@46: break; rlm@46: case "southwest": rlm@46: x -= sw - w; rlm@46: break; rlm@46: case "west": rlm@46: x -= sw - w; rlm@46: break; rlm@46: case "northwest": rlm@46: x -= sw - w; rlm@46: y -= sh - h; rlm@46: break; rlm@46: } rlm@46: w = sw; rlm@46: h = sh; rlm@46: } rlm@46: rlm@46: if(this.preserveRatio){ rlm@46: switch(pos){ rlm@46: case "southeast": rlm@46: case "east": rlm@46: h = oh * (w/ow); rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: w = ow * (h/oh); rlm@46: break; rlm@46: case "south": rlm@46: w = ow * (h/oh); rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: h = oh * (w/ow); rlm@46: break; rlm@46: case "northeast": rlm@46: w = ow * (h/oh); rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: h = oh * (w/ow); rlm@46: break; rlm@46: case "north": rlm@46: var tw = w; rlm@46: w = ow * (h/oh); rlm@46: w = Math.min(Math.max(mw, w), mxw); rlm@46: h = oh * (w/ow); rlm@46: x += (tw - w) / 2; rlm@46: break; rlm@46: case "southwest": rlm@46: h = oh * (w/ow); rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: var tw = w; rlm@46: w = ow * (h/oh); rlm@46: x += tw - w; rlm@46: break; rlm@46: case "west": rlm@46: var th = h; rlm@46: h = oh * (w/ow); rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: y += (th - h) / 2; rlm@46: var tw = w; rlm@46: w = ow * (h/oh); rlm@46: x += tw - w; rlm@46: break; rlm@46: case "northwest": rlm@46: var tw = w; rlm@46: var th = h; rlm@46: h = oh * (w/ow); rlm@46: h = Math.min(Math.max(mh, h), mxh); rlm@46: w = ow * (h/oh); rlm@46: y += th - h; rlm@46: x += tw - w; rlm@46: break; rlm@46: rlm@46: } rlm@46: } rlm@46: this.proxy.setBounds(x, y, w, h); rlm@46: if(this.dynamic){ rlm@46: this.resizeElement(); rlm@46: } rlm@46: }catch(e){} rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: handleOver : function(){ rlm@46: if(this.enabled){ rlm@46: this.el.addClass("x-resizable-over"); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: handleOut : function(){ rlm@46: if(!this.resizing){ rlm@46: this.el.removeClass("x-resizable-over"); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: getResizeChild : function(){ rlm@46: return this.resizeChild; rlm@46: }, rlm@46: rlm@46: rlm@46: destroy : function(removeEl){ rlm@46: this.proxy.remove(); rlm@46: if(this.overlay){ rlm@46: this.overlay.removeAllListeners(); rlm@46: this.overlay.remove(); rlm@46: } rlm@46: var ps = Ext.Resizable.positions; rlm@46: for(var k in ps){ rlm@46: if(typeof ps[k] != "function" && this[ps[k]]){ rlm@46: var h = this[ps[k]]; rlm@46: h.el.removeAllListeners(); rlm@46: h.el.remove(); rlm@46: } rlm@46: } rlm@46: if(removeEl){ rlm@46: this.el.update(""); rlm@46: this.el.remove(); rlm@46: } rlm@46: }, rlm@46: rlm@46: syncHandleHeight : function(){ rlm@46: var h = this.el.getHeight(true); rlm@46: if(this.west){ rlm@46: this.west.el.setHeight(h); rlm@46: } rlm@46: if(this.east){ rlm@46: this.east.el.setHeight(h); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: rlm@46: Ext.Resizable.positions = { rlm@46: n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast" rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){ rlm@46: if(!this.tpl){ rlm@46: rlm@46: var tpl = Ext.DomHelper.createTemplate( rlm@46: {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"} rlm@46: ); rlm@46: tpl.compile(); rlm@46: Ext.Resizable.Handle.prototype.tpl = tpl; rlm@46: } rlm@46: this.position = pos; rlm@46: this.rz = rz; rlm@46: this.el = this.tpl.append(rz.el.dom, [this.position], true); rlm@46: this.el.unselectable(); rlm@46: if(transparent){ rlm@46: this.el.setOpacity(0); rlm@46: } rlm@46: this.el.on("mousedown", this.onMouseDown, this); rlm@46: if(!disableTrackOver){ rlm@46: this.el.on("mouseover", this.onMouseOver, this); rlm@46: this.el.on("mouseout", this.onMouseOut, this); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.Resizable.Handle.prototype = { rlm@46: afterResize : function(rz){ rlm@46: rlm@46: }, rlm@46: rlm@46: onMouseDown : function(e){ rlm@46: this.rz.onMouseDown(this, e); rlm@46: }, rlm@46: rlm@46: onMouseOver : function(e){ rlm@46: this.rz.handleOver(this, e); rlm@46: }, rlm@46: rlm@46: onMouseOut : function(e){ rlm@46: this.rz.handleOut(this, e); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: Ext.Editor = function(field, config){ rlm@46: this.field = field; rlm@46: Ext.Editor.superclass.constructor.call(this, config); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Editor, Ext.Component, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: value : "", rlm@46: rlm@46: alignment: "c-c?", rlm@46: rlm@46: shadow : "frame", rlm@46: rlm@46: constrain : false, rlm@46: rlm@46: swallowKeys : true, rlm@46: rlm@46: completeOnEnter : false, rlm@46: rlm@46: cancelOnEsc : false, rlm@46: rlm@46: updateEl : false, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Editor.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: "beforestartedit", rlm@46: rlm@46: "startedit", rlm@46: rlm@46: "beforecomplete", rlm@46: rlm@46: "complete", rlm@46: rlm@46: "specialkey" rlm@46: ); rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: this.el = new Ext.Layer({ rlm@46: shadow: this.shadow, rlm@46: cls: "x-editor", rlm@46: parentEl : ct, rlm@46: shim : this.shim, rlm@46: shadowOffset:4, rlm@46: id: this.id, rlm@46: constrain: this.constrain rlm@46: }); rlm@46: this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden"); rlm@46: if(this.field.msgTarget != 'title'){ rlm@46: this.field.msgTarget = 'qtip'; rlm@46: } rlm@46: this.field.inEditor = true; rlm@46: this.field.render(this.el); rlm@46: if(Ext.isGecko){ rlm@46: this.field.el.dom.setAttribute('autocomplete', 'off'); rlm@46: } rlm@46: this.field.on("specialkey", this.onSpecialKey, this); rlm@46: if(this.swallowKeys){ rlm@46: this.field.el.swallowEvent(['keydown','keypress']); rlm@46: } rlm@46: this.field.show(); rlm@46: this.field.on("blur", this.onBlur, this); rlm@46: if(this.field.grow){ rlm@46: this.field.on("autosize", this.el.sync, this.el, {delay:1}); rlm@46: } rlm@46: }, rlm@46: rlm@46: onSpecialKey : function(field, e){ rlm@46: if(this.completeOnEnter && e.getKey() == e.ENTER){ rlm@46: e.stopEvent(); rlm@46: this.completeEdit(); rlm@46: }else if(this.cancelOnEsc && e.getKey() == e.ESC){ rlm@46: this.cancelEdit(); rlm@46: }else{ rlm@46: this.fireEvent('specialkey', field, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: startEdit : function(el, value){ rlm@46: if(this.editing){ rlm@46: this.completeEdit(); rlm@46: } rlm@46: this.boundEl = Ext.get(el); rlm@46: var v = value !== undefined ? value : this.boundEl.dom.innerHTML; rlm@46: if(!this.rendered){ rlm@46: this.render(this.parentEl || document.body); rlm@46: } rlm@46: if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){ rlm@46: return; rlm@46: } rlm@46: this.startValue = v; rlm@46: this.field.setValue(v); rlm@46: this.doAutoSize(); rlm@46: this.el.alignTo(this.boundEl, this.alignment); rlm@46: this.editing = true; rlm@46: this.show(); rlm@46: }, rlm@46: rlm@46: doAutoSize : function(){ rlm@46: if(this.autoSize){ rlm@46: var sz = this.boundEl.getSize(); rlm@46: switch(this.autoSize){ rlm@46: case "width": rlm@46: this.setSize(sz.width, ""); rlm@46: break; rlm@46: case "height": rlm@46: this.setSize("", sz.height); rlm@46: break; rlm@46: default: rlm@46: this.setSize(sz.width, sz.height); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setSize : function(w, h){ rlm@46: delete this.field.lastSize; rlm@46: this.field.setSize(w, h); rlm@46: if(this.el){ rlm@46: this.el.sync(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: realign : function(){ rlm@46: this.el.alignTo(this.boundEl, this.alignment); rlm@46: }, rlm@46: rlm@46: rlm@46: completeEdit : function(remainVisible){ rlm@46: if(!this.editing){ rlm@46: return; rlm@46: } rlm@46: var v = this.getValue(); rlm@46: if(this.revertInvalid !== false && !this.field.isValid()){ rlm@46: v = this.startValue; rlm@46: this.cancelEdit(true); rlm@46: } rlm@46: if(String(v) === String(this.startValue) && this.ignoreNoChange){ rlm@46: this.editing = false; rlm@46: this.hide(); rlm@46: return; rlm@46: } rlm@46: if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){ rlm@46: this.editing = false; rlm@46: if(this.updateEl && this.boundEl){ rlm@46: this.boundEl.update(v); rlm@46: } rlm@46: if(remainVisible !== true){ rlm@46: this.hide(); rlm@46: } rlm@46: this.fireEvent("complete", this, v, this.startValue); rlm@46: } rlm@46: }, rlm@46: rlm@46: onShow : function(){ rlm@46: this.el.show(); rlm@46: if(this.hideEl !== false){ rlm@46: this.boundEl.hide(); rlm@46: } rlm@46: this.field.show(); rlm@46: if(Ext.isIE && !this.fixIEFocus){ this.fixIEFocus = true; rlm@46: this.deferredFocus.defer(50, this); rlm@46: }else{ rlm@46: this.field.focus(); rlm@46: } rlm@46: this.fireEvent("startedit", this.boundEl, this.startValue); rlm@46: }, rlm@46: rlm@46: deferredFocus : function(){ rlm@46: if(this.editing){ rlm@46: this.field.focus(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: cancelEdit : function(remainVisible){ rlm@46: if(this.editing){ rlm@46: this.setValue(this.startValue); rlm@46: if(remainVisible !== true){ rlm@46: this.hide(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onBlur : function(){ rlm@46: if(this.allowBlur !== true && this.editing){ rlm@46: this.completeEdit(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: if(this.editing){ rlm@46: this.completeEdit(); rlm@46: return; rlm@46: } rlm@46: this.field.blur(); rlm@46: if(this.field.collapse){ rlm@46: this.field.collapse(); rlm@46: } rlm@46: this.el.hide(); rlm@46: if(this.hideEl !== false){ rlm@46: this.boundEl.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: this.field.setValue(v); rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: return this.field.getValue(); rlm@46: }, rlm@46: rlm@46: beforeDestroy : function(){ rlm@46: this.field.destroy(); rlm@46: this.field = null; rlm@46: } rlm@46: }); rlm@46: Ext.reg('editor', Ext.Editor); rlm@46: rlm@46: Ext.MessageBox = function(){ rlm@46: var dlg, opt, mask, waitTimer; rlm@46: var bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl; rlm@46: var buttons, activeTextEl, bwidth, iconCls = ''; rlm@46: rlm@46: rlm@46: var handleButton = function(button){ rlm@46: if(dlg.isVisible()){ rlm@46: dlg.hide(); rlm@46: Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: var handleHide = function(){ rlm@46: if(opt && opt.cls){ rlm@46: dlg.el.removeClass(opt.cls); rlm@46: } rlm@46: progressBar.reset(); rlm@46: }; rlm@46: rlm@46: rlm@46: var handleEsc = function(d, k, e){ rlm@46: if(opt && opt.closable !== false){ rlm@46: dlg.hide(); rlm@46: } rlm@46: if(e){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: var updateButtons = function(b){ rlm@46: var width = 0; rlm@46: if(!b){ rlm@46: buttons["ok"].hide(); rlm@46: buttons["cancel"].hide(); rlm@46: buttons["yes"].hide(); rlm@46: buttons["no"].hide(); rlm@46: return width; rlm@46: } rlm@46: dlg.footer.dom.style.display = ''; rlm@46: for(var k in buttons){ rlm@46: if(typeof buttons[k] != "function"){ rlm@46: if(b[k]){ rlm@46: buttons[k].show(); rlm@46: buttons[k].setText(typeof b[k] == "string" ? b[k] : Ext.MessageBox.buttonText[k]); rlm@46: width += buttons[k].el.getWidth()+15; rlm@46: }else{ rlm@46: buttons[k].hide(); rlm@46: } rlm@46: } rlm@46: } rlm@46: return width; rlm@46: }; rlm@46: rlm@46: return { rlm@46: rlm@46: getDialog : function(titleText){ rlm@46: if(!dlg){ rlm@46: dlg = new Ext.Window({ rlm@46: autoCreate : true, rlm@46: title:titleText, rlm@46: resizable:false, rlm@46: constrain:true, rlm@46: constrainHeader:true, rlm@46: minimizable : false, rlm@46: maximizable : false, rlm@46: stateful: false, rlm@46: modal: true, rlm@46: shim:true, rlm@46: buttonAlign:"center", rlm@46: width:400, rlm@46: height:100, rlm@46: minHeight: 80, rlm@46: plain:true, rlm@46: footer:true, rlm@46: closable:true, rlm@46: close : function(){ rlm@46: if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){ rlm@46: handleButton("no"); rlm@46: }else{ rlm@46: handleButton("cancel"); rlm@46: } rlm@46: } rlm@46: }); rlm@46: buttons = {}; rlm@46: var bt = this.buttonText; rlm@46: rlm@46: buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok")); rlm@46: buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes")); rlm@46: buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no")); rlm@46: buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel")); rlm@46: buttons["ok"].hideMode = buttons["yes"].hideMode = buttons["no"].hideMode = buttons["cancel"].hideMode = 'offsets'; rlm@46: dlg.render(document.body); rlm@46: dlg.getEl().addClass('x-window-dlg'); rlm@46: mask = dlg.mask; rlm@46: bodyEl = dlg.body.createChild({ rlm@46: html:'

    ' rlm@46: }); rlm@46: iconEl = Ext.get(bodyEl.dom.firstChild); rlm@46: var contentEl = bodyEl.dom.childNodes[1]; rlm@46: msgEl = Ext.get(contentEl.firstChild); rlm@46: textboxEl = Ext.get(contentEl.childNodes[2].firstChild); rlm@46: textboxEl.enableDisplayMode(); rlm@46: textboxEl.addKeyListener([10,13], function(){ rlm@46: if(dlg.isVisible() && opt && opt.buttons){ rlm@46: if(opt.buttons.ok){ rlm@46: handleButton("ok"); rlm@46: }else if(opt.buttons.yes){ rlm@46: handleButton("yes"); rlm@46: } rlm@46: } rlm@46: }); rlm@46: textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]); rlm@46: textareaEl.enableDisplayMode(); rlm@46: progressBar = new Ext.ProgressBar({ rlm@46: renderTo:bodyEl rlm@46: }); rlm@46: bodyEl.createChild({cls:'x-clear'}); rlm@46: } rlm@46: return dlg; rlm@46: }, rlm@46: rlm@46: rlm@46: updateText : function(text){ rlm@46: if(!dlg.isVisible() && !opt.width){ rlm@46: dlg.setSize(this.maxWidth, 100); rlm@46: } rlm@46: msgEl.update(text || ' '); rlm@46: rlm@46: var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0; rlm@46: var mw = msgEl.getWidth() + msgEl.getMargins('lr'); rlm@46: var fw = dlg.getFrameWidth('lr'); rlm@46: var bw = dlg.body.getFrameWidth('lr'); rlm@46: if (Ext.isIE && iw > 0){ rlm@46: rlm@46: rlm@46: iw += 3; rlm@46: } rlm@46: var w = Math.max(Math.min(opt.width || iw+mw+fw+bw, this.maxWidth), rlm@46: Math.max(opt.minWidth || this.minWidth, bwidth || 0)); rlm@46: rlm@46: if(opt.prompt === true){ rlm@46: activeTextEl.setWidth(w-iw-fw-bw); rlm@46: } rlm@46: if(opt.progress === true || opt.wait === true){ rlm@46: progressBar.setSize(w-iw-fw-bw); rlm@46: } rlm@46: dlg.setSize(w, 'auto').center(); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: updateProgress : function(value, progressText, msg){ rlm@46: progressBar.updateProgress(value, progressText); rlm@46: if(msg){ rlm@46: this.updateText(msg); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(){ rlm@46: return dlg && dlg.isVisible(); rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(){ rlm@46: if(this.isVisible()){ rlm@46: dlg.hide(); rlm@46: handleHide(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(options){ rlm@46: if(this.isVisible()){ rlm@46: this.hide(); rlm@46: } rlm@46: opt = options; rlm@46: var d = this.getDialog(opt.title || " "); rlm@46: rlm@46: d.setTitle(opt.title || " "); rlm@46: var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true); rlm@46: d.tools.close.setDisplayed(allowClose); rlm@46: activeTextEl = textboxEl; rlm@46: opt.prompt = opt.prompt || (opt.multiline ? true : false); rlm@46: if(opt.prompt){ rlm@46: if(opt.multiline){ rlm@46: textboxEl.hide(); rlm@46: textareaEl.show(); rlm@46: textareaEl.setHeight(typeof opt.multiline == "number" ? rlm@46: opt.multiline : this.defaultTextHeight); rlm@46: activeTextEl = textareaEl; rlm@46: }else{ rlm@46: textboxEl.show(); rlm@46: textareaEl.hide(); rlm@46: } rlm@46: }else{ rlm@46: textboxEl.hide(); rlm@46: textareaEl.hide(); rlm@46: } rlm@46: activeTextEl.dom.value = opt.value || ""; rlm@46: if(opt.prompt){ rlm@46: d.focusEl = activeTextEl; rlm@46: }else{ rlm@46: var bs = opt.buttons; rlm@46: var db = null; rlm@46: if(bs && bs.ok){ rlm@46: db = buttons["ok"]; rlm@46: }else if(bs && bs.yes){ rlm@46: db = buttons["yes"]; rlm@46: } rlm@46: if (db){ rlm@46: d.focusEl = db; rlm@46: } rlm@46: } rlm@46: if(opt.iconCls){ rlm@46: d.setIconClass(opt.iconCls); rlm@46: } rlm@46: this.setIcon(opt.icon); rlm@46: bwidth = updateButtons(opt.buttons); rlm@46: progressBar.setVisible(opt.progress === true || opt.wait === true); rlm@46: this.updateProgress(0, opt.progressText); rlm@46: this.updateText(opt.msg); rlm@46: if(opt.cls){ rlm@46: d.el.addClass(opt.cls); rlm@46: } rlm@46: d.proxyDrag = opt.proxyDrag === true; rlm@46: d.modal = opt.modal !== false; rlm@46: d.mask = opt.modal !== false ? mask : false; rlm@46: if(!d.isVisible()){ rlm@46: rlm@46: document.body.appendChild(dlg.el.dom); rlm@46: d.setAnimateTarget(opt.animEl); rlm@46: d.show(opt.animEl); rlm@46: } rlm@46: rlm@46: rlm@46: d.on('show', function(){ rlm@46: if(allowClose === true){ rlm@46: d.keyMap.enable(); rlm@46: }else{ rlm@46: d.keyMap.disable(); rlm@46: } rlm@46: }, this, {single:true}); rlm@46: rlm@46: if(opt.wait === true){ rlm@46: progressBar.wait(opt.waitConfig); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setIcon : function(icon){ rlm@46: if(icon && icon != ''){ rlm@46: iconEl.removeClass('x-hidden'); rlm@46: iconEl.replaceClass(iconCls, icon); rlm@46: iconCls = icon; rlm@46: }else{ rlm@46: iconEl.replaceClass(iconCls, 'x-hidden'); rlm@46: iconCls = ''; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: progress : function(title, msg, progressText){ rlm@46: this.show({ rlm@46: title : title, rlm@46: msg : msg, rlm@46: buttons: false, rlm@46: progress:true, rlm@46: closable:false, rlm@46: minWidth: this.minProgressWidth, rlm@46: progressText: progressText rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: wait : function(msg, title, config){ rlm@46: this.show({ rlm@46: title : title, rlm@46: msg : msg, rlm@46: buttons: false, rlm@46: closable:false, rlm@46: wait:true, rlm@46: modal:true, rlm@46: minWidth: this.minProgressWidth, rlm@46: waitConfig: config rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: alert : function(title, msg, fn, scope){ rlm@46: this.show({ rlm@46: title : title, rlm@46: msg : msg, rlm@46: buttons: this.OK, rlm@46: fn: fn, rlm@46: scope : scope rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: confirm : function(title, msg, fn, scope){ rlm@46: this.show({ rlm@46: title : title, rlm@46: msg : msg, rlm@46: buttons: this.YESNO, rlm@46: fn: fn, rlm@46: scope : scope, rlm@46: icon: this.QUESTION rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: prompt : function(title, msg, fn, scope, multiline, value){ rlm@46: this.show({ rlm@46: title : title, rlm@46: msg : msg, rlm@46: buttons: this.OKCANCEL, rlm@46: fn: fn, rlm@46: minWidth:250, rlm@46: scope : scope, rlm@46: prompt:true, rlm@46: multiline: multiline, rlm@46: value: value rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: OK : {ok:true}, rlm@46: rlm@46: CANCEL : {cancel:true}, rlm@46: rlm@46: OKCANCEL : {ok:true, cancel:true}, rlm@46: rlm@46: YESNO : {yes:true, no:true}, rlm@46: rlm@46: YESNOCANCEL : {yes:true, no:true, cancel:true}, rlm@46: rlm@46: INFO : 'ext-mb-info', rlm@46: rlm@46: WARNING : 'ext-mb-warning', rlm@46: rlm@46: QUESTION : 'ext-mb-question', rlm@46: rlm@46: ERROR : 'ext-mb-error', rlm@46: rlm@46: rlm@46: defaultTextHeight : 75, rlm@46: rlm@46: maxWidth : 600, rlm@46: rlm@46: minWidth : 100, rlm@46: rlm@46: minProgressWidth : 250, rlm@46: rlm@46: buttonText : { rlm@46: ok : "OK", rlm@46: cancel : "Cancel", rlm@46: yes : "Yes", rlm@46: no : "No" rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.Msg = Ext.MessageBox; rlm@46: rlm@46: Ext.Tip = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: rlm@46: minWidth : 40, rlm@46: rlm@46: maxWidth : 300, rlm@46: rlm@46: shadow : "sides", rlm@46: rlm@46: defaultAlign : "tl-bl?", rlm@46: autoRender: true, rlm@46: quickShowInterval : 250, rlm@46: rlm@46: rlm@46: frame:true, rlm@46: hidden:true, rlm@46: baseCls: 'x-tip', rlm@46: floating:{shadow:true,shim:true,useDisplay:true,constrain:false}, rlm@46: autoHeight:true, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.Tip.superclass.initComponent.call(this); rlm@46: if(this.closable && !this.title){ rlm@46: this.elements += ',header'; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.Tip.superclass.afterRender.call(this); rlm@46: if(this.closable){ rlm@46: this.addTool({ rlm@46: id: 'close', rlm@46: handler: this.hide, rlm@46: scope: this rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: showAt : function(xy){ rlm@46: Ext.Tip.superclass.show.call(this); rlm@46: if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){ rlm@46: this.doAutoWidth(); rlm@46: } rlm@46: if(this.constrainPosition){ rlm@46: xy = this.el.adjustForConstraints(xy); rlm@46: } rlm@46: this.setPagePosition(xy[0], xy[1]); rlm@46: }, rlm@46: rlm@46: rlm@46: doAutoWidth : function(){ rlm@46: var bw = this.body.getTextWidth(); rlm@46: if(this.title){ rlm@46: bw = Math.max(bw, this.header.child('span').getTextWidth(this.title)); rlm@46: } rlm@46: bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr"); rlm@46: this.setWidth(bw.constrain(this.minWidth, this.maxWidth)); rlm@46: }, rlm@46: rlm@46: rlm@46: showBy : function(el, pos){ rlm@46: if(!this.rendered){ rlm@46: this.render(Ext.getBody()); rlm@46: } rlm@46: this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign)); rlm@46: }, rlm@46: rlm@46: initDraggable : function(){ rlm@46: this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable); rlm@46: this.header.addClass('x-tip-draggable'); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.Tip.DD = function(tip, config){ rlm@46: Ext.apply(this, config); rlm@46: this.tip = tip; rlm@46: Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id); rlm@46: this.setHandleElId(tip.header.id); rlm@46: this.scroll = false; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.Tip.DD, Ext.dd.DD, { rlm@46: moveOnly:true, rlm@46: scroll:false, rlm@46: headerOffsets:[100, 25], rlm@46: startDrag : function(){ rlm@46: this.tip.el.disableShadow(); rlm@46: }, rlm@46: endDrag : function(e){ rlm@46: this.tip.el.enableShadow(true); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.ToolTip = Ext.extend(Ext.Tip, { rlm@46: rlm@46: rlm@46: rlm@46: showDelay: 500, rlm@46: rlm@46: hideDelay: 200, rlm@46: rlm@46: dismissDelay: 5000, rlm@46: rlm@46: mouseOffset: [15,18], rlm@46: rlm@46: trackMouse : false, rlm@46: constrainPosition: true, rlm@46: rlm@46: rlm@46: initComponent: function(){ rlm@46: Ext.ToolTip.superclass.initComponent.call(this); rlm@46: this.lastActive = new Date(); rlm@46: this.initTarget(); rlm@46: }, rlm@46: rlm@46: rlm@46: initTarget : function(){ rlm@46: if(this.target){ rlm@46: this.target = Ext.get(this.target); rlm@46: this.target.on('mouseover', this.onTargetOver, this); rlm@46: this.target.on('mouseout', this.onTargetOut, this); rlm@46: this.target.on('mousemove', this.onMouseMove, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseMove : function(e){ rlm@46: this.targetXY = e.getXY(); rlm@46: if(!this.hidden && this.trackMouse){ rlm@46: this.setPagePosition(this.getTargetXY()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTargetXY : function(){ rlm@46: return [this.targetXY[0]+this.mouseOffset[0], this.targetXY[1]+this.mouseOffset[1]]; rlm@46: }, rlm@46: rlm@46: rlm@46: onTargetOver : function(e){ rlm@46: if(this.disabled || e.within(this.target.dom, true)){ rlm@46: return; rlm@46: } rlm@46: this.clearTimer('hide'); rlm@46: this.targetXY = e.getXY(); rlm@46: this.delayShow(); rlm@46: }, rlm@46: rlm@46: rlm@46: delayShow : function(){ rlm@46: if(this.hidden && !this.showTimer){ rlm@46: if(this.lastActive.getElapsed() < this.quickShowInterval){ rlm@46: this.show(); rlm@46: }else{ rlm@46: this.showTimer = this.show.defer(this.showDelay, this); rlm@46: } rlm@46: }else if(!this.hidden && this.autoHide !== false){ rlm@46: this.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onTargetOut : function(e){ rlm@46: if(this.disabled || e.within(this.target.dom, true)){ rlm@46: return; rlm@46: } rlm@46: this.clearTimer('show'); rlm@46: if(this.autoHide !== false){ rlm@46: this.delayHide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: delayHide : function(){ rlm@46: if(!this.hidden && !this.hideTimer){ rlm@46: this.hideTimer = this.hide.defer(this.hideDelay, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hide: function(){ rlm@46: this.clearTimer('dismiss'); rlm@46: this.lastActive = new Date(); rlm@46: Ext.ToolTip.superclass.hide.call(this); rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(){ rlm@46: this.showAt(this.getTargetXY()); rlm@46: }, rlm@46: rlm@46: rlm@46: showAt : function(xy){ rlm@46: this.lastActive = new Date(); rlm@46: this.clearTimers(); rlm@46: Ext.ToolTip.superclass.showAt.call(this, xy); rlm@46: if(this.dismissDelay && this.autoHide !== false){ rlm@46: this.dismissTimer = this.hide.defer(this.dismissDelay, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clearTimer : function(name){ rlm@46: name = name + 'Timer'; rlm@46: clearTimeout(this[name]); rlm@46: delete this[name]; rlm@46: }, rlm@46: rlm@46: rlm@46: clearTimers : function(){ rlm@46: this.clearTimer('show'); rlm@46: this.clearTimer('dismiss'); rlm@46: this.clearTimer('hide'); rlm@46: }, rlm@46: rlm@46: rlm@46: onShow : function(){ rlm@46: Ext.ToolTip.superclass.onShow.call(this); rlm@46: Ext.getDoc().on('mousedown', this.onDocMouseDown, this); rlm@46: }, rlm@46: rlm@46: rlm@46: onHide : function(){ rlm@46: Ext.ToolTip.superclass.onHide.call(this); rlm@46: Ext.getDoc().un('mousedown', this.onDocMouseDown, this); rlm@46: }, rlm@46: rlm@46: rlm@46: onDocMouseDown : function(e){ rlm@46: if(this.autoHide !== false && !e.within(this.el.dom)){ rlm@46: this.disable(); rlm@46: this.enable.defer(100, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onDisable : function(){ rlm@46: this.clearTimers(); rlm@46: this.hide(); rlm@46: }, rlm@46: rlm@46: rlm@46: adjustPosition : function(x, y){ rlm@46: rlm@46: var ay = this.targetXY[1], h = this.getSize().height; rlm@46: if(this.constrainPosition && y <= ay && (y+h) >= ay){ rlm@46: y = ay-h-5; rlm@46: } rlm@46: return {x : x, y: y}; rlm@46: }, rlm@46: rlm@46: rlm@46: onDestroy : function(){ rlm@46: Ext.ToolTip.superclass.onDestroy.call(this); rlm@46: if(this.target){ rlm@46: this.target.un('mouseover', this.onTargetOver, this); rlm@46: this.target.un('mouseout', this.onTargetOut, this); rlm@46: this.target.un('mousemove', this.onMouseMove, this); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.QuickTip = Ext.extend(Ext.ToolTip, { rlm@46: rlm@46: rlm@46: interceptTitles : false, rlm@46: rlm@46: rlm@46: tagConfig : { rlm@46: namespace : "ext", rlm@46: attribute : "qtip", rlm@46: width : "qwidth", rlm@46: target : "target", rlm@46: title : "qtitle", rlm@46: hide : "hide", rlm@46: cls : "qclass", rlm@46: align : "qalign" rlm@46: }, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: this.target = this.target || Ext.getDoc(); rlm@46: this.targets = this.targets || {}; rlm@46: Ext.QuickTip.superclass.initComponent.call(this); rlm@46: }, rlm@46: rlm@46: rlm@46: register : function(config){ rlm@46: var cs = Ext.isArray(config) ? config : arguments; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: var c = cs[i]; rlm@46: var target = c.target; rlm@46: if(target){ rlm@46: if(Ext.isArray(target)){ rlm@46: for(var j = 0, jlen = target.length; j < jlen; j++){ rlm@46: this.targets[Ext.id(target[j])] = c; rlm@46: } rlm@46: } else{ rlm@46: this.targets[Ext.id(target)] = c; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(el){ rlm@46: delete this.targets[Ext.id(el)]; rlm@46: }, rlm@46: rlm@46: rlm@46: onTargetOver : function(e){ rlm@46: if(this.disabled){ rlm@46: return; rlm@46: } rlm@46: this.targetXY = e.getXY(); rlm@46: var t = e.getTarget(); rlm@46: if(!t || t.nodeType !== 1 || t == document || t == document.body){ rlm@46: return; rlm@46: } rlm@46: if(this.activeTarget && t == this.activeTarget.el){ rlm@46: this.clearTimer('hide'); rlm@46: this.show(); rlm@46: return; rlm@46: } rlm@46: if(t && this.targets[t.id]){ rlm@46: this.activeTarget = this.targets[t.id]; rlm@46: this.activeTarget.el = t; rlm@46: this.delayShow(); rlm@46: return; rlm@46: } rlm@46: var ttp, et = Ext.fly(t), cfg = this.tagConfig; rlm@46: var ns = cfg.namespace; rlm@46: if(this.interceptTitles && t.title){ rlm@46: ttp = t.title; rlm@46: t.qtip = ttp; rlm@46: t.removeAttribute("title"); rlm@46: e.preventDefault(); rlm@46: } else{ rlm@46: ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute); rlm@46: } rlm@46: if(ttp){ rlm@46: var autoHide = et.getAttributeNS(ns, cfg.hide); rlm@46: this.activeTarget = { rlm@46: el: t, rlm@46: text: ttp, rlm@46: width: et.getAttributeNS(ns, cfg.width), rlm@46: autoHide: autoHide != "user" && autoHide !== 'false', rlm@46: title: et.getAttributeNS(ns, cfg.title), rlm@46: cls: et.getAttributeNS(ns, cfg.cls), rlm@46: align: et.getAttributeNS(ns, cfg.align) rlm@46: }; rlm@46: this.delayShow(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onTargetOut : function(e){ rlm@46: this.clearTimer('show'); rlm@46: if(this.autoHide !== false){ rlm@46: this.delayHide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: showAt : function(xy){ rlm@46: var t = this.activeTarget; rlm@46: if(t){ rlm@46: if(!this.rendered){ rlm@46: this.render(Ext.getBody()); rlm@46: this.activeTarget = t; rlm@46: } rlm@46: if(t.width){ rlm@46: this.setWidth(t.width); rlm@46: this.body.setWidth(this.adjustBodyWidth(t.width - this.getFrameWidth())); rlm@46: this.measureWidth = false; rlm@46: } else{ rlm@46: this.measureWidth = true; rlm@46: } rlm@46: this.setTitle(t.title || ''); rlm@46: this.body.update(t.text); rlm@46: this.autoHide = t.autoHide; rlm@46: this.dismissDelay = t.dismissDelay || this.dismissDelay; rlm@46: if(this.lastCls){ rlm@46: this.el.removeClass(this.lastCls); rlm@46: delete this.lastCls; rlm@46: } rlm@46: if(t.cls){ rlm@46: this.el.addClass(t.cls); rlm@46: this.lastCls = t.cls; rlm@46: } rlm@46: if(t.align){ rlm@46: xy = this.el.getAlignToXY(t.el, t.align); rlm@46: this.constrainPosition = false; rlm@46: } else{ rlm@46: this.constrainPosition = true; rlm@46: } rlm@46: } rlm@46: Ext.QuickTip.superclass.showAt.call(this, xy); rlm@46: }, rlm@46: rlm@46: rlm@46: hide: function(){ rlm@46: delete this.activeTarget; rlm@46: Ext.QuickTip.superclass.hide.call(this); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.QuickTips = function(){ rlm@46: var tip, locks = []; rlm@46: return { rlm@46: rlm@46: init : function(){ rlm@46: if(!tip){ rlm@46: tip = new Ext.QuickTip({elements:'header,body'}); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: if(tip){ rlm@46: locks.pop(); rlm@46: if(locks.length < 1){ rlm@46: tip.enable(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: if(tip){ rlm@46: tip.disable(); rlm@46: } rlm@46: locks.push(1); rlm@46: }, rlm@46: rlm@46: rlm@46: isEnabled : function(){ rlm@46: return tip !== undefined && !tip.disabled; rlm@46: }, rlm@46: rlm@46: rlm@46: getQuickTip : function(){ rlm@46: return tip; rlm@46: }, rlm@46: rlm@46: rlm@46: register : function(){ rlm@46: tip.register.apply(tip, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: unregister : function(){ rlm@46: tip.unregister.apply(tip, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: tips :function(){ rlm@46: tip.register.apply(tip, arguments); rlm@46: } rlm@46: } rlm@46: }(); rlm@46: rlm@46: Ext.tree.TreePanel = Ext.extend(Ext.Panel, { rlm@46: rootVisible : true, rlm@46: animate: Ext.enableFx, rlm@46: lines : true, rlm@46: enableDD : false, rlm@46: hlDrop : Ext.enableFx, rlm@46: pathSeparator: "/", rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.tree.TreePanel.superclass.initComponent.call(this); rlm@46: rlm@46: if(!this.eventModel){ rlm@46: this.eventModel = new Ext.tree.TreeEventModel(this); rlm@46: } rlm@46: rlm@46: this.nodeHash = {}; rlm@46: rlm@46: rlm@46: if(this.root){ rlm@46: this.setRootNode(this.root); rlm@46: } rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: rlm@46: "append", rlm@46: rlm@46: "remove", rlm@46: rlm@46: "movenode", rlm@46: rlm@46: "insert", rlm@46: rlm@46: "beforeappend", rlm@46: rlm@46: "beforeremove", rlm@46: rlm@46: "beforemovenode", rlm@46: rlm@46: "beforeinsert", rlm@46: rlm@46: rlm@46: "beforeload", rlm@46: rlm@46: "load", rlm@46: rlm@46: "textchange", rlm@46: rlm@46: "beforeexpandnode", rlm@46: rlm@46: "beforecollapsenode", rlm@46: rlm@46: "expandnode", rlm@46: rlm@46: "disabledchange", rlm@46: rlm@46: "collapsenode", rlm@46: rlm@46: "beforeclick", rlm@46: rlm@46: "click", rlm@46: rlm@46: "checkchange", rlm@46: rlm@46: "dblclick", rlm@46: rlm@46: "contextmenu", rlm@46: rlm@46: "beforechildrenrendered", rlm@46: rlm@46: "startdrag", rlm@46: rlm@46: "enddrag", rlm@46: rlm@46: "dragdrop", rlm@46: rlm@46: "beforenodedrop", rlm@46: rlm@46: "nodedrop", rlm@46: rlm@46: "nodedragover" rlm@46: ); rlm@46: if(this.singleExpand){ rlm@46: this.on("beforeexpandnode", this.restrictExpand, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){ rlm@46: if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){ rlm@46: ename = ename+'node'; rlm@46: } rlm@46: rlm@46: return this.fireEvent(ename, a1, a2, a3, a4, a5, a6); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: getRootNode : function(){ rlm@46: return this.root; rlm@46: }, rlm@46: rlm@46: rlm@46: setRootNode : function(node){ rlm@46: this.root = node; rlm@46: node.ownerTree = this; rlm@46: node.isRoot = true; rlm@46: this.registerNode(node); rlm@46: if(!this.rootVisible){ rlm@46: var uiP = node.attributes.uiProvider; rlm@46: node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node); rlm@46: } rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: getNodeById : function(id){ rlm@46: return this.nodeHash[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: registerNode : function(node){ rlm@46: this.nodeHash[node.id] = node; rlm@46: }, rlm@46: rlm@46: rlm@46: unregisterNode : function(node){ rlm@46: delete this.nodeHash[node.id]; rlm@46: }, rlm@46: rlm@46: rlm@46: toString : function(){ rlm@46: return "[Tree"+(this.id?" "+this.id:"")+"]"; rlm@46: }, rlm@46: rlm@46: rlm@46: restrictExpand : function(node){ rlm@46: var p = node.parentNode; rlm@46: if(p){ rlm@46: if(p.expandedChild && p.expandedChild.parentNode == p){ rlm@46: p.expandedChild.collapse(); rlm@46: } rlm@46: p.expandedChild = node; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getChecked : function(a, startNode){ rlm@46: startNode = startNode || this.root; rlm@46: var r = []; rlm@46: var f = function(){ rlm@46: if(this.attributes.checked){ rlm@46: r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a])); rlm@46: } rlm@46: } rlm@46: startNode.cascade(f); rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: getLoader : function(){ rlm@46: return this.loader; rlm@46: }, rlm@46: rlm@46: rlm@46: expandAll : function(){ rlm@46: this.root.expand(true); rlm@46: }, rlm@46: rlm@46: rlm@46: collapseAll : function(){ rlm@46: this.root.collapse(true); rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectionModel : function(){ rlm@46: if(!this.selModel){ rlm@46: this.selModel = new Ext.tree.DefaultSelectionModel(); rlm@46: } rlm@46: return this.selModel; rlm@46: }, rlm@46: rlm@46: rlm@46: expandPath : function(path, attr, callback){ rlm@46: attr = attr || "id"; rlm@46: var keys = path.split(this.pathSeparator); rlm@46: var curNode = this.root; rlm@46: if(curNode.attributes[attr] != keys[1]){ rlm@46: if(callback){ rlm@46: callback(false, null); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var index = 1; rlm@46: var f = function(){ rlm@46: if(++index == keys.length){ rlm@46: if(callback){ rlm@46: callback(true, curNode); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var c = curNode.findChild(attr, keys[index]); rlm@46: if(!c){ rlm@46: if(callback){ rlm@46: callback(false, curNode); rlm@46: } rlm@46: return; rlm@46: } rlm@46: curNode = c; rlm@46: c.expand(false, false, f); rlm@46: }; rlm@46: curNode.expand(false, false, f); rlm@46: }, rlm@46: rlm@46: rlm@46: selectPath : function(path, attr, callback){ rlm@46: attr = attr || "id"; rlm@46: var keys = path.split(this.pathSeparator); rlm@46: var v = keys.pop(); rlm@46: if(keys.length > 0){ rlm@46: var f = function(success, node){ rlm@46: if(success && node){ rlm@46: var n = node.findChild(attr, v); rlm@46: if(n){ rlm@46: n.select(); rlm@46: if(callback){ rlm@46: callback(true, n); rlm@46: } rlm@46: }else if(callback){ rlm@46: callback(false, n); rlm@46: } rlm@46: }else{ rlm@46: if(callback){ rlm@46: callback(false, n); rlm@46: } rlm@46: } rlm@46: }; rlm@46: this.expandPath(keys.join(this.pathSeparator), attr, f); rlm@46: }else{ rlm@46: this.root.select(); rlm@46: if(callback){ rlm@46: callback(true, this.root); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTreeEl : function(){ rlm@46: return this.body; rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.tree.TreePanel.superclass.onRender.call(this, ct, position); rlm@46: this.el.addClass('x-tree'); rlm@46: this.innerCt = this.body.createChild({tag:"ul", rlm@46: cls:"x-tree-root-ct " + rlm@46: (this.useArrows ? 'x-tree-arrows' : this.lines ? "x-tree-lines" : "x-tree-no-lines")}); rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.tree.TreePanel.superclass.initEvents.call(this); rlm@46: rlm@46: if(this.containerScroll){ rlm@46: Ext.dd.ScrollManager.register(this.body); rlm@46: } rlm@46: if((this.enableDD || this.enableDrop) && !this.dropZone){ rlm@46: rlm@46: this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || { rlm@46: ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true rlm@46: }); rlm@46: } rlm@46: if((this.enableDD || this.enableDrag) && !this.dragZone){ rlm@46: rlm@46: this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || { rlm@46: ddGroup: this.ddGroup || "TreeDD", rlm@46: scroll: this.ddScroll rlm@46: }); rlm@46: } rlm@46: this.getSelectionModel().init(this); rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.tree.TreePanel.superclass.afterRender.call(this); rlm@46: this.root.render(); rlm@46: if(!this.rootVisible){ rlm@46: this.root.renderChildren(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.rendered){ rlm@46: this.body.removeAllListeners(); rlm@46: Ext.dd.ScrollManager.unregister(this.body); rlm@46: if(this.dropZone){ rlm@46: this.dropZone.unreg(); rlm@46: } rlm@46: if(this.dragZone){ rlm@46: this.dragZone.unreg(); rlm@46: } rlm@46: } rlm@46: this.root.destroy(); rlm@46: this.nodeHash = null; rlm@46: Ext.tree.TreePanel.superclass.onDestroy.call(this); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('treepanel', Ext.tree.TreePanel); rlm@46: Ext.tree.TreeEventModel = function(tree){ rlm@46: this.tree = tree; rlm@46: this.tree.on('render', this.initEvents, this); rlm@46: } rlm@46: rlm@46: Ext.tree.TreeEventModel.prototype = { rlm@46: initEvents : function(){ rlm@46: var el = this.tree.getTreeEl(); rlm@46: el.on('click', this.delegateClick, this); rlm@46: if(this.tree.trackMouseOver !== false){ rlm@46: el.on('mouseover', this.delegateOver, this); rlm@46: el.on('mouseout', this.delegateOut, this); rlm@46: } rlm@46: el.on('dblclick', this.delegateDblClick, this); rlm@46: el.on('contextmenu', this.delegateContextMenu, this); rlm@46: }, rlm@46: rlm@46: getNode : function(e){ rlm@46: var t; rlm@46: if(t = e.getTarget('.x-tree-node-el', 10)){ rlm@46: var id = Ext.fly(t, '_treeEvents').getAttributeNS('ext', 'tree-node-id'); rlm@46: if(id){ rlm@46: return this.tree.getNodeById(id); rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: getNodeTarget : function(e){ rlm@46: var t = e.getTarget('.x-tree-node-icon', 1); rlm@46: if(!t){ rlm@46: t = e.getTarget('.x-tree-node-el', 6); rlm@46: } rlm@46: return t; rlm@46: }, rlm@46: rlm@46: delegateOut : function(e, t){ rlm@46: if(!this.beforeEvent(e)){ rlm@46: return; rlm@46: } rlm@46: if(e.getTarget('.x-tree-ec-icon', 1)){ rlm@46: var n = this.getNode(e); rlm@46: this.onIconOut(e, n); rlm@46: if(n == this.lastEcOver){ rlm@46: delete this.lastEcOver; rlm@46: } rlm@46: } rlm@46: if((t = this.getNodeTarget(e)) && !e.within(t, true)){ rlm@46: this.onNodeOut(e, this.getNode(e)); rlm@46: } rlm@46: }, rlm@46: rlm@46: delegateOver : function(e, t){ rlm@46: if(!this.beforeEvent(e)){ rlm@46: return; rlm@46: } rlm@46: if(this.lastEcOver){ rlm@46: this.onIconOut(e, this.lastEcOver); rlm@46: delete this.lastEcOver; rlm@46: } rlm@46: if(e.getTarget('.x-tree-ec-icon', 1)){ rlm@46: this.lastEcOver = this.getNode(e); rlm@46: this.onIconOver(e, this.lastEcOver); rlm@46: } rlm@46: if(t = this.getNodeTarget(e)){ rlm@46: this.onNodeOver(e, this.getNode(e)); rlm@46: } rlm@46: }, rlm@46: rlm@46: delegateClick : function(e, t){ rlm@46: if(!this.beforeEvent(e)){ rlm@46: return; rlm@46: } rlm@46: rlm@46: if(e.getTarget('input[type=checkbox]', 1)){ rlm@46: this.onCheckboxClick(e, this.getNode(e)); rlm@46: } rlm@46: else if(e.getTarget('.x-tree-ec-icon', 1)){ rlm@46: this.onIconClick(e, this.getNode(e)); rlm@46: } rlm@46: else if(this.getNodeTarget(e)){ rlm@46: this.onNodeClick(e, this.getNode(e)); rlm@46: } rlm@46: }, rlm@46: rlm@46: delegateDblClick : function(e, t){ rlm@46: if(this.beforeEvent(e) && this.getNodeTarget(e)){ rlm@46: this.onNodeDblClick(e, this.getNode(e)); rlm@46: } rlm@46: }, rlm@46: rlm@46: delegateContextMenu : function(e, t){ rlm@46: if(this.beforeEvent(e) && this.getNodeTarget(e)){ rlm@46: this.onNodeContextMenu(e, this.getNode(e)); rlm@46: } rlm@46: }, rlm@46: rlm@46: onNodeClick : function(e, node){ rlm@46: node.ui.onClick(e); rlm@46: }, rlm@46: rlm@46: onNodeOver : function(e, node){ rlm@46: node.ui.onOver(e); rlm@46: }, rlm@46: rlm@46: onNodeOut : function(e, node){ rlm@46: node.ui.onOut(e); rlm@46: }, rlm@46: rlm@46: onIconOver : function(e, node){ rlm@46: node.ui.addClass('x-tree-ec-over'); rlm@46: }, rlm@46: rlm@46: onIconOut : function(e, node){ rlm@46: node.ui.removeClass('x-tree-ec-over'); rlm@46: }, rlm@46: rlm@46: onIconClick : function(e, node){ rlm@46: node.ui.ecClick(e); rlm@46: }, rlm@46: rlm@46: onCheckboxClick : function(e, node){ rlm@46: node.ui.onCheckChange(e); rlm@46: }, rlm@46: rlm@46: onNodeDblClick : function(e, node){ rlm@46: node.ui.onDblClick(e); rlm@46: }, rlm@46: rlm@46: onNodeContextMenu : function(e, node){ rlm@46: node.ui.onContextMenu(e); rlm@46: }, rlm@46: rlm@46: beforeEvent : function(e){ rlm@46: if(this.disabled){ rlm@46: e.stopEvent(); rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: disable: function(){ rlm@46: this.disabled = true; rlm@46: }, rlm@46: rlm@46: enable: function(){ rlm@46: this.disabled = false; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.tree.DefaultSelectionModel = function(config){ rlm@46: this.selNode = null; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "selectionchange", rlm@46: rlm@46: rlm@46: "beforeselect" rlm@46: ); rlm@46: rlm@46: Ext.apply(this, config); rlm@46: Ext.tree.DefaultSelectionModel.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, { rlm@46: init : function(tree){ rlm@46: this.tree = tree; rlm@46: tree.getTreeEl().on("keydown", this.onKeyDown, this); rlm@46: tree.on("click", this.onNodeClick, this); rlm@46: }, rlm@46: rlm@46: onNodeClick : function(node, e){ rlm@46: this.select(node); rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(node){ rlm@46: var last = this.selNode; rlm@46: if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){ rlm@46: if(last){ rlm@46: last.ui.onSelectedChange(false); rlm@46: } rlm@46: this.selNode = node; rlm@46: node.ui.onSelectedChange(true); rlm@46: this.fireEvent("selectionchange", this, node, last); rlm@46: } rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: unselect : function(node){ rlm@46: if(this.selNode == node){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clearSelections : function(){ rlm@46: var n = this.selNode; rlm@46: if(n){ rlm@46: n.ui.onSelectedChange(false); rlm@46: this.selNode = null; rlm@46: this.fireEvent("selectionchange", this, null); rlm@46: } rlm@46: return n; rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedNode : function(){ rlm@46: return this.selNode; rlm@46: }, rlm@46: rlm@46: rlm@46: isSelected : function(node){ rlm@46: return this.selNode == node; rlm@46: }, rlm@46: rlm@46: rlm@46: selectPrevious : function(){ rlm@46: var s = this.selNode || this.lastSelNode; rlm@46: if(!s){ rlm@46: return null; rlm@46: } rlm@46: var ps = s.previousSibling; rlm@46: if(ps){ rlm@46: if(!ps.isExpanded() || ps.childNodes.length < 1){ rlm@46: return this.select(ps); rlm@46: } else{ rlm@46: var lc = ps.lastChild; rlm@46: while(lc && lc.isExpanded() && lc.childNodes.length > 0){ rlm@46: lc = lc.lastChild; rlm@46: } rlm@46: return this.select(lc); rlm@46: } rlm@46: } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){ rlm@46: return this.select(s.parentNode); rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: selectNext : function(){ rlm@46: var s = this.selNode || this.lastSelNode; rlm@46: if(!s){ rlm@46: return null; rlm@46: } rlm@46: if(s.firstChild && s.isExpanded()){ rlm@46: return this.select(s.firstChild); rlm@46: }else if(s.nextSibling){ rlm@46: return this.select(s.nextSibling); rlm@46: }else if(s.parentNode){ rlm@46: var newS = null; rlm@46: s.parentNode.bubble(function(){ rlm@46: if(this.nextSibling){ rlm@46: newS = this.getOwnerTree().selModel.select(this.nextSibling); rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: return newS; rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: onKeyDown : function(e){ rlm@46: var s = this.selNode || this.lastSelNode; rlm@46: rlm@46: var sm = this; rlm@46: if(!s){ rlm@46: return; rlm@46: } rlm@46: var k = e.getKey(); rlm@46: switch(k){ rlm@46: case e.DOWN: rlm@46: e.stopEvent(); rlm@46: this.selectNext(); rlm@46: break; rlm@46: case e.UP: rlm@46: e.stopEvent(); rlm@46: this.selectPrevious(); rlm@46: break; rlm@46: case e.RIGHT: rlm@46: e.preventDefault(); rlm@46: if(s.hasChildNodes()){ rlm@46: if(!s.isExpanded()){ rlm@46: s.expand(); rlm@46: }else if(s.firstChild){ rlm@46: this.select(s.firstChild, e); rlm@46: } rlm@46: } rlm@46: break; rlm@46: case e.LEFT: rlm@46: e.preventDefault(); rlm@46: if(s.hasChildNodes() && s.isExpanded()){ rlm@46: s.collapse(); rlm@46: }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){ rlm@46: this.select(s.parentNode, e); rlm@46: } rlm@46: break; rlm@46: }; rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.tree.MultiSelectionModel = function(config){ rlm@46: this.selNodes = []; rlm@46: this.selMap = {}; rlm@46: this.addEvents( rlm@46: rlm@46: "selectionchange" rlm@46: ); rlm@46: Ext.apply(this, config); rlm@46: Ext.tree.MultiSelectionModel.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, { rlm@46: init : function(tree){ rlm@46: this.tree = tree; rlm@46: tree.getTreeEl().on("keydown", this.onKeyDown, this); rlm@46: tree.on("click", this.onNodeClick, this); rlm@46: }, rlm@46: rlm@46: onNodeClick : function(node, e){ rlm@46: this.select(node, e, e.ctrlKey); rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(node, e, keepExisting){ rlm@46: if(keepExisting !== true){ rlm@46: this.clearSelections(true); rlm@46: } rlm@46: if(this.isSelected(node)){ rlm@46: this.lastSelNode = node; rlm@46: return node; rlm@46: } rlm@46: this.selNodes.push(node); rlm@46: this.selMap[node.id] = node; rlm@46: this.lastSelNode = node; rlm@46: node.ui.onSelectedChange(true); rlm@46: this.fireEvent("selectionchange", this, this.selNodes); rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: unselect : function(node){ rlm@46: if(this.selMap[node.id]){ rlm@46: node.ui.onSelectedChange(false); rlm@46: var sn = this.selNodes; rlm@46: var index = sn.indexOf(node); rlm@46: if(index != -1){ rlm@46: this.selNodes.splice(index, 1); rlm@46: } rlm@46: delete this.selMap[node.id]; rlm@46: this.fireEvent("selectionchange", this, this.selNodes); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clearSelections : function(suppressEvent){ rlm@46: var sn = this.selNodes; rlm@46: if(sn.length > 0){ rlm@46: for(var i = 0, len = sn.length; i < len; i++){ rlm@46: sn[i].ui.onSelectedChange(false); rlm@46: } rlm@46: this.selNodes = []; rlm@46: this.selMap = {}; rlm@46: if(suppressEvent !== true){ rlm@46: this.fireEvent("selectionchange", this, this.selNodes); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isSelected : function(node){ rlm@46: return this.selMap[node.id] ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedNodes : function(){ rlm@46: return this.selNodes; rlm@46: }, rlm@46: rlm@46: onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown, rlm@46: rlm@46: selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext, rlm@46: rlm@46: selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious rlm@46: }); rlm@46: rlm@46: Ext.tree.TreeNode = function(attributes){ rlm@46: attributes = attributes || {}; rlm@46: if(typeof attributes == "string"){ rlm@46: attributes = {text: attributes}; rlm@46: } rlm@46: this.childrenRendered = false; rlm@46: this.rendered = false; rlm@46: Ext.tree.TreeNode.superclass.constructor.call(this, attributes); rlm@46: this.expanded = attributes.expanded === true; rlm@46: this.isTarget = attributes.isTarget !== false; rlm@46: this.draggable = attributes.draggable !== false && attributes.allowDrag !== false; rlm@46: this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false; rlm@46: rlm@46: rlm@46: this.text = attributes.text; rlm@46: rlm@46: this.disabled = attributes.disabled === true; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "textchange", rlm@46: rlm@46: "beforeexpand", rlm@46: rlm@46: "beforecollapse", rlm@46: rlm@46: "expand", rlm@46: rlm@46: "disabledchange", rlm@46: rlm@46: "collapse", rlm@46: rlm@46: "beforeclick", rlm@46: rlm@46: "click", rlm@46: rlm@46: "checkchange", rlm@46: rlm@46: "dblclick", rlm@46: rlm@46: "contextmenu", rlm@46: rlm@46: "beforechildrenrendered" rlm@46: ); rlm@46: rlm@46: var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI; rlm@46: rlm@46: rlm@46: this.ui = new uiClass(this); rlm@46: }; rlm@46: Ext.extend(Ext.tree.TreeNode, Ext.data.Node, { rlm@46: preventHScroll: true, rlm@46: rlm@46: isExpanded : function(){ rlm@46: return this.expanded; rlm@46: }, rlm@46: rlm@46: rlm@46: getUI : function(){ rlm@46: return this.ui; rlm@46: }, rlm@46: rlm@46: rlm@46: setFirstChild : function(node){ rlm@46: var of = this.firstChild; rlm@46: Ext.tree.TreeNode.superclass.setFirstChild.call(this, node); rlm@46: if(this.childrenRendered && of && node != of){ rlm@46: of.renderIndent(true, true); rlm@46: } rlm@46: if(this.rendered){ rlm@46: this.renderIndent(true, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setLastChild : function(node){ rlm@46: var ol = this.lastChild; rlm@46: Ext.tree.TreeNode.superclass.setLastChild.call(this, node); rlm@46: if(this.childrenRendered && ol && node != ol){ rlm@46: ol.renderIndent(true, true); rlm@46: } rlm@46: if(this.rendered){ rlm@46: this.renderIndent(true, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: appendChild : function(){ rlm@46: var node = Ext.tree.TreeNode.superclass.appendChild.apply(this, arguments); rlm@46: if(node && this.childrenRendered){ rlm@46: node.render(); rlm@46: } rlm@46: this.ui.updateExpandIcon(); rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: removeChild : function(node){ rlm@46: this.ownerTree.getSelectionModel().unselect(node); rlm@46: Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments); rlm@46: rlm@46: if(this.childrenRendered){ rlm@46: node.ui.remove(); rlm@46: } rlm@46: if(this.childNodes.length < 1){ rlm@46: this.collapse(false, false); rlm@46: }else{ rlm@46: this.ui.updateExpandIcon(); rlm@46: } rlm@46: if(!this.firstChild && !this.isHiddenRoot()) { rlm@46: this.childrenRendered = false; rlm@46: } rlm@46: return node; rlm@46: }, rlm@46: rlm@46: rlm@46: insertBefore : function(node, refNode){ rlm@46: var newNode = Ext.tree.TreeNode.superclass.insertBefore.apply(this, arguments); rlm@46: if(newNode && refNode && this.childrenRendered){ rlm@46: node.render(); rlm@46: } rlm@46: this.ui.updateExpandIcon(); rlm@46: return newNode; rlm@46: }, rlm@46: rlm@46: rlm@46: setText : function(text){ rlm@46: var oldText = this.text; rlm@46: this.text = text; rlm@46: this.attributes.text = text; rlm@46: if(this.rendered){ rlm@46: this.ui.onTextChange(this, text, oldText); rlm@46: } rlm@46: this.fireEvent("textchange", this, text, oldText); rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(){ rlm@46: this.getOwnerTree().getSelectionModel().select(this); rlm@46: }, rlm@46: rlm@46: rlm@46: unselect : function(){ rlm@46: this.getOwnerTree().getSelectionModel().unselect(this); rlm@46: }, rlm@46: rlm@46: rlm@46: isSelected : function(){ rlm@46: return this.getOwnerTree().getSelectionModel().isSelected(this); rlm@46: }, rlm@46: rlm@46: rlm@46: expand : function(deep, anim, callback){ rlm@46: if(!this.expanded){ rlm@46: if(this.fireEvent("beforeexpand", this, deep, anim) === false){ rlm@46: return; rlm@46: } rlm@46: if(!this.childrenRendered){ rlm@46: this.renderChildren(); rlm@46: } rlm@46: this.expanded = true; rlm@46: if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){ rlm@46: this.ui.animExpand(function(){ rlm@46: this.fireEvent("expand", this); rlm@46: if(typeof callback == "function"){ rlm@46: callback(this); rlm@46: } rlm@46: if(deep === true){ rlm@46: this.expandChildNodes(true); rlm@46: } rlm@46: }.createDelegate(this)); rlm@46: return; rlm@46: }else{ rlm@46: this.ui.expand(); rlm@46: this.fireEvent("expand", this); rlm@46: if(typeof callback == "function"){ rlm@46: callback(this); rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: if(typeof callback == "function"){ rlm@46: callback(this); rlm@46: } rlm@46: } rlm@46: if(deep === true){ rlm@46: this.expandChildNodes(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: isHiddenRoot : function(){ rlm@46: return this.isRoot && !this.getOwnerTree().rootVisible; rlm@46: }, rlm@46: rlm@46: rlm@46: collapse : function(deep, anim){ rlm@46: if(this.expanded && !this.isHiddenRoot()){ rlm@46: if(this.fireEvent("beforecollapse", this, deep, anim) === false){ rlm@46: return; rlm@46: } rlm@46: this.expanded = false; rlm@46: if((this.getOwnerTree().animate && anim !== false) || anim){ rlm@46: this.ui.animCollapse(function(){ rlm@46: this.fireEvent("collapse", this); rlm@46: if(deep === true){ rlm@46: this.collapseChildNodes(true); rlm@46: } rlm@46: }.createDelegate(this)); rlm@46: return; rlm@46: }else{ rlm@46: this.ui.collapse(); rlm@46: this.fireEvent("collapse", this); rlm@46: } rlm@46: } rlm@46: if(deep === true){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: cs[i].collapse(true, false); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: delayedExpand : function(delay){ rlm@46: if(!this.expandProcId){ rlm@46: this.expandProcId = this.expand.defer(delay, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: cancelExpand : function(){ rlm@46: if(this.expandProcId){ rlm@46: clearTimeout(this.expandProcId); rlm@46: } rlm@46: this.expandProcId = false; rlm@46: }, rlm@46: rlm@46: rlm@46: toggle : function(){ rlm@46: if(this.expanded){ rlm@46: this.collapse(); rlm@46: }else{ rlm@46: this.expand(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: ensureVisible : function(callback){ rlm@46: var tree = this.getOwnerTree(); rlm@46: tree.expandPath(this.parentNode.getPath(), false, function(){ rlm@46: var node = tree.getNodeById(this.id); rlm@46: tree.getTreeEl().scrollChildIntoView(node.ui.anchor); rlm@46: Ext.callback(callback); rlm@46: }.createDelegate(this)); rlm@46: }, rlm@46: rlm@46: rlm@46: expandChildNodes : function(deep){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: cs[i].expand(deep); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: collapseChildNodes : function(deep){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++) { rlm@46: cs[i].collapse(deep); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: this.disabled = true; rlm@46: this.unselect(); rlm@46: if(this.rendered && this.ui.onDisableChange){ rlm@46: this.ui.onDisableChange(this, true); rlm@46: } rlm@46: this.fireEvent("disabledchange", this, true); rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: this.disabled = false; rlm@46: if(this.rendered && this.ui.onDisableChange){ rlm@46: this.ui.onDisableChange(this, false); rlm@46: } rlm@46: this.fireEvent("disabledchange", this, false); rlm@46: }, rlm@46: rlm@46: rlm@46: renderChildren : function(suppressEvent){ rlm@46: if(suppressEvent !== false){ rlm@46: this.fireEvent("beforechildrenrendered", this); rlm@46: } rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: cs[i].render(true); rlm@46: } rlm@46: this.childrenRendered = true; rlm@46: }, rlm@46: rlm@46: rlm@46: sort : function(fn, scope){ rlm@46: Ext.tree.TreeNode.superclass.sort.apply(this, arguments); rlm@46: if(this.childrenRendered){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: cs[i].render(true); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: render : function(bulkRender){ rlm@46: this.ui.render(bulkRender); rlm@46: if(!this.rendered){ rlm@46: rlm@46: this.getOwnerTree().registerNode(this); rlm@46: this.rendered = true; rlm@46: if(this.expanded){ rlm@46: this.expanded = false; rlm@46: this.expand(false, false); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: renderIndent : function(deep, refresh){ rlm@46: if(refresh){ rlm@46: this.ui.childIndent = null; rlm@46: } rlm@46: this.ui.renderIndent(); rlm@46: if(deep === true && this.childrenRendered){ rlm@46: var cs = this.childNodes; rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: cs[i].renderIndent(true, refresh); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: beginUpdate : function(){ rlm@46: this.childrenRendered = false; rlm@46: }, rlm@46: rlm@46: endUpdate : function(){ rlm@46: if(this.expanded && this.rendered){ rlm@46: this.renderChildren(); rlm@46: } rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: for(var i = 0,l = this.childNodes.length; i < l; i++){ rlm@46: this.childNodes[i].destroy(); rlm@46: } rlm@46: this.childNodes = null; rlm@46: if(this.ui.destroy){ rlm@46: this.ui.destroy(); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.tree.AsyncTreeNode = function(config){ rlm@46: this.loaded = false; rlm@46: this.loading = false; rlm@46: Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments); rlm@46: rlm@46: this.addEvents('beforeload', 'load'); rlm@46: rlm@46: rlm@46: }; rlm@46: Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, { rlm@46: expand : function(deep, anim, callback){ rlm@46: if(this.loading){ rlm@46: var timer; rlm@46: var f = function(){ rlm@46: if(!this.loading){ rlm@46: clearInterval(timer); rlm@46: this.expand(deep, anim, callback); rlm@46: } rlm@46: }.createDelegate(this); rlm@46: timer = setInterval(f, 200); rlm@46: return; rlm@46: } rlm@46: if(!this.loaded){ rlm@46: if(this.fireEvent("beforeload", this) === false){ rlm@46: return; rlm@46: } rlm@46: this.loading = true; rlm@46: this.ui.beforeLoad(this); rlm@46: var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader(); rlm@46: if(loader){ rlm@46: loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback])); rlm@46: return; rlm@46: } rlm@46: } rlm@46: Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback); rlm@46: }, rlm@46: rlm@46: rlm@46: isLoading : function(){ rlm@46: return this.loading; rlm@46: }, rlm@46: rlm@46: loadComplete : function(deep, anim, callback){ rlm@46: this.loading = false; rlm@46: this.loaded = true; rlm@46: this.ui.afterLoad(this); rlm@46: this.fireEvent("load", this); rlm@46: this.expand(deep, anim, callback); rlm@46: }, rlm@46: rlm@46: rlm@46: isLoaded : function(){ rlm@46: return this.loaded; rlm@46: }, rlm@46: rlm@46: hasChildNodes : function(){ rlm@46: if(!this.isLeaf() && !this.loaded){ rlm@46: return true; rlm@46: }else{ rlm@46: return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: reload : function(callback){ rlm@46: this.collapse(false, false); rlm@46: while(this.firstChild){ rlm@46: this.removeChild(this.firstChild); rlm@46: } rlm@46: this.childrenRendered = false; rlm@46: this.loaded = false; rlm@46: if(this.isHiddenRoot()){ rlm@46: this.expanded = false; rlm@46: } rlm@46: this.expand(false, false, callback); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.tree.TreeNodeUI = function(node){ rlm@46: this.node = node; rlm@46: this.rendered = false; rlm@46: this.animating = false; rlm@46: this.wasLeaf = true; rlm@46: this.ecc = 'x-tree-ec-icon x-tree-elbow'; rlm@46: this.emptyIcon = Ext.BLANK_IMAGE_URL; rlm@46: }; rlm@46: rlm@46: Ext.tree.TreeNodeUI.prototype = { rlm@46: rlm@46: removeChild : function(node){ rlm@46: if(this.rendered){ rlm@46: this.ctNode.removeChild(node.ui.getEl()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeLoad : function(){ rlm@46: this.addClass("x-tree-node-loading"); rlm@46: }, rlm@46: rlm@46: rlm@46: afterLoad : function(){ rlm@46: this.removeClass("x-tree-node-loading"); rlm@46: }, rlm@46: rlm@46: rlm@46: onTextChange : function(node, text, oldText){ rlm@46: if(this.rendered){ rlm@46: this.textNode.innerHTML = text; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onDisableChange : function(node, state){ rlm@46: this.disabled = state; rlm@46: if (this.checkbox) { rlm@46: this.checkbox.disabled = state; rlm@46: } rlm@46: if(state){ rlm@46: this.addClass("x-tree-node-disabled"); rlm@46: }else{ rlm@46: this.removeClass("x-tree-node-disabled"); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onSelectedChange : function(state){ rlm@46: if(state){ rlm@46: this.focus(); rlm@46: this.addClass("x-tree-selected"); rlm@46: }else{ rlm@46: rlm@46: this.removeClass("x-tree-selected"); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onMove : function(tree, node, oldParent, newParent, index, refNode){ rlm@46: this.childIndent = null; rlm@46: if(this.rendered){ rlm@46: var targetNode = newParent.ui.getContainer(); rlm@46: if(!targetNode){ rlm@46: this.holder = document.createElement("div"); rlm@46: this.holder.appendChild(this.wrap); rlm@46: return; rlm@46: } rlm@46: var insertBefore = refNode ? refNode.ui.getEl() : null; rlm@46: if(insertBefore){ rlm@46: targetNode.insertBefore(this.wrap, insertBefore); rlm@46: }else{ rlm@46: targetNode.appendChild(this.wrap); rlm@46: } rlm@46: this.node.renderIndent(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: addClass : function(cls){ rlm@46: if(this.elNode){ rlm@46: Ext.fly(this.elNode).addClass(cls); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: removeClass : function(cls){ rlm@46: if(this.elNode){ rlm@46: Ext.fly(this.elNode).removeClass(cls); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(){ rlm@46: if(this.rendered){ rlm@46: this.holder = document.createElement("div"); rlm@46: this.holder.appendChild(this.wrap); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: fireEvent : function(){ rlm@46: return this.node.fireEvent.apply(this.node, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: this.node.on("move", this.onMove, this); rlm@46: rlm@46: if(this.node.disabled){ rlm@46: this.addClass("x-tree-node-disabled"); rlm@46: if (this.checkbox) { rlm@46: this.checkbox.disabled = true; rlm@46: } rlm@46: } rlm@46: if(this.node.hidden){ rlm@46: this.hide(); rlm@46: } rlm@46: var ot = this.node.getOwnerTree(); rlm@46: var dd = ot.enableDD || ot.enableDrag || ot.enableDrop; rlm@46: if(dd && (!this.node.isRoot || ot.rootVisible)){ rlm@46: Ext.dd.Registry.register(this.elNode, { rlm@46: node: this.node, rlm@46: handles: this.getDDHandles(), rlm@46: isHandle: false rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getDDHandles : function(){ rlm@46: return [this.iconNode, this.textNode, this.elNode]; rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(){ rlm@46: this.node.hidden = true; rlm@46: if(this.wrap){ rlm@46: this.wrap.style.display = "none"; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(){ rlm@46: this.node.hidden = false; rlm@46: if(this.wrap){ rlm@46: this.wrap.style.display = ""; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onContextMenu : function(e){ rlm@46: if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) { rlm@46: e.preventDefault(); rlm@46: this.focus(); rlm@46: this.fireEvent("contextmenu", this.node, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onClick : function(e){ rlm@46: if(this.dropping){ rlm@46: e.stopEvent(); rlm@46: return; rlm@46: } rlm@46: if(this.fireEvent("beforeclick", this.node, e) !== false){ rlm@46: var a = e.getTarget('a'); rlm@46: if(!this.disabled && this.node.attributes.href && a){ rlm@46: this.fireEvent("click", this.node, e); rlm@46: return; rlm@46: }else if(a && e.ctrlKey){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: e.preventDefault(); rlm@46: if(this.disabled){ rlm@46: return; rlm@46: } rlm@46: rlm@46: if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){ rlm@46: this.node.toggle(); rlm@46: } rlm@46: rlm@46: this.fireEvent("click", this.node, e); rlm@46: }else{ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onDblClick : function(e){ rlm@46: e.preventDefault(); rlm@46: if(this.disabled){ rlm@46: return; rlm@46: } rlm@46: if(this.checkbox){ rlm@46: this.toggleCheck(); rlm@46: } rlm@46: if(!this.animating && this.node.hasChildNodes()){ rlm@46: this.node.toggle(); rlm@46: } rlm@46: this.fireEvent("dblclick", this.node, e); rlm@46: }, rlm@46: rlm@46: onOver : function(e){ rlm@46: this.addClass('x-tree-node-over'); rlm@46: }, rlm@46: rlm@46: onOut : function(e){ rlm@46: this.removeClass('x-tree-node-over'); rlm@46: }, rlm@46: rlm@46: rlm@46: onCheckChange : function(){ rlm@46: var checked = this.checkbox.checked; rlm@46: rlm@46: this.checkbox.defaultChecked = checked; rlm@46: this.node.attributes.checked = checked; rlm@46: this.fireEvent('checkchange', this.node, checked); rlm@46: }, rlm@46: rlm@46: rlm@46: ecClick : function(e){ rlm@46: if(!this.animating && (this.node.hasChildNodes() || this.node.attributes.expandable)){ rlm@46: this.node.toggle(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: startDrop : function(){ rlm@46: this.dropping = true; rlm@46: }, rlm@46: rlm@46: rlm@46: endDrop : function(){ rlm@46: setTimeout(function(){ rlm@46: this.dropping = false; rlm@46: }.createDelegate(this), 50); rlm@46: }, rlm@46: rlm@46: rlm@46: expand : function(){ rlm@46: this.updateExpandIcon(); rlm@46: this.ctNode.style.display = ""; rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: if(!this.node.preventHScroll){ rlm@46: try{this.anchor.focus(); rlm@46: }catch(e){} rlm@46: }else if(!Ext.isIE){ rlm@46: try{ rlm@46: var noscroll = this.node.getOwnerTree().getTreeEl().dom; rlm@46: var l = noscroll.scrollLeft; rlm@46: this.anchor.focus(); rlm@46: noscroll.scrollLeft = l; rlm@46: }catch(e){} rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toggleCheck : function(value){ rlm@46: var cb = this.checkbox; rlm@46: if(cb){ rlm@46: cb.checked = (value === undefined ? !cb.checked : value); rlm@46: this.onCheckChange(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: blur : function(){ rlm@46: try{ rlm@46: this.anchor.blur(); rlm@46: }catch(e){} rlm@46: }, rlm@46: rlm@46: rlm@46: animExpand : function(callback){ rlm@46: var ct = Ext.get(this.ctNode); rlm@46: ct.stopFx(); rlm@46: if(!this.node.hasChildNodes()){ rlm@46: this.updateExpandIcon(); rlm@46: this.ctNode.style.display = ""; rlm@46: Ext.callback(callback); rlm@46: return; rlm@46: } rlm@46: this.animating = true; rlm@46: this.updateExpandIcon(); rlm@46: rlm@46: ct.slideIn('t', { rlm@46: callback : function(){ rlm@46: this.animating = false; rlm@46: Ext.callback(callback); rlm@46: }, rlm@46: scope: this, rlm@46: duration: this.node.ownerTree.duration || .25 rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: highlight : function(){ rlm@46: var tree = this.node.getOwnerTree(); rlm@46: Ext.fly(this.wrap).highlight( rlm@46: tree.hlColor || "C3DAF9", rlm@46: {endColor: tree.hlBaseColor} rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: collapse : function(){ rlm@46: this.updateExpandIcon(); rlm@46: this.ctNode.style.display = "none"; rlm@46: }, rlm@46: rlm@46: rlm@46: animCollapse : function(callback){ rlm@46: var ct = Ext.get(this.ctNode); rlm@46: ct.enableDisplayMode('block'); rlm@46: ct.stopFx(); rlm@46: rlm@46: this.animating = true; rlm@46: this.updateExpandIcon(); rlm@46: rlm@46: ct.slideOut('t', { rlm@46: callback : function(){ rlm@46: this.animating = false; rlm@46: Ext.callback(callback); rlm@46: }, rlm@46: scope: this, rlm@46: duration: this.node.ownerTree.duration || .25 rlm@46: }); rlm@46: }, rlm@46: rlm@46: rlm@46: getContainer : function(){ rlm@46: return this.ctNode; rlm@46: }, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: rlm@46: appendDDGhost : function(ghostNode){ rlm@46: ghostNode.appendChild(this.elNode.cloneNode(true)); rlm@46: }, rlm@46: rlm@46: rlm@46: getDDRepairXY : function(){ rlm@46: return Ext.lib.Dom.getXY(this.iconNode); rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(){ rlm@46: this.render(); rlm@46: }, rlm@46: rlm@46: rlm@46: render : function(bulkRender){ rlm@46: var n = this.node, a = n.attributes; rlm@46: var targetNode = n.parentNode ? rlm@46: n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom; rlm@46: rlm@46: if(!this.rendered){ rlm@46: this.rendered = true; rlm@46: rlm@46: this.renderElements(n, a, targetNode, bulkRender); rlm@46: rlm@46: if(a.qtip){ rlm@46: if(this.textNode.setAttributeNS){ rlm@46: this.textNode.setAttributeNS("ext", "qtip", a.qtip); rlm@46: if(a.qtipTitle){ rlm@46: this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle); rlm@46: } rlm@46: }else{ rlm@46: this.textNode.setAttribute("ext:qtip", a.qtip); rlm@46: if(a.qtipTitle){ rlm@46: this.textNode.setAttribute("ext:qtitle", a.qtipTitle); rlm@46: } rlm@46: } rlm@46: }else if(a.qtipCfg){ rlm@46: a.qtipCfg.target = Ext.id(this.textNode); rlm@46: Ext.QuickTips.register(a.qtipCfg); rlm@46: } rlm@46: this.initEvents(); rlm@46: if(!this.node.expanded){ rlm@46: this.updateExpandIcon(true); rlm@46: } rlm@46: }else{ rlm@46: if(bulkRender === true) { rlm@46: targetNode.appendChild(this.wrap); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: renderElements : function(n, a, targetNode, bulkRender){ rlm@46: rlm@46: this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : ''; rlm@46: rlm@46: var cb = typeof a.checked == 'boolean'; rlm@46: rlm@46: var href = a.href ? a.href : Ext.isGecko ? "" : "#"; rlm@46: var buf = ['
  • ', rlm@46: '',this.indentMarkup,"", rlm@46: '', rlm@46: '', rlm@46: cb ? ('' : '/>')) : '', rlm@46: '',n.text,"
    ", rlm@46: '', rlm@46: "
  • "].join(''); rlm@46: rlm@46: var nel; rlm@46: if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){ rlm@46: this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf); rlm@46: }else{ rlm@46: this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf); rlm@46: } rlm@46: rlm@46: this.elNode = this.wrap.childNodes[0]; rlm@46: this.ctNode = this.wrap.childNodes[1]; rlm@46: var cs = this.elNode.childNodes; rlm@46: this.indentNode = cs[0]; rlm@46: this.ecNode = cs[1]; rlm@46: this.iconNode = cs[2]; rlm@46: var index = 3; rlm@46: if(cb){ rlm@46: this.checkbox = cs[3]; rlm@46: rlm@46: this.checkbox.defaultChecked = this.checkbox.checked; rlm@46: index++; rlm@46: } rlm@46: this.anchor = cs[index]; rlm@46: this.textNode = cs[index].firstChild; rlm@46: }, rlm@46: rlm@46: rlm@46: getAnchor : function(){ rlm@46: return this.anchor; rlm@46: }, rlm@46: rlm@46: rlm@46: getTextEl : function(){ rlm@46: return this.textNode; rlm@46: }, rlm@46: rlm@46: rlm@46: getIconEl : function(){ rlm@46: return this.iconNode; rlm@46: }, rlm@46: rlm@46: rlm@46: isChecked : function(){ rlm@46: return this.checkbox ? this.checkbox.checked : false; rlm@46: }, rlm@46: rlm@46: rlm@46: updateExpandIcon : function(){ rlm@46: if(this.rendered){ rlm@46: var n = this.node, c1, c2; rlm@46: var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow"; rlm@46: var hasChild = n.hasChildNodes(); rlm@46: if(hasChild || n.attributes.expandable){ rlm@46: if(n.expanded){ rlm@46: cls += "-minus"; rlm@46: c1 = "x-tree-node-collapsed"; rlm@46: c2 = "x-tree-node-expanded"; rlm@46: }else{ rlm@46: cls += "-plus"; rlm@46: c1 = "x-tree-node-expanded"; rlm@46: c2 = "x-tree-node-collapsed"; rlm@46: } rlm@46: if(this.wasLeaf){ rlm@46: this.removeClass("x-tree-node-leaf"); rlm@46: this.wasLeaf = false; rlm@46: } rlm@46: if(this.c1 != c1 || this.c2 != c2){ rlm@46: Ext.fly(this.elNode).replaceClass(c1, c2); rlm@46: this.c1 = c1; this.c2 = c2; rlm@46: } rlm@46: }else{ rlm@46: if(!this.wasLeaf){ rlm@46: Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf"); rlm@46: delete this.c1; rlm@46: delete this.c2; rlm@46: this.wasLeaf = true; rlm@46: } rlm@46: } rlm@46: var ecc = "x-tree-ec-icon "+cls; rlm@46: if(this.ecc != ecc){ rlm@46: this.ecNode.className = ecc; rlm@46: this.ecc = ecc; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getChildIndent : function(){ rlm@46: if(!this.childIndent){ rlm@46: var buf = []; rlm@46: var p = this.node; rlm@46: while(p){ rlm@46: if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){ rlm@46: if(!p.isLast()) { rlm@46: buf.unshift(''); rlm@46: } else { rlm@46: buf.unshift(''); rlm@46: } rlm@46: } rlm@46: p = p.parentNode; rlm@46: } rlm@46: this.childIndent = buf.join(""); rlm@46: } rlm@46: return this.childIndent; rlm@46: }, rlm@46: rlm@46: rlm@46: renderIndent : function(){ rlm@46: if(this.rendered){ rlm@46: var indent = ""; rlm@46: var p = this.node.parentNode; rlm@46: if(p){ rlm@46: indent = p.ui.getChildIndent(); rlm@46: } rlm@46: if(this.indentMarkup != indent){ rlm@46: this.indentNode.innerHTML = indent; rlm@46: this.indentMarkup = indent; rlm@46: } rlm@46: this.updateExpandIcon(); rlm@46: } rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.elNode){ rlm@46: Ext.dd.Registry.unregister(this.elNode.id); rlm@46: } rlm@46: delete this.elNode; rlm@46: delete this.ctNode; rlm@46: delete this.indentNode; rlm@46: delete this.ecNode; rlm@46: delete this.iconNode; rlm@46: delete this.checkbox; rlm@46: delete this.anchor; rlm@46: delete this.textNode; rlm@46: Ext.removeNode(this.ctNode); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, { rlm@46: rlm@46: render : function(){ rlm@46: if(!this.rendered){ rlm@46: var targetNode = this.node.ownerTree.innerCt.dom; rlm@46: this.node.expanded = true; rlm@46: targetNode.innerHTML = '
    '; rlm@46: this.wrap = this.ctNode = targetNode.firstChild; rlm@46: } rlm@46: }, rlm@46: collapse : Ext.emptyFn, rlm@46: expand : Ext.emptyFn rlm@46: }); rlm@46: rlm@46: Ext.tree.TreeLoader = function(config){ rlm@46: this.baseParams = {}; rlm@46: Ext.apply(this, config); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "beforeload", rlm@46: rlm@46: "load", rlm@46: rlm@46: "loadexception" rlm@46: ); rlm@46: rlm@46: Ext.tree.TreeLoader.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: uiProviders : {}, rlm@46: rlm@46: rlm@46: clearOnLoad : true, rlm@46: rlm@46: rlm@46: load : function(node, callback){ rlm@46: if(this.clearOnLoad){ rlm@46: while(node.firstChild){ rlm@46: node.removeChild(node.firstChild); rlm@46: } rlm@46: } rlm@46: if(this.doPreload(node)){ rlm@46: if(typeof callback == "function"){ rlm@46: callback(); rlm@46: } rlm@46: }else if(this.dataUrl||this.url){ rlm@46: this.requestData(node, callback); rlm@46: } rlm@46: }, rlm@46: rlm@46: doPreload : function(node){ rlm@46: if(node.attributes.children){ rlm@46: if(node.childNodes.length < 1){ rlm@46: var cs = node.attributes.children; rlm@46: node.beginUpdate(); rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: var cn = node.appendChild(this.createNode(cs[i])); rlm@46: if(this.preloadChildren){ rlm@46: this.doPreload(cn); rlm@46: } rlm@46: } rlm@46: node.endUpdate(); rlm@46: } rlm@46: return true; rlm@46: }else { rlm@46: return false; rlm@46: } rlm@46: }, rlm@46: rlm@46: getParams: function(node){ rlm@46: var buf = [], bp = this.baseParams; rlm@46: for(var key in bp){ rlm@46: if(typeof bp[key] != "function"){ rlm@46: buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&"); rlm@46: } rlm@46: } rlm@46: buf.push("node=", encodeURIComponent(node.id)); rlm@46: return buf.join(""); rlm@46: }, rlm@46: rlm@46: requestData : function(node, callback){ rlm@46: if(this.fireEvent("beforeload", this, node, callback) !== false){ rlm@46: this.transId = Ext.Ajax.request({ rlm@46: method:this.requestMethod, rlm@46: url: this.dataUrl||this.url, rlm@46: success: this.handleResponse, rlm@46: failure: this.handleFailure, rlm@46: scope: this, rlm@46: argument: {callback: callback, node: node}, rlm@46: params: this.getParams(node) rlm@46: }); rlm@46: }else{ rlm@46: rlm@46: rlm@46: if(typeof callback == "function"){ rlm@46: callback(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: isLoading : function(){ rlm@46: return this.transId ? true : false; rlm@46: }, rlm@46: rlm@46: abort : function(){ rlm@46: if(this.isLoading()){ rlm@46: Ext.Ajax.abort(this.transId); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: createNode : function(attr){ rlm@46: rlm@46: if(this.baseAttrs){ rlm@46: Ext.applyIf(attr, this.baseAttrs); rlm@46: } rlm@46: if(this.applyLoader !== false){ rlm@46: attr.loader = this; rlm@46: } rlm@46: if(typeof attr.uiProvider == 'string'){ rlm@46: attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider); rlm@46: } rlm@46: return(attr.leaf ? rlm@46: new Ext.tree.TreeNode(attr) : rlm@46: new Ext.tree.AsyncTreeNode(attr)); rlm@46: }, rlm@46: rlm@46: processResponse : function(response, node, callback){ rlm@46: var json = response.responseText; rlm@46: try { rlm@46: var o = eval("("+json+")"); rlm@46: node.beginUpdate(); rlm@46: for(var i = 0, len = o.length; i < len; i++){ rlm@46: var n = this.createNode(o[i]); rlm@46: if(n){ rlm@46: node.appendChild(n); rlm@46: } rlm@46: } rlm@46: node.endUpdate(); rlm@46: if(typeof callback == "function"){ rlm@46: callback(this, node); rlm@46: } rlm@46: }catch(e){ rlm@46: this.handleFailure(response); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleResponse : function(response){ rlm@46: this.transId = false; rlm@46: var a = response.argument; rlm@46: this.processResponse(response, a.node, a.callback); rlm@46: this.fireEvent("load", this, a.node, response); rlm@46: }, rlm@46: rlm@46: handleFailure : function(response){ rlm@46: this.transId = false; rlm@46: var a = response.argument; rlm@46: this.fireEvent("loadexception", this, a.node, response); rlm@46: if(typeof a.callback == "function"){ rlm@46: a.callback(this, a.node); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.tree.TreeFilter = function(tree, config){ rlm@46: this.tree = tree; rlm@46: this.filtered = {}; rlm@46: Ext.apply(this, config); rlm@46: }; rlm@46: rlm@46: Ext.tree.TreeFilter.prototype = { rlm@46: clearBlank:false, rlm@46: reverse:false, rlm@46: autoClear:false, rlm@46: remove:false, rlm@46: rlm@46: rlm@46: filter : function(value, attr, startNode){ rlm@46: attr = attr || "text"; rlm@46: var f; rlm@46: if(typeof value == "string"){ rlm@46: var vlen = value.length; rlm@46: rlm@46: if(vlen == 0 && this.clearBlank){ rlm@46: this.clear(); rlm@46: return; rlm@46: } rlm@46: value = value.toLowerCase(); rlm@46: f = function(n){ rlm@46: return n.attributes[attr].substr(0, vlen).toLowerCase() == value; rlm@46: }; rlm@46: }else if(value.exec){ rlm@46: f = function(n){ rlm@46: return value.test(n.attributes[attr]); rlm@46: }; rlm@46: }else{ rlm@46: throw 'Illegal filter type, must be string or regex'; rlm@46: } rlm@46: this.filterBy(f, null, startNode); rlm@46: }, rlm@46: rlm@46: rlm@46: filterBy : function(fn, scope, startNode){ rlm@46: startNode = startNode || this.tree.root; rlm@46: if(this.autoClear){ rlm@46: this.clear(); rlm@46: } rlm@46: var af = this.filtered, rv = this.reverse; rlm@46: var f = function(n){ rlm@46: if(n == startNode){ rlm@46: return true; rlm@46: } rlm@46: if(af[n.id]){ rlm@46: return false; rlm@46: } rlm@46: var m = fn.call(scope || n, n); rlm@46: if(!m || rv){ rlm@46: af[n.id] = n; rlm@46: n.ui.hide(); rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }; rlm@46: startNode.cascade(f); rlm@46: if(this.remove){ rlm@46: for(var id in af){ rlm@46: if(typeof id != "function"){ rlm@46: var n = af[id]; rlm@46: if(n && n.parentNode){ rlm@46: n.parentNode.removeChild(n); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clear : function(){ rlm@46: var t = this.tree; rlm@46: var af = this.filtered; rlm@46: for(var id in af){ rlm@46: if(typeof id != "function"){ rlm@46: var n = af[id]; rlm@46: if(n){ rlm@46: n.ui.show(); rlm@46: } rlm@46: } rlm@46: } rlm@46: this.filtered = {}; rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.tree.TreeSorter = function(tree, config){ rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: Ext.apply(this, config); rlm@46: tree.on("beforechildrenrendered", this.doSort, this); rlm@46: tree.on("append", this.updateSort, this); rlm@46: tree.on("insert", this.updateSort, this); rlm@46: tree.on("textchange", this.updateSortParent, this); rlm@46: rlm@46: var dsc = this.dir && this.dir.toLowerCase() == "desc"; rlm@46: var p = this.property || "text"; rlm@46: var sortType = this.sortType; rlm@46: var fs = this.folderSort; rlm@46: var cs = this.caseSensitive === true; rlm@46: var leafAttr = this.leafAttr || 'leaf'; rlm@46: rlm@46: this.sortFn = function(n1, n2){ rlm@46: if(fs){ rlm@46: if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){ rlm@46: return 1; rlm@46: } rlm@46: if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){ rlm@46: return -1; rlm@46: } rlm@46: } rlm@46: var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase()); rlm@46: var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase()); rlm@46: if(v1 < v2){ rlm@46: return dsc ? +1 : -1; rlm@46: }else if(v1 > v2){ rlm@46: return dsc ? -1 : +1; rlm@46: }else{ rlm@46: return 0; rlm@46: } rlm@46: }; rlm@46: }; rlm@46: rlm@46: Ext.tree.TreeSorter.prototype = { rlm@46: doSort : function(node){ rlm@46: node.sort(this.sortFn); rlm@46: }, rlm@46: rlm@46: compareNodes : function(n1, n2){ rlm@46: return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1); rlm@46: }, rlm@46: rlm@46: updateSort : function(tree, node){ rlm@46: if(node.childrenRendered){ rlm@46: this.doSort.defer(1, this, [node]); rlm@46: } rlm@46: }, rlm@46: rlm@46: updateSortParent : function(node){ rlm@46: var p = node.parentNode; rlm@46: if(p && p.childrenRendered){ rlm@46: this.doSort.defer(1, this, [p]); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: if(Ext.dd.DropZone){ rlm@46: rlm@46: Ext.tree.TreeDropZone = function(tree, config){ rlm@46: rlm@46: this.allowParentInsert = false; rlm@46: rlm@46: this.allowContainerDrop = false; rlm@46: rlm@46: this.appendOnly = false; rlm@46: Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config); rlm@46: rlm@46: this.tree = tree; rlm@46: rlm@46: this.dragOverData = {}; rlm@46: rlm@46: this.lastInsertClass = "x-tree-no-status"; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, { rlm@46: rlm@46: ddGroup : "TreeDD", rlm@46: rlm@46: rlm@46: expandDelay : 1000, rlm@46: rlm@46: rlm@46: expandNode : function(node){ rlm@46: if(node.hasChildNodes() && !node.isExpanded()){ rlm@46: node.expand(false, null, this.triggerCacheRefresh.createDelegate(this)); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: queueExpand : function(node){ rlm@46: this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]); rlm@46: }, rlm@46: rlm@46: rlm@46: cancelExpand : function(){ rlm@46: if(this.expandProcId){ rlm@46: clearTimeout(this.expandProcId); rlm@46: this.expandProcId = false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isValidDropPoint : function(n, pt, dd, e, data){ rlm@46: if(!n || !data){ return false; } rlm@46: var targetNode = n.node; rlm@46: var dropNode = data.node; rlm@46: rlm@46: if(!(targetNode && targetNode.isTarget && pt)){ rlm@46: return false; rlm@46: } rlm@46: if(pt == "append" && targetNode.allowChildren === false){ rlm@46: return false; rlm@46: } rlm@46: if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){ rlm@46: return false; rlm@46: } rlm@46: if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: var overEvent = this.dragOverData; rlm@46: overEvent.tree = this.tree; rlm@46: overEvent.target = targetNode; rlm@46: overEvent.data = data; rlm@46: overEvent.point = pt; rlm@46: overEvent.source = dd; rlm@46: overEvent.rawEvent = e; rlm@46: overEvent.dropNode = dropNode; rlm@46: overEvent.cancel = false; rlm@46: var result = this.tree.fireEvent("nodedragover", overEvent); rlm@46: return overEvent.cancel === false && result !== false; rlm@46: }, rlm@46: rlm@46: rlm@46: getDropPoint : function(e, n, dd){ rlm@46: var tn = n.node; rlm@46: if(tn.isRoot){ rlm@46: return tn.allowChildren !== false ? "append" : false; rlm@46: } rlm@46: var dragEl = n.ddel; rlm@46: var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight; rlm@46: var y = Ext.lib.Event.getPageY(e); rlm@46: var noAppend = tn.allowChildren === false || tn.isLeaf(); rlm@46: if(this.appendOnly || tn.parentNode.allowChildren === false){ rlm@46: return noAppend ? false : "append"; rlm@46: } rlm@46: var noBelow = false; rlm@46: if(!this.allowParentInsert){ rlm@46: noBelow = tn.hasChildNodes() && tn.isExpanded(); rlm@46: } rlm@46: var q = (b - t) / (noAppend ? 2 : 3); rlm@46: if(y >= t && y < (t + q)){ rlm@46: return "above"; rlm@46: }else if(!noBelow && (noAppend || y >= b-q && y <= b)){ rlm@46: return "below"; rlm@46: }else{ rlm@46: return "append"; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeEnter : function(n, dd, e, data){ rlm@46: this.cancelExpand(); rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeOver : function(n, dd, e, data){ rlm@46: var pt = this.getDropPoint(e, n, dd); rlm@46: var node = n.node; rlm@46: rlm@46: rlm@46: if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){ rlm@46: this.queueExpand(node); rlm@46: }else if(pt != "append"){ rlm@46: this.cancelExpand(); rlm@46: } rlm@46: rlm@46: rlm@46: var returnCls = this.dropNotAllowed; rlm@46: if(this.isValidDropPoint(n, pt, dd, e, data)){ rlm@46: if(pt){ rlm@46: var el = n.ddel; rlm@46: var cls; rlm@46: if(pt == "above"){ rlm@46: returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between"; rlm@46: cls = "x-tree-drag-insert-above"; rlm@46: }else if(pt == "below"){ rlm@46: returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between"; rlm@46: cls = "x-tree-drag-insert-below"; rlm@46: }else{ rlm@46: returnCls = "x-tree-drop-ok-append"; rlm@46: cls = "x-tree-drag-append"; rlm@46: } rlm@46: if(this.lastInsertClass != cls){ rlm@46: Ext.fly(el).replaceClass(this.lastInsertClass, cls); rlm@46: this.lastInsertClass = cls; rlm@46: } rlm@46: } rlm@46: } rlm@46: return returnCls; rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeOut : function(n, dd, e, data){ rlm@46: this.cancelExpand(); rlm@46: this.removeDropIndicators(n); rlm@46: }, rlm@46: rlm@46: rlm@46: onNodeDrop : function(n, dd, e, data){ rlm@46: var point = this.getDropPoint(e, n, dd); rlm@46: var targetNode = n.node; rlm@46: targetNode.ui.startDrop(); rlm@46: if(!this.isValidDropPoint(n, point, dd, e, data)){ rlm@46: targetNode.ui.endDrop(); rlm@46: return false; rlm@46: } rlm@46: rlm@46: var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null); rlm@46: var dropEvent = { rlm@46: tree : this.tree, rlm@46: target: targetNode, rlm@46: data: data, rlm@46: point: point, rlm@46: source: dd, rlm@46: rawEvent: e, rlm@46: dropNode: dropNode, rlm@46: cancel: !dropNode, rlm@46: dropStatus: false rlm@46: }; rlm@46: var retval = this.tree.fireEvent("beforenodedrop", dropEvent); rlm@46: if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){ rlm@46: targetNode.ui.endDrop(); rlm@46: return dropEvent.dropStatus; rlm@46: } rlm@46: rlm@46: targetNode = dropEvent.target; rlm@46: if(point == "append" && !targetNode.isExpanded()){ rlm@46: targetNode.expand(false, null, function(){ rlm@46: this.completeDrop(dropEvent); rlm@46: }.createDelegate(this)); rlm@46: }else{ rlm@46: this.completeDrop(dropEvent); rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: completeDrop : function(de){ rlm@46: var ns = de.dropNode, p = de.point, t = de.target; rlm@46: if(!Ext.isArray(ns)){ rlm@46: ns = [ns]; rlm@46: } rlm@46: var n; rlm@46: for(var i = 0, len = ns.length; i < len; i++){ rlm@46: n = ns[i]; rlm@46: if(p == "above"){ rlm@46: t.parentNode.insertBefore(n, t); rlm@46: }else if(p == "below"){ rlm@46: t.parentNode.insertBefore(n, t.nextSibling); rlm@46: }else{ rlm@46: t.appendChild(n); rlm@46: } rlm@46: } rlm@46: n.ui.focus(); rlm@46: if(this.tree.hlDrop){ rlm@46: n.ui.highlight(); rlm@46: } rlm@46: t.ui.endDrop(); rlm@46: this.tree.fireEvent("nodedrop", de); rlm@46: }, rlm@46: rlm@46: rlm@46: afterNodeMoved : function(dd, data, e, targetNode, dropNode){ rlm@46: if(this.tree.hlDrop){ rlm@46: dropNode.ui.focus(); rlm@46: dropNode.ui.highlight(); rlm@46: } rlm@46: this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e); rlm@46: }, rlm@46: rlm@46: rlm@46: getTree : function(){ rlm@46: return this.tree; rlm@46: }, rlm@46: rlm@46: rlm@46: removeDropIndicators : function(n){ rlm@46: if(n && n.ddel){ rlm@46: var el = n.ddel; rlm@46: Ext.fly(el).removeClass([ rlm@46: "x-tree-drag-insert-above", rlm@46: "x-tree-drag-insert-below", rlm@46: "x-tree-drag-append"]); rlm@46: this.lastInsertClass = "_noclass"; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeDragDrop : function(target, e, id){ rlm@46: this.cancelExpand(); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: afterRepair : function(data){ rlm@46: if(data && Ext.enableFx){ rlm@46: data.node.ui.highlight(); rlm@46: } rlm@46: this.hideProxy(); rlm@46: } rlm@46: }); rlm@46: rlm@46: } rlm@46: rlm@46: if(Ext.dd.DragZone){ rlm@46: Ext.tree.TreeDragZone = function(tree, config){ rlm@46: Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config); rlm@46: rlm@46: this.tree = tree; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, { rlm@46: rlm@46: ddGroup : "TreeDD", rlm@46: rlm@46: rlm@46: onBeforeDrag : function(data, e){ rlm@46: var n = data.node; rlm@46: return n && n.draggable && !n.disabled; rlm@46: }, rlm@46: rlm@46: rlm@46: onInitDrag : function(e){ rlm@46: var data = this.dragData; rlm@46: this.tree.getSelectionModel().select(data.node); rlm@46: this.tree.eventModel.disable(); rlm@46: this.proxy.update(""); rlm@46: data.node.ui.appendDDGhost(this.proxy.ghost.dom); rlm@46: this.tree.fireEvent("startdrag", this.tree, data.node, e); rlm@46: }, rlm@46: rlm@46: rlm@46: getRepairXY : function(e, data){ rlm@46: return data.node.ui.getDDRepairXY(); rlm@46: }, rlm@46: rlm@46: rlm@46: onEndDrag : function(data, e){ rlm@46: this.tree.eventModel.enable.defer(100, this.tree.eventModel); rlm@46: this.tree.fireEvent("enddrag", this.tree, data.node, e); rlm@46: }, rlm@46: rlm@46: rlm@46: onValidDrop : function(dd, e, id){ rlm@46: this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e); rlm@46: this.hideProxy(); rlm@46: }, rlm@46: rlm@46: rlm@46: beforeInvalidDrop : function(e, id){ rlm@46: rlm@46: var sm = this.tree.getSelectionModel(); rlm@46: sm.clearSelections(); rlm@46: sm.select(this.dragData.node); rlm@46: } rlm@46: }); rlm@46: } rlm@46: rlm@46: Ext.tree.TreeEditor = function(tree, fc, config){ rlm@46: fc = fc || {}; rlm@46: var field = fc.events ? fc : new Ext.form.TextField(fc); rlm@46: Ext.tree.TreeEditor.superclass.constructor.call(this, field, config); rlm@46: rlm@46: this.tree = tree; rlm@46: rlm@46: if(!tree.rendered){ rlm@46: tree.on('render', this.initEditor, this); rlm@46: }else{ rlm@46: this.initEditor(tree); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.tree.TreeEditor, Ext.Editor, { rlm@46: rlm@46: alignment: "l-l", rlm@46: autoSize: false, rlm@46: rlm@46: hideEl : false, rlm@46: rlm@46: cls: "x-small-editor x-tree-editor", rlm@46: rlm@46: shim:false, rlm@46: shadow:"frame", rlm@46: rlm@46: maxWidth: 250, rlm@46: rlm@46: editDelay : 350, rlm@46: rlm@46: initEditor : function(tree){ rlm@46: tree.on('beforeclick', this.beforeNodeClick, this); rlm@46: tree.on('dblclick', this.onNodeDblClick, this); rlm@46: this.on('complete', this.updateNode, this); rlm@46: this.on('beforestartedit', this.fitToTree, this); rlm@46: this.on('startedit', this.bindScroll, this, {delay:10}); rlm@46: this.on('specialkey', this.onSpecialKey, this); rlm@46: }, rlm@46: rlm@46: fitToTree : function(ed, el){ rlm@46: var td = this.tree.getTreeEl().dom, nd = el.dom; rlm@46: if(td.scrollLeft > nd.offsetLeft){ td.scrollLeft = nd.offsetLeft; rlm@46: } rlm@46: var w = Math.min( rlm@46: this.maxWidth, rlm@46: (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - 5); rlm@46: this.setSize(w, ''); rlm@46: }, rlm@46: rlm@46: triggerEdit : function(node, defer){ rlm@46: this.completeEdit(); rlm@46: if(node.attributes.editable !== false){ rlm@46: this.editNode = node; rlm@46: this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, node.text]); rlm@46: return false; rlm@46: } rlm@46: }, rlm@46: rlm@46: bindScroll : function(){ rlm@46: this.tree.getTreeEl().on('scroll', this.cancelEdit, this); rlm@46: }, rlm@46: rlm@46: beforeNodeClick : function(node, e){ rlm@46: clearTimeout(this.autoEditTimer); rlm@46: if(this.tree.getSelectionModel().isSelected(node)){ rlm@46: e.stopEvent(); rlm@46: return this.triggerEdit(node); rlm@46: } rlm@46: }, rlm@46: rlm@46: onNodeDblClick : function(node, e){ rlm@46: clearTimeout(this.autoEditTimer); rlm@46: }, rlm@46: rlm@46: updateNode : function(ed, value){ rlm@46: this.tree.getTreeEl().un('scroll', this.cancelEdit, this); rlm@46: this.editNode.setText(value); rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: Ext.tree.TreeEditor.superclass.onHide.call(this); rlm@46: if(this.editNode){ rlm@46: this.editNode.ui.focus.defer(50, this.editNode.ui); rlm@46: } rlm@46: }, rlm@46: rlm@46: onSpecialKey : function(field, e){ rlm@46: var k = e.getKey(); rlm@46: if(k == e.ESC){ rlm@46: e.stopEvent(); rlm@46: this.cancelEdit(); rlm@46: }else if(k == e.ENTER && !e.hasModifier()){ rlm@46: e.stopEvent(); rlm@46: this.completeEdit(); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.Menu = function(config){ rlm@46: if(Ext.isArray(config)){ rlm@46: config = {items:config}; rlm@46: } rlm@46: Ext.apply(this, config); rlm@46: this.id = this.id || Ext.id(); rlm@46: this.addEvents( rlm@46: rlm@46: 'beforeshow', rlm@46: rlm@46: 'beforehide', rlm@46: rlm@46: 'show', rlm@46: rlm@46: 'hide', rlm@46: rlm@46: 'click', rlm@46: rlm@46: 'mouseover', rlm@46: rlm@46: 'mouseout', rlm@46: rlm@46: 'itemclick' rlm@46: ); rlm@46: Ext.menu.MenuMgr.register(this); rlm@46: Ext.menu.Menu.superclass.constructor.call(this); rlm@46: var mis = this.items; rlm@46: rlm@46: rlm@46: this.items = new Ext.util.MixedCollection(); rlm@46: if(mis){ rlm@46: this.add.apply(this, mis); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.Menu, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: minWidth : 120, rlm@46: rlm@46: shadow : "sides", rlm@46: rlm@46: subMenuAlign : "tl-tr?", rlm@46: rlm@46: defaultAlign : "tl-bl?", rlm@46: rlm@46: allowOtherMenus : false, rlm@46: rlm@46: hidden:true, rlm@46: rlm@46: createEl : function(){ rlm@46: return new Ext.Layer({ rlm@46: cls: "x-menu", rlm@46: shadow:this.shadow, rlm@46: constrain: false, rlm@46: parentEl: this.parentEl || document.body, rlm@46: zindex:15000 rlm@46: }); rlm@46: }, rlm@46: rlm@46: render : function(){ rlm@46: if(this.el){ rlm@46: return; rlm@46: } rlm@46: var el = this.el = this.createEl(); rlm@46: rlm@46: if(!this.keyNav){ rlm@46: this.keyNav = new Ext.menu.MenuNav(this); rlm@46: } rlm@46: if(this.plain){ rlm@46: el.addClass("x-menu-plain"); rlm@46: } rlm@46: if(this.cls){ rlm@46: el.addClass(this.cls); rlm@46: } rlm@46: this.focusEl = el.createChild({ rlm@46: tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1" rlm@46: }); rlm@46: var ul = el.createChild({tag: "ul", cls: "x-menu-list"}); rlm@46: ul.on("click", this.onClick, this); rlm@46: ul.on("mouseover", this.onMouseOver, this); rlm@46: ul.on("mouseout", this.onMouseOut, this); rlm@46: this.items.each(function(item){ rlm@46: var li = document.createElement("li"); rlm@46: li.className = "x-menu-list-item"; rlm@46: ul.dom.appendChild(li); rlm@46: item.render(li, this); rlm@46: }, this); rlm@46: this.ul = ul; rlm@46: this.autoWidth(); rlm@46: }, rlm@46: rlm@46: autoWidth : function(){ rlm@46: var el = this.el, ul = this.ul; rlm@46: if(!el){ rlm@46: return; rlm@46: } rlm@46: var w = this.width; rlm@46: if(w){ rlm@46: el.setWidth(w); rlm@46: }else if(Ext.isIE){ rlm@46: el.setWidth(this.minWidth); rlm@46: var t = el.dom.offsetWidth; el.setWidth(ul.getWidth()+el.getFrameWidth("lr")); rlm@46: } rlm@46: }, rlm@46: rlm@46: delayAutoWidth : function(){ rlm@46: if(this.el){ rlm@46: if(!this.awTask){ rlm@46: this.awTask = new Ext.util.DelayedTask(this.autoWidth, this); rlm@46: } rlm@46: this.awTask.delay(20); rlm@46: } rlm@46: }, rlm@46: rlm@46: findTargetItem : function(e){ rlm@46: var t = e.getTarget(".x-menu-list-item", this.ul, true); rlm@46: if(t && t.menuItemId){ rlm@46: return this.items.get(t.menuItemId); rlm@46: } rlm@46: }, rlm@46: rlm@46: onClick : function(e){ rlm@46: var t; rlm@46: if(t = this.findTargetItem(e)){ rlm@46: t.onClick(e); rlm@46: this.fireEvent("click", this, t, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: setActiveItem : function(item, autoExpand){ rlm@46: if(item != this.activeItem){ rlm@46: if(this.activeItem){ rlm@46: this.activeItem.deactivate(); rlm@46: } rlm@46: this.activeItem = item; rlm@46: item.activate(autoExpand); rlm@46: }else if(autoExpand){ rlm@46: item.expandMenu(); rlm@46: } rlm@46: }, rlm@46: rlm@46: tryActivate : function(start, step){ rlm@46: var items = this.items; rlm@46: for(var i = start, len = items.length; i >= 0 && i < len; i+= step){ rlm@46: var item = items.get(i); rlm@46: if(!item.disabled && item.canActivate){ rlm@46: this.setActiveItem(item, false); rlm@46: return item; rlm@46: } rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onMouseOver : function(e){ rlm@46: var t; rlm@46: if(t = this.findTargetItem(e)){ rlm@46: if(t.canActivate && !t.disabled){ rlm@46: this.setActiveItem(t, true); rlm@46: } rlm@46: } rlm@46: this.fireEvent("mouseover", this, e, t); rlm@46: }, rlm@46: rlm@46: onMouseOut : function(e){ rlm@46: var t; rlm@46: if(t = this.findTargetItem(e)){ rlm@46: if(t == this.activeItem && t.shouldDeactivate(e)){ rlm@46: this.activeItem.deactivate(); rlm@46: delete this.activeItem; rlm@46: } rlm@46: } rlm@46: this.fireEvent("mouseout", this, e, t); rlm@46: }, rlm@46: rlm@46: rlm@46: isVisible : function(){ rlm@46: return this.el && !this.hidden; rlm@46: }, rlm@46: rlm@46: rlm@46: show : function(el, pos, parentMenu){ rlm@46: this.parentMenu = parentMenu; rlm@46: if(!this.el){ rlm@46: this.render(); rlm@46: } rlm@46: this.fireEvent("beforeshow", this); rlm@46: this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false); rlm@46: }, rlm@46: rlm@46: rlm@46: showAt : function(xy, parentMenu, _e){ rlm@46: this.parentMenu = parentMenu; rlm@46: if(!this.el){ rlm@46: this.render(); rlm@46: } rlm@46: if(_e !== false){ rlm@46: this.fireEvent("beforeshow", this); rlm@46: xy = this.el.adjustForConstraints(xy); rlm@46: } rlm@46: this.el.setXY(xy); rlm@46: this.el.show(); rlm@46: this.hidden = false; rlm@46: this.focus(); rlm@46: this.fireEvent("show", this); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: if(!this.hidden){ rlm@46: this.doFocus.defer(50, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: doFocus : function(){ rlm@46: if(!this.hidden){ rlm@46: this.focusEl.focus(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hide : function(deep){ rlm@46: if(this.el && this.isVisible()){ rlm@46: this.fireEvent("beforehide", this); rlm@46: if(this.activeItem){ rlm@46: this.activeItem.deactivate(); rlm@46: this.activeItem = null; rlm@46: } rlm@46: this.el.hide(); rlm@46: this.hidden = true; rlm@46: this.fireEvent("hide", this); rlm@46: } rlm@46: if(deep === true && this.parentMenu){ rlm@46: this.parentMenu.hide(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: add : function(){ rlm@46: var a = arguments, l = a.length, item; rlm@46: for(var i = 0; i < l; i++){ rlm@46: var el = a[i]; rlm@46: if(el.render){ item = this.addItem(el); rlm@46: }else if(typeof el == "string"){ if(el == "separator" || el == "-"){ rlm@46: item = this.addSeparator(); rlm@46: }else{ rlm@46: item = this.addText(el); rlm@46: } rlm@46: }else if(el.tagName || el.el){ item = this.addElement(el); rlm@46: }else if(typeof el == "object"){ Ext.applyIf(el, this.defaults); rlm@46: item = this.addMenuItem(el); rlm@46: } rlm@46: } rlm@46: return item; rlm@46: }, rlm@46: rlm@46: rlm@46: getEl : function(){ rlm@46: if(!this.el){ rlm@46: this.render(); rlm@46: } rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: rlm@46: addSeparator : function(){ rlm@46: return this.addItem(new Ext.menu.Separator()); rlm@46: }, rlm@46: rlm@46: rlm@46: addElement : function(el){ rlm@46: return this.addItem(new Ext.menu.BaseItem(el)); rlm@46: }, rlm@46: rlm@46: rlm@46: addItem : function(item){ rlm@46: this.items.add(item); rlm@46: if(this.ul){ rlm@46: var li = document.createElement("li"); rlm@46: li.className = "x-menu-list-item"; rlm@46: this.ul.dom.appendChild(li); rlm@46: item.render(li, this); rlm@46: this.delayAutoWidth(); rlm@46: } rlm@46: return item; rlm@46: }, rlm@46: rlm@46: rlm@46: addMenuItem : function(config){ rlm@46: if(!(config instanceof Ext.menu.Item)){ rlm@46: if(typeof config.checked == "boolean"){ config = new Ext.menu.CheckItem(config); rlm@46: }else{ rlm@46: config = new Ext.menu.Item(config); rlm@46: } rlm@46: } rlm@46: return this.addItem(config); rlm@46: }, rlm@46: rlm@46: rlm@46: addText : function(text){ rlm@46: return this.addItem(new Ext.menu.TextItem(text)); rlm@46: }, rlm@46: rlm@46: rlm@46: insert : function(index, item){ rlm@46: this.items.insert(index, item); rlm@46: if(this.ul){ rlm@46: var li = document.createElement("li"); rlm@46: li.className = "x-menu-list-item"; rlm@46: this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]); rlm@46: item.render(li, this); rlm@46: this.delayAutoWidth(); rlm@46: } rlm@46: return item; rlm@46: }, rlm@46: rlm@46: rlm@46: remove : function(item){ rlm@46: this.items.removeKey(item.id); rlm@46: item.destroy(); rlm@46: }, rlm@46: rlm@46: rlm@46: removeAll : function(){ rlm@46: if(this.items){ rlm@46: var f; rlm@46: while(f = this.items.first()){ rlm@46: this.remove(f); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: destroy : function(){ rlm@46: this.beforeDestroy(); rlm@46: Ext.menu.MenuMgr.unregister(this); rlm@46: if (this.keyNav) { rlm@46: this.keyNav.disable(); rlm@46: } rlm@46: this.removeAll(); rlm@46: if (this.ul) { rlm@46: this.ul.removeAllListeners(); rlm@46: } rlm@46: if (this.el) { rlm@46: this.el.destroy(); rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeDestroy : Ext.emptyFn rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.menu.MenuNav = function(menu){ rlm@46: Ext.menu.MenuNav.superclass.constructor.call(this, menu.el); rlm@46: this.scope = this.menu = menu; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.MenuNav, Ext.KeyNav, { rlm@46: doRelay : function(e, h){ rlm@46: var k = e.getKey(); rlm@46: if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){ rlm@46: this.menu.tryActivate(0, 1); rlm@46: return false; rlm@46: } rlm@46: return h.call(this.scope || this, e, this.menu); rlm@46: }, rlm@46: rlm@46: up : function(e, m){ rlm@46: if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){ rlm@46: m.tryActivate(m.items.length-1, -1); rlm@46: } rlm@46: }, rlm@46: rlm@46: down : function(e, m){ rlm@46: if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){ rlm@46: m.tryActivate(0, 1); rlm@46: } rlm@46: }, rlm@46: rlm@46: right : function(e, m){ rlm@46: if(m.activeItem){ rlm@46: m.activeItem.expandMenu(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: left : function(e, m){ rlm@46: m.hide(); rlm@46: if(m.parentMenu && m.parentMenu.activeItem){ rlm@46: m.parentMenu.activeItem.activate(); rlm@46: } rlm@46: }, rlm@46: rlm@46: enter : function(e, m){ rlm@46: if(m.activeItem){ rlm@46: e.stopPropagation(); rlm@46: m.activeItem.onClick(e); rlm@46: m.fireEvent("click", this, m.activeItem); rlm@46: return true; rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.MenuMgr = function(){ rlm@46: var menus, active, groups = {}, attached = false, lastShow = new Date(); rlm@46: rlm@46: function init(){ rlm@46: menus = {}; rlm@46: active = new Ext.util.MixedCollection(); rlm@46: Ext.getDoc().addKeyListener(27, function(){ rlm@46: if(active.length > 0){ rlm@46: hideAll(); rlm@46: } rlm@46: }); rlm@46: } rlm@46: rlm@46: function hideAll(){ rlm@46: if(active && active.length > 0){ rlm@46: var c = active.clone(); rlm@46: c.each(function(m){ rlm@46: m.hide(); rlm@46: }); rlm@46: } rlm@46: } rlm@46: rlm@46: function onHide(m){ rlm@46: active.remove(m); rlm@46: if(active.length < 1){ rlm@46: Ext.getDoc().un("mousedown", onMouseDown); rlm@46: attached = false; rlm@46: } rlm@46: } rlm@46: rlm@46: function onShow(m){ rlm@46: var last = active.last(); rlm@46: lastShow = new Date(); rlm@46: active.add(m); rlm@46: if(!attached){ rlm@46: Ext.getDoc().on("mousedown", onMouseDown); rlm@46: attached = true; rlm@46: } rlm@46: if(m.parentMenu){ rlm@46: m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3); rlm@46: m.parentMenu.activeChild = m; rlm@46: }else if(last && last.isVisible()){ rlm@46: m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3); rlm@46: } rlm@46: } rlm@46: rlm@46: function onBeforeHide(m){ rlm@46: if(m.activeChild){ rlm@46: m.activeChild.hide(); rlm@46: } rlm@46: if(m.autoHideTimer){ rlm@46: clearTimeout(m.autoHideTimer); rlm@46: delete m.autoHideTimer; rlm@46: } rlm@46: } rlm@46: rlm@46: function onBeforeShow(m){ rlm@46: var pm = m.parentMenu; rlm@46: if(!pm && !m.allowOtherMenus){ rlm@46: hideAll(); rlm@46: }else if(pm && pm.activeChild){ rlm@46: pm.activeChild.hide(); rlm@46: } rlm@46: } rlm@46: rlm@46: function onMouseDown(e){ rlm@46: if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){ rlm@46: hideAll(); rlm@46: } rlm@46: } rlm@46: rlm@46: function onBeforeCheck(mi, state){ rlm@46: if(state){ rlm@46: var g = groups[mi.group]; rlm@46: for(var i = 0, l = g.length; i < l; i++){ rlm@46: if(g[i] != mi){ rlm@46: g[i].setChecked(false); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: rlm@46: return { rlm@46: rlm@46: rlm@46: hideAll : function(){ rlm@46: hideAll(); rlm@46: }, rlm@46: rlm@46: register : function(menu){ rlm@46: if(!menus){ rlm@46: init(); rlm@46: } rlm@46: menus[menu.id] = menu; rlm@46: menu.on("beforehide", onBeforeHide); rlm@46: menu.on("hide", onHide); rlm@46: menu.on("beforeshow", onBeforeShow); rlm@46: menu.on("show", onShow); rlm@46: var g = menu.group; rlm@46: if(g && menu.events["checkchange"]){ rlm@46: if(!groups[g]){ rlm@46: groups[g] = []; rlm@46: } rlm@46: groups[g].push(menu); rlm@46: menu.on("checkchange", onCheck); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: get : function(menu){ rlm@46: if(typeof menu == "string"){ if(!menus){ return null; rlm@46: } rlm@46: return menus[menu]; rlm@46: }else if(menu.events){ return menu; rlm@46: }else if(typeof menu.length == 'number'){ return new Ext.menu.Menu({items:menu}); rlm@46: }else{ return new Ext.menu.Menu(menu); rlm@46: } rlm@46: }, rlm@46: rlm@46: unregister : function(menu){ rlm@46: delete menus[menu.id]; rlm@46: menu.un("beforehide", onBeforeHide); rlm@46: menu.un("hide", onHide); rlm@46: menu.un("beforeshow", onBeforeShow); rlm@46: menu.un("show", onShow); rlm@46: var g = menu.group; rlm@46: if(g && menu.events["checkchange"]){ rlm@46: groups[g].remove(menu); rlm@46: menu.un("checkchange", onCheck); rlm@46: } rlm@46: }, rlm@46: rlm@46: registerCheckable : function(menuItem){ rlm@46: var g = menuItem.group; rlm@46: if(g){ rlm@46: if(!groups[g]){ rlm@46: groups[g] = []; rlm@46: } rlm@46: groups[g].push(menuItem); rlm@46: menuItem.on("beforecheckchange", onBeforeCheck); rlm@46: } rlm@46: }, rlm@46: rlm@46: unregisterCheckable : function(menuItem){ rlm@46: var g = menuItem.group; rlm@46: if(g){ rlm@46: groups[g].remove(menuItem); rlm@46: menuItem.un("beforecheckchange", onBeforeCheck); rlm@46: } rlm@46: }, rlm@46: rlm@46: getCheckedItem : function(groupId){ rlm@46: var g = groups[groupId]; rlm@46: if(g){ rlm@46: for(var i = 0, l = g.length; i < l; i++){ rlm@46: if(g[i].checked){ rlm@46: return g[i]; rlm@46: } rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: setCheckedItem : function(groupId, itemId){ rlm@46: var g = groups[groupId]; rlm@46: if(g){ rlm@46: for(var i = 0, l = g.length; i < l; i++){ rlm@46: if(g[i].id == itemId){ rlm@46: g[i].setChecked(true); rlm@46: } rlm@46: } rlm@46: } rlm@46: return null; rlm@46: } rlm@46: }; rlm@46: }(); rlm@46: rlm@46: rlm@46: Ext.menu.BaseItem = function(config){ rlm@46: Ext.menu.BaseItem.superclass.constructor.call(this, config); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'click', rlm@46: rlm@46: 'activate', rlm@46: rlm@46: 'deactivate' rlm@46: ); rlm@46: rlm@46: if(this.handler){ rlm@46: this.on("click", this.handler, this.scope); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.BaseItem, Ext.Component, { rlm@46: rlm@46: rlm@46: rlm@46: canActivate : false, rlm@46: rlm@46: activeClass : "x-menu-item-active", rlm@46: rlm@46: hideOnClick : true, rlm@46: rlm@46: hideDelay : 100, rlm@46: rlm@46: ctype: "Ext.menu.BaseItem", rlm@46: rlm@46: actionMode : "container", rlm@46: rlm@46: render : function(container, parentMenu){ rlm@46: this.parentMenu = parentMenu; rlm@46: Ext.menu.BaseItem.superclass.render.call(this, container); rlm@46: this.container.menuItemId = this.id; rlm@46: }, rlm@46: rlm@46: onRender : function(container, position){ rlm@46: this.el = Ext.get(this.el); rlm@46: container.dom.appendChild(this.el.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: setHandler : function(handler, scope){ rlm@46: if(this.handler){ rlm@46: this.un("click", this.handler, this.scope); rlm@46: } rlm@46: this.on("click", this.handler = handler, this.scope = scope); rlm@46: }, rlm@46: rlm@46: onClick : function(e){ rlm@46: if(!this.disabled && this.fireEvent("click", this, e) !== false rlm@46: && this.parentMenu.fireEvent("itemclick", this, e) !== false){ rlm@46: this.handleClick(e); rlm@46: }else{ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: activate : function(){ rlm@46: if(this.disabled){ rlm@46: return false; rlm@46: } rlm@46: var li = this.container; rlm@46: li.addClass(this.activeClass); rlm@46: this.region = li.getRegion().adjust(2, 2, -2, -2); rlm@46: this.fireEvent("activate", this); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: deactivate : function(){ rlm@46: this.container.removeClass(this.activeClass); rlm@46: this.fireEvent("deactivate", this); rlm@46: }, rlm@46: rlm@46: shouldDeactivate : function(e){ rlm@46: return !this.region || !this.region.contains(e.getPoint()); rlm@46: }, rlm@46: rlm@46: handleClick : function(e){ rlm@46: if(this.hideOnClick){ rlm@46: this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]); rlm@46: } rlm@46: }, rlm@46: rlm@46: expandMenu : function(autoActivate){ rlm@46: }, rlm@46: rlm@46: hideMenu : function(){ rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.TextItem = function(text){ rlm@46: this.text = text; rlm@46: Ext.menu.TextItem.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.TextItem, Ext.menu.BaseItem, { rlm@46: rlm@46: rlm@46: hideOnClick : false, rlm@46: rlm@46: itemCls : "x-menu-text", rlm@46: rlm@46: onRender : function(){ rlm@46: var s = document.createElement("span"); rlm@46: s.className = this.itemCls; rlm@46: s.innerHTML = this.text; rlm@46: this.el = s; rlm@46: Ext.menu.TextItem.superclass.onRender.apply(this, arguments); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.Separator = function(config){ rlm@46: Ext.menu.Separator.superclass.constructor.call(this, config); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.Separator, Ext.menu.BaseItem, { rlm@46: rlm@46: itemCls : "x-menu-sep", rlm@46: rlm@46: hideOnClick : false, rlm@46: rlm@46: onRender : function(li){ rlm@46: var s = document.createElement("span"); rlm@46: s.className = this.itemCls; rlm@46: s.innerHTML = " "; rlm@46: this.el = s; rlm@46: li.addClass("x-menu-sep-li"); rlm@46: Ext.menu.Separator.superclass.onRender.apply(this, arguments); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.Item = function(config){ rlm@46: Ext.menu.Item.superclass.constructor.call(this, config); rlm@46: if(this.menu){ rlm@46: this.menu = Ext.menu.MenuMgr.get(this.menu); rlm@46: } rlm@46: }; rlm@46: Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: itemCls : "x-menu-item", rlm@46: rlm@46: canActivate : true, rlm@46: rlm@46: showDelay: 200, rlm@46: hideDelay: 200, rlm@46: rlm@46: ctype: "Ext.menu.Item", rlm@46: rlm@46: onRender : function(container, position){ rlm@46: var el = document.createElement("a"); rlm@46: el.hideFocus = true; rlm@46: el.unselectable = "on"; rlm@46: el.href = this.href || "#"; rlm@46: if(this.hrefTarget){ rlm@46: el.target = this.hrefTarget; rlm@46: } rlm@46: el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : ""); rlm@46: el.innerHTML = String.format( rlm@46: '{1}', rlm@46: this.icon || Ext.BLANK_IMAGE_URL, this.itemText||this.text, this.iconCls || ''); rlm@46: this.el = el; rlm@46: Ext.menu.Item.superclass.onRender.call(this, container, position); rlm@46: }, rlm@46: rlm@46: rlm@46: setText : function(text){ rlm@46: this.text = text; rlm@46: if(this.rendered){ rlm@46: this.el.update(String.format( rlm@46: '{1}', rlm@46: this.icon || Ext.BLANK_IMAGE_URL, this.text, this.iconCls || '')); rlm@46: this.parentMenu.autoWidth(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setIconClass : function(cls){ rlm@46: var oldCls = this.iconCls; rlm@46: this.iconCls = cls; rlm@46: if(this.rendered){ rlm@46: this.el.child('img.x-menu-item-icon').replaceClass(oldCls, this.iconCls); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleClick : function(e){ rlm@46: if(!this.href){ e.stopEvent(); rlm@46: } rlm@46: Ext.menu.Item.superclass.handleClick.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: activate : function(autoExpand){ rlm@46: if(Ext.menu.Item.superclass.activate.apply(this, arguments)){ rlm@46: this.focus(); rlm@46: if(autoExpand){ rlm@46: this.expandMenu(); rlm@46: } rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: shouldDeactivate : function(e){ rlm@46: if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){ rlm@46: if(this.menu && this.menu.isVisible()){ rlm@46: return !this.menu.getEl().getRegion().contains(e.getPoint()); rlm@46: } rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: deactivate : function(){ rlm@46: Ext.menu.Item.superclass.deactivate.apply(this, arguments); rlm@46: this.hideMenu(); rlm@46: }, rlm@46: rlm@46: expandMenu : function(autoActivate){ rlm@46: if(!this.disabled && this.menu){ rlm@46: clearTimeout(this.hideTimer); rlm@46: delete this.hideTimer; rlm@46: if(!this.menu.isVisible() && !this.showTimer){ rlm@46: this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]); rlm@46: }else if (this.menu.isVisible() && autoActivate){ rlm@46: this.menu.tryActivate(0, 1); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: deferExpand : function(autoActivate){ rlm@46: delete this.showTimer; rlm@46: this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu); rlm@46: if(autoActivate){ rlm@46: this.menu.tryActivate(0, 1); rlm@46: } rlm@46: }, rlm@46: rlm@46: hideMenu : function(){ rlm@46: clearTimeout(this.showTimer); rlm@46: delete this.showTimer; rlm@46: if(!this.hideTimer && this.menu && this.menu.isVisible()){ rlm@46: this.hideTimer = this.deferHide.defer(this.hideDelay, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: deferHide : function(){ rlm@46: delete this.hideTimer; rlm@46: this.menu.hide(); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.CheckItem = function(config){ rlm@46: Ext.menu.CheckItem.superclass.constructor.call(this, config); rlm@46: this.addEvents( rlm@46: rlm@46: "beforecheckchange" , rlm@46: rlm@46: "checkchange" rlm@46: ); rlm@46: rlm@46: if(this.checkHandler){ rlm@46: this.on('checkchange', this.checkHandler, this.scope); rlm@46: } rlm@46: Ext.menu.MenuMgr.registerCheckable(this); rlm@46: }; rlm@46: Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, { rlm@46: rlm@46: rlm@46: itemCls : "x-menu-item x-menu-check-item", rlm@46: rlm@46: groupClass : "x-menu-group-item", rlm@46: rlm@46: rlm@46: checked: false, rlm@46: rlm@46: ctype: "Ext.menu.CheckItem", rlm@46: rlm@46: onRender : function(c){ rlm@46: Ext.menu.CheckItem.superclass.onRender.apply(this, arguments); rlm@46: if(this.group){ rlm@46: this.el.addClass(this.groupClass); rlm@46: } rlm@46: if(this.checked){ rlm@46: this.checked = false; rlm@46: this.setChecked(true, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: Ext.menu.MenuMgr.unregisterCheckable(this); rlm@46: Ext.menu.CheckItem.superclass.destroy.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: setChecked : function(state, suppressEvent){ rlm@46: if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){ rlm@46: if(this.container){ rlm@46: this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked"); rlm@46: } rlm@46: this.checked = state; rlm@46: if(suppressEvent !== true){ rlm@46: this.fireEvent("checkchange", this, state); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: handleClick : function(e){ rlm@46: if(!this.disabled && !(this.checked && this.group)){ this.setChecked(!this.checked); rlm@46: } rlm@46: Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.Adapter = function(component, config){ rlm@46: Ext.menu.Adapter.superclass.constructor.call(this, config); rlm@46: this.component = component; rlm@46: }; rlm@46: Ext.extend(Ext.menu.Adapter, Ext.menu.BaseItem, { rlm@46: canActivate : true, rlm@46: rlm@46: onRender : function(container, position){ rlm@46: this.component.render(container); rlm@46: this.el = this.component.getEl(); rlm@46: }, rlm@46: rlm@46: activate : function(){ rlm@46: if(this.disabled){ rlm@46: return false; rlm@46: } rlm@46: this.component.focus(); rlm@46: this.fireEvent("activate", this); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: deactivate : function(){ rlm@46: this.fireEvent("deactivate", this); rlm@46: }, rlm@46: rlm@46: disable : function(){ rlm@46: this.component.disable(); rlm@46: Ext.menu.Adapter.superclass.disable.call(this); rlm@46: }, rlm@46: rlm@46: enable : function(){ rlm@46: this.component.enable(); rlm@46: Ext.menu.Adapter.superclass.enable.call(this); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.DateItem = function(config){ rlm@46: Ext.menu.DateItem.superclass.constructor.call(this, new Ext.DatePicker(config), config); rlm@46: rlm@46: this.picker = this.component; rlm@46: this.addEvents('select'); rlm@46: rlm@46: this.picker.on("render", function(picker){ rlm@46: picker.getEl().swallowEvent("click"); rlm@46: picker.container.addClass("x-menu-date-item"); rlm@46: }); rlm@46: rlm@46: this.picker.on("select", this.onSelect, this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.menu.DateItem, Ext.menu.Adapter, { rlm@46: onSelect : function(picker, date){ rlm@46: this.fireEvent("select", this, date, picker); rlm@46: Ext.menu.DateItem.superclass.handleClick.call(this); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.ColorItem = function(config){ rlm@46: Ext.menu.ColorItem.superclass.constructor.call(this, new Ext.ColorPalette(config), config); rlm@46: rlm@46: this.palette = this.component; rlm@46: this.relayEvents(this.palette, ["select"]); rlm@46: if(this.selectHandler){ rlm@46: this.on('select', this.selectHandler, this.scope); rlm@46: } rlm@46: }; rlm@46: Ext.extend(Ext.menu.ColorItem, Ext.menu.Adapter); rlm@46: rlm@46: Ext.menu.DateMenu = function(config){ rlm@46: Ext.menu.DateMenu.superclass.constructor.call(this, config); rlm@46: this.plain = true; rlm@46: var di = new Ext.menu.DateItem(config); rlm@46: this.add(di); rlm@46: rlm@46: this.picker = di.picker; rlm@46: rlm@46: this.relayEvents(di, ["select"]); rlm@46: rlm@46: this.on('beforeshow', function(){ rlm@46: if(this.picker){ rlm@46: this.picker.hideMonthPicker(true); rlm@46: } rlm@46: }, this); rlm@46: }; rlm@46: Ext.extend(Ext.menu.DateMenu, Ext.menu.Menu, { rlm@46: cls:'x-date-menu', rlm@46: rlm@46: beforeDestroy : function() { rlm@46: this.picker.destroy(); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.menu.ColorMenu = function(config){ rlm@46: Ext.menu.ColorMenu.superclass.constructor.call(this, config); rlm@46: this.plain = true; rlm@46: var ci = new Ext.menu.ColorItem(config); rlm@46: this.add(ci); rlm@46: rlm@46: this.palette = ci.palette; rlm@46: rlm@46: this.relayEvents(ci, ["select"]); rlm@46: }; rlm@46: Ext.extend(Ext.menu.ColorMenu, Ext.menu.Menu); rlm@46: rlm@46: Ext.form.Field = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: invalidClass : "x-form-invalid", rlm@46: rlm@46: invalidText : "The value in this field is invalid", rlm@46: rlm@46: focusClass : "x-form-focus", rlm@46: rlm@46: validationEvent : "keyup", rlm@46: rlm@46: validateOnBlur : true, rlm@46: rlm@46: validationDelay : 250, rlm@46: rlm@46: defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"}, rlm@46: rlm@46: fieldClass : "x-form-field", rlm@46: rlm@46: msgTarget : 'qtip', rlm@46: rlm@46: msgFx : 'normal', rlm@46: rlm@46: readOnly : false, rlm@46: rlm@46: disabled : false, rlm@46: rlm@46: isFormField : true, rlm@46: rlm@46: hasFocus : false, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.Field.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'focus', rlm@46: rlm@46: 'blur', rlm@46: rlm@46: 'specialkey', rlm@46: rlm@46: 'change', rlm@46: rlm@46: 'invalid', rlm@46: rlm@46: 'valid' rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: getName: function(){ rlm@46: return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || ''); rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.form.Field.superclass.onRender.call(this, ct, position); rlm@46: if(!this.el){ rlm@46: var cfg = this.getAutoCreate(); rlm@46: if(!cfg.name){ rlm@46: cfg.name = this.name || this.id; rlm@46: } rlm@46: if(this.inputType){ rlm@46: cfg.type = this.inputType; rlm@46: } rlm@46: this.el = ct.createChild(cfg, position); rlm@46: } rlm@46: var type = this.el.dom.type; rlm@46: if(type){ rlm@46: if(type == 'password'){ rlm@46: type = 'text'; rlm@46: } rlm@46: this.el.addClass('x-form-'+type); rlm@46: } rlm@46: if(this.readOnly){ rlm@46: this.el.dom.readOnly = true; rlm@46: } rlm@46: if(this.tabIndex !== undefined){ rlm@46: this.el.dom.setAttribute('tabIndex', this.tabIndex); rlm@46: } rlm@46: rlm@46: this.el.addClass([this.fieldClass, this.cls]); rlm@46: this.initValue(); rlm@46: }, rlm@46: rlm@46: initValue : function(){ rlm@46: if(this.value !== undefined){ rlm@46: this.setValue(this.value); rlm@46: }else if(this.el.dom.value.length > 0){ rlm@46: this.setValue(this.el.dom.value); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: isDirty : function() { rlm@46: if(this.disabled) { rlm@46: return false; rlm@46: } rlm@46: return String(this.getValue()) !== String(this.originalValue); rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.form.Field.superclass.afterRender.call(this); rlm@46: this.initEvents(); rlm@46: }, rlm@46: rlm@46: fireKey : function(e){ rlm@46: if(e.isSpecialKey()){ rlm@46: this.fireEvent("specialkey", this, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: reset : function(){ rlm@46: this.setValue(this.originalValue); rlm@46: this.clearInvalid(); rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: this.el.on(Ext.isIE || Ext.isSafari3 ? "keydown" : "keypress", this.fireKey, this); rlm@46: this.el.on("focus", this.onFocus, this); rlm@46: this.el.on("blur", this.onBlur, this); rlm@46: rlm@46: this.originalValue = this.getValue(); rlm@46: }, rlm@46: rlm@46: onFocus : function(){ rlm@46: if(!Ext.isOpera && this.focusClass){ this.el.addClass(this.focusClass); rlm@46: } rlm@46: if(!this.hasFocus){ rlm@46: this.hasFocus = true; rlm@46: this.startValue = this.getValue(); rlm@46: this.fireEvent("focus", this); rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeBlur : Ext.emptyFn, rlm@46: rlm@46: onBlur : function(){ rlm@46: this.beforeBlur(); rlm@46: if(!Ext.isOpera && this.focusClass){ this.el.removeClass(this.focusClass); rlm@46: } rlm@46: this.hasFocus = false; rlm@46: if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){ rlm@46: this.validate(); rlm@46: } rlm@46: var v = this.getValue(); rlm@46: if(String(v) !== String(this.startValue)){ rlm@46: this.fireEvent('change', this, v, this.startValue); rlm@46: } rlm@46: this.fireEvent("blur", this); rlm@46: }, rlm@46: rlm@46: rlm@46: isValid : function(preventMark){ rlm@46: if(this.disabled){ rlm@46: return true; rlm@46: } rlm@46: var restore = this.preventMark; rlm@46: this.preventMark = preventMark === true; rlm@46: var v = this.validateValue(this.processValue(this.getRawValue())); rlm@46: this.preventMark = restore; rlm@46: return v; rlm@46: }, rlm@46: rlm@46: rlm@46: validate : function(){ rlm@46: if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){ rlm@46: this.clearInvalid(); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: processValue : function(value){ rlm@46: return value; rlm@46: }, rlm@46: rlm@46: validateValue : function(value){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: markInvalid : function(msg){ rlm@46: if(!this.rendered || this.preventMark){ return; rlm@46: } rlm@46: this.el.addClass(this.invalidClass); rlm@46: msg = msg || this.invalidText; rlm@46: switch(this.msgTarget){ rlm@46: case 'qtip': rlm@46: this.el.dom.qtip = msg; rlm@46: this.el.dom.qclass = 'x-form-invalid-tip'; rlm@46: if(Ext.QuickTips){ Ext.QuickTips.enable(); rlm@46: } rlm@46: break; rlm@46: case 'title': rlm@46: this.el.dom.title = msg; rlm@46: break; rlm@46: case 'under': rlm@46: if(!this.errorEl){ rlm@46: var elp = this.getErrorCt(); rlm@46: this.errorEl = elp.createChild({cls:'x-form-invalid-msg'}); rlm@46: this.errorEl.setWidth(elp.getWidth(true)-20); rlm@46: } rlm@46: this.errorEl.update(msg); rlm@46: Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this); rlm@46: break; rlm@46: case 'side': rlm@46: if(!this.errorIcon){ rlm@46: var elp = this.getErrorCt(); rlm@46: this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'}); rlm@46: } rlm@46: this.alignErrorIcon(); rlm@46: this.errorIcon.dom.qtip = msg; rlm@46: this.errorIcon.dom.qclass = 'x-form-invalid-tip'; rlm@46: this.errorIcon.show(); rlm@46: this.on('resize', this.alignErrorIcon, this); rlm@46: break; rlm@46: default: rlm@46: var t = Ext.getDom(this.msgTarget); rlm@46: t.innerHTML = msg; rlm@46: t.style.display = this.msgDisplay; rlm@46: break; rlm@46: } rlm@46: this.fireEvent('invalid', this, msg); rlm@46: }, rlm@46: rlm@46: getErrorCt : function(){ rlm@46: return this.el.findParent('.x-form-element', 5, true) || this.el.findParent('.x-form-field-wrap', 5, true); }, rlm@46: rlm@46: alignErrorIcon : function(){ rlm@46: this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]); rlm@46: }, rlm@46: rlm@46: rlm@46: clearInvalid : function(){ rlm@46: if(!this.rendered || this.preventMark){ return; rlm@46: } rlm@46: this.el.removeClass(this.invalidClass); rlm@46: switch(this.msgTarget){ rlm@46: case 'qtip': rlm@46: this.el.dom.qtip = ''; rlm@46: break; rlm@46: case 'title': rlm@46: this.el.dom.title = ''; rlm@46: break; rlm@46: case 'under': rlm@46: if(this.errorEl){ rlm@46: Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this); rlm@46: } rlm@46: break; rlm@46: case 'side': rlm@46: if(this.errorIcon){ rlm@46: this.errorIcon.dom.qtip = ''; rlm@46: this.errorIcon.hide(); rlm@46: this.un('resize', this.alignErrorIcon, this); rlm@46: } rlm@46: break; rlm@46: default: rlm@46: var t = Ext.getDom(this.msgTarget); rlm@46: t.innerHTML = ''; rlm@46: t.style.display = 'none'; rlm@46: break; rlm@46: } rlm@46: this.fireEvent('valid', this); rlm@46: }, rlm@46: rlm@46: rlm@46: getRawValue : function(){ rlm@46: var v = this.rendered ? this.el.getValue() : Ext.value(this.value, ''); rlm@46: if(v === this.emptyText){ rlm@46: v = ''; rlm@46: } rlm@46: return v; rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: if(!this.rendered) { rlm@46: return this.value; rlm@46: } rlm@46: var v = this.el.getValue(); rlm@46: if(v === this.emptyText || v === undefined){ rlm@46: v = ''; rlm@46: } rlm@46: return v; rlm@46: }, rlm@46: rlm@46: rlm@46: setRawValue : function(v){ rlm@46: return this.el.dom.value = (v === null || v === undefined ? '' : v); rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: this.value = v; rlm@46: if(this.rendered){ rlm@46: this.el.dom.value = (v === null || v === undefined ? '' : v); rlm@46: this.validate(); rlm@46: } rlm@46: }, rlm@46: rlm@46: adjustSize : function(w, h){ rlm@46: var s = Ext.form.Field.superclass.adjustSize.call(this, w, h); rlm@46: s.width = this.adjustWidth(this.el.dom.tagName, s.width); rlm@46: return s; rlm@46: }, rlm@46: rlm@46: adjustWidth : function(tag, w){ rlm@46: tag = tag.toLowerCase(); rlm@46: if(typeof w == 'number' && !Ext.isSafari){ rlm@46: if(Ext.isIE && (tag == 'input' || tag == 'textarea')){ rlm@46: if(tag == 'input' && !Ext.isStrict){ rlm@46: return this.inEditor ? w : w - 3; rlm@46: } rlm@46: if(tag == 'input' && Ext.isStrict){ rlm@46: return w - (Ext.isIE6 ? 4 : 1); rlm@46: } rlm@46: if(tag == 'textarea' && Ext.isStrict){ rlm@46: return w-2; rlm@46: } rlm@46: }else if(Ext.isOpera && Ext.isStrict){ rlm@46: if(tag == 'input'){ rlm@46: return w + 2; rlm@46: } rlm@46: if(tag == 'textarea'){ rlm@46: return w-2; rlm@46: } rlm@46: } rlm@46: } rlm@46: return w; rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.form.Field.msgFx = { rlm@46: normal : { rlm@46: show: function(msgEl, f){ rlm@46: msgEl.setDisplayed('block'); rlm@46: }, rlm@46: rlm@46: hide : function(msgEl, f){ rlm@46: msgEl.setDisplayed(false).update(''); rlm@46: } rlm@46: }, rlm@46: rlm@46: slide : { rlm@46: show: function(msgEl, f){ rlm@46: msgEl.slideIn('t', {stopFx:true}); rlm@46: }, rlm@46: rlm@46: hide : function(msgEl, f){ rlm@46: msgEl.slideOut('t', {stopFx:true,useDisplay:true}); rlm@46: } rlm@46: }, rlm@46: rlm@46: slideRight : { rlm@46: show: function(msgEl, f){ rlm@46: msgEl.fixDisplay(); rlm@46: msgEl.alignTo(f.el, 'tl-tr'); rlm@46: msgEl.slideIn('l', {stopFx:true}); rlm@46: }, rlm@46: rlm@46: hide : function(msgEl, f){ rlm@46: msgEl.slideOut('l', {stopFx:true,useDisplay:true}); rlm@46: } rlm@46: } rlm@46: }; rlm@46: Ext.reg('field', Ext.form.Field); rlm@46: rlm@46: rlm@46: Ext.form.TextField = Ext.extend(Ext.form.Field, { rlm@46: rlm@46: rlm@46: grow : false, rlm@46: rlm@46: growMin : 30, rlm@46: rlm@46: growMax : 800, rlm@46: rlm@46: vtype : null, rlm@46: rlm@46: maskRe : null, rlm@46: rlm@46: disableKeyFilter : false, rlm@46: rlm@46: allowBlank : true, rlm@46: rlm@46: minLength : 0, rlm@46: rlm@46: maxLength : Number.MAX_VALUE, rlm@46: rlm@46: minLengthText : "The minimum length for this field is {0}", rlm@46: rlm@46: maxLengthText : "The maximum length for this field is {0}", rlm@46: rlm@46: selectOnFocus : false, rlm@46: rlm@46: blankText : "This field is required", rlm@46: rlm@46: validator : null, rlm@46: rlm@46: regex : null, rlm@46: rlm@46: regexText : "", rlm@46: rlm@46: emptyText : null, rlm@46: rlm@46: emptyClass : 'x-form-empty-field', rlm@46: rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.TextField.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'autosize', rlm@46: rlm@46: rlm@46: 'keydown', rlm@46: rlm@46: 'keyup', rlm@46: rlm@46: 'keypress' rlm@46: ); rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.form.TextField.superclass.initEvents.call(this); rlm@46: if(this.validationEvent == 'keyup'){ rlm@46: this.validationTask = new Ext.util.DelayedTask(this.validate, this); rlm@46: this.el.on('keyup', this.filterValidation, this); rlm@46: } rlm@46: else if(this.validationEvent !== false){ rlm@46: this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay}); rlm@46: } rlm@46: if(this.selectOnFocus || this.emptyText){ rlm@46: this.on("focus", this.preFocus, this); rlm@46: if(this.emptyText){ rlm@46: this.on('blur', this.postBlur, this); rlm@46: this.applyEmptyText(); rlm@46: } rlm@46: } rlm@46: if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){ rlm@46: this.el.on("keypress", this.filterKeys, this); rlm@46: } rlm@46: if(this.grow){ rlm@46: this.el.on("keyup", this.onKeyUpBuffered, this, {buffer:50}); rlm@46: this.el.on("click", this.autoSize, this); rlm@46: } rlm@46: rlm@46: if(this.enableKeyEvents){ rlm@46: this.el.on("keyup", this.onKeyUp, this); rlm@46: this.el.on("keydown", this.onKeyDown, this); rlm@46: this.el.on("keypress", this.onKeyPress, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: processValue : function(value){ rlm@46: if(this.stripCharsRe){ rlm@46: var newValue = value.replace(this.stripCharsRe, ''); rlm@46: if(newValue !== value){ rlm@46: this.setRawValue(newValue); rlm@46: return newValue; rlm@46: } rlm@46: } rlm@46: return value; rlm@46: }, rlm@46: rlm@46: filterValidation : function(e){ rlm@46: if(!e.isNavKeyPress()){ rlm@46: this.validationTask.delay(this.validationDelay); rlm@46: } rlm@46: }, rlm@46: rlm@46: onKeyUpBuffered : function(e){ rlm@46: if(!e.isNavKeyPress()){ rlm@46: this.autoSize(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onKeyUp : function(e){ rlm@46: this.fireEvent('keyup', this, e); rlm@46: }, rlm@46: rlm@46: onKeyDown : function(e){ rlm@46: this.fireEvent('keydown', this, e); rlm@46: }, rlm@46: rlm@46: onKeyPress : function(e){ rlm@46: this.fireEvent('keypress', this, e); rlm@46: }, rlm@46: rlm@46: rlm@46: reset : function(){ rlm@46: Ext.form.TextField.superclass.reset.call(this); rlm@46: this.applyEmptyText(); rlm@46: }, rlm@46: rlm@46: applyEmptyText : function(){ rlm@46: if(this.rendered && this.emptyText && this.getRawValue().length < 1){ rlm@46: this.setRawValue(this.emptyText); rlm@46: this.el.addClass(this.emptyClass); rlm@46: } rlm@46: }, rlm@46: rlm@46: preFocus : function(){ rlm@46: if(this.emptyText){ rlm@46: if(this.el.dom.value == this.emptyText){ rlm@46: this.setRawValue(''); rlm@46: } rlm@46: this.el.removeClass(this.emptyClass); rlm@46: } rlm@46: if(this.selectOnFocus){ rlm@46: this.el.dom.select(); rlm@46: } rlm@46: }, rlm@46: rlm@46: postBlur : function(){ rlm@46: this.applyEmptyText(); rlm@46: }, rlm@46: rlm@46: filterKeys : function(e){ rlm@46: var k = e.getKey(); rlm@46: if(!Ext.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){ rlm@46: return; rlm@46: } rlm@46: var c = e.getCharCode(), cc = String.fromCharCode(c); rlm@46: if(Ext.isIE && (e.isSpecialKey() || !cc)){ rlm@46: return; rlm@46: } rlm@46: if(!this.maskRe.test(cc)){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: setValue : function(v){ rlm@46: if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){ rlm@46: this.el.removeClass(this.emptyClass); rlm@46: } rlm@46: Ext.form.TextField.superclass.setValue.apply(this, arguments); rlm@46: this.applyEmptyText(); rlm@46: this.autoSize(); rlm@46: }, rlm@46: rlm@46: rlm@46: validateValue : function(value){ rlm@46: if(value.length < 1 || value === this.emptyText){ if(this.allowBlank){ rlm@46: this.clearInvalid(); rlm@46: return true; rlm@46: }else{ rlm@46: this.markInvalid(this.blankText); rlm@46: return false; rlm@46: } rlm@46: } rlm@46: if(value.length < this.minLength){ rlm@46: this.markInvalid(String.format(this.minLengthText, this.minLength)); rlm@46: return false; rlm@46: } rlm@46: if(value.length > this.maxLength){ rlm@46: this.markInvalid(String.format(this.maxLengthText, this.maxLength)); rlm@46: return false; rlm@46: } rlm@46: if(this.vtype){ rlm@46: var vt = Ext.form.VTypes; rlm@46: if(!vt[this.vtype](value, this)){ rlm@46: this.markInvalid(this.vtypeText || vt[this.vtype +'Text']); rlm@46: return false; rlm@46: } rlm@46: } rlm@46: if(typeof this.validator == "function"){ rlm@46: var msg = this.validator(value); rlm@46: if(msg !== true){ rlm@46: this.markInvalid(msg); rlm@46: return false; rlm@46: } rlm@46: } rlm@46: if(this.regex && !this.regex.test(value)){ rlm@46: this.markInvalid(this.regexText); rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: selectText : function(start, end){ rlm@46: var v = this.getRawValue(); rlm@46: if(v.length > 0){ rlm@46: start = start === undefined ? 0 : start; rlm@46: end = end === undefined ? v.length : end; rlm@46: var d = this.el.dom; rlm@46: if(d.setSelectionRange){ rlm@46: d.setSelectionRange(start, end); rlm@46: }else if(d.createTextRange){ rlm@46: var range = d.createTextRange(); rlm@46: range.moveStart("character", start); rlm@46: range.moveEnd("character", end-v.length); rlm@46: range.select(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: autoSize : function(){ rlm@46: if(!this.grow || !this.rendered){ rlm@46: return; rlm@46: } rlm@46: if(!this.metrics){ rlm@46: this.metrics = Ext.util.TextMetrics.createInstance(this.el); rlm@46: } rlm@46: var el = this.el; rlm@46: var v = el.dom.value; rlm@46: var d = document.createElement('div'); rlm@46: d.appendChild(document.createTextNode(v)); rlm@46: v = d.innerHTML; rlm@46: d = null; rlm@46: v += " "; rlm@46: var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + 10, this.growMin)); rlm@46: this.el.setWidth(w); rlm@46: this.fireEvent("autosize", this, w); rlm@46: } rlm@46: }); rlm@46: Ext.reg('textfield', Ext.form.TextField); rlm@46: rlm@46: rlm@46: Ext.form.TriggerField = Ext.extend(Ext.form.TextField, { rlm@46: rlm@46: rlm@46: defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"}, rlm@46: rlm@46: hideTrigger:false, rlm@46: rlm@46: rlm@46: autoSize: Ext.emptyFn, rlm@46: monitorTab : true, rlm@46: deferHeight : true, rlm@46: mimicing : false, rlm@46: rlm@46: onResize : function(w, h){ rlm@46: Ext.form.TriggerField.superclass.onResize.call(this, w, h); rlm@46: if(typeof w == 'number'){ rlm@46: this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth())); rlm@46: } rlm@46: this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth()); rlm@46: }, rlm@46: rlm@46: adjustSize : Ext.BoxComponent.prototype.adjustSize, rlm@46: rlm@46: getResizeEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: getPositionEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: alignErrorIcon : function(){ rlm@46: this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]); rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.form.TriggerField.superclass.onRender.call(this, ct, position); rlm@46: this.wrap = this.el.wrap({cls: "x-form-field-wrap"}); rlm@46: this.trigger = this.wrap.createChild(this.triggerConfig || rlm@46: {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}); rlm@46: if(this.hideTrigger){ rlm@46: this.trigger.setDisplayed(false); rlm@46: } rlm@46: this.initTrigger(); rlm@46: if(!this.width){ rlm@46: this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth()); rlm@46: } rlm@46: }, rlm@46: rlm@46: initTrigger : function(){ rlm@46: this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true}); rlm@46: this.trigger.addClassOnOver('x-form-trigger-over'); rlm@46: this.trigger.addClassOnClick('x-form-trigger-click'); rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.trigger){ rlm@46: this.trigger.removeAllListeners(); rlm@46: this.trigger.remove(); rlm@46: } rlm@46: if(this.wrap){ rlm@46: this.wrap.remove(); rlm@46: } rlm@46: Ext.form.TriggerField.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: onFocus : function(){ rlm@46: Ext.form.TriggerField.superclass.onFocus.call(this); rlm@46: if(!this.mimicing){ rlm@46: this.wrap.addClass('x-trigger-wrap-focus'); rlm@46: this.mimicing = true; rlm@46: Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {delay: 10}); rlm@46: if(this.monitorTab){ rlm@46: this.el.on("keydown", this.checkTab, this); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: checkTab : function(e){ rlm@46: if(e.getKey() == e.TAB){ rlm@46: this.triggerBlur(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onBlur : function(){ rlm@46: }, rlm@46: rlm@46: mimicBlur : function(e){ rlm@46: if(!this.wrap.contains(e.target) && this.validateBlur(e)){ rlm@46: this.triggerBlur(); rlm@46: } rlm@46: }, rlm@46: rlm@46: triggerBlur : function(){ rlm@46: this.mimicing = false; rlm@46: Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur); rlm@46: if(this.monitorTab){ rlm@46: this.el.un("keydown", this.checkTab, this); rlm@46: } rlm@46: this.beforeBlur(); rlm@46: this.wrap.removeClass('x-trigger-wrap-focus'); rlm@46: Ext.form.TriggerField.superclass.onBlur.call(this); rlm@46: }, rlm@46: rlm@46: beforeBlur : Ext.emptyFn, rlm@46: rlm@46: validateBlur : function(e){ rlm@46: return true; rlm@46: }, rlm@46: rlm@46: onDisable : function(){ rlm@46: Ext.form.TriggerField.superclass.onDisable.call(this); rlm@46: if(this.wrap){ rlm@46: this.wrap.addClass('x-item-disabled'); rlm@46: } rlm@46: }, rlm@46: rlm@46: onEnable : function(){ rlm@46: Ext.form.TriggerField.superclass.onEnable.call(this); rlm@46: if(this.wrap){ rlm@46: this.wrap.removeClass('x-item-disabled'); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onShow : function(){ rlm@46: if(this.wrap){ rlm@46: this.wrap.dom.style.display = ''; rlm@46: this.wrap.dom.style.visibility = 'visible'; rlm@46: } rlm@46: }, rlm@46: rlm@46: onHide : function(){ rlm@46: this.wrap.dom.style.display = 'none'; rlm@46: }, rlm@46: rlm@46: rlm@46: onTriggerClick : Ext.emptyFn rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, { rlm@46: initComponent : function(){ rlm@46: Ext.form.TwinTriggerField.superclass.initComponent.call(this); rlm@46: rlm@46: this.triggerConfig = { rlm@46: tag:'span', cls:'x-form-twin-triggers', cn:[ rlm@46: {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class}, rlm@46: {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class} rlm@46: ]}; rlm@46: }, rlm@46: rlm@46: getTrigger : function(index){ rlm@46: return this.triggers[index]; rlm@46: }, rlm@46: rlm@46: initTrigger : function(){ rlm@46: var ts = this.trigger.select('.x-form-trigger', true); rlm@46: this.wrap.setStyle('overflow', 'hidden'); rlm@46: var triggerField = this; rlm@46: ts.each(function(t, all, index){ rlm@46: t.hide = function(){ rlm@46: var w = triggerField.wrap.getWidth(); rlm@46: this.dom.style.display = 'none'; rlm@46: triggerField.el.setWidth(w-triggerField.trigger.getWidth()); rlm@46: }; rlm@46: t.show = function(){ rlm@46: var w = triggerField.wrap.getWidth(); rlm@46: this.dom.style.display = ''; rlm@46: triggerField.el.setWidth(w-triggerField.trigger.getWidth()); rlm@46: }; rlm@46: var triggerIndex = 'Trigger'+(index+1); rlm@46: rlm@46: if(this['hide'+triggerIndex]){ rlm@46: t.dom.style.display = 'none'; rlm@46: } rlm@46: t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true}); rlm@46: t.addClassOnOver('x-form-trigger-over'); rlm@46: t.addClassOnClick('x-form-trigger-click'); rlm@46: }, this); rlm@46: this.triggers = ts.elements; rlm@46: }, rlm@46: rlm@46: onTrigger1Click : Ext.emptyFn, rlm@46: onTrigger2Click : Ext.emptyFn rlm@46: }); rlm@46: Ext.reg('trigger', Ext.form.TriggerField); rlm@46: rlm@46: Ext.form.TextArea = Ext.extend(Ext.form.TextField, { rlm@46: rlm@46: growMin : 60, rlm@46: rlm@46: growMax: 1000, rlm@46: growAppend : ' \n ', rlm@46: growPad : 0, rlm@46: rlm@46: enterIsSpecial : false, rlm@46: rlm@46: rlm@46: preventScrollbars: false, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: if(!this.el){ rlm@46: this.defaultAutoCreate = { rlm@46: tag: "textarea", rlm@46: style:"width:100px;height:60px;", rlm@46: autocomplete: "off" rlm@46: }; rlm@46: } rlm@46: Ext.form.TextArea.superclass.onRender.call(this, ct, position); rlm@46: if(this.grow){ rlm@46: this.textSizeEl = Ext.DomHelper.append(document.body, { rlm@46: tag: "pre", cls: "x-form-grow-sizer" rlm@46: }); rlm@46: if(this.preventScrollbars){ rlm@46: this.el.setStyle("overflow", "hidden"); rlm@46: } rlm@46: this.el.setHeight(this.growMin); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.textSizeEl){ rlm@46: Ext.removeNode(this.textSizeEl); rlm@46: } rlm@46: Ext.form.TextArea.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: fireKey : function(e){ rlm@46: if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){ rlm@46: this.fireEvent("specialkey", this, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onKeyUp : function(e){ rlm@46: if(!e.isNavKeyPress() || e.getKey() == e.ENTER){ rlm@46: this.autoSize(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: autoSize : function(){ rlm@46: if(!this.grow || !this.textSizeEl){ rlm@46: return; rlm@46: } rlm@46: var el = this.el; rlm@46: var v = el.dom.value; rlm@46: var ts = this.textSizeEl; rlm@46: ts.innerHTML = ''; rlm@46: ts.appendChild(document.createTextNode(v)); rlm@46: v = ts.innerHTML; rlm@46: rlm@46: Ext.fly(ts).setWidth(this.el.getWidth()); rlm@46: if(v.length < 1){ rlm@46: v = "  "; rlm@46: }else{ rlm@46: if(Ext.isIE){ rlm@46: v = v.replace(/\n/g, '

     

    '); rlm@46: } rlm@46: v += this.growAppend; rlm@46: } rlm@46: ts.innerHTML = v; rlm@46: var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin)+this.growPad); rlm@46: if(h != this.lastHeight){ rlm@46: this.lastHeight = h; rlm@46: this.el.setHeight(h); rlm@46: this.fireEvent("autosize", this, h); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.reg('textarea', Ext.form.TextArea); rlm@46: rlm@46: Ext.form.NumberField = Ext.extend(Ext.form.TextField, { rlm@46: rlm@46: fieldClass: "x-form-field x-form-num-field", rlm@46: rlm@46: allowDecimals : true, rlm@46: rlm@46: decimalSeparator : ".", rlm@46: rlm@46: decimalPrecision : 2, rlm@46: rlm@46: allowNegative : true, rlm@46: rlm@46: minValue : Number.NEGATIVE_INFINITY, rlm@46: rlm@46: maxValue : Number.MAX_VALUE, rlm@46: rlm@46: minText : "The minimum value for this field is {0}", rlm@46: rlm@46: maxText : "The maximum value for this field is {0}", rlm@46: rlm@46: nanText : "{0} is not a valid number", rlm@46: rlm@46: baseChars : "0123456789", rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.form.NumberField.superclass.initEvents.call(this); rlm@46: var allowed = this.baseChars+''; rlm@46: if(this.allowDecimals){ rlm@46: allowed += this.decimalSeparator; rlm@46: } rlm@46: if(this.allowNegative){ rlm@46: allowed += "-"; rlm@46: } rlm@46: this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi'); rlm@46: var keyPress = function(e){ rlm@46: var k = e.getKey(); rlm@46: if(!Ext.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){ rlm@46: return; rlm@46: } rlm@46: var c = e.getCharCode(); rlm@46: if(allowed.indexOf(String.fromCharCode(c)) === -1){ rlm@46: e.stopEvent(); rlm@46: } rlm@46: }; rlm@46: this.el.on("keypress", keyPress, this); rlm@46: }, rlm@46: rlm@46: validateValue : function(value){ rlm@46: if(!Ext.form.NumberField.superclass.validateValue.call(this, value)){ rlm@46: return false; rlm@46: } rlm@46: if(value.length < 1){ return true; rlm@46: } rlm@46: value = String(value).replace(this.decimalSeparator, "."); rlm@46: if(isNaN(value)){ rlm@46: this.markInvalid(String.format(this.nanText, value)); rlm@46: return false; rlm@46: } rlm@46: var num = this.parseValue(value); rlm@46: if(num < this.minValue){ rlm@46: this.markInvalid(String.format(this.minText, this.minValue)); rlm@46: return false; rlm@46: } rlm@46: if(num > this.maxValue){ rlm@46: this.markInvalid(String.format(this.maxText, this.maxValue)); rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: getValue : function(){ rlm@46: return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this))); rlm@46: }, rlm@46: rlm@46: setValue : function(v){ rlm@46: v = typeof v == 'number' ? v : parseFloat(String(v).replace(this.decimalSeparator, ".")); rlm@46: v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator); rlm@46: Ext.form.NumberField.superclass.setValue.call(this, v); rlm@46: }, rlm@46: rlm@46: parseValue : function(value){ rlm@46: value = parseFloat(String(value).replace(this.decimalSeparator, ".")); rlm@46: return isNaN(value) ? '' : value; rlm@46: }, rlm@46: rlm@46: fixPrecision : function(value){ rlm@46: var nan = isNaN(value); rlm@46: if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){ rlm@46: return nan ? '' : value; rlm@46: } rlm@46: return parseFloat(parseFloat(value).toFixed(this.decimalPrecision)); rlm@46: }, rlm@46: rlm@46: beforeBlur : function(){ rlm@46: var v = this.parseValue(this.getRawValue()); rlm@46: if(v){ rlm@46: this.setValue(this.fixPrecision(v)); rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.reg('numberfield', Ext.form.NumberField); rlm@46: rlm@46: Ext.form.DateField = Ext.extend(Ext.form.TriggerField, { rlm@46: rlm@46: format : "m/d/Y", rlm@46: rlm@46: altFormats : "m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d", rlm@46: rlm@46: disabledDays : null, rlm@46: rlm@46: disabledDaysText : "Disabled", rlm@46: rlm@46: disabledDates : null, rlm@46: rlm@46: disabledDatesText : "Disabled", rlm@46: rlm@46: minValue : null, rlm@46: rlm@46: maxValue : null, rlm@46: rlm@46: minText : "The date in this field must be equal to or after {0}", rlm@46: rlm@46: maxText : "The date in this field must be equal to or before {0}", rlm@46: rlm@46: invalidText : "{0} is not a valid date - it must be in the format {1}", rlm@46: rlm@46: triggerClass : 'x-form-date-trigger', rlm@46: rlm@46: rlm@46: defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"}, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.DateField.superclass.initComponent.call(this); rlm@46: if(typeof this.minValue == "string"){ rlm@46: this.minValue = this.parseDate(this.minValue); rlm@46: } rlm@46: if(typeof this.maxValue == "string"){ rlm@46: this.maxValue = this.parseDate(this.maxValue); rlm@46: } rlm@46: this.ddMatch = null; rlm@46: if(this.disabledDates){ rlm@46: var dd = this.disabledDates; rlm@46: var re = "(?:"; rlm@46: for(var i = 0; i < dd.length; i++){ rlm@46: re += dd[i]; rlm@46: if(i != dd.length-1) re += "|"; rlm@46: } rlm@46: this.ddMatch = new RegExp(re + ")"); rlm@46: } rlm@46: }, rlm@46: rlm@46: validateValue : function(value){ rlm@46: value = this.formatDate(value); rlm@46: if(!Ext.form.DateField.superclass.validateValue.call(this, value)){ rlm@46: return false; rlm@46: } rlm@46: if(value.length < 1){ return true; rlm@46: } rlm@46: var svalue = value; rlm@46: value = this.parseDate(value); rlm@46: if(!value){ rlm@46: this.markInvalid(String.format(this.invalidText, svalue, this.format)); rlm@46: return false; rlm@46: } rlm@46: var time = value.getTime(); rlm@46: if(this.minValue && time < this.minValue.getTime()){ rlm@46: this.markInvalid(String.format(this.minText, this.formatDate(this.minValue))); rlm@46: return false; rlm@46: } rlm@46: if(this.maxValue && time > this.maxValue.getTime()){ rlm@46: this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue))); rlm@46: return false; rlm@46: } rlm@46: if(this.disabledDays){ rlm@46: var day = value.getDay(); rlm@46: for(var i = 0; i < this.disabledDays.length; i++) { rlm@46: if(day === this.disabledDays[i]){ rlm@46: this.markInvalid(this.disabledDaysText); rlm@46: return false; rlm@46: } rlm@46: } rlm@46: } rlm@46: var fvalue = this.formatDate(value); rlm@46: if(this.ddMatch && this.ddMatch.test(fvalue)){ rlm@46: this.markInvalid(String.format(this.disabledDatesText, fvalue)); rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: validateBlur : function(){ rlm@46: return !this.menu || !this.menu.isVisible(); rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || ""; rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(date){ rlm@46: Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date))); rlm@46: }, rlm@46: rlm@46: parseDate : function(value){ rlm@46: if(!value || Ext.isDate(value)){ rlm@46: return value; rlm@46: } rlm@46: var v = Date.parseDate(value, this.format); rlm@46: if(!v && this.altFormats){ rlm@46: if(!this.altFormatsArray){ rlm@46: this.altFormatsArray = this.altFormats.split("|"); rlm@46: } rlm@46: for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){ rlm@46: v = Date.parseDate(value, this.altFormatsArray[i]); rlm@46: } rlm@46: } rlm@46: return v; rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.menu) { rlm@46: this.menu.destroy(); rlm@46: } rlm@46: if(this.wrap){ rlm@46: this.wrap.remove(); rlm@46: } rlm@46: Ext.form.DateField.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: formatDate : function(date){ rlm@46: return Ext.isDate(date) ? date.dateFormat(this.format) : date; rlm@46: }, rlm@46: rlm@46: menuListeners : { rlm@46: select: function(m, d){ rlm@46: this.setValue(d); rlm@46: }, rlm@46: show : function(){ this.onFocus(); rlm@46: }, rlm@46: hide : function(){ rlm@46: this.focus.defer(10, this); rlm@46: var ml = this.menuListeners; rlm@46: this.menu.un("select", ml.select, this); rlm@46: this.menu.un("show", ml.show, this); rlm@46: this.menu.un("hide", ml.hide, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: onTriggerClick : function(){ rlm@46: if(this.disabled){ rlm@46: return; rlm@46: } rlm@46: if(this.menu == null){ rlm@46: this.menu = new Ext.menu.DateMenu(); rlm@46: } rlm@46: Ext.apply(this.menu.picker, { rlm@46: minDate : this.minValue, rlm@46: maxDate : this.maxValue, rlm@46: disabledDatesRE : this.ddMatch, rlm@46: disabledDatesText : this.disabledDatesText, rlm@46: disabledDays : this.disabledDays, rlm@46: disabledDaysText : this.disabledDaysText, rlm@46: format : this.format, rlm@46: minText : String.format(this.minText, this.formatDate(this.minValue)), rlm@46: maxText : String.format(this.maxText, this.formatDate(this.maxValue)) rlm@46: }); rlm@46: this.menu.on(Ext.apply({}, this.menuListeners, { rlm@46: scope:this rlm@46: })); rlm@46: this.menu.picker.setValue(this.getValue() || new Date()); rlm@46: this.menu.show(this.el, "tl-bl?"); rlm@46: }, rlm@46: rlm@46: beforeBlur : function(){ rlm@46: var v = this.parseDate(this.getRawValue()); rlm@46: if(v){ rlm@46: this.setValue(v); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('datefield', Ext.form.DateField); rlm@46: rlm@46: Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"}, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: listClass: '', rlm@46: rlm@46: selectedClass: 'x-combo-selected', rlm@46: rlm@46: triggerClass : 'x-form-arrow-trigger', rlm@46: rlm@46: shadow:'sides', rlm@46: rlm@46: listAlign: 'tl-bl?', rlm@46: rlm@46: maxHeight: 300, rlm@46: rlm@46: minHeight: 90, rlm@46: rlm@46: triggerAction: 'query', rlm@46: rlm@46: minChars : 4, rlm@46: rlm@46: typeAhead: false, rlm@46: rlm@46: queryDelay: 500, rlm@46: rlm@46: pageSize: 0, rlm@46: rlm@46: selectOnFocus:false, rlm@46: rlm@46: queryParam: 'query', rlm@46: rlm@46: loadingText: 'Loading...', rlm@46: rlm@46: resizable: false, rlm@46: rlm@46: handleHeight : 8, rlm@46: rlm@46: editable: true, rlm@46: rlm@46: allQuery: '', rlm@46: rlm@46: mode: 'remote', rlm@46: rlm@46: minListWidth : 70, rlm@46: rlm@46: forceSelection:false, rlm@46: rlm@46: typeAheadDelay : 250, rlm@46: rlm@46: rlm@46: rlm@46: lazyInit : true, rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.ComboBox.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'expand', rlm@46: rlm@46: 'collapse', rlm@46: rlm@46: 'beforeselect', rlm@46: rlm@46: 'select', rlm@46: rlm@46: 'beforequery' rlm@46: ); rlm@46: if(this.transform){ rlm@46: this.allowDomMove = false; rlm@46: var s = Ext.getDom(this.transform); rlm@46: if(!this.hiddenName){ rlm@46: this.hiddenName = s.name; rlm@46: } rlm@46: if(!this.store){ rlm@46: this.mode = 'local'; rlm@46: var d = [], opts = s.options; rlm@46: for(var i = 0, len = opts.length;i < len; i++){ rlm@46: var o = opts[i]; rlm@46: var value = (Ext.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text; rlm@46: if(o.selected) { rlm@46: this.value = value; rlm@46: } rlm@46: d.push([value, o.text]); rlm@46: } rlm@46: this.store = new Ext.data.SimpleStore({ rlm@46: 'id': 0, rlm@46: fields: ['value', 'text'], rlm@46: data : d rlm@46: }); rlm@46: this.valueField = 'value'; rlm@46: this.displayField = 'text'; rlm@46: } rlm@46: s.name = Ext.id(); if(!this.lazyRender){ rlm@46: this.target = true; rlm@46: this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate); rlm@46: Ext.removeNode(s); this.render(this.el.parentNode); rlm@46: }else{ rlm@46: Ext.removeNode(s); } rlm@46: } rlm@46: else if(Ext.isArray(this.store)){ rlm@46: if (Ext.isArray(this.store[0])){ rlm@46: this.store = new Ext.data.SimpleStore({ rlm@46: fields: ['value','text'], rlm@46: data: this.store rlm@46: }); rlm@46: this.valueField = 'value'; rlm@46: }else{ rlm@46: this.store = new Ext.data.SimpleStore({ rlm@46: fields: ['text'], rlm@46: data: this.store, rlm@46: expandData: true rlm@46: }); rlm@46: this.valueField = 'text'; rlm@46: } rlm@46: this.displayField = 'text'; rlm@46: this.mode = 'local'; rlm@46: } rlm@46: rlm@46: this.selectedIndex = -1; rlm@46: if(this.mode == 'local'){ rlm@46: if(this.initialConfig.queryDelay === undefined){ rlm@46: this.queryDelay = 10; rlm@46: } rlm@46: if(this.initialConfig.minChars === undefined){ rlm@46: this.minChars = 0; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.form.ComboBox.superclass.onRender.call(this, ct, position); rlm@46: if(this.hiddenName){ rlm@46: this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)}, rlm@46: 'before', true); rlm@46: this.hiddenField.value = rlm@46: this.hiddenValue !== undefined ? this.hiddenValue : rlm@46: this.value !== undefined ? this.value : ''; rlm@46: rlm@46: this.el.dom.removeAttribute('name'); rlm@46: } rlm@46: if(Ext.isGecko){ rlm@46: this.el.dom.setAttribute('autocomplete', 'off'); rlm@46: } rlm@46: rlm@46: if(!this.lazyInit){ rlm@46: this.initList(); rlm@46: }else{ rlm@46: this.on('focus', this.initList, this, {single: true}); rlm@46: } rlm@46: rlm@46: if(!this.editable){ rlm@46: this.editable = true; rlm@46: this.setEditable(false); rlm@46: } rlm@46: }, rlm@46: rlm@46: initList : function(){ rlm@46: if(!this.list){ rlm@46: var cls = 'x-combo-list'; rlm@46: rlm@46: this.list = new Ext.Layer({ rlm@46: shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false rlm@46: }); rlm@46: rlm@46: var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth); rlm@46: this.list.setWidth(lw); rlm@46: this.list.swallowEvent('mousewheel'); rlm@46: this.assetHeight = 0; rlm@46: rlm@46: if(this.title){ rlm@46: this.header = this.list.createChild({cls:cls+'-hd', html: this.title}); rlm@46: this.assetHeight += this.header.getHeight(); rlm@46: } rlm@46: rlm@46: this.innerList = this.list.createChild({cls:cls+'-inner'}); rlm@46: this.innerList.on('mouseover', this.onViewOver, this); rlm@46: this.innerList.on('mousemove', this.onViewMove, this); rlm@46: this.innerList.setWidth(lw - this.list.getFrameWidth('lr')); rlm@46: rlm@46: if(this.pageSize){ rlm@46: this.footer = this.list.createChild({cls:cls+'-ft'}); rlm@46: this.pageTb = new Ext.PagingToolbar({ rlm@46: store:this.store, rlm@46: pageSize: this.pageSize, rlm@46: renderTo:this.footer rlm@46: }); rlm@46: this.assetHeight += this.footer.getHeight(); rlm@46: } rlm@46: rlm@46: if(!this.tpl){ rlm@46: rlm@46: this.tpl = '
    {' + this.displayField + '}
    '; rlm@46: rlm@46: } rlm@46: rlm@46: rlm@46: this.view = new Ext.DataView({ rlm@46: applyTo: this.innerList, rlm@46: tpl: this.tpl, rlm@46: singleSelect: true, rlm@46: selectedClass: this.selectedClass, rlm@46: itemSelector: this.itemSelector || '.' + cls + '-item' rlm@46: }); rlm@46: rlm@46: this.view.on('click', this.onViewClick, this); rlm@46: rlm@46: this.bindStore(this.store, true); rlm@46: rlm@46: if(this.resizable){ rlm@46: this.resizer = new Ext.Resizable(this.list, { rlm@46: pinned:true, handles:'se' rlm@46: }); rlm@46: this.resizer.on('resize', function(r, w, h){ rlm@46: this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight; rlm@46: this.listWidth = w; rlm@46: this.innerList.setWidth(w - this.list.getFrameWidth('lr')); rlm@46: this.restrictHeight(); rlm@46: }, this); rlm@46: this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px'); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: bindStore : function(store, initial){ rlm@46: if(this.store && !initial){ rlm@46: this.store.un('beforeload', this.onBeforeLoad, this); rlm@46: this.store.un('load', this.onLoad, this); rlm@46: this.store.un('loadexception', this.collapse, this); rlm@46: if(!store){ rlm@46: this.store = null; rlm@46: if(this.view){ rlm@46: this.view.setStore(null); rlm@46: } rlm@46: } rlm@46: } rlm@46: if(store){ rlm@46: this.store = Ext.StoreMgr.lookup(store); rlm@46: rlm@46: this.store.on('beforeload', this.onBeforeLoad, this); rlm@46: this.store.on('load', this.onLoad, this); rlm@46: this.store.on('loadexception', this.collapse, this); rlm@46: rlm@46: if(this.view){ rlm@46: this.view.setStore(store); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.form.ComboBox.superclass.initEvents.call(this); rlm@46: rlm@46: this.keyNav = new Ext.KeyNav(this.el, { rlm@46: "up" : function(e){ rlm@46: this.inKeyMode = true; rlm@46: this.selectPrev(); rlm@46: }, rlm@46: rlm@46: "down" : function(e){ rlm@46: if(!this.isExpanded()){ rlm@46: this.onTriggerClick(); rlm@46: }else{ rlm@46: this.inKeyMode = true; rlm@46: this.selectNext(); rlm@46: } rlm@46: }, rlm@46: rlm@46: "enter" : function(e){ rlm@46: this.onViewClick(); rlm@46: this.delayedCheck = true; rlm@46: this.unsetDelayCheck.defer(10, this); rlm@46: }, rlm@46: rlm@46: "esc" : function(e){ rlm@46: this.collapse(); rlm@46: }, rlm@46: rlm@46: "tab" : function(e){ rlm@46: this.onViewClick(false); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: scope : this, rlm@46: rlm@46: doRelay : function(foo, bar, hname){ rlm@46: if(hname == 'down' || this.scope.isExpanded()){ rlm@46: return Ext.KeyNav.prototype.doRelay.apply(this, arguments); rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: forceKeyDown : true rlm@46: }); rlm@46: this.queryDelay = Math.max(this.queryDelay || 10, rlm@46: this.mode == 'local' ? 10 : 250); rlm@46: this.dqTask = new Ext.util.DelayedTask(this.initQuery, this); rlm@46: if(this.typeAhead){ rlm@46: this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this); rlm@46: } rlm@46: if(this.editable !== false){ rlm@46: this.el.on("keyup", this.onKeyUp, this); rlm@46: } rlm@46: if(this.forceSelection){ rlm@46: this.on('blur', this.doForce, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.view){ rlm@46: this.view.el.removeAllListeners(); rlm@46: this.view.el.remove(); rlm@46: this.view.purgeListeners(); rlm@46: } rlm@46: if(this.list){ rlm@46: this.list.destroy(); rlm@46: } rlm@46: this.bindStore(null); rlm@46: Ext.form.ComboBox.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: unsetDelayCheck : function(){ rlm@46: delete this.delayedCheck; rlm@46: }, rlm@46: fireKey : function(e){ rlm@46: if(e.isNavKeyPress() && !this.isExpanded() && !this.delayedCheck){ rlm@46: this.fireEvent("specialkey", this, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onResize: function(w, h){ rlm@46: Ext.form.ComboBox.superclass.onResize.apply(this, arguments); rlm@46: if(this.list && this.listWidth === undefined){ rlm@46: var lw = Math.max(w, this.minListWidth); rlm@46: this.list.setWidth(lw); rlm@46: this.innerList.setWidth(lw - this.list.getFrameWidth('lr')); rlm@46: } rlm@46: }, rlm@46: rlm@46: onEnable: function(){ rlm@46: Ext.form.ComboBox.superclass.onEnable.apply(this, arguments); rlm@46: if(this.hiddenField){ rlm@46: this.hiddenField.disabled = false; rlm@46: } rlm@46: }, rlm@46: rlm@46: onDisable: function(){ rlm@46: Ext.form.ComboBox.superclass.onDisable.apply(this, arguments); rlm@46: if(this.hiddenField){ rlm@46: this.hiddenField.disabled = true; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setEditable : function(value){ rlm@46: if(value == this.editable){ rlm@46: return; rlm@46: } rlm@46: this.editable = value; rlm@46: if(!value){ rlm@46: this.el.dom.setAttribute('readOnly', true); rlm@46: this.el.on('mousedown', this.onTriggerClick, this); rlm@46: this.el.addClass('x-combo-noedit'); rlm@46: }else{ rlm@46: this.el.dom.setAttribute('readOnly', false); rlm@46: this.el.un('mousedown', this.onTriggerClick, this); rlm@46: this.el.removeClass('x-combo-noedit'); rlm@46: } rlm@46: }, rlm@46: rlm@46: onBeforeLoad : function(){ rlm@46: if(!this.hasFocus){ rlm@46: return; rlm@46: } rlm@46: this.innerList.update(this.loadingText ? rlm@46: '
    '+this.loadingText+'
    ' : ''); rlm@46: this.restrictHeight(); rlm@46: this.selectedIndex = -1; rlm@46: }, rlm@46: rlm@46: onLoad : function(){ rlm@46: if(!this.hasFocus){ rlm@46: return; rlm@46: } rlm@46: if(this.store.getCount() > 0){ rlm@46: this.expand(); rlm@46: this.restrictHeight(); rlm@46: if(this.lastQuery == this.allQuery){ rlm@46: if(this.editable){ rlm@46: this.el.dom.select(); rlm@46: } rlm@46: if(!this.selectByValue(this.value, true)){ rlm@46: this.select(0, true); rlm@46: } rlm@46: }else{ rlm@46: this.selectNext(); rlm@46: if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){ rlm@46: this.taTask.delay(this.typeAheadDelay); rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: this.onEmptyResults(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onTypeAhead : function(){ rlm@46: if(this.store.getCount() > 0){ rlm@46: var r = this.store.getAt(0); rlm@46: var newValue = r.data[this.displayField]; rlm@46: var len = newValue.length; rlm@46: var selStart = this.getRawValue().length; rlm@46: if(selStart != len){ rlm@46: this.setRawValue(newValue); rlm@46: this.selectText(selStart, newValue.length); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onSelect : function(record, index){ rlm@46: if(this.fireEvent('beforeselect', this, record, index) !== false){ rlm@46: this.setValue(record.data[this.valueField || this.displayField]); rlm@46: this.collapse(); rlm@46: this.fireEvent('select', this, record, index); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: if(this.valueField){ rlm@46: return typeof this.value != 'undefined' ? this.value : ''; rlm@46: }else{ rlm@46: return Ext.form.ComboBox.superclass.getValue.call(this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: clearValue : function(){ rlm@46: if(this.hiddenField){ rlm@46: this.hiddenField.value = ''; rlm@46: } rlm@46: this.setRawValue(''); rlm@46: this.lastSelectionText = ''; rlm@46: this.applyEmptyText(); rlm@46: this.value = ''; rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: var text = v; rlm@46: if(this.valueField){ rlm@46: var r = this.findRecord(this.valueField, v); rlm@46: if(r){ rlm@46: text = r.data[this.displayField]; rlm@46: }else if(this.valueNotFoundText !== undefined){ rlm@46: text = this.valueNotFoundText; rlm@46: } rlm@46: } rlm@46: this.lastSelectionText = text; rlm@46: if(this.hiddenField){ rlm@46: this.hiddenField.value = v; rlm@46: } rlm@46: Ext.form.ComboBox.superclass.setValue.call(this, text); rlm@46: this.value = v; rlm@46: }, rlm@46: rlm@46: findRecord : function(prop, value){ rlm@46: var record; rlm@46: if(this.store.getCount() > 0){ rlm@46: this.store.each(function(r){ rlm@46: if(r.data[prop] == value){ rlm@46: record = r; rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: } rlm@46: return record; rlm@46: }, rlm@46: rlm@46: onViewMove : function(e, t){ rlm@46: this.inKeyMode = false; rlm@46: }, rlm@46: rlm@46: onViewOver : function(e, t){ rlm@46: if(this.inKeyMode){ return; rlm@46: } rlm@46: var item = this.view.findItemFromChild(t); rlm@46: if(item){ rlm@46: var index = this.view.indexOf(item); rlm@46: this.select(index, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: onViewClick : function(doFocus){ rlm@46: var index = this.view.getSelectedIndexes()[0]; rlm@46: var r = this.store.getAt(index); rlm@46: if(r){ rlm@46: this.onSelect(r, index); rlm@46: } rlm@46: if(doFocus !== false){ rlm@46: this.el.focus(); rlm@46: } rlm@46: }, rlm@46: rlm@46: restrictHeight : function(){ rlm@46: this.innerList.dom.style.height = ''; rlm@46: var inner = this.innerList.dom; rlm@46: var pad = this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight; rlm@46: var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight); rlm@46: var ha = this.getPosition()[1]-Ext.getBody().getScroll().top; rlm@46: var hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height; rlm@46: var space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5; rlm@46: h = Math.min(h, space, this.maxHeight); rlm@46: rlm@46: this.innerList.setHeight(h); rlm@46: this.list.beginUpdate(); rlm@46: this.list.setHeight(h+pad); rlm@46: this.list.alignTo(this.wrap, this.listAlign); rlm@46: this.list.endUpdate(); rlm@46: }, rlm@46: rlm@46: onEmptyResults : function(){ rlm@46: this.collapse(); rlm@46: }, rlm@46: rlm@46: rlm@46: isExpanded : function(){ rlm@46: return this.list && this.list.isVisible(); rlm@46: }, rlm@46: rlm@46: rlm@46: selectByValue : function(v, scrollIntoView){ rlm@46: if(v !== undefined && v !== null){ rlm@46: var r = this.findRecord(this.valueField || this.displayField, v); rlm@46: if(r){ rlm@46: this.select(this.store.indexOf(r), scrollIntoView); rlm@46: return true; rlm@46: } rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(index, scrollIntoView){ rlm@46: this.selectedIndex = index; rlm@46: this.view.select(index); rlm@46: if(scrollIntoView !== false){ rlm@46: var el = this.view.getNode(index); rlm@46: if(el){ rlm@46: this.innerList.scrollChildIntoView(el, false); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: selectNext : function(){ rlm@46: var ct = this.store.getCount(); rlm@46: if(ct > 0){ rlm@46: if(this.selectedIndex == -1){ rlm@46: this.select(0); rlm@46: }else if(this.selectedIndex < ct-1){ rlm@46: this.select(this.selectedIndex+1); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: selectPrev : function(){ rlm@46: var ct = this.store.getCount(); rlm@46: if(ct > 0){ rlm@46: if(this.selectedIndex == -1){ rlm@46: this.select(0); rlm@46: }else if(this.selectedIndex != 0){ rlm@46: this.select(this.selectedIndex-1); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onKeyUp : function(e){ rlm@46: if(this.editable !== false && !e.isSpecialKey()){ rlm@46: this.lastKey = e.getKey(); rlm@46: this.dqTask.delay(this.queryDelay); rlm@46: } rlm@46: }, rlm@46: rlm@46: validateBlur : function(){ rlm@46: return !this.list || !this.list.isVisible(); rlm@46: }, rlm@46: rlm@46: initQuery : function(){ rlm@46: this.doQuery(this.getRawValue()); rlm@46: }, rlm@46: rlm@46: doForce : function(){ rlm@46: if(this.el.dom.value.length > 0){ rlm@46: this.el.dom.value = rlm@46: this.lastSelectionText === undefined ? '' : this.lastSelectionText; rlm@46: this.applyEmptyText(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: doQuery : function(q, forceAll){ rlm@46: if(q === undefined || q === null){ rlm@46: q = ''; rlm@46: } rlm@46: var qe = { rlm@46: query: q, rlm@46: forceAll: forceAll, rlm@46: combo: this, rlm@46: cancel:false rlm@46: }; rlm@46: if(this.fireEvent('beforequery', qe)===false || qe.cancel){ rlm@46: return false; rlm@46: } rlm@46: q = qe.query; rlm@46: forceAll = qe.forceAll; rlm@46: if(forceAll === true || (q.length >= this.minChars)){ rlm@46: if(this.lastQuery !== q){ rlm@46: this.lastQuery = q; rlm@46: if(this.mode == 'local'){ rlm@46: this.selectedIndex = -1; rlm@46: if(forceAll){ rlm@46: this.store.clearFilter(); rlm@46: }else{ rlm@46: this.store.filter(this.displayField, q); rlm@46: } rlm@46: this.onLoad(); rlm@46: }else{ rlm@46: this.store.baseParams[this.queryParam] = q; rlm@46: this.store.load({ rlm@46: params: this.getParams(q) rlm@46: }); rlm@46: this.expand(); rlm@46: } rlm@46: }else{ rlm@46: this.selectedIndex = -1; rlm@46: this.onLoad(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: getParams : function(q){ rlm@46: var p = {}; rlm@46: if(this.pageSize){ rlm@46: p.start = 0; rlm@46: p.limit = this.pageSize; rlm@46: } rlm@46: return p; rlm@46: }, rlm@46: rlm@46: rlm@46: collapse : function(){ rlm@46: if(!this.isExpanded()){ rlm@46: return; rlm@46: } rlm@46: this.list.hide(); rlm@46: Ext.getDoc().un('mousewheel', this.collapseIf, this); rlm@46: Ext.getDoc().un('mousedown', this.collapseIf, this); rlm@46: this.fireEvent('collapse', this); rlm@46: }, rlm@46: rlm@46: collapseIf : function(e){ rlm@46: if(!e.within(this.wrap) && !e.within(this.list)){ rlm@46: this.collapse(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: expand : function(){ rlm@46: if(this.isExpanded() || !this.hasFocus){ rlm@46: return; rlm@46: } rlm@46: this.list.alignTo(this.wrap, this.listAlign); rlm@46: this.list.show(); rlm@46: this.innerList.setOverflow('auto'); Ext.getDoc().on('mousewheel', this.collapseIf, this); rlm@46: Ext.getDoc().on('mousedown', this.collapseIf, this); rlm@46: this.fireEvent('expand', this); rlm@46: }, rlm@46: rlm@46: onTriggerClick : function(){ rlm@46: if(this.disabled){ rlm@46: return; rlm@46: } rlm@46: if(this.isExpanded()){ rlm@46: this.collapse(); rlm@46: this.el.focus(); rlm@46: }else { rlm@46: this.onFocus({}); rlm@46: if(this.triggerAction == 'all') { rlm@46: this.doQuery(this.allQuery, true); rlm@46: } else { rlm@46: this.doQuery(this.getRawValue()); rlm@46: } rlm@46: this.el.focus(); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('combo', Ext.form.ComboBox); rlm@46: rlm@46: Ext.form.Checkbox = Ext.extend(Ext.form.Field, { rlm@46: rlm@46: focusClass : undefined, rlm@46: rlm@46: fieldClass: "x-form-field", rlm@46: rlm@46: checked: false, rlm@46: rlm@46: defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"}, rlm@46: rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.Checkbox.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: 'check' rlm@46: ); rlm@46: }, rlm@46: rlm@46: onResize : function(){ rlm@46: Ext.form.Checkbox.superclass.onResize.apply(this, arguments); rlm@46: if(!this.boxLabel){ rlm@46: this.el.alignTo(this.wrap, 'c-c'); rlm@46: } rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.form.Checkbox.superclass.initEvents.call(this); rlm@46: this.el.on("click", this.onClick, this); rlm@46: this.el.on("change", this.onClick, this); rlm@46: }, rlm@46: rlm@46: getResizeEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: getPositionEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: rlm@46: markInvalid : Ext.emptyFn, rlm@46: rlm@46: clearInvalid : Ext.emptyFn, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.form.Checkbox.superclass.onRender.call(this, ct, position); rlm@46: if(this.inputValue !== undefined){ rlm@46: this.el.dom.value = this.inputValue; rlm@46: } rlm@46: this.wrap = this.el.wrap({cls: "x-form-check-wrap"}); rlm@46: if(this.boxLabel){ rlm@46: this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel}); rlm@46: } rlm@46: if(this.checked){ rlm@46: this.setValue(true); rlm@46: }else{ rlm@46: this.checked = this.el.dom.checked; rlm@46: } rlm@46: }, rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.wrap){ rlm@46: this.wrap.remove(); rlm@46: } rlm@46: Ext.form.Checkbox.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: initValue : Ext.emptyFn, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: if(this.rendered){ rlm@46: return this.el.dom.checked; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onClick : function(){ rlm@46: if(this.el.dom.checked != this.checked){ rlm@46: this.setValue(this.el.dom.checked); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); rlm@46: if(this.el && this.el.dom){ rlm@46: this.el.dom.checked = this.checked; rlm@46: this.el.dom.defaultChecked = this.checked; rlm@46: } rlm@46: this.fireEvent("check", this, this.checked); rlm@46: } rlm@46: }); rlm@46: Ext.reg('checkbox', Ext.form.Checkbox); rlm@46: rlm@46: Ext.form.Radio = Ext.extend(Ext.form.Checkbox, { rlm@46: inputType: 'radio', rlm@46: rlm@46: rlm@46: markInvalid : Ext.emptyFn, rlm@46: rlm@46: clearInvalid : Ext.emptyFn, rlm@46: rlm@46: rlm@46: getGroupValue : function(){ rlm@46: var p = this.el.up('form') || Ext.getBody(); rlm@46: var c = p.child('input[name='+this.el.dom.name+']:checked', true); rlm@46: return c ? c.value : null; rlm@46: }, rlm@46: rlm@46: onClick : function(){ rlm@46: if(this.el.dom.checked != this.checked){ rlm@46: var p = this.el.up('form') || Ext.getBody(); rlm@46: var els = p.select('input[name='+this.el.dom.name+']'); rlm@46: els.each(function(el){ rlm@46: if(el.dom.id == this.id){ rlm@46: this.setValue(true); rlm@46: }else{ rlm@46: Ext.getCmp(el.dom.id).setValue(false); rlm@46: } rlm@46: }, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: if (typeof v == 'boolean') { rlm@46: Ext.form.Radio.superclass.setValue.call(this, v); rlm@46: } else { rlm@46: var r = this.el.up('form').child('input[name='+this.el.dom.name+'][value='+v+']', true); rlm@46: if (r){ rlm@46: r.checked = true; rlm@46: }; rlm@46: } rlm@46: } rlm@46: }); rlm@46: Ext.reg('radio', Ext.form.Radio); rlm@46: rlm@46: Ext.form.Hidden = Ext.extend(Ext.form.Field, { rlm@46: rlm@46: inputType : 'hidden', rlm@46: rlm@46: rlm@46: onRender : function(){ rlm@46: Ext.form.Hidden.superclass.onRender.apply(this, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: this.originalValue = this.getValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: setSize : Ext.emptyFn, rlm@46: setWidth : Ext.emptyFn, rlm@46: setHeight : Ext.emptyFn, rlm@46: setPosition : Ext.emptyFn, rlm@46: setPagePosition : Ext.emptyFn, rlm@46: markInvalid : Ext.emptyFn, rlm@46: clearInvalid : Ext.emptyFn rlm@46: }); rlm@46: Ext.reg('hidden', Ext.form.Hidden); rlm@46: rlm@46: Ext.form.BasicForm = function(el, config){ rlm@46: Ext.apply(this, config); rlm@46: rlm@46: this.items = new Ext.util.MixedCollection(false, function(o){ rlm@46: return o.id || (o.id = Ext.id()); rlm@46: }); rlm@46: this.addEvents( rlm@46: rlm@46: 'beforeaction', rlm@46: rlm@46: 'actionfailed', rlm@46: rlm@46: 'actioncomplete' rlm@46: ); rlm@46: rlm@46: if(el){ rlm@46: this.initEl(el); rlm@46: } rlm@46: Ext.form.BasicForm.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.form.BasicForm, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: timeout: 30, rlm@46: rlm@46: activeAction : null, rlm@46: rlm@46: rlm@46: trackResetOnLoad : false, rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: initEl : function(el){ rlm@46: this.el = Ext.get(el); rlm@46: this.id = this.el.id || Ext.id(); rlm@46: if(!this.standardSubmit){ rlm@46: this.el.on('submit', this.onSubmit, this); rlm@46: } rlm@46: this.el.addClass('x-form'); rlm@46: }, rlm@46: rlm@46: rlm@46: getEl: function(){ rlm@46: return this.el; rlm@46: }, rlm@46: rlm@46: onSubmit : function(e){ rlm@46: e.stopEvent(); rlm@46: }, rlm@46: rlm@46: destroy: function() { rlm@46: this.items.each(function(f){ rlm@46: Ext.destroy(f); rlm@46: }); rlm@46: if(this.el){ rlm@46: this.el.removeAllListeners(); rlm@46: this.el.remove(); rlm@46: } rlm@46: this.purgeListeners(); rlm@46: }, rlm@46: rlm@46: rlm@46: isValid : function(){ rlm@46: var valid = true; rlm@46: this.items.each(function(f){ rlm@46: if(!f.validate()){ rlm@46: valid = false; rlm@46: } rlm@46: }); rlm@46: return valid; rlm@46: }, rlm@46: rlm@46: rlm@46: isDirty : function(){ rlm@46: var dirty = false; rlm@46: this.items.each(function(f){ rlm@46: if(f.isDirty()){ rlm@46: dirty = true; rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: return dirty; rlm@46: }, rlm@46: rlm@46: rlm@46: doAction : function(action, options){ rlm@46: if(typeof action == 'string'){ rlm@46: action = new Ext.form.Action.ACTION_TYPES[action](this, options); rlm@46: } rlm@46: if(this.fireEvent('beforeaction', this, action) !== false){ rlm@46: this.beforeAction(action); rlm@46: action.run.defer(100, action); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: submit : function(options){ rlm@46: if(this.standardSubmit){ rlm@46: var v = this.isValid(); rlm@46: if(v){ rlm@46: this.el.dom.submit(); rlm@46: } rlm@46: return v; rlm@46: } rlm@46: this.doAction('submit', options); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(options){ rlm@46: this.doAction('load', options); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: updateRecord : function(record){ rlm@46: record.beginEdit(); rlm@46: var fs = record.fields; rlm@46: fs.each(function(f){ rlm@46: var field = this.findField(f.name); rlm@46: if(field){ rlm@46: record.set(f.name, field.getValue()); rlm@46: } rlm@46: }, this); rlm@46: record.endEdit(); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: loadRecord : function(record){ rlm@46: this.setValues(record.data); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: beforeAction : function(action){ rlm@46: var o = action.options; rlm@46: if(o.waitMsg){ rlm@46: if(this.waitMsgTarget === true){ rlm@46: this.el.mask(o.waitMsg, 'x-mask-loading'); rlm@46: }else if(this.waitMsgTarget){ rlm@46: this.waitMsgTarget = Ext.get(this.waitMsgTarget); rlm@46: this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading'); rlm@46: }else{ rlm@46: Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...'); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: afterAction : function(action, success){ rlm@46: this.activeAction = null; rlm@46: var o = action.options; rlm@46: if(o.waitMsg){ rlm@46: if(this.waitMsgTarget === true){ rlm@46: this.el.unmask(); rlm@46: }else if(this.waitMsgTarget){ rlm@46: this.waitMsgTarget.unmask(); rlm@46: }else{ rlm@46: Ext.MessageBox.updateProgress(1); rlm@46: Ext.MessageBox.hide(); rlm@46: } rlm@46: } rlm@46: if(success){ rlm@46: if(o.reset){ rlm@46: this.reset(); rlm@46: } rlm@46: Ext.callback(o.success, o.scope, [this, action]); rlm@46: this.fireEvent('actioncomplete', this, action); rlm@46: }else{ rlm@46: Ext.callback(o.failure, o.scope, [this, action]); rlm@46: this.fireEvent('actionfailed', this, action); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: findField : function(id){ rlm@46: var field = this.items.get(id); rlm@46: if(!field){ rlm@46: this.items.each(function(f){ rlm@46: if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){ rlm@46: field = f; rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: } rlm@46: return field || null; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: markInvalid : function(errors){ rlm@46: if(Ext.isArray(errors)){ rlm@46: for(var i = 0, len = errors.length; i < len; i++){ rlm@46: var fieldError = errors[i]; rlm@46: var f = this.findField(fieldError.id); rlm@46: if(f){ rlm@46: f.markInvalid(fieldError.msg); rlm@46: } rlm@46: } rlm@46: }else{ rlm@46: var field, id; rlm@46: for(id in errors){ rlm@46: if(typeof errors[id] != 'function' && (field = this.findField(id))){ rlm@46: field.markInvalid(errors[id]); rlm@46: } rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setValues : function(values){ rlm@46: if(Ext.isArray(values)){ for(var i = 0, len = values.length; i < len; i++){ rlm@46: var v = values[i]; rlm@46: var f = this.findField(v.id); rlm@46: if(f){ rlm@46: f.setValue(v.value); rlm@46: if(this.trackResetOnLoad){ rlm@46: f.originalValue = f.getValue(); rlm@46: } rlm@46: } rlm@46: } rlm@46: }else{ var field, id; rlm@46: for(id in values){ rlm@46: if(typeof values[id] != 'function' && (field = this.findField(id))){ rlm@46: field.setValue(values[id]); rlm@46: if(this.trackResetOnLoad){ rlm@46: field.originalValue = field.getValue(); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getValues : function(asString){ rlm@46: var fs = Ext.lib.Ajax.serializeForm(this.el.dom); rlm@46: if(asString === true){ rlm@46: return fs; rlm@46: } rlm@46: return Ext.urlDecode(fs); rlm@46: }, rlm@46: rlm@46: rlm@46: clearInvalid : function(){ rlm@46: this.items.each(function(f){ rlm@46: f.clearInvalid(); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: reset : function(){ rlm@46: this.items.each(function(f){ rlm@46: f.reset(); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: add : function(){ rlm@46: this.items.addAll(Array.prototype.slice.call(arguments, 0)); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: remove : function(field){ rlm@46: this.items.remove(field); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: render : function(){ rlm@46: this.items.each(function(f){ rlm@46: if(f.isFormField && !f.rendered && document.getElementById(f.id)){ f.applyToMarkup(f.id); rlm@46: } rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: applyToFields : function(o){ rlm@46: this.items.each(function(f){ rlm@46: Ext.apply(f, o); rlm@46: }); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: applyIfToFields : function(o){ rlm@46: this.items.each(function(f){ rlm@46: Ext.applyIf(f, o); rlm@46: }); rlm@46: return this; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.BasicForm = Ext.form.BasicForm; rlm@46: rlm@46: Ext.FormPanel = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: buttonAlign:'center', rlm@46: rlm@46: rlm@46: minButtonWidth:75, rlm@46: rlm@46: rlm@46: labelAlign:'left', rlm@46: rlm@46: rlm@46: monitorValid : false, rlm@46: rlm@46: rlm@46: monitorPoll : 200, rlm@46: rlm@46: rlm@46: layout: 'form', rlm@46: rlm@46: initComponent :function(){ rlm@46: this.form = this.createForm(); rlm@46: rlm@46: Ext.FormPanel.superclass.initComponent.call(this); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: 'clientvalidation' rlm@46: ); rlm@46: rlm@46: this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']); rlm@46: }, rlm@46: rlm@46: createForm: function(){ rlm@46: delete this.initialConfig.listeners; rlm@46: return new Ext.form.BasicForm(null, this.initialConfig); rlm@46: }, rlm@46: rlm@46: initFields : function(){ rlm@46: var f = this.form; rlm@46: var formPanel = this; rlm@46: var fn = function(c){ rlm@46: if(c.doLayout && c != formPanel){ rlm@46: Ext.applyIf(c, { rlm@46: labelAlign: c.ownerCt.labelAlign, rlm@46: labelWidth: c.ownerCt.labelWidth, rlm@46: itemCls: c.ownerCt.itemCls rlm@46: }); rlm@46: if(c.items){ rlm@46: c.items.each(fn); rlm@46: } rlm@46: }else if(c.isFormField){ rlm@46: f.add(c); rlm@46: } rlm@46: } rlm@46: this.items.each(fn); rlm@46: }, rlm@46: rlm@46: getLayoutTarget : function(){ rlm@46: return this.form.el; rlm@46: }, rlm@46: rlm@46: rlm@46: getForm : function(){ rlm@46: return this.form; rlm@46: }, rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: this.initFields(); rlm@46: rlm@46: Ext.FormPanel.superclass.onRender.call(this, ct, position); rlm@46: var o = { rlm@46: tag: 'form', rlm@46: method : this.method || 'POST', rlm@46: id : this.formId || Ext.id() rlm@46: }; rlm@46: if(this.fileUpload) { rlm@46: o.enctype = 'multipart/form-data'; rlm@46: } rlm@46: this.form.initEl(this.body.createChild(o)); rlm@46: }, rlm@46: rlm@46: beforeDestroy: function(){ rlm@46: Ext.FormPanel.superclass.beforeDestroy.call(this); rlm@46: Ext.destroy(this.form); rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.FormPanel.superclass.initEvents.call(this); rlm@46: this.items.on('remove', this.onRemove, this); rlm@46: this.items.on('add', this.onAdd, this); rlm@46: if(this.monitorValid){ this.startMonitoring(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onAdd : function(ct, c) { rlm@46: if (c.isFormField) { rlm@46: this.form.add(c); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRemove : function(c) { rlm@46: if (c.isFormField) { rlm@46: Ext.destroy(c.container.up('.x-form-item')); rlm@46: this.form.remove(c); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: startMonitoring : function(){ rlm@46: if(!this.bound){ rlm@46: this.bound = true; rlm@46: Ext.TaskMgr.start({ rlm@46: run : this.bindHandler, rlm@46: interval : this.monitorPoll || 200, rlm@46: scope: this rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: stopMonitoring : function(){ rlm@46: this.bound = false; rlm@46: }, rlm@46: rlm@46: rlm@46: load : function(){ rlm@46: this.form.load.apply(this.form, arguments); rlm@46: }, rlm@46: rlm@46: onDisable : function(){ rlm@46: Ext.FormPanel.superclass.onDisable.call(this); rlm@46: if(this.form){ rlm@46: this.form.items.each(function(){ rlm@46: this.disable(); rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: onEnable : function(){ rlm@46: Ext.FormPanel.superclass.onEnable.call(this); rlm@46: if(this.form){ rlm@46: this.form.items.each(function(){ rlm@46: this.enable(); rlm@46: }); rlm@46: } rlm@46: }, rlm@46: rlm@46: bindHandler : function(){ rlm@46: if(!this.bound){ rlm@46: return false; } rlm@46: var valid = true; rlm@46: this.form.items.each(function(f){ rlm@46: if(!f.isValid(true)){ rlm@46: valid = false; rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: if(this.buttons){ rlm@46: for(var i = 0, len = this.buttons.length; i < len; i++){ rlm@46: var btn = this.buttons[i]; rlm@46: if(btn.formBind === true && btn.disabled === valid){ rlm@46: btn.setDisabled(!valid); rlm@46: } rlm@46: } rlm@46: } rlm@46: this.fireEvent('clientvalidation', this, valid); rlm@46: } rlm@46: }); rlm@46: Ext.reg('form', Ext.FormPanel); rlm@46: rlm@46: Ext.form.FormPanel = Ext.FormPanel; rlm@46: rlm@46: rlm@46: rlm@46: Ext.form.FieldSet = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: baseCls:'x-fieldset', rlm@46: rlm@46: layout: 'form', rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: if(!this.el){ rlm@46: this.el = document.createElement('fieldset'); rlm@46: this.el.id = this.id; rlm@46: if (this.title || this.header || this.checkboxToggle) { rlm@46: this.el.appendChild(document.createElement('legend')).className = 'x-fieldset-header'; rlm@46: } rlm@46: } rlm@46: rlm@46: Ext.form.FieldSet.superclass.onRender.call(this, ct, position); rlm@46: rlm@46: if(this.checkboxToggle){ rlm@46: var o = typeof this.checkboxToggle == 'object' ? rlm@46: this.checkboxToggle : rlm@46: {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'}; rlm@46: this.checkbox = this.header.insertFirst(o); rlm@46: this.checkbox.dom.checked = !this.collapsed; rlm@46: this.checkbox.on('click', this.onCheckClick, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onCollapse : function(doAnim, animArg){ rlm@46: if(this.checkbox){ rlm@46: this.checkbox.dom.checked = false; rlm@46: } rlm@46: this.afterCollapse(); rlm@46: rlm@46: }, rlm@46: rlm@46: rlm@46: onExpand : function(doAnim, animArg){ rlm@46: if(this.checkbox){ rlm@46: this.checkbox.dom.checked = true; rlm@46: } rlm@46: this.afterExpand(); rlm@46: }, rlm@46: rlm@46: rlm@46: onCheckClick : function(){ rlm@46: this[this.checkbox.dom.checked ? 'expand' : 'collapse'](); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('fieldset', Ext.form.FieldSet); rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { rlm@46: rlm@46: enableFormat : true, rlm@46: rlm@46: enableFontSize : true, rlm@46: rlm@46: enableColors : true, rlm@46: rlm@46: enableAlignments : true, rlm@46: rlm@46: enableLists : true, rlm@46: rlm@46: enableSourceEdit : true, rlm@46: rlm@46: enableLinks : true, rlm@46: rlm@46: enableFont : true, rlm@46: rlm@46: createLinkText : 'Please enter the URL for the link:', rlm@46: rlm@46: defaultLinkValue : 'http:/'+'/', rlm@46: rlm@46: fontFamilies : [ rlm@46: 'Arial', rlm@46: 'Courier New', rlm@46: 'Tahoma', rlm@46: 'Times New Roman', rlm@46: 'Verdana' rlm@46: ], rlm@46: defaultFont: 'tahoma', rlm@46: rlm@46: rlm@46: validationEvent : false, rlm@46: deferHeight: true, rlm@46: initialized : false, rlm@46: activated : false, rlm@46: sourceEditMode : false, rlm@46: onFocus : Ext.emptyFn, rlm@46: iframePad:3, rlm@46: hideMode:'offsets', rlm@46: defaultAutoCreate : { rlm@46: tag: "textarea", rlm@46: style:"width:500px;height:300px;", rlm@46: autocomplete: "off" rlm@46: }, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: this.addEvents( rlm@46: rlm@46: 'initialize', rlm@46: rlm@46: 'activate', rlm@46: rlm@46: 'beforesync', rlm@46: rlm@46: 'beforepush', rlm@46: rlm@46: 'sync', rlm@46: rlm@46: 'push', rlm@46: rlm@46: 'editmodechange' rlm@46: ) rlm@46: }, rlm@46: rlm@46: rlm@46: createFontOptions : function(){ rlm@46: var buf = [], fs = this.fontFamilies, ff, lc; rlm@46: for(var i = 0, len = fs.length; i< len; i++){ rlm@46: ff = fs[i]; rlm@46: lc = ff.toLowerCase(); rlm@46: buf.push( rlm@46: '' rlm@46: ); rlm@46: } rlm@46: return buf.join(''); rlm@46: }, rlm@46: rlm@46: rlm@46: createToolbar : function(editor){ rlm@46: rlm@46: var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled(); rlm@46: rlm@46: function btn(id, toggle, handler){ rlm@46: return { rlm@46: itemId : id, rlm@46: cls : 'x-btn-icon x-edit-'+id, rlm@46: enableToggle:toggle !== false, rlm@46: scope: editor, rlm@46: handler:handler||editor.relayBtnCmd, rlm@46: clickEvent:'mousedown', rlm@46: tooltip: tipsEnabled ? editor.buttonTips[id] || undefined : undefined, rlm@46: tabIndex:-1 rlm@46: }; rlm@46: } rlm@46: rlm@46: rlm@46: var tb = new Ext.Toolbar({ rlm@46: renderTo:this.wrap.dom.firstChild rlm@46: }); rlm@46: rlm@46: rlm@46: tb.el.on('click', function(e){ rlm@46: e.preventDefault(); rlm@46: }); rlm@46: rlm@46: if(this.enableFont && !Ext.isSafari){ rlm@46: this.fontSelect = tb.el.createChild({ rlm@46: tag:'select', rlm@46: cls:'x-font-select', rlm@46: html: this.createFontOptions() rlm@46: }); rlm@46: this.fontSelect.on('change', function(){ rlm@46: var font = this.fontSelect.dom.value; rlm@46: this.relayCmd('fontname', font); rlm@46: this.deferFocus(); rlm@46: }, this); rlm@46: tb.add( rlm@46: this.fontSelect.dom, rlm@46: '-' rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(this.enableFormat){ rlm@46: tb.add( rlm@46: btn('bold'), rlm@46: btn('italic'), rlm@46: btn('underline') rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(this.enableFontSize){ rlm@46: tb.add( rlm@46: '-', rlm@46: btn('increasefontsize', false, this.adjustFont), rlm@46: btn('decreasefontsize', false, this.adjustFont) rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(this.enableColors){ rlm@46: tb.add( rlm@46: '-', { rlm@46: itemId:'forecolor', rlm@46: cls:'x-btn-icon x-edit-forecolor', rlm@46: clickEvent:'mousedown', rlm@46: tooltip: tipsEnabled ? editor.buttonTips['forecolor'] || undefined : undefined, rlm@46: tabIndex:-1, rlm@46: menu : new Ext.menu.ColorMenu({ rlm@46: allowReselect: true, rlm@46: focus: Ext.emptyFn, rlm@46: value:'000000', rlm@46: plain:true, rlm@46: selectHandler: function(cp, color){ rlm@46: this.execCmd('forecolor', Ext.isSafari || Ext.isIE ? '#'+color : color); rlm@46: this.deferFocus(); rlm@46: }, rlm@46: scope: this, rlm@46: clickEvent:'mousedown' rlm@46: }) rlm@46: }, { rlm@46: itemId:'backcolor', rlm@46: cls:'x-btn-icon x-edit-backcolor', rlm@46: clickEvent:'mousedown', rlm@46: tooltip: tipsEnabled ? editor.buttonTips['backcolor'] || undefined : undefined, rlm@46: tabIndex:-1, rlm@46: menu : new Ext.menu.ColorMenu({ rlm@46: focus: Ext.emptyFn, rlm@46: value:'FFFFFF', rlm@46: plain:true, rlm@46: allowReselect: true, rlm@46: selectHandler: function(cp, color){ rlm@46: if(Ext.isGecko){ rlm@46: this.execCmd('useCSS', false); rlm@46: this.execCmd('hilitecolor', color); rlm@46: this.execCmd('useCSS', true); rlm@46: this.deferFocus(); rlm@46: }else{ rlm@46: this.execCmd(Ext.isOpera ? 'hilitecolor' : 'backcolor', Ext.isSafari || Ext.isIE ? '#'+color : color); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }, rlm@46: scope:this, rlm@46: clickEvent:'mousedown' rlm@46: }) rlm@46: } rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(this.enableAlignments){ rlm@46: tb.add( rlm@46: '-', rlm@46: btn('justifyleft'), rlm@46: btn('justifycenter'), rlm@46: btn('justifyright') rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(!Ext.isSafari){ rlm@46: if(this.enableLinks){ rlm@46: tb.add( rlm@46: '-', rlm@46: btn('createlink', false, this.createLink) rlm@46: ); rlm@46: }; rlm@46: rlm@46: if(this.enableLists){ rlm@46: tb.add( rlm@46: '-', rlm@46: btn('insertorderedlist'), rlm@46: btn('insertunorderedlist') rlm@46: ); rlm@46: } rlm@46: if(this.enableSourceEdit){ rlm@46: tb.add( rlm@46: '-', rlm@46: btn('sourceedit', true, function(btn){ rlm@46: this.toggleSourceEdit(btn.pressed); rlm@46: }) rlm@46: ); rlm@46: } rlm@46: } rlm@46: rlm@46: this.tb = tb; rlm@46: }, rlm@46: rlm@46: rlm@46: getDocMarkup : function(){ rlm@46: return ''; rlm@46: }, rlm@46: rlm@46: rlm@46: getEditorBody : function(){ rlm@46: return this.doc.body || this.doc.documentElement; rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.form.HtmlEditor.superclass.onRender.call(this, ct, position); rlm@46: this.el.dom.style.border = '0 none'; rlm@46: this.el.dom.setAttribute('tabIndex', -1); rlm@46: this.el.addClass('x-hidden'); rlm@46: if(Ext.isIE){ rlm@46: this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;') rlm@46: } rlm@46: this.wrap = this.el.wrap({ rlm@46: cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'} rlm@46: }); rlm@46: rlm@46: this.createToolbar(this); rlm@46: rlm@46: this.tb.items.each(function(item){ rlm@46: if(item.itemId != 'sourceedit'){ rlm@46: item.disable(); rlm@46: } rlm@46: }); rlm@46: rlm@46: var iframe = document.createElement('iframe'); rlm@46: iframe.name = Ext.id(); rlm@46: iframe.frameBorder = 'no'; rlm@46: rlm@46: iframe.src=(Ext.SSL_SECURE_URL || "javascript:false"); rlm@46: rlm@46: this.wrap.dom.appendChild(iframe); rlm@46: rlm@46: this.iframe = iframe; rlm@46: rlm@46: if(Ext.isIE){ rlm@46: iframe.contentWindow.document.designMode = 'on'; rlm@46: this.doc = iframe.contentWindow.document; rlm@46: this.win = iframe.contentWindow; rlm@46: } else { rlm@46: this.doc = (iframe.contentDocument || window.frames[iframe.name].document); rlm@46: this.win = window.frames[iframe.name]; rlm@46: this.doc.designMode = 'on'; rlm@46: } rlm@46: this.doc.open(); rlm@46: this.doc.write(this.getDocMarkup()) rlm@46: this.doc.close(); rlm@46: rlm@46: var task = { rlm@46: run : function(){ rlm@46: if(this.doc.body || this.doc.readyState == 'complete'){ rlm@46: Ext.TaskMgr.stop(task); rlm@46: this.doc.designMode="on"; rlm@46: this.initEditor.defer(10, this); rlm@46: } rlm@46: }, rlm@46: interval : 10, rlm@46: duration:10000, rlm@46: scope: this rlm@46: }; rlm@46: Ext.TaskMgr.start(task); rlm@46: rlm@46: if(!this.width){ rlm@46: this.setSize(this.el.getSize()); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onResize : function(w, h){ rlm@46: Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments); rlm@46: if(this.el && this.iframe){ rlm@46: if(typeof w == 'number'){ rlm@46: var aw = w - this.wrap.getFrameWidth('lr'); rlm@46: this.el.setWidth(this.adjustWidth('textarea', aw)); rlm@46: this.iframe.style.width = aw + 'px'; rlm@46: } rlm@46: if(typeof h == 'number'){ rlm@46: var ah = h - this.wrap.getFrameWidth('tb') - this.tb.el.getHeight(); rlm@46: this.el.setHeight(this.adjustWidth('textarea', ah)); rlm@46: this.iframe.style.height = ah + 'px'; rlm@46: if(this.doc){ rlm@46: this.getEditorBody().style.height = (ah - (this.iframePad*2)) + 'px'; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toggleSourceEdit : function(sourceEditMode){ rlm@46: if(sourceEditMode === undefined){ rlm@46: sourceEditMode = !this.sourceEditMode; rlm@46: } rlm@46: this.sourceEditMode = sourceEditMode === true; rlm@46: var btn = this.tb.items.get('sourceedit'); rlm@46: if(btn.pressed !== this.sourceEditMode){ rlm@46: btn.toggle(this.sourceEditMode); rlm@46: return; rlm@46: } rlm@46: if(this.sourceEditMode){ rlm@46: this.tb.items.each(function(item){ rlm@46: if(item.itemId != 'sourceedit'){ rlm@46: item.disable(); rlm@46: } rlm@46: }); rlm@46: this.syncValue(); rlm@46: this.iframe.className = 'x-hidden'; rlm@46: this.el.removeClass('x-hidden'); rlm@46: this.el.dom.removeAttribute('tabIndex'); rlm@46: this.el.focus(); rlm@46: }else{ rlm@46: if(this.initialized){ rlm@46: this.tb.items.each(function(item){ rlm@46: item.enable(); rlm@46: }); rlm@46: } rlm@46: this.pushValue(); rlm@46: this.iframe.className = ''; rlm@46: this.el.addClass('x-hidden'); rlm@46: this.el.dom.setAttribute('tabIndex', -1); rlm@46: this.deferFocus(); rlm@46: } rlm@46: var lastSize = this.lastSize; rlm@46: if(lastSize){ rlm@46: delete this.lastSize; rlm@46: this.setSize(lastSize); rlm@46: } rlm@46: this.fireEvent('editmodechange', this, this.sourceEditMode); rlm@46: }, rlm@46: rlm@46: rlm@46: createLink : function(){ rlm@46: var url = prompt(this.createLinkText, this.defaultLinkValue); rlm@46: if(url && url != 'http:/'+'/'){ rlm@46: this.relayCmd('createlink', url); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: adjustSize : Ext.BoxComponent.prototype.adjustSize, rlm@46: rlm@46: rlm@46: getResizeEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: rlm@46: getPositionEl : function(){ rlm@46: return this.wrap; rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: this.originalValue = this.getValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: markInvalid : Ext.emptyFn, rlm@46: rlm@46: rlm@46: clearInvalid : Ext.emptyFn, rlm@46: rlm@46: rlm@46: setValue : function(v){ rlm@46: Ext.form.HtmlEditor.superclass.setValue.call(this, v); rlm@46: this.pushValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: cleanHtml : function(html){ rlm@46: html = String(html); rlm@46: if(html.length > 5){ rlm@46: if(Ext.isSafari){ rlm@46: html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, ''); rlm@46: } rlm@46: } rlm@46: if(html == ' '){ rlm@46: html = ''; rlm@46: } rlm@46: return html; rlm@46: }, rlm@46: rlm@46: rlm@46: syncValue : function(){ rlm@46: if(this.initialized){ rlm@46: var bd = this.getEditorBody(); rlm@46: var html = bd.innerHTML; rlm@46: if(Ext.isSafari){ rlm@46: var bs = bd.getAttribute('style'); rlm@46: var m = bs.match(/text-align:(.*?);/i); rlm@46: if(m && m[1]){ rlm@46: html = '
    ' + html + '
    '; rlm@46: } rlm@46: } rlm@46: html = this.cleanHtml(html); rlm@46: if(this.fireEvent('beforesync', this, html) !== false){ rlm@46: this.el.dom.value = html; rlm@46: this.fireEvent('sync', this, html); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: pushValue : function(){ rlm@46: if(this.initialized){ rlm@46: var v = this.el.dom.value; rlm@46: if(!this.activated && v.length < 1){ rlm@46: v = ' '; rlm@46: } rlm@46: if(this.fireEvent('beforepush', this, v) !== false){ rlm@46: this.getEditorBody().innerHTML = v; rlm@46: this.fireEvent('push', this, v); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: deferFocus : function(){ rlm@46: this.focus.defer(10, this); rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: if(this.win && !this.sourceEditMode){ rlm@46: this.win.focus(); rlm@46: }else{ rlm@46: this.el.focus(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: initEditor : function(){ rlm@46: var dbody = this.getEditorBody(); rlm@46: var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat'); rlm@46: ss['background-attachment'] = 'fixed'; rlm@46: dbody.bgProperties = 'fixed'; rlm@46: Ext.DomHelper.applyStyles(dbody, ss); rlm@46: Ext.EventManager.on(this.doc, { rlm@46: 'mousedown': this.onEditorEvent, rlm@46: 'dblclick': this.onEditorEvent, rlm@46: 'click': this.onEditorEvent, rlm@46: 'keyup': this.onEditorEvent, rlm@46: buffer:100, rlm@46: scope: this rlm@46: }); rlm@46: if(Ext.isGecko){ rlm@46: Ext.EventManager.on(this.doc, 'keypress', this.applyCommand, this); rlm@46: } rlm@46: if(Ext.isIE || Ext.isSafari || Ext.isOpera){ rlm@46: Ext.EventManager.on(this.doc, 'keydown', this.fixKeys, this); rlm@46: } rlm@46: this.initialized = true; rlm@46: rlm@46: this.fireEvent('initialize', this); rlm@46: this.pushValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.rendered){ rlm@46: this.tb.items.each(function(item){ rlm@46: if(item.menu){ rlm@46: item.menu.removeAll(); rlm@46: if(item.menu.el){ rlm@46: item.menu.el.destroy(); rlm@46: } rlm@46: } rlm@46: item.destroy(); rlm@46: }); rlm@46: this.wrap.dom.innerHTML = ''; rlm@46: this.wrap.remove(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onFirstFocus : function(){ rlm@46: this.activated = true; rlm@46: this.tb.items.each(function(item){ rlm@46: item.enable(); rlm@46: }); rlm@46: if(Ext.isGecko){ rlm@46: this.win.focus(); rlm@46: var s = this.win.getSelection(); rlm@46: if(!s.focusNode || s.focusNode.nodeType != 3){ rlm@46: var r = s.getRangeAt(0); rlm@46: r.selectNodeContents(this.getEditorBody()); rlm@46: r.collapse(true); rlm@46: this.deferFocus(); rlm@46: } rlm@46: try{ rlm@46: this.execCmd('useCSS', true); rlm@46: this.execCmd('styleWithCSS', false); rlm@46: }catch(e){} rlm@46: } rlm@46: this.fireEvent('activate', this); rlm@46: }, rlm@46: rlm@46: rlm@46: adjustFont: function(btn){ rlm@46: var adjust = btn.itemId == 'increasefontsize' ? 1 : -1; rlm@46: rlm@46: var v = parseInt(this.doc.queryCommandValue('FontSize') || 2, 10); rlm@46: if(Ext.isSafari3 || Ext.isAir){ rlm@46: rlm@46: rlm@46: if(v <= 10){ rlm@46: v = 1 + adjust; rlm@46: }else if(v <= 13){ rlm@46: v = 2 + adjust; rlm@46: }else if(v <= 16){ rlm@46: v = 3 + adjust; rlm@46: }else if(v <= 18){ rlm@46: v = 4 + adjust; rlm@46: }else if(v <= 24){ rlm@46: v = 5 + adjust; rlm@46: }else { rlm@46: v = 6 + adjust; rlm@46: } rlm@46: v = v.constrain(1, 6); rlm@46: }else{ rlm@46: if(Ext.isSafari){ rlm@46: adjust *= 2; rlm@46: } rlm@46: v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0); rlm@46: } rlm@46: this.execCmd('FontSize', v); rlm@46: }, rlm@46: rlm@46: rlm@46: onEditorEvent : function(e){ rlm@46: this.updateToolbar(); rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: updateToolbar: function(){ rlm@46: rlm@46: if(!this.activated){ rlm@46: this.onFirstFocus(); rlm@46: return; rlm@46: } rlm@46: rlm@46: var btns = this.tb.items.map, doc = this.doc; rlm@46: rlm@46: if(this.enableFont && !Ext.isSafari){ rlm@46: var name = (this.doc.queryCommandValue('FontName')||this.defaultFont).toLowerCase(); rlm@46: if(name != this.fontSelect.dom.value){ rlm@46: this.fontSelect.dom.value = name; rlm@46: } rlm@46: } rlm@46: if(this.enableFormat){ rlm@46: btns.bold.toggle(doc.queryCommandState('bold')); rlm@46: btns.italic.toggle(doc.queryCommandState('italic')); rlm@46: btns.underline.toggle(doc.queryCommandState('underline')); rlm@46: } rlm@46: if(this.enableAlignments){ rlm@46: btns.justifyleft.toggle(doc.queryCommandState('justifyleft')); rlm@46: btns.justifycenter.toggle(doc.queryCommandState('justifycenter')); rlm@46: btns.justifyright.toggle(doc.queryCommandState('justifyright')); rlm@46: } rlm@46: if(!Ext.isSafari && this.enableLists){ rlm@46: btns.insertorderedlist.toggle(doc.queryCommandState('insertorderedlist')); rlm@46: btns.insertunorderedlist.toggle(doc.queryCommandState('insertunorderedlist')); rlm@46: } rlm@46: rlm@46: Ext.menu.MenuMgr.hideAll(); rlm@46: rlm@46: this.syncValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: relayBtnCmd : function(btn){ rlm@46: this.relayCmd(btn.itemId); rlm@46: }, rlm@46: rlm@46: rlm@46: relayCmd : function(cmd, value){ rlm@46: this.win.focus(); rlm@46: this.execCmd(cmd, value); rlm@46: this.updateToolbar(); rlm@46: this.deferFocus(); rlm@46: }, rlm@46: rlm@46: rlm@46: execCmd : function(cmd, value){ rlm@46: this.doc.execCommand(cmd, false, value === undefined ? null : value); rlm@46: this.syncValue(); rlm@46: }, rlm@46: rlm@46: rlm@46: applyCommand : function(e){ rlm@46: if(e.ctrlKey){ rlm@46: var c = e.getCharCode(), cmd; rlm@46: if(c > 0){ rlm@46: c = String.fromCharCode(c); rlm@46: switch(c){ rlm@46: case 'b': rlm@46: cmd = 'bold'; rlm@46: break; rlm@46: case 'i': rlm@46: cmd = 'italic'; rlm@46: break; rlm@46: case 'u': rlm@46: cmd = 'underline'; rlm@46: break; rlm@46: } rlm@46: if(cmd){ rlm@46: this.win.focus(); rlm@46: this.execCmd(cmd); rlm@46: this.deferFocus(); rlm@46: e.preventDefault(); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: insertAtCursor : function(text){ rlm@46: if(!this.activated){ rlm@46: return; rlm@46: } rlm@46: if(Ext.isIE){ rlm@46: this.win.focus(); rlm@46: var r = this.doc.selection.createRange(); rlm@46: if(r){ rlm@46: r.collapse(true); rlm@46: r.pasteHTML(text); rlm@46: this.syncValue(); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }else if(Ext.isGecko || Ext.isOpera){ rlm@46: this.win.focus(); rlm@46: this.execCmd('InsertHTML', text); rlm@46: this.deferFocus(); rlm@46: }else if(Ext.isSafari){ rlm@46: this.execCmd('InsertText', text); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: fixKeys : function(){ rlm@46: if(Ext.isIE){ rlm@46: return function(e){ rlm@46: var k = e.getKey(), r; rlm@46: if(k == e.TAB){ rlm@46: e.stopEvent(); rlm@46: r = this.doc.selection.createRange(); rlm@46: if(r){ rlm@46: r.collapse(true); rlm@46: r.pasteHTML('    '); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }else if(k == e.ENTER){ rlm@46: r = this.doc.selection.createRange(); rlm@46: if(r){ rlm@46: var target = r.parentElement(); rlm@46: if(!target || target.tagName.toLowerCase() != 'li'){ rlm@46: e.stopEvent(); rlm@46: r.pasteHTML('
    '); rlm@46: r.collapse(false); rlm@46: r.select(); rlm@46: } rlm@46: } rlm@46: } rlm@46: }; rlm@46: }else if(Ext.isOpera){ rlm@46: return function(e){ rlm@46: var k = e.getKey(); rlm@46: if(k == e.TAB){ rlm@46: e.stopEvent(); rlm@46: this.win.focus(); rlm@46: this.execCmd('InsertHTML','    '); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }; rlm@46: }else if(Ext.isSafari){ rlm@46: return function(e){ rlm@46: var k = e.getKey(); rlm@46: if(k == e.TAB){ rlm@46: e.stopEvent(); rlm@46: this.execCmd('InsertText','\t'); rlm@46: this.deferFocus(); rlm@46: } rlm@46: }; rlm@46: } rlm@46: }(), rlm@46: rlm@46: rlm@46: getToolbar : function(){ rlm@46: return this.tb; rlm@46: }, rlm@46: rlm@46: rlm@46: buttonTips : { rlm@46: bold : { rlm@46: title: 'Bold (Ctrl+B)', rlm@46: text: 'Make the selected text bold.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: italic : { rlm@46: title: 'Italic (Ctrl+I)', rlm@46: text: 'Make the selected text italic.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: underline : { rlm@46: title: 'Underline (Ctrl+U)', rlm@46: text: 'Underline the selected text.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: increasefontsize : { rlm@46: title: 'Grow Text', rlm@46: text: 'Increase the font size.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: decreasefontsize : { rlm@46: title: 'Shrink Text', rlm@46: text: 'Decrease the font size.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: backcolor : { rlm@46: title: 'Text Highlight Color', rlm@46: text: 'Change the background color of the selected text.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: forecolor : { rlm@46: title: 'Font Color', rlm@46: text: 'Change the color of the selected text.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: justifyleft : { rlm@46: title: 'Align Text Left', rlm@46: text: 'Align text to the left.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: justifycenter : { rlm@46: title: 'Center Text', rlm@46: text: 'Center text in the editor.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: justifyright : { rlm@46: title: 'Align Text Right', rlm@46: text: 'Align text to the right.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: insertunorderedlist : { rlm@46: title: 'Bullet List', rlm@46: text: 'Start a bulleted list.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: insertorderedlist : { rlm@46: title: 'Numbered List', rlm@46: text: 'Start a numbered list.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: createlink : { rlm@46: title: 'Hyperlink', rlm@46: text: 'Make the selected text a hyperlink.', rlm@46: cls: 'x-html-editor-tip' rlm@46: }, rlm@46: sourceedit : { rlm@46: title: 'Source Edit', rlm@46: text: 'Switch to source editing mode.', rlm@46: cls: 'x-html-editor-tip' rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('htmleditor', Ext.form.HtmlEditor); rlm@46: rlm@46: Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, { rlm@46: rlm@46: minValue : null, rlm@46: rlm@46: maxValue : null, rlm@46: rlm@46: minText : "The time in this field must be equal to or after {0}", rlm@46: rlm@46: maxText : "The time in this field must be equal to or before {0}", rlm@46: rlm@46: invalidText : "{0} is not a valid time", rlm@46: rlm@46: format : "g:i A", rlm@46: rlm@46: altFormats : "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H", rlm@46: rlm@46: increment: 15, rlm@46: rlm@46: rlm@46: mode: 'local', rlm@46: rlm@46: triggerAction: 'all', rlm@46: rlm@46: typeAhead: false, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.form.TimeField.superclass.initComponent.call(this); rlm@46: rlm@46: if(typeof this.minValue == "string"){ rlm@46: this.minValue = this.parseDate(this.minValue); rlm@46: } rlm@46: if(typeof this.maxValue == "string"){ rlm@46: this.maxValue = this.parseDate(this.maxValue); rlm@46: } rlm@46: rlm@46: if(!this.store){ rlm@46: var min = this.parseDate(this.minValue); rlm@46: if(!min){ rlm@46: min = new Date().clearTime(); rlm@46: } rlm@46: var max = this.parseDate(this.maxValue); rlm@46: if(!max){ rlm@46: max = new Date().clearTime().add('mi', (24 * 60) - 1); rlm@46: } rlm@46: var times = []; rlm@46: while(min <= max){ rlm@46: times.push([min.dateFormat(this.format)]); rlm@46: min = min.add('mi', this.increment); rlm@46: } rlm@46: this.store = new Ext.data.SimpleStore({ rlm@46: fields: ['text'], rlm@46: data : times rlm@46: }); rlm@46: this.displayField = 'text'; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: var v = Ext.form.TimeField.superclass.getValue.call(this); rlm@46: return this.formatDate(this.parseDate(v)) || ''; rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(value){ rlm@46: Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value))); rlm@46: }, rlm@46: rlm@46: rlm@46: validateValue : Ext.form.DateField.prototype.validateValue, rlm@46: parseDate : Ext.form.DateField.prototype.parseDate, rlm@46: formatDate : Ext.form.DateField.prototype.formatDate, rlm@46: rlm@46: rlm@46: beforeBlur : function(){ rlm@46: var v = this.parseDate(this.getRawValue()); rlm@46: if(v){ rlm@46: this.setValue(v.dateFormat(this.format)); rlm@46: } rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('timefield', Ext.form.TimeField); rlm@46: rlm@46: Ext.form.Label = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: if(!this.el){ rlm@46: this.el = document.createElement('label'); rlm@46: this.el.id = this.getId(); rlm@46: this.el.innerHTML = this.text ? Ext.util.Format.htmlEncode(this.text) : (this.html || ''); rlm@46: if(this.forId){ rlm@46: this.el.setAttribute('htmlFor', this.forId); rlm@46: } rlm@46: } rlm@46: Ext.form.Label.superclass.onRender.call(this, ct, position); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.reg('label', Ext.form.Label); rlm@46: rlm@46: Ext.form.Action = function(form, options){ rlm@46: this.form = form; rlm@46: this.options = options || {}; rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.form.Action.CLIENT_INVALID = 'client'; rlm@46: rlm@46: Ext.form.Action.SERVER_INVALID = 'server'; rlm@46: rlm@46: Ext.form.Action.CONNECT_FAILURE = 'connect'; rlm@46: rlm@46: Ext.form.Action.LOAD_FAILURE = 'load'; rlm@46: rlm@46: Ext.form.Action.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: type : 'default', rlm@46: rlm@46: rlm@46: run : function(options){ rlm@46: rlm@46: }, rlm@46: rlm@46: success : function(response){ rlm@46: rlm@46: }, rlm@46: rlm@46: handleResponse : function(response){ rlm@46: rlm@46: }, rlm@46: rlm@46: failure : function(response){ rlm@46: this.response = response; rlm@46: this.failureType = Ext.form.Action.CONNECT_FAILURE; rlm@46: this.form.afterAction(this, false); rlm@46: }, rlm@46: rlm@46: processResponse : function(response){ rlm@46: this.response = response; rlm@46: if(!response.responseText){ rlm@46: return true; rlm@46: } rlm@46: this.result = this.handleResponse(response); rlm@46: return this.result; rlm@46: }, rlm@46: rlm@46: getUrl : function(appendParams){ rlm@46: var url = this.options.url || this.form.url || this.form.el.dom.action; rlm@46: if(appendParams){ rlm@46: var p = this.getParams(); rlm@46: if(p){ rlm@46: url += (url.indexOf('?') != -1 ? '&' : '?') + p; rlm@46: } rlm@46: } rlm@46: return url; rlm@46: }, rlm@46: rlm@46: getMethod : function(){ rlm@46: return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase(); rlm@46: }, rlm@46: rlm@46: getParams : function(){ rlm@46: var bp = this.form.baseParams; rlm@46: var p = this.options.params; rlm@46: if(p){ rlm@46: if(typeof p == "object"){ rlm@46: p = Ext.urlEncode(Ext.applyIf(p, bp)); rlm@46: }else if(typeof p == 'string' && bp){ rlm@46: p += '&' + Ext.urlEncode(bp); rlm@46: } rlm@46: }else if(bp){ rlm@46: p = Ext.urlEncode(bp); rlm@46: } rlm@46: return p; rlm@46: }, rlm@46: rlm@46: createCallback : function(opts){ rlm@46: var opts = opts || {}; rlm@46: return { rlm@46: success: this.success, rlm@46: failure: this.failure, rlm@46: scope: this, rlm@46: timeout: (opts.timeout*1000) || (this.form.timeout*1000), rlm@46: upload: this.form.fileUpload ? this.success : undefined rlm@46: }; rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.form.Action.Submit = function(form, options){ rlm@46: Ext.form.Action.Submit.superclass.constructor.call(this, form, options); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.form.Action.Submit, Ext.form.Action, { rlm@46: rlm@46: type : 'submit', rlm@46: rlm@46: run : function(){ rlm@46: var o = this.options; rlm@46: var method = this.getMethod(); rlm@46: var isGet = method == 'GET'; rlm@46: if(o.clientValidation === false || this.form.isValid()){ rlm@46: Ext.Ajax.request(Ext.apply(this.createCallback(o), { rlm@46: form:this.form.el.dom, rlm@46: url:this.getUrl(isGet), rlm@46: method: method, rlm@46: headers: o.headers, rlm@46: params:!isGet ? this.getParams() : null, rlm@46: isUpload: this.form.fileUpload rlm@46: })); rlm@46: }else if (o.clientValidation !== false){ this.failureType = Ext.form.Action.CLIENT_INVALID; rlm@46: this.form.afterAction(this, false); rlm@46: } rlm@46: }, rlm@46: rlm@46: success : function(response){ rlm@46: var result = this.processResponse(response); rlm@46: if(result === true || result.success){ rlm@46: this.form.afterAction(this, true); rlm@46: return; rlm@46: } rlm@46: if(result.errors){ rlm@46: this.form.markInvalid(result.errors); rlm@46: this.failureType = Ext.form.Action.SERVER_INVALID; rlm@46: } rlm@46: this.form.afterAction(this, false); rlm@46: }, rlm@46: rlm@46: handleResponse : function(response){ rlm@46: if(this.form.errorReader){ rlm@46: var rs = this.form.errorReader.read(response); rlm@46: var errors = []; rlm@46: if(rs.records){ rlm@46: for(var i = 0, len = rs.records.length; i < len; i++) { rlm@46: var r = rs.records[i]; rlm@46: errors[i] = r.data; rlm@46: } rlm@46: } rlm@46: if(errors.length < 1){ rlm@46: errors = null; rlm@46: } rlm@46: return { rlm@46: success : rs.success, rlm@46: errors : errors rlm@46: }; rlm@46: } rlm@46: return Ext.decode(response.responseText); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: rlm@46: Ext.form.Action.Load = function(form, options){ rlm@46: Ext.form.Action.Load.superclass.constructor.call(this, form, options); rlm@46: this.reader = this.form.reader; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.form.Action.Load, Ext.form.Action, { rlm@46: type : 'load', rlm@46: rlm@46: run : function(){ rlm@46: Ext.Ajax.request(Ext.apply( rlm@46: this.createCallback(this.options), { rlm@46: method:this.getMethod(), rlm@46: url:this.getUrl(false), rlm@46: headers: this.options.headers, rlm@46: params:this.getParams() rlm@46: })); rlm@46: }, rlm@46: rlm@46: success : function(response){ rlm@46: var result = this.processResponse(response); rlm@46: if(result === true || !result.success || !result.data){ rlm@46: this.failureType = Ext.form.Action.LOAD_FAILURE; rlm@46: this.form.afterAction(this, false); rlm@46: return; rlm@46: } rlm@46: this.form.clearInvalid(); rlm@46: this.form.setValues(result.data); rlm@46: this.form.afterAction(this, true); rlm@46: }, rlm@46: rlm@46: handleResponse : function(response){ rlm@46: if(this.form.reader){ rlm@46: var rs = this.form.reader.read(response); rlm@46: var data = rs.records && rs.records[0] ? rs.records[0].data : null; rlm@46: return { rlm@46: success : rs.success, rlm@46: data : data rlm@46: }; rlm@46: } rlm@46: return Ext.decode(response.responseText); rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.form.Action.ACTION_TYPES = { rlm@46: 'load' : Ext.form.Action.Load, rlm@46: 'submit' : Ext.form.Action.Submit rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.form.VTypes = function(){ rlm@46: var alpha = /^[a-zA-Z_]+$/; rlm@46: var alphanum = /^[a-zA-Z0-9_]+$/; rlm@46: var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/; rlm@46: var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; rlm@46: rlm@46: return { rlm@46: rlm@46: 'email' : function(v){ rlm@46: return email.test(v); rlm@46: }, rlm@46: rlm@46: 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"', rlm@46: rlm@46: 'emailMask' : /[a-z0-9_\.\-@]/i, rlm@46: rlm@46: rlm@46: 'url' : function(v){ rlm@46: return url.test(v); rlm@46: }, rlm@46: rlm@46: 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"', rlm@46: rlm@46: rlm@46: 'alpha' : function(v){ rlm@46: return alpha.test(v); rlm@46: }, rlm@46: rlm@46: 'alphaText' : 'This field should only contain letters and _', rlm@46: rlm@46: 'alphaMask' : /[a-z_]/i, rlm@46: rlm@46: rlm@46: 'alphanum' : function(v){ rlm@46: return alphanum.test(v); rlm@46: }, rlm@46: rlm@46: 'alphanumText' : 'This field should only contain letters, numbers and _', rlm@46: rlm@46: 'alphanumMask' : /[a-z0-9_]/i rlm@46: }; rlm@46: }(); rlm@46: rlm@46: Ext.grid.GridPanel = Ext.extend(Ext.Panel, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: ddText : "{0} selected row{1}", rlm@46: rlm@46: minColumnWidth : 25, rlm@46: rlm@46: trackMouseOver : true, rlm@46: rlm@46: enableDragDrop : false, rlm@46: rlm@46: enableColumnMove : true, rlm@46: rlm@46: enableColumnHide : true, rlm@46: rlm@46: enableHdMenu : true, rlm@46: rlm@46: stripeRows : false, rlm@46: rlm@46: autoExpandColumn : false, rlm@46: rlm@46: autoExpandMin : 50, rlm@46: rlm@46: autoExpandMax : 1000, rlm@46: rlm@46: view : null, rlm@46: rlm@46: loadMask : false, rlm@46: rlm@46: rlm@46: rendered : false, rlm@46: rlm@46: viewReady: false, rlm@46: rlm@46: stateEvents: ["columnmove", "columnresize", "sortchange"], rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.grid.GridPanel.superclass.initComponent.call(this); rlm@46: rlm@46: rlm@46: rlm@46: this.autoScroll = false; rlm@46: this.autoWidth = false; rlm@46: rlm@46: if(Ext.isArray(this.columns)){ rlm@46: this.colModel = new Ext.grid.ColumnModel(this.columns); rlm@46: delete this.columns; rlm@46: } rlm@46: rlm@46: rlm@46: if(this.ds){ rlm@46: this.store = this.ds; rlm@46: delete this.ds; rlm@46: } rlm@46: if(this.cm){ rlm@46: this.colModel = this.cm; rlm@46: delete this.cm; rlm@46: } rlm@46: if(this.sm){ rlm@46: this.selModel = this.sm; rlm@46: delete this.sm; rlm@46: } rlm@46: this.store = Ext.StoreMgr.lookup(this.store); rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: rlm@46: "click", rlm@46: rlm@46: "dblclick", rlm@46: rlm@46: "contextmenu", rlm@46: rlm@46: "mousedown", rlm@46: rlm@46: "mouseup", rlm@46: rlm@46: "mouseover", rlm@46: rlm@46: "mouseout", rlm@46: rlm@46: "keypress", rlm@46: rlm@46: "keydown", rlm@46: rlm@46: rlm@46: rlm@46: "cellmousedown", rlm@46: rlm@46: "rowmousedown", rlm@46: rlm@46: "headermousedown", rlm@46: rlm@46: rlm@46: "cellclick", rlm@46: rlm@46: "celldblclick", rlm@46: rlm@46: "rowclick", rlm@46: rlm@46: "rowdblclick", rlm@46: rlm@46: "headerclick", rlm@46: rlm@46: "headerdblclick", rlm@46: rlm@46: "rowcontextmenu", rlm@46: rlm@46: "cellcontextmenu", rlm@46: rlm@46: "headercontextmenu", rlm@46: rlm@46: "bodyscroll", rlm@46: rlm@46: "columnresize", rlm@46: rlm@46: "columnmove", rlm@46: rlm@46: "sortchange" rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.grid.GridPanel.superclass.onRender.apply(this, arguments); rlm@46: rlm@46: var c = this.body; rlm@46: rlm@46: this.el.addClass('x-grid-panel'); rlm@46: rlm@46: var view = this.getView(); rlm@46: view.init(this); rlm@46: rlm@46: c.on("mousedown", this.onMouseDown, this); rlm@46: c.on("click", this.onClick, this); rlm@46: c.on("dblclick", this.onDblClick, this); rlm@46: c.on("contextmenu", this.onContextMenu, this); rlm@46: c.on("keydown", this.onKeyDown, this); rlm@46: rlm@46: this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]); rlm@46: rlm@46: this.getSelectionModel().init(this); rlm@46: this.view.render(); rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.grid.GridPanel.superclass.initEvents.call(this); rlm@46: rlm@46: if(this.loadMask){ rlm@46: this.loadMask = new Ext.LoadMask(this.bwrap, rlm@46: Ext.apply({store:this.store}, this.loadMask)); rlm@46: } rlm@46: }, rlm@46: rlm@46: initStateEvents : function(){ rlm@46: Ext.grid.GridPanel.superclass.initStateEvents.call(this); rlm@46: this.colModel.on('hiddenchange', this.saveState, this, {delay: 100}); rlm@46: }, rlm@46: rlm@46: applyState : function(state){ rlm@46: var cm = this.colModel; rlm@46: var cs = state.columns; rlm@46: if(cs){ rlm@46: for(var i = 0, len = cs.length; i < len; i++){ rlm@46: var s = cs[i]; rlm@46: var c = cm.getColumnById(s.id); rlm@46: if(c){ rlm@46: c.hidden = s.hidden; rlm@46: c.width = s.width; rlm@46: var oldIndex = cm.getIndexById(s.id); rlm@46: if(oldIndex != i){ rlm@46: cm.moveColumn(oldIndex, i); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: if(state.sort){ rlm@46: this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction); rlm@46: } rlm@46: }, rlm@46: rlm@46: getState : function(){ rlm@46: var o = {columns: []}; rlm@46: for(var i = 0, c; c = this.colModel.config[i]; i++){ rlm@46: o.columns[i] = { rlm@46: id: c.id, rlm@46: width: c.width rlm@46: }; rlm@46: if(c.hidden){ rlm@46: o.columns[i].hidden = true; rlm@46: } rlm@46: } rlm@46: var ss = this.store.getSortState(); rlm@46: if(ss){ rlm@46: o.sort = ss; rlm@46: } rlm@46: return o; rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.grid.GridPanel.superclass.afterRender.call(this); rlm@46: this.view.layout(); rlm@46: this.viewReady = true; rlm@46: }, rlm@46: rlm@46: rlm@46: reconfigure : function(store, colModel){ rlm@46: if(this.loadMask){ rlm@46: this.loadMask.destroy(); rlm@46: this.loadMask = new Ext.LoadMask(this.bwrap, rlm@46: Ext.apply({store:store}, this.initialConfig.loadMask)); rlm@46: } rlm@46: this.view.bind(store, colModel); rlm@46: this.store = store; rlm@46: this.colModel = colModel; rlm@46: if(this.rendered){ rlm@46: this.view.refresh(true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onKeyDown : function(e){ rlm@46: this.fireEvent("keydown", e); rlm@46: }, rlm@46: rlm@46: rlm@46: onDestroy : function(){ rlm@46: if(this.rendered){ rlm@46: if(this.loadMask){ rlm@46: this.loadMask.destroy(); rlm@46: } rlm@46: var c = this.body; rlm@46: c.removeAllListeners(); rlm@46: this.view.destroy(); rlm@46: c.update(""); rlm@46: } rlm@46: this.colModel.purgeListeners(); rlm@46: Ext.grid.GridPanel.superclass.onDestroy.call(this); rlm@46: }, rlm@46: rlm@46: rlm@46: processEvent : function(name, e){ rlm@46: this.fireEvent(name, e); rlm@46: var t = e.getTarget(); rlm@46: var v = this.view; rlm@46: var header = v.findHeaderIndex(t); rlm@46: if(header !== false){ rlm@46: this.fireEvent("header" + name, this, header, e); rlm@46: }else{ rlm@46: var row = v.findRowIndex(t); rlm@46: var cell = v.findCellIndex(t); rlm@46: if(row !== false){ rlm@46: this.fireEvent("row" + name, this, row, e); rlm@46: if(cell !== false){ rlm@46: this.fireEvent("cell" + name, this, row, cell, e); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onClick : function(e){ rlm@46: this.processEvent("click", e); rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseDown : function(e){ rlm@46: this.processEvent("mousedown", e); rlm@46: }, rlm@46: rlm@46: rlm@46: onContextMenu : function(e, t){ rlm@46: this.processEvent("contextmenu", e); rlm@46: }, rlm@46: rlm@46: rlm@46: onDblClick : function(e){ rlm@46: this.processEvent("dblclick", e); rlm@46: }, rlm@46: rlm@46: rlm@46: walkCells : function(row, col, step, fn, scope){ rlm@46: var cm = this.colModel, clen = cm.getColumnCount(); rlm@46: var ds = this.store, rlen = ds.getCount(), first = true; rlm@46: if(step < 0){ rlm@46: if(col < 0){ rlm@46: row--; rlm@46: first = false; rlm@46: } rlm@46: while(row >= 0){ rlm@46: if(!first){ rlm@46: col = clen-1; rlm@46: } rlm@46: first = false; rlm@46: while(col >= 0){ rlm@46: if(fn.call(scope || this, row, col, cm) === true){ rlm@46: return [row, col]; rlm@46: } rlm@46: col--; rlm@46: } rlm@46: row--; rlm@46: } rlm@46: } else { rlm@46: if(col >= clen){ rlm@46: row++; rlm@46: first = false; rlm@46: } rlm@46: while(row < rlen){ rlm@46: if(!first){ rlm@46: col = 0; rlm@46: } rlm@46: first = false; rlm@46: while(col < clen){ rlm@46: if(fn.call(scope || this, row, col, cm) === true){ rlm@46: return [row, col]; rlm@46: } rlm@46: col++; rlm@46: } rlm@46: row++; rlm@46: } rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: rlm@46: getSelections : function(){ rlm@46: return this.selModel.getSelections(); rlm@46: }, rlm@46: rlm@46: rlm@46: onResize : function(){ rlm@46: Ext.grid.GridPanel.superclass.onResize.apply(this, arguments); rlm@46: if(this.viewReady){ rlm@46: this.view.layout(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getGridEl : function(){ rlm@46: return this.body; rlm@46: }, rlm@46: rlm@46: rlm@46: stopEditing : function(){}, rlm@46: rlm@46: rlm@46: getSelectionModel : function(){ rlm@46: if(!this.selModel){ rlm@46: this.selModel = new Ext.grid.RowSelectionModel( rlm@46: this.disableSelection ? {selectRow: Ext.emptyFn} : null); rlm@46: } rlm@46: return this.selModel; rlm@46: }, rlm@46: rlm@46: rlm@46: getStore : function(){ rlm@46: return this.store; rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnModel : function(){ rlm@46: return this.colModel; rlm@46: }, rlm@46: rlm@46: rlm@46: getView : function(){ rlm@46: if(!this.view){ rlm@46: this.view = new Ext.grid.GridView(this.viewConfig); rlm@46: } rlm@46: return this.view; rlm@46: }, rlm@46: rlm@46: getDragDropText : function(){ rlm@46: var count = this.selModel.getCount(); rlm@46: return String.format(this.ddText, count, count == 1 ? '' : 's'); rlm@46: } rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: }); rlm@46: Ext.reg('grid', Ext.grid.GridPanel); rlm@46: rlm@46: Ext.grid.GridView = function(config){ rlm@46: Ext.apply(this, config); rlm@46: this.addEvents( rlm@46: rlm@46: "beforerowremoved", rlm@46: rlm@46: "beforerowsinserted", rlm@46: rlm@46: "beforerefresh", rlm@46: rlm@46: "rowremoved", rlm@46: rlm@46: "rowsinserted", rlm@46: rlm@46: "rowupdated", rlm@46: rlm@46: "refresh" rlm@46: ); rlm@46: Ext.grid.GridView.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.GridView, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: deferEmptyText: true, rlm@46: rlm@46: scrollOffset: 19, rlm@46: rlm@46: autoFill: false, rlm@46: rlm@46: forceFit: false, rlm@46: rlm@46: sortClasses : ["sort-asc", "sort-desc"], rlm@46: rlm@46: sortAscText : "Sort Ascending", rlm@46: rlm@46: sortDescText : "Sort Descending", rlm@46: rlm@46: columnsText : "Columns", rlm@46: rlm@46: borderWidth: 2, rlm@46: rlm@46: rlm@46: rlm@46: initTemplates : function(){ rlm@46: var ts = this.templates || {}; rlm@46: if(!ts.master){ rlm@46: ts.master = new Ext.Template( rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
    {header}
    ', rlm@46: '
    {body}
    ', rlm@46: "
    ", rlm@46: '
     
    ', rlm@46: '
     
    ', rlm@46: "
    " rlm@46: ); rlm@46: } rlm@46: rlm@46: if(!ts.header){ rlm@46: ts.header = new Ext.Template( rlm@46: '', rlm@46: '{cells}', rlm@46: "
    " rlm@46: ); rlm@46: } rlm@46: rlm@46: if(!ts.hcell){ rlm@46: ts.hcell = new Ext.Template( rlm@46: '
    ', this.grid.enableHdMenu ? '' : '', rlm@46: '{value}', rlm@46: "
    " rlm@46: ); rlm@46: } rlm@46: rlm@46: if(!ts.body){ rlm@46: ts.body = new Ext.Template('{rows}'); rlm@46: } rlm@46: rlm@46: if(!ts.row){ rlm@46: ts.row = new Ext.Template( rlm@46: '
    ', rlm@46: '{cells}', rlm@46: (this.enableRowBody ? '' : ''), rlm@46: '
    {body}
    ' rlm@46: ); rlm@46: } rlm@46: rlm@46: if(!ts.cell){ rlm@46: ts.cell = new Ext.Template( rlm@46: '', rlm@46: '
    {value}
    ', rlm@46: "" rlm@46: ); rlm@46: } rlm@46: rlm@46: for(var k in ts){ rlm@46: var t = ts[k]; rlm@46: if(t && typeof t.compile == 'function' && !t.compiled){ rlm@46: t.disableFormats = true; rlm@46: t.compile(); rlm@46: } rlm@46: } rlm@46: rlm@46: this.templates = ts; rlm@46: rlm@46: this.tdClass = 'x-grid3-cell'; rlm@46: this.cellSelector = 'td.x-grid3-cell'; rlm@46: this.hdCls = 'x-grid3-hd'; rlm@46: this.rowSelector = 'div.x-grid3-row'; rlm@46: this.colRe = new RegExp("x-grid3-td-([^\\s]+)", ""); rlm@46: }, rlm@46: rlm@46: fly : function(el){ rlm@46: if(!this._flyweight){ rlm@46: this._flyweight = new Ext.Element.Flyweight(document.body); rlm@46: } rlm@46: this._flyweight.dom = el; rlm@46: return this._flyweight; rlm@46: }, rlm@46: rlm@46: getEditorParent : function(ed){ rlm@46: return this.scroller.dom; rlm@46: }, rlm@46: rlm@46: initElements : function(){ rlm@46: var E = Ext.Element; rlm@46: rlm@46: var el = this.grid.getGridEl().dom.firstChild; rlm@46: var cs = el.childNodes; rlm@46: rlm@46: this.el = new E(el); rlm@46: rlm@46: this.mainWrap = new E(cs[0]); rlm@46: this.mainHd = new E(this.mainWrap.dom.firstChild); rlm@46: rlm@46: if(this.grid.hideHeaders){ rlm@46: this.mainHd.setDisplayed(false); rlm@46: } rlm@46: rlm@46: this.innerHd = this.mainHd.dom.firstChild; rlm@46: this.scroller = new E(this.mainWrap.dom.childNodes[1]); rlm@46: if(this.forceFit){ rlm@46: this.scroller.setStyle('overflow-x', 'hidden'); rlm@46: } rlm@46: this.mainBody = new E(this.scroller.dom.firstChild); rlm@46: rlm@46: this.focusEl = new E(this.scroller.dom.childNodes[1]); rlm@46: this.focusEl.swallowEvent("click", true); rlm@46: rlm@46: this.resizeMarker = new E(cs[1]); rlm@46: this.resizeProxy = new E(cs[2]); rlm@46: }, rlm@46: rlm@46: getRows : function(){ rlm@46: return this.hasRows() ? this.mainBody.dom.childNodes : []; rlm@46: }, rlm@46: rlm@46: rlm@46: findCell : function(el){ rlm@46: if(!el){ rlm@46: return false; rlm@46: } rlm@46: return this.fly(el).findParent(this.cellSelector, 3); rlm@46: }, rlm@46: rlm@46: findCellIndex : function(el, requiredCls){ rlm@46: var cell = this.findCell(el); rlm@46: if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){ rlm@46: return this.getCellIndex(cell); rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: getCellIndex : function(el){ rlm@46: if(el){ rlm@46: var m = el.className.match(this.colRe); rlm@46: if(m && m[1]){ rlm@46: return this.cm.getIndexById(m[1]); rlm@46: } rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: findHeaderCell : function(el){ rlm@46: var cell = this.findCell(el); rlm@46: return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null; rlm@46: }, rlm@46: rlm@46: findHeaderIndex : function(el){ rlm@46: return this.findCellIndex(el, this.hdCls); rlm@46: }, rlm@46: rlm@46: findRow : function(el){ rlm@46: if(!el){ rlm@46: return false; rlm@46: } rlm@46: return this.fly(el).findParent(this.rowSelector, 10); rlm@46: }, rlm@46: rlm@46: findRowIndex : function(el){ rlm@46: var r = this.findRow(el); rlm@46: return r ? r.rowIndex : false; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: getRow : function(row){ rlm@46: return this.getRows()[row]; rlm@46: }, rlm@46: rlm@46: rlm@46: getCell : function(row, col){ rlm@46: return this.getRow(row).getElementsByTagName('td')[col]; rlm@46: }, rlm@46: rlm@46: rlm@46: getHeaderCell : function(index){ rlm@46: return this.mainHd.dom.getElementsByTagName('td')[index]; rlm@46: }, rlm@46: rlm@46: rlm@46: addRowClass : function(row, cls){ rlm@46: var r = this.getRow(row); rlm@46: if(r){ rlm@46: this.fly(r).addClass(cls); rlm@46: } rlm@46: }, rlm@46: rlm@46: removeRowClass : function(row, cls){ rlm@46: var r = this.getRow(row); rlm@46: if(r){ rlm@46: this.fly(r).removeClass(cls); rlm@46: } rlm@46: }, rlm@46: rlm@46: removeRow : function(row){ rlm@46: Ext.removeNode(this.getRow(row)); rlm@46: }, rlm@46: rlm@46: removeRows : function(firstRow, lastRow){ rlm@46: var bd = this.mainBody.dom; rlm@46: for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){ rlm@46: Ext.removeNode(bd.childNodes[firstRow]); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getScrollState : function(){ rlm@46: var sb = this.scroller.dom; rlm@46: return {left: sb.scrollLeft, top: sb.scrollTop}; rlm@46: }, rlm@46: rlm@46: restoreScroll : function(state){ rlm@46: var sb = this.scroller.dom; rlm@46: sb.scrollLeft = state.left; rlm@46: sb.scrollTop = state.top; rlm@46: }, rlm@46: rlm@46: rlm@46: scrollToTop : function(){ rlm@46: this.scroller.dom.scrollTop = 0; rlm@46: this.scroller.dom.scrollLeft = 0; rlm@46: }, rlm@46: rlm@46: syncScroll : function(){ rlm@46: this.syncHeaderScroll(); rlm@46: var mb = this.scroller.dom; rlm@46: this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop); rlm@46: }, rlm@46: rlm@46: syncHeaderScroll : function(){ rlm@46: var mb = this.scroller.dom; rlm@46: this.innerHd.scrollLeft = mb.scrollLeft; rlm@46: this.innerHd.scrollLeft = mb.scrollLeft; }, rlm@46: rlm@46: updateSortIcon : function(col, dir){ rlm@46: var sc = this.sortClasses; rlm@46: var hds = this.mainHd.select('td').removeClass(sc); rlm@46: hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]); rlm@46: }, rlm@46: rlm@46: updateAllColumnWidths : function(){ rlm@46: var tw = this.getTotalWidth(); rlm@46: var clen = this.cm.getColumnCount(); rlm@46: var ws = []; rlm@46: for(var i = 0; i < clen; i++){ rlm@46: ws[i] = this.getColumnWidth(i); rlm@46: } rlm@46: rlm@46: this.innerHd.firstChild.firstChild.style.width = tw; rlm@46: rlm@46: for(var i = 0; i < clen; i++){ rlm@46: var hd = this.getHeaderCell(i); rlm@46: hd.style.width = ws[i]; rlm@46: } rlm@46: rlm@46: var ns = this.getRows(); rlm@46: for(var i = 0, len = ns.length; i < len; i++){ rlm@46: ns[i].style.width = tw; rlm@46: ns[i].firstChild.style.width = tw; rlm@46: var row = ns[i].firstChild.rows[0]; rlm@46: for(var j = 0; j < clen; j++){ rlm@46: row.childNodes[j].style.width = ws[j]; rlm@46: } rlm@46: } rlm@46: rlm@46: this.onAllColumnWidthsUpdated(ws, tw); rlm@46: }, rlm@46: rlm@46: updateColumnWidth : function(col, width){ rlm@46: var w = this.getColumnWidth(col); rlm@46: var tw = this.getTotalWidth(); rlm@46: rlm@46: this.innerHd.firstChild.firstChild.style.width = tw; rlm@46: var hd = this.getHeaderCell(col); rlm@46: hd.style.width = w; rlm@46: rlm@46: var ns = this.getRows(); rlm@46: for(var i = 0, len = ns.length; i < len; i++){ rlm@46: ns[i].style.width = tw; rlm@46: ns[i].firstChild.style.width = tw; rlm@46: ns[i].firstChild.rows[0].childNodes[col].style.width = w; rlm@46: } rlm@46: rlm@46: this.onColumnWidthUpdated(col, w, tw); rlm@46: }, rlm@46: rlm@46: updateColumnHidden : function(col, hidden){ rlm@46: var tw = this.getTotalWidth(); rlm@46: rlm@46: this.innerHd.firstChild.firstChild.style.width = tw; rlm@46: rlm@46: var display = hidden ? 'none' : ''; rlm@46: rlm@46: var hd = this.getHeaderCell(col); rlm@46: hd.style.display = display; rlm@46: rlm@46: var ns = this.getRows(); rlm@46: for(var i = 0, len = ns.length; i < len; i++){ rlm@46: ns[i].style.width = tw; rlm@46: ns[i].firstChild.style.width = tw; rlm@46: ns[i].firstChild.rows[0].childNodes[col].style.display = display; rlm@46: } rlm@46: rlm@46: this.onColumnHiddenUpdated(col, hidden, tw); rlm@46: rlm@46: delete this.lastViewWidth; this.layout(); rlm@46: }, rlm@46: rlm@46: doRender : function(cs, rs, ds, startRow, colCount, stripe){ rlm@46: var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1; rlm@46: var tstyle = 'width:'+this.getTotalWidth()+';'; rlm@46: var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r; rlm@46: for(var j = 0, len = rs.length; j < len; j++){ rlm@46: r = rs[j]; cb = []; rlm@46: var rowIndex = (j+startRow); rlm@46: for(var i = 0; i < colCount; i++){ rlm@46: c = cs[i]; rlm@46: p.id = c.id; rlm@46: p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); rlm@46: p.attr = p.cellAttr = ""; rlm@46: p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds); rlm@46: p.style = c.style; rlm@46: if(p.value == undefined || p.value === "") p.value = " "; rlm@46: if(r.dirty && typeof r.modified[c.name] !== 'undefined'){ rlm@46: p.css += ' x-grid3-dirty-cell'; rlm@46: } rlm@46: cb[cb.length] = ct.apply(p); rlm@46: } rlm@46: var alt = []; rlm@46: if(stripe && ((rowIndex+1) % 2 == 0)){ rlm@46: alt[0] = "x-grid3-row-alt"; rlm@46: } rlm@46: if(r.dirty){ rlm@46: alt[1] = " x-grid3-dirty-row"; rlm@46: } rlm@46: rp.cols = colCount; rlm@46: if(this.getRowClass){ rlm@46: alt[2] = this.getRowClass(r, rowIndex, rp, ds); rlm@46: } rlm@46: rp.alt = alt.join(" "); rlm@46: rp.cells = cb.join(""); rlm@46: buf[buf.length] = rt.apply(rp); rlm@46: } rlm@46: return buf.join(""); rlm@46: }, rlm@46: rlm@46: processRows : function(startRow, skipStripe){ rlm@46: if(this.ds.getCount() < 1){ rlm@46: return; rlm@46: } rlm@46: skipStripe = skipStripe || !this.grid.stripeRows; rlm@46: startRow = startRow || 0; rlm@46: var rows = this.getRows(); rlm@46: var cls = ' x-grid3-row-alt '; rlm@46: for(var i = startRow, len = rows.length; i < len; i++){ rlm@46: var row = rows[i]; rlm@46: row.rowIndex = i; rlm@46: if(!skipStripe){ rlm@46: var isAlt = ((i+1) % 2 == 0); rlm@46: var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1; rlm@46: if(isAlt == hasAlt){ rlm@46: continue; rlm@46: } rlm@46: if(isAlt){ rlm@46: row.className += " x-grid3-row-alt"; rlm@46: }else{ rlm@46: row.className = row.className.replace("x-grid3-row-alt", ""); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: renderUI : function(){ rlm@46: rlm@46: var header = this.renderHeaders(); rlm@46: var body = this.templates.body.apply({rows:''}); rlm@46: rlm@46: rlm@46: var html = this.templates.master.apply({ rlm@46: body: body, rlm@46: header: header rlm@46: }); rlm@46: rlm@46: var g = this.grid; rlm@46: rlm@46: g.getGridEl().dom.innerHTML = html; rlm@46: rlm@46: this.initElements(); rlm@46: rlm@46: rlm@46: this.mainBody.dom.innerHTML = this.renderRows(); rlm@46: this.processRows(0, true); rlm@46: rlm@46: if(this.deferEmptyText !== true){ rlm@46: this.applyEmptyText(); rlm@46: } rlm@46: rlm@46: Ext.fly(this.innerHd).on("click", this.handleHdDown, this); rlm@46: this.mainHd.on("mouseover", this.handleHdOver, this); rlm@46: this.mainHd.on("mouseout", this.handleHdOut, this); rlm@46: this.mainHd.on("mousemove", this.handleHdMove, this); rlm@46: rlm@46: this.scroller.on('scroll', this.syncScroll, this); rlm@46: if(g.enableColumnResize !== false){ rlm@46: this.splitone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom); rlm@46: } rlm@46: rlm@46: if(g.enableColumnMove){ rlm@46: this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd); rlm@46: this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom); rlm@46: } rlm@46: rlm@46: if(g.enableHdMenu !== false){ rlm@46: if(g.enableColumnHide !== false){ rlm@46: this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"}); rlm@46: this.colMenu.on("beforeshow", this.beforeColMenuShow, this); rlm@46: this.colMenu.on("itemclick", this.handleHdMenuClick, this); rlm@46: } rlm@46: this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"}); rlm@46: this.hmenu.add( rlm@46: {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"}, rlm@46: {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"} rlm@46: ); rlm@46: if(g.enableColumnHide !== false){ rlm@46: this.hmenu.add('-', rlm@46: {id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'} rlm@46: ); rlm@46: } rlm@46: this.hmenu.on("itemclick", this.handleHdMenuClick, this); rlm@46: rlm@46: } rlm@46: rlm@46: if(g.enableDragDrop || g.enableDrag){ rlm@46: this.dragZone = new Ext.grid.GridDragZone(g, { rlm@46: ddGroup : g.ddGroup || 'GridDD' rlm@46: }); rlm@46: } rlm@46: rlm@46: this.updateHeaderSortState(); rlm@46: rlm@46: }, rlm@46: rlm@46: layout : function(){ rlm@46: if(!this.mainBody){ rlm@46: return; } rlm@46: var g = this.grid; rlm@46: var c = g.getGridEl(); rlm@46: var csize = c.getSize(true); rlm@46: var vw = csize.width; rlm@46: rlm@46: if(vw < 20 || csize.height < 20){ return; rlm@46: } rlm@46: rlm@46: if(g.autoHeight){ rlm@46: this.scroller.dom.style.overflow = 'visible'; rlm@46: }else{ rlm@46: this.el.setSize(csize.width, csize.height); rlm@46: rlm@46: var hdHeight = this.mainHd.getHeight(); rlm@46: var vh = csize.height - (hdHeight); rlm@46: rlm@46: this.scroller.setSize(vw, vh); rlm@46: if(this.innerHd){ rlm@46: this.innerHd.style.width = (vw)+'px'; rlm@46: } rlm@46: } rlm@46: if(this.forceFit){ rlm@46: if(this.lastViewWidth != vw){ rlm@46: this.fitColumns(false, false); rlm@46: this.lastViewWidth = vw; rlm@46: } rlm@46: }else { rlm@46: this.autoExpand(); rlm@46: this.syncHeaderScroll(); rlm@46: } rlm@46: this.onLayout(vw, vh); rlm@46: }, rlm@46: rlm@46: onLayout : function(vw, vh){ rlm@46: }, rlm@46: rlm@46: onColumnWidthUpdated : function(col, w, tw){ rlm@46: }, rlm@46: rlm@46: onAllColumnWidthsUpdated : function(ws, tw){ rlm@46: }, rlm@46: rlm@46: onColumnHiddenUpdated : function(col, hidden, tw){ rlm@46: }, rlm@46: rlm@46: updateColumnText : function(col, text){ rlm@46: }, rlm@46: rlm@46: afterMove : function(colIndex){ rlm@46: }, rlm@46: rlm@46: rlm@46: init: function(grid){ rlm@46: this.grid = grid; rlm@46: rlm@46: this.initTemplates(); rlm@46: this.initData(grid.store, grid.colModel); rlm@46: this.initUI(grid); rlm@46: }, rlm@46: rlm@46: getColumnId : function(index){ rlm@46: return this.cm.getColumnId(index); rlm@46: }, rlm@46: rlm@46: renderHeaders : function(){ rlm@46: var cm = this.cm, ts = this.templates; rlm@46: var ct = ts.hcell; rlm@46: rlm@46: var cb = [], sb = [], p = {}; rlm@46: rlm@46: for(var i = 0, len = cm.getColumnCount(); i < len; i++){ rlm@46: p.id = cm.getColumnId(i); rlm@46: p.value = cm.getColumnHeader(i) || ""; rlm@46: p.style = this.getColumnStyle(i, true); rlm@46: p.tooltip = this.getColumnTooltip(i); rlm@46: if(cm.config[i].align == 'right'){ rlm@46: p.istyle = 'padding-right:16px'; rlm@46: } else { rlm@46: delete p.istyle; rlm@46: } rlm@46: cb[cb.length] = ct.apply(p); rlm@46: } rlm@46: return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'}); rlm@46: }, rlm@46: rlm@46: getColumnTooltip : function(i){ rlm@46: var tt = this.cm.getColumnTooltip(i); rlm@46: if(tt){ rlm@46: if(Ext.QuickTips.isEnabled()){ rlm@46: return 'ext:qtip="'+tt+'"'; rlm@46: }else{ rlm@46: return 'title="'+tt+'"'; rlm@46: } rlm@46: } rlm@46: return ""; rlm@46: }, rlm@46: rlm@46: beforeUpdate : function(){ rlm@46: this.grid.stopEditing(true); rlm@46: }, rlm@46: rlm@46: updateHeaders : function(){ rlm@46: this.innerHd.firstChild.innerHTML = this.renderHeaders(); rlm@46: }, rlm@46: rlm@46: rlm@46: focusRow : function(row){ rlm@46: this.focusCell(row, 0, false); rlm@46: }, rlm@46: rlm@46: rlm@46: focusCell : function(row, col, hscroll){ rlm@46: var xy = this.ensureVisible(row, col, hscroll); rlm@46: this.focusEl.setXY(xy); rlm@46: if(Ext.isGecko){ rlm@46: this.focusEl.focus(); rlm@46: }else{ rlm@46: this.focusEl.focus.defer(1, this.focusEl); rlm@46: } rlm@46: }, rlm@46: rlm@46: ensureVisible : function(row, col, hscroll){ rlm@46: if(typeof row != "number"){ rlm@46: row = row.rowIndex; rlm@46: } rlm@46: if(!this.ds){ rlm@46: return; rlm@46: } rlm@46: if(row < 0 || row >= this.ds.getCount()){ rlm@46: return; rlm@46: } rlm@46: col = (col !== undefined ? col : 0); rlm@46: rlm@46: var rowEl = this.getRow(row), cellEl; rlm@46: if(!(hscroll === false && col === 0)){ rlm@46: while(this.cm.isHidden(col)){ rlm@46: col++; rlm@46: } rlm@46: cellEl = this.getCell(row, col); rlm@46: } rlm@46: if(!rowEl){ rlm@46: return; rlm@46: } rlm@46: rlm@46: var c = this.scroller.dom; rlm@46: rlm@46: var ctop = 0; rlm@46: var p = rowEl, stop = this.el.dom; rlm@46: while(p && p != stop){ rlm@46: ctop += p.offsetTop; rlm@46: p = p.offsetParent; rlm@46: } rlm@46: ctop -= this.mainHd.dom.offsetHeight; rlm@46: rlm@46: var cbot = ctop + rowEl.offsetHeight; rlm@46: rlm@46: var ch = c.clientHeight; rlm@46: var stop = parseInt(c.scrollTop, 10); rlm@46: var sbot = stop + ch; rlm@46: rlm@46: if(ctop < stop){ rlm@46: c.scrollTop = ctop; rlm@46: }else if(cbot > sbot){ rlm@46: c.scrollTop = cbot-ch; rlm@46: } rlm@46: rlm@46: if(hscroll !== false){ rlm@46: var cleft = parseInt(cellEl.offsetLeft, 10); rlm@46: var cright = cleft + cellEl.offsetWidth; rlm@46: rlm@46: var sleft = parseInt(c.scrollLeft, 10); rlm@46: var sright = sleft + c.clientWidth; rlm@46: if(cleft < sleft){ rlm@46: c.scrollLeft = cleft; rlm@46: }else if(cright > sright){ rlm@46: c.scrollLeft = cright-c.clientWidth; rlm@46: } rlm@46: } rlm@46: return cellEl ? Ext.fly(cellEl).getXY() : [c.scrollLeft, Ext.fly(rowEl).getY()]; rlm@46: }, rlm@46: rlm@46: insertRows : function(dm, firstRow, lastRow, isUpdate){ rlm@46: if(!isUpdate && firstRow === 0 && lastRow == dm.getCount()-1){ rlm@46: this.refresh(); rlm@46: }else{ rlm@46: if(!isUpdate){ rlm@46: this.fireEvent("beforerowsinserted", this, firstRow, lastRow); rlm@46: } rlm@46: var html = this.renderRows(firstRow, lastRow); rlm@46: var before = this.getRow(firstRow); rlm@46: if(before){ rlm@46: Ext.DomHelper.insertHtml('beforeBegin', before, html); rlm@46: }else{ rlm@46: Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html); rlm@46: } rlm@46: if(!isUpdate){ rlm@46: this.fireEvent("rowsinserted", this, firstRow, lastRow); rlm@46: this.processRows(firstRow); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: deleteRows : function(dm, firstRow, lastRow){ rlm@46: if(dm.getRowCount()<1){ rlm@46: this.refresh(); rlm@46: }else{ rlm@46: this.fireEvent("beforerowsdeleted", this, firstRow, lastRow); rlm@46: rlm@46: this.removeRows(firstRow, lastRow); rlm@46: rlm@46: this.processRows(firstRow); rlm@46: this.fireEvent("rowsdeleted", this, firstRow, lastRow); rlm@46: } rlm@46: }, rlm@46: rlm@46: getColumnStyle : function(col, isHeader){ rlm@46: var style = !isHeader ? (this.cm.config[col].css || '') : ''; rlm@46: style += 'width:'+this.getColumnWidth(col)+';'; rlm@46: if(this.cm.isHidden(col)){ rlm@46: style += 'display:none;'; rlm@46: } rlm@46: var align = this.cm.config[col].align; rlm@46: if(align){ rlm@46: style += 'text-align:'+align+';'; rlm@46: } rlm@46: return style; rlm@46: }, rlm@46: rlm@46: getColumnWidth : function(col){ rlm@46: var w = this.cm.getColumnWidth(col); rlm@46: if(typeof w == 'number'){ rlm@46: return (Ext.isBorderBox ? w : (w-this.borderWidth > 0 ? w-this.borderWidth:0)) + 'px'; rlm@46: } rlm@46: return w; rlm@46: }, rlm@46: rlm@46: getTotalWidth : function(){ rlm@46: return this.cm.getTotalWidth()+'px'; rlm@46: }, rlm@46: rlm@46: fitColumns : function(preventRefresh, onlyExpand, omitColumn){ rlm@46: var cm = this.cm, leftOver, dist, i; rlm@46: var tw = cm.getTotalWidth(false); rlm@46: var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset; rlm@46: rlm@46: if(aw < 20){ return; rlm@46: } rlm@46: var extra = aw - tw; rlm@46: rlm@46: if(extra === 0){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: var vc = cm.getColumnCount(true); rlm@46: var ac = vc-(typeof omitColumn == 'number' ? 1 : 0); rlm@46: if(ac === 0){ rlm@46: ac = 1; rlm@46: omitColumn = undefined; rlm@46: } rlm@46: var colCount = cm.getColumnCount(); rlm@46: var cols = []; rlm@46: var extraCol = 0; rlm@46: var width = 0; rlm@46: var w; rlm@46: for (i = 0; i < colCount; i++){ rlm@46: if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){ rlm@46: w = cm.getColumnWidth(i); rlm@46: cols.push(i); rlm@46: extraCol = i; rlm@46: cols.push(w); rlm@46: width += w; rlm@46: } rlm@46: } rlm@46: var frac = (aw - cm.getTotalWidth())/width; rlm@46: while (cols.length){ rlm@46: w = cols.pop(); rlm@46: i = cols.pop(); rlm@46: cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true); rlm@46: } rlm@46: rlm@46: if((tw = cm.getTotalWidth(false)) > aw){ rlm@46: var adjustCol = ac != vc ? omitColumn : extraCol; rlm@46: cm.setColumnWidth(adjustCol, Math.max(1, rlm@46: cm.getColumnWidth(adjustCol)- (tw-aw)), true); rlm@46: } rlm@46: rlm@46: if(preventRefresh !== true){ rlm@46: this.updateAllColumnWidths(); rlm@46: } rlm@46: rlm@46: rlm@46: return true; rlm@46: }, rlm@46: rlm@46: autoExpand : function(preventUpdate){ rlm@46: var g = this.grid, cm = this.cm; rlm@46: if(!this.userResized && g.autoExpandColumn){ rlm@46: var tw = cm.getTotalWidth(false); rlm@46: var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset; rlm@46: if(tw != aw){ rlm@46: var ci = cm.getIndexById(g.autoExpandColumn); rlm@46: var currentWidth = cm.getColumnWidth(ci); rlm@46: var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax); rlm@46: if(cw != currentWidth){ rlm@46: cm.setColumnWidth(ci, cw, true); rlm@46: if(preventUpdate !== true){ rlm@46: this.updateColumnWidth(ci, cw); rlm@46: } rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: getColumnData : function(){ rlm@46: var cs = [], cm = this.cm, colCount = cm.getColumnCount(); rlm@46: for(var i = 0; i < colCount; i++){ rlm@46: var name = cm.getDataIndex(i); rlm@46: cs[i] = { rlm@46: name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name), rlm@46: renderer : cm.getRenderer(i), rlm@46: id : cm.getColumnId(i), rlm@46: style : this.getColumnStyle(i) rlm@46: }; rlm@46: } rlm@46: return cs; rlm@46: }, rlm@46: rlm@46: renderRows : function(startRow, endRow){ rlm@46: var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows; rlm@46: var colCount = cm.getColumnCount(); rlm@46: rlm@46: if(ds.getCount() < 1){ rlm@46: return ""; rlm@46: } rlm@46: rlm@46: var cs = this.getColumnData(); rlm@46: rlm@46: startRow = startRow || 0; rlm@46: endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow; rlm@46: rlm@46: var rs = ds.getRange(startRow, endRow); rlm@46: rlm@46: return this.doRender(cs, rs, ds, startRow, colCount, stripe); rlm@46: }, rlm@46: rlm@46: renderBody : function(){ rlm@46: var markup = this.renderRows(); rlm@46: return this.templates.body.apply({rows: markup}); rlm@46: }, rlm@46: rlm@46: refreshRow : function(record){ rlm@46: var ds = this.ds, index; rlm@46: if(typeof record == 'number'){ rlm@46: index = record; rlm@46: record = ds.getAt(index); rlm@46: }else{ rlm@46: index = ds.indexOf(record); rlm@46: } rlm@46: var cls = []; rlm@46: this.insertRows(ds, index, index, true); rlm@46: this.getRow(index).rowIndex = index; rlm@46: this.onRemove(ds, record, index+1, true); rlm@46: this.fireEvent("rowupdated", this, index, record); rlm@46: }, rlm@46: rlm@46: rlm@46: refresh : function(headersToo){ rlm@46: this.fireEvent("beforerefresh", this); rlm@46: this.grid.stopEditing(true); rlm@46: rlm@46: var result = this.renderBody(); rlm@46: this.mainBody.update(result); rlm@46: rlm@46: if(headersToo === true){ rlm@46: this.updateHeaders(); rlm@46: this.updateHeaderSortState(); rlm@46: } rlm@46: this.processRows(0, true); rlm@46: this.layout(); rlm@46: this.applyEmptyText(); rlm@46: this.fireEvent("refresh", this); rlm@46: }, rlm@46: rlm@46: applyEmptyText : function(){ rlm@46: if(this.emptyText && !this.hasRows()){ rlm@46: this.mainBody.update('
    ' + this.emptyText + '
    '); rlm@46: } rlm@46: }, rlm@46: rlm@46: updateHeaderSortState : function(){ rlm@46: var state = this.ds.getSortState(); rlm@46: if(!state){ rlm@46: return; rlm@46: } rlm@46: if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){ rlm@46: this.grid.fireEvent('sortchange', this.grid, state); rlm@46: } rlm@46: this.sortState = state; rlm@46: var sortColumn = this.cm.findColumnIndex(state.field); rlm@46: if(sortColumn != -1){ rlm@46: var sortDir = state.direction; rlm@46: this.updateSortIcon(sortColumn, sortDir); rlm@46: } rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.colMenu){ rlm@46: this.colMenu.removeAll(); rlm@46: Ext.menu.MenuMgr.unregister(this.colMenu); rlm@46: this.colMenu.getEl().remove(); rlm@46: delete this.colMenu; rlm@46: } rlm@46: if(this.hmenu){ rlm@46: this.hmenu.removeAll(); rlm@46: Ext.menu.MenuMgr.unregister(this.hmenu); rlm@46: this.hmenu.getEl().remove(); rlm@46: delete this.hmenu; rlm@46: } rlm@46: if(this.grid.enableColumnMove){ rlm@46: var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id]; rlm@46: if(dds){ rlm@46: for(var dd in dds){ rlm@46: if(!dds[dd].config.isTarget && dds[dd].dragElId){ rlm@46: var elid = dds[dd].dragElId; rlm@46: dds[dd].unreg(); rlm@46: Ext.get(elid).remove(); rlm@46: } else if(dds[dd].config.isTarget){ rlm@46: dds[dd].proxyTop.remove(); rlm@46: dds[dd].proxyBottom.remove(); rlm@46: dds[dd].unreg(); rlm@46: } rlm@46: if(Ext.dd.DDM.locationCache[dd]){ rlm@46: delete Ext.dd.DDM.locationCache[dd]; rlm@46: } rlm@46: } rlm@46: delete Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id]; rlm@46: } rlm@46: } rlm@46: rlm@46: Ext.destroy(this.resizeMarker, this.resizeProxy); rlm@46: rlm@46: if(this.dragZone){ rlm@46: this.dragZone.unreg(); rlm@46: } rlm@46: rlm@46: this.initData(null, null); rlm@46: Ext.EventManager.removeResizeListener(this.onWindowResize, this); rlm@46: }, rlm@46: rlm@46: onDenyColumnHide : function(){ rlm@46: rlm@46: }, rlm@46: rlm@46: render : function(){ rlm@46: rlm@46: var cm = this.cm; rlm@46: var colCount = cm.getColumnCount(); rlm@46: rlm@46: if(this.autoFill){ rlm@46: this.fitColumns(true, true); rlm@46: }else if(this.forceFit){ rlm@46: this.fitColumns(true, false); rlm@46: }else if(this.grid.autoExpandColumn){ rlm@46: this.autoExpand(true); rlm@46: } rlm@46: rlm@46: this.renderUI(); rlm@46: }, rlm@46: rlm@46: rlm@46: initData : function(ds, cm){ rlm@46: if(this.ds){ rlm@46: this.ds.un("load", this.onLoad, this); rlm@46: this.ds.un("datachanged", this.onDataChange, this); rlm@46: this.ds.un("add", this.onAdd, this); rlm@46: this.ds.un("remove", this.onRemove, this); rlm@46: this.ds.un("update", this.onUpdate, this); rlm@46: this.ds.un("clear", this.onClear, this); rlm@46: } rlm@46: if(ds){ rlm@46: ds.on("load", this.onLoad, this); rlm@46: ds.on("datachanged", this.onDataChange, this); rlm@46: ds.on("add", this.onAdd, this); rlm@46: ds.on("remove", this.onRemove, this); rlm@46: ds.on("update", this.onUpdate, this); rlm@46: ds.on("clear", this.onClear, this); rlm@46: } rlm@46: this.ds = ds; rlm@46: rlm@46: if(this.cm){ rlm@46: this.cm.un("configchange", this.onColConfigChange, this); rlm@46: this.cm.un("widthchange", this.onColWidthChange, this); rlm@46: this.cm.un("headerchange", this.onHeaderChange, this); rlm@46: this.cm.un("hiddenchange", this.onHiddenChange, this); rlm@46: this.cm.un("columnmoved", this.onColumnMove, this); rlm@46: this.cm.un("columnlockchange", this.onColumnLock, this); rlm@46: } rlm@46: if(cm){ rlm@46: cm.on("configchange", this.onColConfigChange, this); rlm@46: cm.on("widthchange", this.onColWidthChange, this); rlm@46: cm.on("headerchange", this.onHeaderChange, this); rlm@46: cm.on("hiddenchange", this.onHiddenChange, this); rlm@46: cm.on("columnmoved", this.onColumnMove, this); rlm@46: cm.on("columnlockchange", this.onColumnLock, this); rlm@46: } rlm@46: this.cm = cm; rlm@46: }, rlm@46: rlm@46: onDataChange : function(){ rlm@46: this.refresh(); rlm@46: this.updateHeaderSortState(); rlm@46: }, rlm@46: rlm@46: onClear : function(){ rlm@46: this.refresh(); rlm@46: }, rlm@46: rlm@46: onUpdate : function(ds, record){ rlm@46: this.refreshRow(record); rlm@46: }, rlm@46: rlm@46: onAdd : function(ds, records, index){ rlm@46: this.insertRows(ds, index, index + (records.length-1)); rlm@46: }, rlm@46: rlm@46: onRemove : function(ds, record, index, isUpdate){ rlm@46: if(isUpdate !== true){ rlm@46: this.fireEvent("beforerowremoved", this, index, record); rlm@46: } rlm@46: this.removeRow(index); rlm@46: if(isUpdate !== true){ rlm@46: this.processRows(index); rlm@46: this.applyEmptyText(); rlm@46: this.fireEvent("rowremoved", this, index, record); rlm@46: } rlm@46: }, rlm@46: rlm@46: onLoad : function(){ rlm@46: this.scrollToTop(); rlm@46: }, rlm@46: rlm@46: onColWidthChange : function(cm, col, width){ rlm@46: this.updateColumnWidth(col, width); rlm@46: }, rlm@46: rlm@46: onHeaderChange : function(cm, col, text){ rlm@46: this.updateHeaders(); rlm@46: }, rlm@46: rlm@46: onHiddenChange : function(cm, col, hidden){ rlm@46: this.updateColumnHidden(col, hidden); rlm@46: }, rlm@46: rlm@46: onColumnMove : function(cm, oldIndex, newIndex){ rlm@46: this.indexMap = null; rlm@46: var s = this.getScrollState(); rlm@46: this.refresh(true); rlm@46: this.restoreScroll(s); rlm@46: this.afterMove(newIndex); rlm@46: }, rlm@46: rlm@46: onColConfigChange : function(){ rlm@46: delete this.lastViewWidth; rlm@46: this.indexMap = null; rlm@46: this.refresh(true); rlm@46: }, rlm@46: rlm@46: rlm@46: initUI : function(grid){ rlm@46: grid.on("headerclick", this.onHeaderClick, this); rlm@46: rlm@46: if(grid.trackMouseOver){ rlm@46: grid.on("mouseover", this.onRowOver, this); rlm@46: grid.on("mouseout", this.onRowOut, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: rlm@46: }, rlm@46: rlm@46: onHeaderClick : function(g, index){ rlm@46: if(this.headersDisabled || !this.cm.isSortable(index)){ rlm@46: return; rlm@46: } rlm@46: g.stopEditing(true); rlm@46: g.store.sort(this.cm.getDataIndex(index)); rlm@46: }, rlm@46: rlm@46: onRowOver : function(e, t){ rlm@46: var row; rlm@46: if((row = this.findRowIndex(t)) !== false){ rlm@46: this.addRowClass(row, "x-grid3-row-over"); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRowOut : function(e, t){ rlm@46: var row; rlm@46: if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){ rlm@46: this.removeRowClass(row, "x-grid3-row-over"); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleWheel : function(e){ rlm@46: e.stopPropagation(); rlm@46: }, rlm@46: rlm@46: onRowSelect : function(row){ rlm@46: this.addRowClass(row, "x-grid3-row-selected"); rlm@46: }, rlm@46: rlm@46: onRowDeselect : function(row){ rlm@46: this.removeRowClass(row, "x-grid3-row-selected"); rlm@46: }, rlm@46: rlm@46: onCellSelect : function(row, col){ rlm@46: var cell = this.getCell(row, col); rlm@46: if(cell){ rlm@46: this.fly(cell).addClass("x-grid3-cell-selected"); rlm@46: } rlm@46: }, rlm@46: rlm@46: onCellDeselect : function(row, col){ rlm@46: var cell = this.getCell(row, col); rlm@46: if(cell){ rlm@46: this.fly(cell).removeClass("x-grid3-cell-selected"); rlm@46: } rlm@46: }, rlm@46: rlm@46: onColumnSplitterMoved : function(i, w){ rlm@46: this.userResized = true; rlm@46: var cm = this.grid.colModel; rlm@46: cm.setColumnWidth(i, w, true); rlm@46: rlm@46: if(this.forceFit){ rlm@46: this.fitColumns(true, false, i); rlm@46: this.updateAllColumnWidths(); rlm@46: }else{ rlm@46: this.updateColumnWidth(i, w); rlm@46: } rlm@46: rlm@46: this.grid.fireEvent("columnresize", i, w); rlm@46: }, rlm@46: rlm@46: handleHdMenuClick : function(item){ rlm@46: var index = this.hdCtxIndex; rlm@46: var cm = this.cm, ds = this.ds; rlm@46: switch(item.id){ rlm@46: case "asc": rlm@46: ds.sort(cm.getDataIndex(index), "ASC"); rlm@46: break; rlm@46: case "desc": rlm@46: ds.sort(cm.getDataIndex(index), "DESC"); rlm@46: break; rlm@46: default: rlm@46: index = cm.getIndexById(item.id.substr(4)); rlm@46: if(index != -1){ rlm@46: if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){ rlm@46: this.onDenyColumnHide(); rlm@46: return false; rlm@46: } rlm@46: cm.setHidden(index, item.checked); rlm@46: } rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: isHideableColumn : function(c){ rlm@46: return !c.hidden && !c.fixed; rlm@46: }, rlm@46: rlm@46: beforeColMenuShow : function(){ rlm@46: var cm = this.cm, colCount = cm.getColumnCount(); rlm@46: this.colMenu.removeAll(); rlm@46: for(var i = 0; i < colCount; i++){ rlm@46: if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){ rlm@46: this.colMenu.add(new Ext.menu.CheckItem({ rlm@46: id: "col-"+cm.getColumnId(i), rlm@46: text: cm.getColumnHeader(i), rlm@46: checked: !cm.isHidden(i), rlm@46: hideOnClick:false, rlm@46: disabled: cm.config[i].hideable === false rlm@46: })); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: handleHdDown : function(e, t){ rlm@46: if(Ext.fly(t).hasClass('x-grid3-hd-btn')){ rlm@46: e.stopEvent(); rlm@46: var hd = this.findHeaderCell(t); rlm@46: Ext.fly(hd).addClass('x-grid3-hd-menu-open'); rlm@46: var index = this.getCellIndex(hd); rlm@46: this.hdCtxIndex = index; rlm@46: var ms = this.hmenu.items, cm = this.cm; rlm@46: ms.get("asc").setDisabled(!cm.isSortable(index)); rlm@46: ms.get("desc").setDisabled(!cm.isSortable(index)); rlm@46: this.hmenu.on("hide", function(){ rlm@46: Ext.fly(hd).removeClass('x-grid3-hd-menu-open'); rlm@46: }, this, {single:true}); rlm@46: this.hmenu.show(t, "tl-bl?"); rlm@46: } rlm@46: }, rlm@46: rlm@46: handleHdOver : function(e, t){ rlm@46: var hd = this.findHeaderCell(t); rlm@46: if(hd && !this.headersDisabled){ rlm@46: this.activeHd = hd; rlm@46: this.activeHdIndex = this.getCellIndex(hd); rlm@46: var fly = this.fly(hd); rlm@46: this.activeHdRegion = fly.getRegion(); rlm@46: if(!this.cm.isMenuDisabled(this.activeHdIndex)){ rlm@46: fly.addClass("x-grid3-hd-over"); rlm@46: this.activeHdBtn = fly.child('.x-grid3-hd-btn'); rlm@46: if(this.activeHdBtn){ rlm@46: this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px'; rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: handleHdMove : function(e, t){ rlm@46: if(this.activeHd && !this.headersDisabled){ rlm@46: var hw = this.splitHandleWidth || 5; rlm@46: var r = this.activeHdRegion; rlm@46: var x = e.getPageX(); rlm@46: var ss = this.activeHd.style; rlm@46: if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){ rlm@46: ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'e-resize' : 'col-resize'; }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){ rlm@46: ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'w-resize' : 'col-resize'; rlm@46: }else{ rlm@46: ss.cursor = ''; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: handleHdOut : function(e, t){ rlm@46: var hd = this.findHeaderCell(t); rlm@46: if(hd && (!Ext.isIE || !e.within(hd, true))){ rlm@46: this.activeHd = null; rlm@46: this.fly(hd).removeClass("x-grid3-hd-over"); rlm@46: hd.style.cursor = ''; rlm@46: } rlm@46: }, rlm@46: rlm@46: hasRows : function(){ rlm@46: var fc = this.mainBody.dom.firstChild; rlm@46: return fc && fc.className != 'x-grid-empty'; rlm@46: }, rlm@46: rlm@46: bind : function(d, c){ rlm@46: this.initData(d, c); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.GridView.SplitDragZone = function(grid, hd){ rlm@46: this.grid = grid; rlm@46: this.view = grid.getView(); rlm@46: this.marker = this.view.resizeMarker; rlm@46: this.proxy = this.view.resizeProxy; rlm@46: Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd, rlm@46: "gridSplitters" + this.grid.getGridEl().id, { rlm@46: dragElId : Ext.id(this.proxy.dom), resizeFrame:false rlm@46: }); rlm@46: this.scroll = false; rlm@46: this.hw = this.view.splitHandleWidth || 5; rlm@46: }; rlm@46: Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, { rlm@46: rlm@46: b4StartDrag : function(x, y){ rlm@46: this.view.headersDisabled = true; rlm@46: var h = this.view.mainWrap.getHeight(); rlm@46: this.marker.setHeight(h); rlm@46: this.marker.show(); rlm@46: this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]); rlm@46: this.proxy.setHeight(h); rlm@46: var w = this.cm.getColumnWidth(this.cellIndex); rlm@46: var minw = Math.max(w-this.grid.minColumnWidth, 0); rlm@46: this.resetConstraints(); rlm@46: this.setXConstraint(minw, 1000); rlm@46: this.setYConstraint(0, 0); rlm@46: this.minX = x - minw; rlm@46: this.maxX = x + 1000; rlm@46: this.startPos = x; rlm@46: Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseDown : function(e){ rlm@46: var t = this.view.findHeaderCell(e.getTarget()); rlm@46: if(t){ rlm@46: var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1]; rlm@46: var exy = e.getXY(), ex = exy[0], ey = exy[1]; rlm@46: var w = t.offsetWidth, adjust = false; rlm@46: if((ex - x) <= this.hw){ rlm@46: adjust = -1; rlm@46: }else if((x+w) - ex <= this.hw){ rlm@46: adjust = 0; rlm@46: } rlm@46: if(adjust !== false){ rlm@46: this.cm = this.grid.colModel; rlm@46: var ci = this.view.getCellIndex(t); rlm@46: if(adjust == -1){ rlm@46: if (ci + adjust < 0) { rlm@46: return; rlm@46: } rlm@46: while(this.cm.isHidden(ci+adjust)){ rlm@46: --adjust; rlm@46: if(ci+adjust < 0){ rlm@46: return; rlm@46: } rlm@46: } rlm@46: } rlm@46: this.cellIndex = ci+adjust; rlm@46: this.split = t.dom; rlm@46: if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){ rlm@46: Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments); rlm@46: } rlm@46: }else if(this.view.columnDrag){ rlm@46: this.view.columnDrag.callHandleMouseDown(e); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: endDrag : function(e){ rlm@46: this.marker.hide(); rlm@46: var v = this.view; rlm@46: var endX = Math.max(this.minX, e.getPageX()); rlm@46: var diff = endX - this.startPos; rlm@46: v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff); rlm@46: setTimeout(function(){ rlm@46: v.headersDisabled = false; rlm@46: }, 50); rlm@46: }, rlm@46: rlm@46: autoOffset : function(){ rlm@46: this.setDelta(0,0); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.GroupingView = Ext.extend(Ext.grid.GridView, { rlm@46: rlm@46: hideGroupedColumn:false, rlm@46: rlm@46: showGroupName:true, rlm@46: rlm@46: startCollapsed:false, rlm@46: rlm@46: enableGrouping:true, rlm@46: rlm@46: enableGroupingMenu:true, rlm@46: rlm@46: enableNoGroups:true, rlm@46: rlm@46: emptyGroupText : '(None)', rlm@46: rlm@46: ignoreAdd: false, rlm@46: rlm@46: groupTextTpl : '{text}', rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: gidSeed : 1000, rlm@46: rlm@46: rlm@46: initTemplates : function(){ rlm@46: Ext.grid.GroupingView.superclass.initTemplates.call(this); rlm@46: this.state = {}; rlm@46: rlm@46: var sm = this.grid.getSelectionModel(); rlm@46: sm.on(sm.selectRow ? 'beforerowselect' : 'beforecellselect', rlm@46: this.onBeforeRowSelect, this); rlm@46: rlm@46: if(!this.startGroup){ rlm@46: this.startGroup = new Ext.XTemplate( rlm@46: '
    ', rlm@46: '
    ', this.groupTextTpl ,'
    ', rlm@46: '
    ' rlm@46: ); rlm@46: } rlm@46: this.startGroup.compile(); rlm@46: this.endGroup = '
    '; rlm@46: }, rlm@46: rlm@46: rlm@46: findGroup : function(el){ rlm@46: return Ext.fly(el).up('.x-grid-group', this.mainBody.dom); rlm@46: }, rlm@46: rlm@46: rlm@46: getGroups : function(){ rlm@46: return this.hasRows() ? this.mainBody.dom.childNodes : []; rlm@46: }, rlm@46: rlm@46: rlm@46: onAdd : function(){ rlm@46: if(this.enableGrouping && !this.ignoreAdd){ rlm@46: var ss = this.getScrollState(); rlm@46: this.refresh(); rlm@46: this.restoreScroll(ss); rlm@46: }else if(!this.enableGrouping){ rlm@46: Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onRemove : function(ds, record, index, isUpdate){ rlm@46: Ext.grid.GroupingView.superclass.onRemove.apply(this, arguments); rlm@46: var g = document.getElementById(record._groupId); rlm@46: if(g && g.childNodes[1].childNodes.length < 1){ rlm@46: Ext.removeNode(g); rlm@46: } rlm@46: this.applyEmptyText(); rlm@46: }, rlm@46: rlm@46: rlm@46: refreshRow : function(record){ rlm@46: if(this.ds.getCount()==1){ rlm@46: this.refresh(); rlm@46: }else{ rlm@46: this.isUpdating = true; rlm@46: Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments); rlm@46: this.isUpdating = false; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: beforeMenuShow : function(){ rlm@46: var field = this.getGroupField(); rlm@46: var g = this.hmenu.items.get('groupBy'); rlm@46: if(g){ rlm@46: g.setDisabled(this.cm.config[this.hdCtxIndex].groupable === false); rlm@46: } rlm@46: var s = this.hmenu.items.get('showGroups'); rlm@46: if(s){ rlm@46: s.setDisabled(!field && this.cm.config[this.hdCtxIndex].groupable === false); rlm@46: s.setChecked(!!field, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: renderUI : function(){ rlm@46: Ext.grid.GroupingView.superclass.renderUI.call(this); rlm@46: this.mainBody.on('mousedown', this.interceptMouse, this); rlm@46: rlm@46: if(this.enableGroupingMenu && this.hmenu){ rlm@46: this.hmenu.add('-',{ rlm@46: id:'groupBy', rlm@46: text: this.groupByText, rlm@46: handler: this.onGroupByClick, rlm@46: scope: this, rlm@46: iconCls:'x-group-by-icon' rlm@46: }); rlm@46: if(this.enableNoGroups){ rlm@46: this.hmenu.add({ rlm@46: id:'showGroups', rlm@46: text: this.showGroupsText, rlm@46: checked: true, rlm@46: checkHandler: this.onShowGroupsClick, rlm@46: scope: this rlm@46: }); rlm@46: } rlm@46: this.hmenu.on('beforeshow', this.beforeMenuShow, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onGroupByClick : function(){ rlm@46: this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex)); rlm@46: this.beforeMenuShow(); rlm@46: }, rlm@46: rlm@46: rlm@46: onShowGroupsClick : function(mi, checked){ rlm@46: if(checked){ rlm@46: this.onGroupByClick(); rlm@46: }else{ rlm@46: this.grid.store.clearGrouping(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: toggleGroup : function(group, expanded){ rlm@46: this.grid.stopEditing(true); rlm@46: group = Ext.getDom(group); rlm@46: var gel = Ext.fly(group); rlm@46: expanded = expanded !== undefined ? rlm@46: expanded : gel.hasClass('x-grid-group-collapsed'); rlm@46: rlm@46: this.state[gel.dom.id] = expanded; rlm@46: gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed'); rlm@46: }, rlm@46: rlm@46: rlm@46: toggleAllGroups : function(expanded){ rlm@46: var groups = this.getGroups(); rlm@46: for(var i = 0, len = groups.length; i < len; i++){ rlm@46: this.toggleGroup(groups[i], expanded); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: expandAllGroups : function(){ rlm@46: this.toggleAllGroups(true); rlm@46: }, rlm@46: rlm@46: rlm@46: collapseAllGroups : function(){ rlm@46: this.toggleAllGroups(false); rlm@46: }, rlm@46: rlm@46: rlm@46: interceptMouse : function(e){ rlm@46: var hd = e.getTarget('.x-grid-group-hd', this.mainBody); rlm@46: if(hd){ rlm@46: e.stopEvent(); rlm@46: this.toggleGroup(hd.parentNode); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getGroup : function(v, r, groupRenderer, rowIndex, colIndex, ds){ rlm@46: var g = groupRenderer ? groupRenderer(v, {}, r, rowIndex, colIndex, ds) : String(v); rlm@46: if(g === ''){ rlm@46: g = this.cm.config[colIndex].emptyGroupText || this.emptyGroupText; rlm@46: } rlm@46: return g; rlm@46: }, rlm@46: rlm@46: rlm@46: getGroupField : function(){ rlm@46: return this.grid.store.getGroupState(); rlm@46: }, rlm@46: rlm@46: rlm@46: renderRows : function(){ rlm@46: var groupField = this.getGroupField(); rlm@46: var eg = !!groupField; rlm@46: rlm@46: if(this.hideGroupedColumn) { rlm@46: var colIndex = this.cm.findColumnIndex(groupField); rlm@46: if(!eg && this.lastGroupField !== undefined) { rlm@46: this.mainBody.update(''); rlm@46: this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField), false); rlm@46: delete this.lastGroupField; rlm@46: }else if (eg && this.lastGroupField === undefined) { rlm@46: this.lastGroupField = groupField; rlm@46: this.cm.setHidden(colIndex, true); rlm@46: }else if (eg && this.lastGroupField !== undefined && groupField !== this.lastGroupField) { rlm@46: this.mainBody.update(''); rlm@46: var oldIndex = this.cm.findColumnIndex(this.lastGroupField); rlm@46: this.cm.setHidden(oldIndex, false); rlm@46: this.lastGroupField = groupField; rlm@46: this.cm.setHidden(colIndex, true); rlm@46: } rlm@46: } rlm@46: return Ext.grid.GroupingView.superclass.renderRows.apply( rlm@46: this, arguments); rlm@46: }, rlm@46: rlm@46: rlm@46: doRender : function(cs, rs, ds, startRow, colCount, stripe){ rlm@46: if(rs.length < 1){ rlm@46: return ''; rlm@46: } rlm@46: var groupField = this.getGroupField(); rlm@46: var colIndex = this.cm.findColumnIndex(groupField); rlm@46: rlm@46: this.enableGrouping = !!groupField; rlm@46: rlm@46: if(!this.enableGrouping || this.isUpdating){ rlm@46: return Ext.grid.GroupingView.superclass.doRender.apply( rlm@46: this, arguments); rlm@46: } rlm@46: var gstyle = 'width:'+this.getTotalWidth()+';'; rlm@46: rlm@46: var gidPrefix = this.grid.getGridEl().id; rlm@46: var cfg = this.cm.config[colIndex]; rlm@46: var groupRenderer = cfg.groupRenderer || cfg.renderer; rlm@46: var prefix = this.showGroupName ? rlm@46: (cfg.groupName || cfg.header)+': ' : ''; rlm@46: rlm@46: var groups = [], curGroup, i, len, gid; rlm@46: for(i = 0, len = rs.length; i < len; i++){ rlm@46: var rowIndex = startRow + i; rlm@46: var r = rs[i], rlm@46: gvalue = r.data[groupField], rlm@46: g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds); rlm@46: if(!curGroup || curGroup.group != g){ rlm@46: gid = gidPrefix + '-gp-' + groupField + '-' + Ext.util.Format.htmlEncode(g); rlm@46: rlm@46: rlm@46: var isCollapsed = typeof this.state[gid] !== 'undefined' ? !this.state[gid] : this.startCollapsed; rlm@46: var gcls = isCollapsed ? 'x-grid-group-collapsed' : ''; rlm@46: curGroup = { rlm@46: group: g, rlm@46: gvalue: gvalue, rlm@46: text: prefix + g, rlm@46: groupId: gid, rlm@46: startRow: rowIndex, rlm@46: rs: [r], rlm@46: cls: gcls, rlm@46: style: gstyle rlm@46: }; rlm@46: groups.push(curGroup); rlm@46: }else{ rlm@46: curGroup.rs.push(r); rlm@46: } rlm@46: r._groupId = gid; rlm@46: } rlm@46: rlm@46: var buf = []; rlm@46: for(i = 0, len = groups.length; i < len; i++){ rlm@46: var g = groups[i]; rlm@46: this.doGroupStart(buf, g, cs, ds, colCount); rlm@46: buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call( rlm@46: this, cs, g.rs, ds, g.startRow, colCount, stripe); rlm@46: rlm@46: this.doGroupEnd(buf, g, cs, ds, colCount); rlm@46: } rlm@46: return buf.join(''); rlm@46: }, rlm@46: rlm@46: rlm@46: getGroupId : function(value){ rlm@46: var gidPrefix = this.grid.getGridEl().id; rlm@46: var groupField = this.getGroupField(); rlm@46: var colIndex = this.cm.findColumnIndex(groupField); rlm@46: var cfg = this.cm.config[colIndex]; rlm@46: var groupRenderer = cfg.groupRenderer || cfg.renderer; rlm@46: var gtext = this.getGroup(value, {data:{}}, groupRenderer, 0, colIndex, this.ds); rlm@46: return gidPrefix + '-gp-' + groupField + '-' + Ext.util.Format.htmlEncode(value); rlm@46: }, rlm@46: rlm@46: rlm@46: doGroupStart : function(buf, g, cs, ds, colCount){ rlm@46: buf[buf.length] = this.startGroup.apply(g); rlm@46: }, rlm@46: rlm@46: rlm@46: doGroupEnd : function(buf, g, cs, ds, colCount){ rlm@46: buf[buf.length] = this.endGroup; rlm@46: }, rlm@46: rlm@46: rlm@46: getRows : function(){ rlm@46: if(!this.enableGrouping){ rlm@46: return Ext.grid.GroupingView.superclass.getRows.call(this); rlm@46: } rlm@46: var r = []; rlm@46: var g, gs = this.getGroups(); rlm@46: for(var i = 0, len = gs.length; i < len; i++){ rlm@46: g = gs[i].childNodes[1].childNodes; rlm@46: for(var j = 0, jlen = g.length; j < jlen; j++){ rlm@46: r[r.length] = g[j]; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: updateGroupWidths : function(){ rlm@46: if(!this.enableGrouping || !this.hasRows()){ rlm@46: return; rlm@46: } rlm@46: var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.scrollOffset) +'px'; rlm@46: var gs = this.getGroups(); rlm@46: for(var i = 0, len = gs.length; i < len; i++){ rlm@46: gs[i].firstChild.style.width = tw; rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onColumnWidthUpdated : function(col, w, tw){ rlm@46: this.updateGroupWidths(); rlm@46: }, rlm@46: rlm@46: rlm@46: onAllColumnWidthsUpdated : function(ws, tw){ rlm@46: this.updateGroupWidths(); rlm@46: }, rlm@46: rlm@46: rlm@46: onColumnHiddenUpdated : function(col, hidden, tw){ rlm@46: this.updateGroupWidths(); rlm@46: }, rlm@46: rlm@46: rlm@46: onLayout : function(){ rlm@46: this.updateGroupWidths(); rlm@46: }, rlm@46: rlm@46: rlm@46: onBeforeRowSelect : function(sm, rowIndex){ rlm@46: if(!this.enableGrouping){ rlm@46: return; rlm@46: } rlm@46: var row = this.getRow(rowIndex); rlm@46: if(row && !row.offsetParent){ rlm@46: var g = this.findGroup(row); rlm@46: this.toggleGroup(g, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: groupByText: 'Group By This Field', rlm@46: rlm@46: showGroupsText: 'Show in Groups' rlm@46: }); rlm@46: rlm@46: Ext.grid.GroupingView.GROUP_ID = 1000; rlm@46: rlm@46: rlm@46: Ext.grid.HeaderDragZone = function(grid, hd, hd2){ rlm@46: this.grid = grid; rlm@46: this.view = grid.getView(); rlm@46: this.ddGroup = "gridHeader" + this.grid.getGridEl().id; rlm@46: Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd); rlm@46: if(hd2){ rlm@46: this.setHandleElId(Ext.id(hd)); rlm@46: this.setOuterHandleElId(Ext.id(hd2)); rlm@46: } rlm@46: this.scroll = false; rlm@46: }; rlm@46: Ext.extend(Ext.grid.HeaderDragZone, Ext.dd.DragZone, { rlm@46: maxDragWidth: 120, rlm@46: getDragData : function(e){ rlm@46: var t = Ext.lib.Event.getTarget(e); rlm@46: var h = this.view.findHeaderCell(t); rlm@46: if(h){ rlm@46: return {ddel: h.firstChild, header:h}; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onInitDrag : function(e){ rlm@46: this.view.headersDisabled = true; rlm@46: var clone = this.dragData.ddel.cloneNode(true); rlm@46: clone.id = Ext.id(); rlm@46: clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px"; rlm@46: this.proxy.update(clone); rlm@46: return true; rlm@46: }, rlm@46: rlm@46: afterValidDrop : function(){ rlm@46: var v = this.view; rlm@46: setTimeout(function(){ rlm@46: v.headersDisabled = false; rlm@46: }, 50); rlm@46: }, rlm@46: rlm@46: afterInvalidDrop : function(){ rlm@46: var v = this.view; rlm@46: setTimeout(function(){ rlm@46: v.headersDisabled = false; rlm@46: }, 50); rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: rlm@46: Ext.grid.HeaderDropZone = function(grid, hd, hd2){ rlm@46: this.grid = grid; rlm@46: this.view = grid.getView(); rlm@46: rlm@46: this.proxyTop = Ext.DomHelper.append(document.body, { rlm@46: cls:"col-move-top", html:" " rlm@46: }, true); rlm@46: this.proxyBottom = Ext.DomHelper.append(document.body, { rlm@46: cls:"col-move-bottom", html:" " rlm@46: }, true); rlm@46: this.proxyTop.hide = this.proxyBottom.hide = function(){ rlm@46: this.setLeftTop(-100,-100); rlm@46: this.setStyle("visibility", "hidden"); rlm@46: }; rlm@46: this.ddGroup = "gridHeader" + this.grid.getGridEl().id; rlm@46: rlm@46: rlm@46: Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom); rlm@46: }; rlm@46: Ext.extend(Ext.grid.HeaderDropZone, Ext.dd.DropZone, { rlm@46: proxyOffsets : [-4, -9], rlm@46: fly: Ext.Element.fly, rlm@46: rlm@46: getTargetFromEvent : function(e){ rlm@46: var t = Ext.lib.Event.getTarget(e); rlm@46: var cindex = this.view.findCellIndex(t); rlm@46: if(cindex !== false){ rlm@46: return this.view.getHeaderCell(cindex); rlm@46: } rlm@46: }, rlm@46: rlm@46: nextVisible : function(h){ rlm@46: var v = this.view, cm = this.grid.colModel; rlm@46: h = h.nextSibling; rlm@46: while(h){ rlm@46: if(!cm.isHidden(v.getCellIndex(h))){ rlm@46: return h; rlm@46: } rlm@46: h = h.nextSibling; rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: prevVisible : function(h){ rlm@46: var v = this.view, cm = this.grid.colModel; rlm@46: h = h.prevSibling; rlm@46: while(h){ rlm@46: if(!cm.isHidden(v.getCellIndex(h))){ rlm@46: return h; rlm@46: } rlm@46: h = h.prevSibling; rlm@46: } rlm@46: return null; rlm@46: }, rlm@46: rlm@46: positionIndicator : function(h, n, e){ rlm@46: var x = Ext.lib.Event.getPageX(e); rlm@46: var r = Ext.lib.Dom.getRegion(n.firstChild); rlm@46: var px, pt, py = r.top + this.proxyOffsets[1]; rlm@46: if((r.right - x) <= (r.right-r.left)/2){ rlm@46: px = r.right+this.view.borderWidth; rlm@46: pt = "after"; rlm@46: }else{ rlm@46: px = r.left; rlm@46: pt = "before"; rlm@46: } rlm@46: var oldIndex = this.view.getCellIndex(h); rlm@46: var newIndex = this.view.getCellIndex(n); rlm@46: rlm@46: if(this.grid.colModel.isFixed(newIndex)){ rlm@46: return false; rlm@46: } rlm@46: rlm@46: var locked = this.grid.colModel.isLocked(newIndex); rlm@46: rlm@46: if(pt == "after"){ rlm@46: newIndex++; rlm@46: } rlm@46: if(oldIndex < newIndex){ rlm@46: newIndex--; rlm@46: } rlm@46: if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){ rlm@46: return false; rlm@46: } rlm@46: px += this.proxyOffsets[0]; rlm@46: this.proxyTop.setLeftTop(px, py); rlm@46: this.proxyTop.show(); rlm@46: if(!this.bottomOffset){ rlm@46: this.bottomOffset = this.view.mainHd.getHeight(); rlm@46: } rlm@46: this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset); rlm@46: this.proxyBottom.show(); rlm@46: return pt; rlm@46: }, rlm@46: rlm@46: onNodeEnter : function(n, dd, e, data){ rlm@46: if(data.header != n){ rlm@46: this.positionIndicator(data.header, n, e); rlm@46: } rlm@46: }, rlm@46: rlm@46: onNodeOver : function(n, dd, e, data){ rlm@46: var result = false; rlm@46: if(data.header != n){ rlm@46: result = this.positionIndicator(data.header, n, e); rlm@46: } rlm@46: if(!result){ rlm@46: this.proxyTop.hide(); rlm@46: this.proxyBottom.hide(); rlm@46: } rlm@46: return result ? this.dropAllowed : this.dropNotAllowed; rlm@46: }, rlm@46: rlm@46: onNodeOut : function(n, dd, e, data){ rlm@46: this.proxyTop.hide(); rlm@46: this.proxyBottom.hide(); rlm@46: }, rlm@46: rlm@46: onNodeDrop : function(n, dd, e, data){ rlm@46: var h = data.header; rlm@46: if(h != n){ rlm@46: var cm = this.grid.colModel; rlm@46: var x = Ext.lib.Event.getPageX(e); rlm@46: var r = Ext.lib.Dom.getRegion(n.firstChild); rlm@46: var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before"; rlm@46: var oldIndex = this.view.getCellIndex(h); rlm@46: var newIndex = this.view.getCellIndex(n); rlm@46: var locked = cm.isLocked(newIndex); rlm@46: if(pt == "after"){ rlm@46: newIndex++; rlm@46: } rlm@46: if(oldIndex < newIndex){ rlm@46: newIndex--; rlm@46: } rlm@46: if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){ rlm@46: return false; rlm@46: } rlm@46: cm.setLocked(oldIndex, locked, true); rlm@46: cm.moveColumn(oldIndex, newIndex); rlm@46: this.grid.fireEvent("columnmove", oldIndex, newIndex); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.GridView.ColumnDragZone = function(grid, hd){ rlm@46: Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null); rlm@46: this.proxy.el.addClass('x-grid3-col-dd'); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.GridView.ColumnDragZone, Ext.grid.HeaderDragZone, { rlm@46: handleMouseDown : function(e){ rlm@46: rlm@46: }, rlm@46: rlm@46: callHandleMouseDown : function(e){ rlm@46: Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e); rlm@46: } rlm@46: }); rlm@46: Ext.grid.SplitDragZone = function(grid, hd, hd2){ rlm@46: this.grid = grid; rlm@46: this.view = grid.getView(); rlm@46: this.proxy = this.view.resizeProxy; rlm@46: Ext.grid.SplitDragZone.superclass.constructor.call(this, hd, rlm@46: "gridSplitters" + this.grid.getGridEl().id, { rlm@46: dragElId : Ext.id(this.proxy.dom), resizeFrame:false rlm@46: }); rlm@46: this.setHandleElId(Ext.id(hd)); rlm@46: this.setOuterHandleElId(Ext.id(hd2)); rlm@46: this.scroll = false; rlm@46: }; rlm@46: Ext.extend(Ext.grid.SplitDragZone, Ext.dd.DDProxy, { rlm@46: fly: Ext.Element.fly, rlm@46: rlm@46: b4StartDrag : function(x, y){ rlm@46: this.view.headersDisabled = true; rlm@46: this.proxy.setHeight(this.view.mainWrap.getHeight()); rlm@46: var w = this.cm.getColumnWidth(this.cellIndex); rlm@46: var minw = Math.max(w-this.grid.minColumnWidth, 0); rlm@46: this.resetConstraints(); rlm@46: this.setXConstraint(minw, 1000); rlm@46: this.setYConstraint(0, 0); rlm@46: this.minX = x - minw; rlm@46: this.maxX = x + 1000; rlm@46: this.startPos = x; rlm@46: Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y); rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseDown : function(e){ rlm@46: ev = Ext.EventObject.setEvent(e); rlm@46: var t = this.fly(ev.getTarget()); rlm@46: if(t.hasClass("x-grid-split")){ rlm@46: this.cellIndex = this.view.getCellIndex(t.dom); rlm@46: this.split = t.dom; rlm@46: this.cm = this.grid.colModel; rlm@46: if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){ rlm@46: Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: endDrag : function(e){ rlm@46: this.view.headersDisabled = false; rlm@46: var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e)); rlm@46: var diff = endX - this.startPos; rlm@46: this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff); rlm@46: }, rlm@46: rlm@46: autoOffset : function(){ rlm@46: this.setDelta(0,0); rlm@46: } rlm@46: }); rlm@46: Ext.grid.GridDragZone = function(grid, config){ rlm@46: this.view = grid.getView(); rlm@46: Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config); rlm@46: if(this.view.lockedBody){ rlm@46: this.setHandleElId(Ext.id(this.view.mainBody.dom)); rlm@46: this.setOuterHandleElId(Ext.id(this.view.lockedBody.dom)); rlm@46: } rlm@46: this.scroll = false; rlm@46: this.grid = grid; rlm@46: this.ddel = document.createElement('div'); rlm@46: this.ddel.className = 'x-grid-dd-wrap'; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, { rlm@46: ddGroup : "GridDD", rlm@46: rlm@46: getDragData : function(e){ rlm@46: var t = Ext.lib.Event.getTarget(e); rlm@46: var rowIndex = this.view.findRowIndex(t); rlm@46: if(rowIndex !== false){ rlm@46: var sm = this.grid.selModel; rlm@46: if(!sm.isSelected(rowIndex) || e.hasModifier()){ rlm@46: sm.handleMouseDown(this.grid, rowIndex, e); rlm@46: } rlm@46: return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()}; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onInitDrag : function(e){ rlm@46: var data = this.dragData; rlm@46: this.ddel.innerHTML = this.grid.getDragDropText(); rlm@46: this.proxy.update(this.ddel); rlm@46: }, rlm@46: rlm@46: afterRepair : function(){ rlm@46: this.dragging = false; rlm@46: }, rlm@46: rlm@46: getRepairXY : function(e, data){ rlm@46: return false; rlm@46: }, rlm@46: rlm@46: onEndDrag : function(data, e){ rlm@46: }, rlm@46: rlm@46: onValidDrop : function(dd, e, id){ rlm@46: this.hideProxy(); rlm@46: }, rlm@46: rlm@46: beforeInvalidDrop : function(e, id){ rlm@46: rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.ColumnModel = function(config){ rlm@46: rlm@46: this.defaultWidth = 100; rlm@46: rlm@46: rlm@46: this.defaultSortable = false; rlm@46: rlm@46: rlm@46: if(config.columns){ rlm@46: Ext.apply(this, config); rlm@46: this.setConfig(config.columns, true); rlm@46: }else{ rlm@46: this.setConfig(config, true); rlm@46: } rlm@46: this.addEvents( rlm@46: rlm@46: "widthchange", rlm@46: rlm@46: "headerchange", rlm@46: rlm@46: "hiddenchange", rlm@46: rlm@46: "columnmoved", rlm@46: "columnlockchange", rlm@46: rlm@46: "configchange" rlm@46: ); rlm@46: Ext.grid.ColumnModel.superclass.constructor.call(this); rlm@46: }; rlm@46: Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: getColumnId : function(index){ rlm@46: return this.config[index].id; rlm@46: }, rlm@46: rlm@46: rlm@46: setConfig : function(config, initial){ rlm@46: if(!initial){ delete this.totalWidth; rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: var c = this.config[i]; rlm@46: if(c.editor){ rlm@46: c.editor.destroy(); rlm@46: } rlm@46: } rlm@46: } rlm@46: this.config = config; rlm@46: this.lookup = {}; rlm@46: for(var i = 0, len = config.length; i < len; i++){ rlm@46: var c = config[i]; rlm@46: if(typeof c.renderer == "string"){ rlm@46: c.renderer = Ext.util.Format[c.renderer]; rlm@46: } rlm@46: if(typeof c.id == "undefined"){ rlm@46: c.id = i; rlm@46: } rlm@46: if(c.editor && c.editor.isFormField){ rlm@46: c.editor = new Ext.grid.GridEditor(c.editor); rlm@46: } rlm@46: this.lookup[c.id] = c; rlm@46: } rlm@46: if(!initial){ rlm@46: this.fireEvent('configchange', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnById : function(id){ rlm@46: return this.lookup[id]; rlm@46: }, rlm@46: rlm@46: rlm@46: getIndexById : function(id){ rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: if(this.config[i].id == id){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: return -1; rlm@46: }, rlm@46: rlm@46: moveColumn : function(oldIndex, newIndex){ rlm@46: var c = this.config[oldIndex]; rlm@46: this.config.splice(oldIndex, 1); rlm@46: this.config.splice(newIndex, 0, c); rlm@46: this.dataMap = null; rlm@46: this.fireEvent("columnmoved", this, oldIndex, newIndex); rlm@46: }, rlm@46: rlm@46: isLocked : function(colIndex){ rlm@46: return this.config[colIndex].locked === true; rlm@46: }, rlm@46: rlm@46: setLocked : function(colIndex, value, suppressEvent){ rlm@46: if(this.isLocked(colIndex) == value){ rlm@46: return; rlm@46: } rlm@46: this.config[colIndex].locked = value; rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent("columnlockchange", this, colIndex, value); rlm@46: } rlm@46: }, rlm@46: rlm@46: getTotalLockedWidth : function(){ rlm@46: var totalWidth = 0; rlm@46: for(var i = 0; i < this.config.length; i++){ rlm@46: if(this.isLocked(i) && !this.isHidden(i)){ rlm@46: this.totalWidth += this.getColumnWidth(i); rlm@46: } rlm@46: } rlm@46: return totalWidth; rlm@46: }, rlm@46: rlm@46: getLockedCount : function(){ rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: if(!this.isLocked(i)){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnCount : function(visibleOnly){ rlm@46: if(visibleOnly === true){ rlm@46: var c = 0; rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: if(!this.isHidden(i)){ rlm@46: c++; rlm@46: } rlm@46: } rlm@46: return c; rlm@46: } rlm@46: return this.config.length; rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnsBy : function(fn, scope){ rlm@46: var r = []; rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: var c = this.config[i]; rlm@46: if(fn.call(scope||this, c, i) === true){ rlm@46: r[r.length] = c; rlm@46: } rlm@46: } rlm@46: return r; rlm@46: }, rlm@46: rlm@46: rlm@46: isSortable : function(col){ rlm@46: if(typeof this.config[col].sortable == "undefined"){ rlm@46: return this.defaultSortable; rlm@46: } rlm@46: return this.config[col].sortable; rlm@46: }, rlm@46: rlm@46: rlm@46: isMenuDisabled : function(col){ rlm@46: return !!this.config[col].menuDisabled; rlm@46: }, rlm@46: rlm@46: rlm@46: getRenderer : function(col){ rlm@46: if(!this.config[col].renderer){ rlm@46: return Ext.grid.ColumnModel.defaultRenderer; rlm@46: } rlm@46: return this.config[col].renderer; rlm@46: }, rlm@46: rlm@46: rlm@46: setRenderer : function(col, fn){ rlm@46: this.config[col].renderer = fn; rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnWidth : function(col){ rlm@46: return this.config[col].width || this.defaultWidth; rlm@46: }, rlm@46: rlm@46: rlm@46: setColumnWidth : function(col, width, suppressEvent){ rlm@46: this.config[col].width = width; rlm@46: this.totalWidth = null; rlm@46: if(!suppressEvent){ rlm@46: this.fireEvent("widthchange", this, col, width); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getTotalWidth : function(includeHidden){ rlm@46: if(!this.totalWidth){ rlm@46: this.totalWidth = 0; rlm@46: for(var i = 0, len = this.config.length; i < len; i++){ rlm@46: if(includeHidden || !this.isHidden(i)){ rlm@46: this.totalWidth += this.getColumnWidth(i); rlm@46: } rlm@46: } rlm@46: } rlm@46: return this.totalWidth; rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnHeader : function(col){ rlm@46: return this.config[col].header; rlm@46: }, rlm@46: rlm@46: rlm@46: setColumnHeader : function(col, header){ rlm@46: this.config[col].header = header; rlm@46: this.fireEvent("headerchange", this, col, header); rlm@46: }, rlm@46: rlm@46: rlm@46: getColumnTooltip : function(col){ rlm@46: return this.config[col].tooltip; rlm@46: }, rlm@46: rlm@46: setColumnTooltip : function(col, tooltip){ rlm@46: this.config[col].tooltip = tooltip; rlm@46: }, rlm@46: rlm@46: rlm@46: getDataIndex : function(col){ rlm@46: return this.config[col].dataIndex; rlm@46: }, rlm@46: rlm@46: rlm@46: setDataIndex : function(col, dataIndex){ rlm@46: this.config[col].dataIndex = dataIndex; rlm@46: }, rlm@46: rlm@46: rlm@46: findColumnIndex : function(dataIndex){ rlm@46: var c = this.config; rlm@46: for(var i = 0, len = c.length; i < len; i++){ rlm@46: if(c[i].dataIndex == dataIndex){ rlm@46: return i; rlm@46: } rlm@46: } rlm@46: return -1; rlm@46: }, rlm@46: rlm@46: rlm@46: isCellEditable : function(colIndex, rowIndex){ rlm@46: return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: getCellEditor : function(colIndex, rowIndex){ rlm@46: return this.config[colIndex].editor; rlm@46: }, rlm@46: rlm@46: rlm@46: setEditable : function(col, editable){ rlm@46: this.config[col].editable = editable; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: isHidden : function(colIndex){ rlm@46: return this.config[colIndex].hidden; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: isFixed : function(colIndex){ rlm@46: return this.config[colIndex].fixed; rlm@46: }, rlm@46: rlm@46: rlm@46: isResizable : function(colIndex){ rlm@46: return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true; rlm@46: }, rlm@46: rlm@46: setHidden : function(colIndex, hidden){ rlm@46: var c = this.config[colIndex]; rlm@46: if(c.hidden !== hidden){ rlm@46: c.hidden = hidden; rlm@46: this.totalWidth = null; rlm@46: this.fireEvent("hiddenchange", this, colIndex, hidden); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setEditor : function(col, editor){ rlm@46: this.config[col].editor = editor; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.grid.ColumnModel.defaultRenderer = function(value){ rlm@46: if(typeof value == "string" && value.length < 1){ rlm@46: return " "; rlm@46: } rlm@46: return value; rlm@46: }; rlm@46: rlm@46: Ext.grid.DefaultColumnModel = Ext.grid.ColumnModel; rlm@46: rlm@46: rlm@46: Ext.grid.AbstractSelectionModel = function(){ rlm@46: this.locked = false; rlm@46: Ext.grid.AbstractSelectionModel.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.AbstractSelectionModel, Ext.util.Observable, { rlm@46: rlm@46: init : function(grid){ rlm@46: this.grid = grid; rlm@46: this.initEvents(); rlm@46: }, rlm@46: rlm@46: rlm@46: lock : function(){ rlm@46: this.locked = true; rlm@46: }, rlm@46: rlm@46: rlm@46: unlock : function(){ rlm@46: this.locked = false; rlm@46: }, rlm@46: rlm@46: rlm@46: isLocked : function(){ rlm@46: return this.locked; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.grid.RowSelectionModel = function(config){ rlm@46: Ext.apply(this, config); rlm@46: this.selections = new Ext.util.MixedCollection(false, function(o){ rlm@46: return o.id; rlm@46: }); rlm@46: rlm@46: this.last = false; rlm@46: this.lastActive = false; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "selectionchange", rlm@46: rlm@46: "beforerowselect", rlm@46: rlm@46: "rowselect", rlm@46: rlm@46: "rowdeselect" rlm@46: ); rlm@46: rlm@46: Ext.grid.RowSelectionModel.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.RowSelectionModel, Ext.grid.AbstractSelectionModel, { rlm@46: rlm@46: singleSelect : false, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: rlm@46: if(!this.grid.enableDragDrop && !this.grid.enableDrag){ rlm@46: this.grid.on("rowmousedown", this.handleMouseDown, this); rlm@46: }else{ this.grid.on("rowclick", function(grid, rowIndex, e) { rlm@46: if(e.button === 0 && !e.shiftKey && !e.ctrlKey) { rlm@46: this.selectRow(rowIndex, false); rlm@46: grid.view.focusRow(rowIndex); rlm@46: } rlm@46: }, this); rlm@46: } rlm@46: rlm@46: this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), { rlm@46: "up" : function(e){ rlm@46: if(!e.shiftKey){ rlm@46: this.selectPrevious(e.shiftKey); rlm@46: }else if(this.last !== false && this.lastActive !== false){ rlm@46: var last = this.last; rlm@46: this.selectRange(this.last, this.lastActive-1); rlm@46: this.grid.getView().focusRow(this.lastActive); rlm@46: if(last !== false){ rlm@46: this.last = last; rlm@46: } rlm@46: }else{ rlm@46: this.selectFirstRow(); rlm@46: } rlm@46: }, rlm@46: "down" : function(e){ rlm@46: if(!e.shiftKey){ rlm@46: this.selectNext(e.shiftKey); rlm@46: }else if(this.last !== false && this.lastActive !== false){ rlm@46: var last = this.last; rlm@46: this.selectRange(this.last, this.lastActive+1); rlm@46: this.grid.getView().focusRow(this.lastActive); rlm@46: if(last !== false){ rlm@46: this.last = last; rlm@46: } rlm@46: }else{ rlm@46: this.selectFirstRow(); rlm@46: } rlm@46: }, rlm@46: scope: this rlm@46: }); rlm@46: rlm@46: var view = this.grid.view; rlm@46: view.on("refresh", this.onRefresh, this); rlm@46: view.on("rowupdated", this.onRowUpdated, this); rlm@46: view.on("rowremoved", this.onRemove, this); rlm@46: }, rlm@46: rlm@46: onRefresh : function(){ rlm@46: var ds = this.grid.store, index; rlm@46: var s = this.getSelections(); rlm@46: this.clearSelections(true); rlm@46: for(var i = 0, len = s.length; i < len; i++){ rlm@46: var r = s[i]; rlm@46: if((index = ds.indexOfId(r.id)) != -1){ rlm@46: this.selectRow(index, true); rlm@46: } rlm@46: } rlm@46: if(s.length != this.selections.getCount()){ rlm@46: this.fireEvent("selectionchange", this); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRemove : function(v, index, r){ rlm@46: if(this.selections.remove(r) !== false){ rlm@46: this.fireEvent('selectionchange', this); rlm@46: } rlm@46: }, rlm@46: rlm@46: onRowUpdated : function(v, index, r){ rlm@46: if(this.isSelected(r)){ rlm@46: v.onRowSelect(index); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectRecords : function(records, keepExisting){ rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: var ds = this.grid.store; rlm@46: for(var i = 0, len = records.length; i < len; i++){ rlm@46: this.selectRow(ds.indexOf(records[i]), true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getCount : function(){ rlm@46: return this.selections.length; rlm@46: }, rlm@46: rlm@46: rlm@46: selectFirstRow : function(){ rlm@46: this.selectRow(0); rlm@46: }, rlm@46: rlm@46: rlm@46: selectLastRow : function(keepExisting){ rlm@46: this.selectRow(this.grid.store.getCount() - 1, keepExisting); rlm@46: }, rlm@46: rlm@46: rlm@46: selectNext : function(keepExisting){ rlm@46: if(this.hasNext()){ rlm@46: this.selectRow(this.last+1, keepExisting); rlm@46: this.grid.getView().focusRow(this.last); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: selectPrevious : function(keepExisting){ rlm@46: if(this.hasPrevious()){ rlm@46: this.selectRow(this.last-1, keepExisting); rlm@46: this.grid.getView().focusRow(this.last); rlm@46: return true; rlm@46: } rlm@46: return false; rlm@46: }, rlm@46: rlm@46: rlm@46: hasNext : function(){ rlm@46: return this.last !== false && (this.last+1) < this.grid.store.getCount(); rlm@46: }, rlm@46: rlm@46: rlm@46: hasPrevious : function(){ rlm@46: return !!this.last; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: getSelections : function(){ rlm@46: return [].concat(this.selections.items); rlm@46: }, rlm@46: rlm@46: rlm@46: getSelected : function(){ rlm@46: return this.selections.itemAt(0); rlm@46: }, rlm@46: rlm@46: rlm@46: each : function(fn, scope){ rlm@46: var s = this.getSelections(); rlm@46: for(var i = 0, len = s.length; i < len; i++){ rlm@46: if(fn.call(scope || this, s[i], i) === false){ rlm@46: return false; rlm@46: } rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: rlm@46: clearSelections : function(fast){ rlm@46: if(this.locked) return; rlm@46: if(fast !== true){ rlm@46: var ds = this.grid.store; rlm@46: var s = this.selections; rlm@46: s.each(function(r){ rlm@46: this.deselectRow(ds.indexOfId(r.id)); rlm@46: }, this); rlm@46: s.clear(); rlm@46: }else{ rlm@46: this.selections.clear(); rlm@46: } rlm@46: this.last = false; rlm@46: }, rlm@46: rlm@46: rlm@46: rlm@46: selectAll : function(){ rlm@46: if(this.locked) return; rlm@46: this.selections.clear(); rlm@46: for(var i = 0, len = this.grid.store.getCount(); i < len; i++){ rlm@46: this.selectRow(i, true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hasSelection : function(){ rlm@46: return this.selections.length > 0; rlm@46: }, rlm@46: rlm@46: rlm@46: isSelected : function(index){ rlm@46: var r = typeof index == "number" ? this.grid.store.getAt(index) : index; rlm@46: return (r && this.selections.key(r.id) ? true : false); rlm@46: }, rlm@46: rlm@46: rlm@46: isIdSelected : function(id){ rlm@46: return (this.selections.key(id) ? true : false); rlm@46: }, rlm@46: rlm@46: handleMouseDown : function(g, rowIndex, e){ rlm@46: if(e.button !== 0 || this.isLocked()){ rlm@46: return; rlm@46: }; rlm@46: var view = this.grid.getView(); rlm@46: if(e.shiftKey && this.last !== false){ rlm@46: var last = this.last; rlm@46: this.selectRange(last, rowIndex, e.ctrlKey); rlm@46: this.last = last; view.focusRow(rowIndex); rlm@46: }else{ rlm@46: var isSelected = this.isSelected(rowIndex); rlm@46: if(e.ctrlKey && isSelected){ rlm@46: this.deselectRow(rowIndex); rlm@46: }else if(!isSelected || this.getCount() > 1){ rlm@46: this.selectRow(rowIndex, e.ctrlKey || e.shiftKey); rlm@46: view.focusRow(rowIndex); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectRows : function(rows, keepExisting){ rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: for(var i = 0, len = rows.length; i < len; i++){ rlm@46: this.selectRow(rows[i], true); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectRange : function(startRow, endRow, keepExisting){ rlm@46: if(this.locked) return; rlm@46: if(!keepExisting){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: if(startRow <= endRow){ rlm@46: for(var i = startRow; i <= endRow; i++){ rlm@46: this.selectRow(i, true); rlm@46: } rlm@46: }else{ rlm@46: for(var i = startRow; i >= endRow; i--){ rlm@46: this.selectRow(i, true); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: deselectRange : function(startRow, endRow, preventViewNotify){ rlm@46: if(this.locked) return; rlm@46: for(var i = startRow; i <= endRow; i++){ rlm@46: this.deselectRow(i, preventViewNotify); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: selectRow : function(index, keepExisting, preventViewNotify){ rlm@46: if(this.locked || (index < 0 || index >= this.grid.store.getCount())) return; rlm@46: var r = this.grid.store.getAt(index); rlm@46: if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){ rlm@46: if(!keepExisting || this.singleSelect){ rlm@46: this.clearSelections(); rlm@46: } rlm@46: this.selections.add(r); rlm@46: this.last = this.lastActive = index; rlm@46: if(!preventViewNotify){ rlm@46: this.grid.getView().onRowSelect(index); rlm@46: } rlm@46: this.fireEvent("rowselect", this, index, r); rlm@46: this.fireEvent("selectionchange", this); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: deselectRow : function(index, preventViewNotify){ rlm@46: if(this.locked) return; rlm@46: if(this.last == index){ rlm@46: this.last = false; rlm@46: } rlm@46: if(this.lastActive == index){ rlm@46: this.lastActive = false; rlm@46: } rlm@46: var r = this.grid.store.getAt(index); rlm@46: if(r){ rlm@46: this.selections.remove(r); rlm@46: if(!preventViewNotify){ rlm@46: this.grid.getView().onRowDeselect(index); rlm@46: } rlm@46: this.fireEvent("rowdeselect", this, index, r); rlm@46: this.fireEvent("selectionchange", this); rlm@46: } rlm@46: }, rlm@46: rlm@46: restoreLast : function(){ rlm@46: if(this._last){ rlm@46: this.last = this._last; rlm@46: } rlm@46: }, rlm@46: rlm@46: acceptsNav : function(row, col, cm){ rlm@46: return !cm.isHidden(col) && cm.isCellEditable(col, row); rlm@46: }, rlm@46: rlm@46: onEditorKey : function(field, e){ rlm@46: var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor; rlm@46: var shift = e.shiftKey; rlm@46: if(k == e.TAB){ rlm@46: e.stopEvent(); rlm@46: ed.completeEdit(); rlm@46: if(shift){ rlm@46: newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this); rlm@46: }else{ rlm@46: newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this); rlm@46: } rlm@46: }else if(k == e.ENTER){ rlm@46: e.stopEvent(); rlm@46: ed.completeEdit(); rlm@46: if(this.moveEditorOnEnter !== false){ rlm@46: if(shift){ rlm@46: newCell = g.walkCells(ed.row - 1, ed.col, -1, this.acceptsNav, this); rlm@46: }else{ rlm@46: newCell = g.walkCells(ed.row + 1, ed.col, 1, this.acceptsNav, this); rlm@46: } rlm@46: } rlm@46: }else if(k == e.ESC){ rlm@46: ed.cancelEdit(); rlm@46: } rlm@46: if(newCell){ rlm@46: g.startEditing(newCell[0], newCell[1]); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.grid.CellSelectionModel = function(config){ rlm@46: Ext.apply(this, config); rlm@46: rlm@46: this.selection = null; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "beforecellselect", rlm@46: rlm@46: "cellselect", rlm@46: rlm@46: "selectionchange" rlm@46: ); rlm@46: rlm@46: Ext.grid.CellSelectionModel.superclass.constructor.call(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.CellSelectionModel, Ext.grid.AbstractSelectionModel, { rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: this.grid.on("cellmousedown", this.handleMouseDown, this); rlm@46: this.grid.getGridEl().on(Ext.isIE || Ext.isSafari3 ? "keydown" : "keypress", this.handleKeyDown, this); rlm@46: var view = this.grid.view; rlm@46: view.on("refresh", this.onViewChange, this); rlm@46: view.on("rowupdated", this.onRowUpdated, this); rlm@46: view.on("beforerowremoved", this.clearSelections, this); rlm@46: view.on("beforerowsinserted", this.clearSelections, this); rlm@46: if(this.grid.isEditor){ rlm@46: this.grid.on("beforeedit", this.beforeEdit, this); rlm@46: } rlm@46: }, rlm@46: rlm@46: beforeEdit : function(e){ rlm@46: this.select(e.row, e.column, false, true, e.record); rlm@46: }, rlm@46: rlm@46: onRowUpdated : function(v, index, r){ rlm@46: if(this.selection && this.selection.record == r){ rlm@46: v.onCellSelect(index, this.selection.cell[1]); rlm@46: } rlm@46: }, rlm@46: rlm@46: onViewChange : function(){ rlm@46: this.clearSelections(true); rlm@46: }, rlm@46: rlm@46: rlm@46: getSelectedCell : function(){ rlm@46: return this.selection ? this.selection.cell : null; rlm@46: }, rlm@46: rlm@46: rlm@46: clearSelections : function(preventNotify){ rlm@46: var s = this.selection; rlm@46: if(s){ rlm@46: if(preventNotify !== true){ rlm@46: this.grid.view.onCellDeselect(s.cell[0], s.cell[1]); rlm@46: } rlm@46: this.selection = null; rlm@46: this.fireEvent("selectionchange", this, null); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: hasSelection : function(){ rlm@46: return this.selection ? true : false; rlm@46: }, rlm@46: rlm@46: rlm@46: handleMouseDown : function(g, row, cell, e){ rlm@46: if(e.button !== 0 || this.isLocked()){ rlm@46: return; rlm@46: }; rlm@46: this.select(row, cell); rlm@46: }, rlm@46: rlm@46: rlm@46: select : function(rowIndex, colIndex, preventViewNotify, preventFocus, r){ rlm@46: if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){ rlm@46: this.clearSelections(); rlm@46: r = r || this.grid.store.getAt(rowIndex); rlm@46: this.selection = { rlm@46: record : r, rlm@46: cell : [rowIndex, colIndex] rlm@46: }; rlm@46: if(!preventViewNotify){ rlm@46: var v = this.grid.getView(); rlm@46: v.onCellSelect(rowIndex, colIndex); rlm@46: if(preventFocus !== true){ rlm@46: v.focusCell(rowIndex, colIndex); rlm@46: } rlm@46: } rlm@46: this.fireEvent("cellselect", this, rowIndex, colIndex); rlm@46: this.fireEvent("selectionchange", this, this.selection); rlm@46: } rlm@46: }, rlm@46: rlm@46: isSelectable : function(rowIndex, colIndex, cm){ rlm@46: return !cm.isHidden(colIndex); rlm@46: }, rlm@46: rlm@46: rlm@46: handleKeyDown : function(e){ rlm@46: if(!e.isNavKeyPress()){ rlm@46: return; rlm@46: } rlm@46: var g = this.grid, s = this.selection; rlm@46: if(!s){ rlm@46: e.stopEvent(); rlm@46: var cell = g.walkCells(0, 0, 1, this.isSelectable, this); rlm@46: if(cell){ rlm@46: this.select(cell[0], cell[1]); rlm@46: } rlm@46: return; rlm@46: } rlm@46: var sm = this; rlm@46: var walk = function(row, col, step){ rlm@46: return g.walkCells(row, col, step, sm.isSelectable, sm); rlm@46: }; rlm@46: var k = e.getKey(), r = s.cell[0], c = s.cell[1]; rlm@46: var newCell; rlm@46: rlm@46: switch(k){ rlm@46: case e.TAB: rlm@46: if(e.shiftKey){ rlm@46: newCell = walk(r, c-1, -1); rlm@46: }else{ rlm@46: newCell = walk(r, c+1, 1); rlm@46: } rlm@46: break; rlm@46: case e.DOWN: rlm@46: newCell = walk(r+1, c, 1); rlm@46: break; rlm@46: case e.UP: rlm@46: newCell = walk(r-1, c, -1); rlm@46: break; rlm@46: case e.RIGHT: rlm@46: newCell = walk(r, c+1, 1); rlm@46: break; rlm@46: case e.LEFT: rlm@46: newCell = walk(r, c-1, -1); rlm@46: break; rlm@46: case e.ENTER: rlm@46: if(g.isEditor && !g.editing){ rlm@46: g.startEditing(r, c); rlm@46: e.stopEvent(); rlm@46: return; rlm@46: } rlm@46: break; rlm@46: }; rlm@46: if(newCell){ rlm@46: this.select(newCell[0], newCell[1]); rlm@46: e.stopEvent(); rlm@46: } rlm@46: }, rlm@46: rlm@46: acceptsNav : function(row, col, cm){ rlm@46: return !cm.isHidden(col) && cm.isCellEditable(col, row); rlm@46: }, rlm@46: rlm@46: onEditorKey : function(field, e){ rlm@46: var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor; rlm@46: if(k == e.TAB){ rlm@46: if(e.shiftKey){ rlm@46: newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this); rlm@46: }else{ rlm@46: newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this); rlm@46: } rlm@46: e.stopEvent(); rlm@46: }else if(k == e.ENTER){ rlm@46: ed.completeEdit(); rlm@46: e.stopEvent(); rlm@46: }else if(k == e.ESC){ rlm@46: e.stopEvent(); rlm@46: ed.cancelEdit(); rlm@46: } rlm@46: if(newCell){ rlm@46: g.startEditing(newCell[0], newCell[1]); rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, { rlm@46: rlm@46: clicksToEdit: 2, rlm@46: rlm@46: isEditor : true, rlm@46: detectEdit: false, rlm@46: rlm@46: rlm@46: autoEncode : false, rlm@46: rlm@46: rlm@46: trackMouseOver: false, rlm@46: initComponent : function(){ rlm@46: Ext.grid.EditorGridPanel.superclass.initComponent.call(this); rlm@46: rlm@46: if(!this.selModel){ rlm@46: rlm@46: this.selModel = new Ext.grid.CellSelectionModel(); rlm@46: } rlm@46: rlm@46: this.activeEditor = null; rlm@46: rlm@46: this.addEvents( rlm@46: rlm@46: "beforeedit", rlm@46: rlm@46: "afteredit", rlm@46: rlm@46: "validateedit" rlm@46: ); rlm@46: }, rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.grid.EditorGridPanel.superclass.initEvents.call(this); rlm@46: rlm@46: this.on("bodyscroll", this.stopEditing, this, [true]); rlm@46: rlm@46: if(this.clicksToEdit == 1){ rlm@46: this.on("cellclick", this.onCellDblClick, this); rlm@46: }else { rlm@46: if(this.clicksToEdit == 'auto' && this.view.mainBody){ rlm@46: this.view.mainBody.on("mousedown", this.onAutoEditClick, this); rlm@46: } rlm@46: this.on("celldblclick", this.onCellDblClick, this); rlm@46: } rlm@46: this.getGridEl().addClass("xedit-grid"); rlm@46: }, rlm@46: rlm@46: onCellDblClick : function(g, row, col){ rlm@46: this.startEditing(row, col); rlm@46: }, rlm@46: rlm@46: onAutoEditClick : function(e, t){ rlm@46: if(e.button !== 0){ rlm@46: return; rlm@46: } rlm@46: var row = this.view.findRowIndex(t); rlm@46: var col = this.view.findCellIndex(t); rlm@46: if(row !== false && col !== false){ rlm@46: this.stopEditing(); rlm@46: if(this.selModel.getSelectedCell){ var sc = this.selModel.getSelectedCell(); rlm@46: if(sc && sc.cell[0] === row && sc.cell[1] === col){ rlm@46: this.startEditing(row, col); rlm@46: } rlm@46: }else{ rlm@46: if(this.selModel.isSelected(row)){ rlm@46: this.startEditing(row, col); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: onEditComplete : function(ed, value, startValue){ rlm@46: this.editing = false; rlm@46: this.activeEditor = null; rlm@46: ed.un("specialkey", this.selModel.onEditorKey, this.selModel); rlm@46: var r = ed.record; rlm@46: var field = this.colModel.getDataIndex(ed.col); rlm@46: value = this.postEditValue(value, startValue, r, field); rlm@46: if(String(value) !== String(startValue)){ rlm@46: var e = { rlm@46: grid: this, rlm@46: record: r, rlm@46: field: field, rlm@46: originalValue: startValue, rlm@46: value: value, rlm@46: row: ed.row, rlm@46: column: ed.col, rlm@46: cancel:false rlm@46: }; rlm@46: if(this.fireEvent("validateedit", e) !== false && !e.cancel){ rlm@46: r.set(field, e.value); rlm@46: delete e.cancel; rlm@46: this.fireEvent("afteredit", e); rlm@46: } rlm@46: } rlm@46: this.view.focusCell(ed.row, ed.col); rlm@46: }, rlm@46: rlm@46: rlm@46: startEditing : function(row, col){ rlm@46: this.stopEditing(); rlm@46: if(this.colModel.isCellEditable(col, row)){ rlm@46: this.view.ensureVisible(row, col, true); rlm@46: var r = this.store.getAt(row); rlm@46: var field = this.colModel.getDataIndex(col); rlm@46: var e = { rlm@46: grid: this, rlm@46: record: r, rlm@46: field: field, rlm@46: value: r.data[field], rlm@46: row: row, rlm@46: column: col, rlm@46: cancel:false rlm@46: }; rlm@46: if(this.fireEvent("beforeedit", e) !== false && !e.cancel){ rlm@46: this.editing = true; rlm@46: var ed = this.colModel.getCellEditor(col, row); rlm@46: if(!ed.rendered){ rlm@46: ed.render(this.view.getEditorParent(ed)); rlm@46: } rlm@46: (function(){ ed.row = row; rlm@46: ed.col = col; rlm@46: ed.record = r; rlm@46: ed.on("complete", this.onEditComplete, this, {single: true}); rlm@46: ed.on("specialkey", this.selModel.onEditorKey, this.selModel); rlm@46: this.activeEditor = ed; rlm@46: var v = this.preEditValue(r, field); rlm@46: ed.startEdit(this.view.getCell(row, col), v); rlm@46: }).defer(50, this); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: preEditValue : function(r, field){ rlm@46: return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlDecode(r.data[field]) : r.data[field]; rlm@46: }, rlm@46: rlm@46: postEditValue : function(value, originalValue, r, field){ rlm@46: return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value; rlm@46: }, rlm@46: rlm@46: rlm@46: stopEditing : function(cancel){ rlm@46: if(this.activeEditor){ rlm@46: this.activeEditor[cancel === true ? 'cancelEdit' : 'completeEdit'](); rlm@46: } rlm@46: this.activeEditor = null; rlm@46: } rlm@46: }); rlm@46: Ext.reg('editorgrid', Ext.grid.EditorGridPanel); rlm@46: Ext.grid.GridEditor = function(field, config){ rlm@46: Ext.grid.GridEditor.superclass.constructor.call(this, field, config); rlm@46: field.monitorTab = false; rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.GridEditor, Ext.Editor, { rlm@46: alignment: "tl-tl", rlm@46: autoSize: "width", rlm@46: hideEl : false, rlm@46: cls: "x-small-editor x-grid-editor", rlm@46: shim:false, rlm@46: shadow:false rlm@46: }); rlm@46: rlm@46: Ext.grid.PropertyRecord = Ext.data.Record.create([ rlm@46: {name:'name',type:'string'}, 'value' rlm@46: ]); rlm@46: rlm@46: rlm@46: Ext.grid.PropertyStore = function(grid, source){ rlm@46: this.grid = grid; rlm@46: this.store = new Ext.data.Store({ rlm@46: recordType : Ext.grid.PropertyRecord rlm@46: }); rlm@46: this.store.on('update', this.onUpdate, this); rlm@46: if(source){ rlm@46: this.setSource(source); rlm@46: } rlm@46: Ext.grid.PropertyStore.superclass.constructor.call(this); rlm@46: }; rlm@46: Ext.extend(Ext.grid.PropertyStore, Ext.util.Observable, { rlm@46: setSource : function(o){ rlm@46: this.source = o; rlm@46: this.store.removeAll(); rlm@46: var data = []; rlm@46: for(var k in o){ rlm@46: if(this.isEditableValue(o[k])){ rlm@46: data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k)); rlm@46: } rlm@46: } rlm@46: this.store.loadRecords({records: data}, {}, true); rlm@46: }, rlm@46: rlm@46: onUpdate : function(ds, record, type){ rlm@46: if(type == Ext.data.Record.EDIT){ rlm@46: var v = record.data['value']; rlm@46: var oldValue = record.modified['value']; rlm@46: if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){ rlm@46: this.source[record.id] = v; rlm@46: record.commit(); rlm@46: this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue); rlm@46: }else{ rlm@46: record.reject(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: getProperty : function(row){ rlm@46: return this.store.getAt(row); rlm@46: }, rlm@46: rlm@46: isEditableValue: function(val){ rlm@46: if(Ext.isDate(val)){ rlm@46: return true; rlm@46: }else if(typeof val == 'object' || typeof val == 'function'){ rlm@46: return false; rlm@46: } rlm@46: return true; rlm@46: }, rlm@46: rlm@46: setValue : function(prop, value){ rlm@46: this.source[prop] = value; rlm@46: this.store.getById(prop).set('value', value); rlm@46: }, rlm@46: rlm@46: getSource : function(){ rlm@46: return this.source; rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.PropertyColumnModel = function(grid, store){ rlm@46: this.grid = grid; rlm@46: var g = Ext.grid; rlm@46: g.PropertyColumnModel.superclass.constructor.call(this, [ rlm@46: {header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true}, rlm@46: {header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true} rlm@46: ]); rlm@46: this.store = store; rlm@46: this.bselect = Ext.DomHelper.append(document.body, { rlm@46: tag: 'select', cls: 'x-grid-editor x-hide-display', children: [ rlm@46: {tag: 'option', value: 'true', html: 'true'}, rlm@46: {tag: 'option', value: 'false', html: 'false'} rlm@46: ] rlm@46: }); rlm@46: var f = Ext.form; rlm@46: rlm@46: var bfield = new f.Field({ rlm@46: el:this.bselect, rlm@46: bselect : this.bselect, rlm@46: autoShow: true, rlm@46: getValue : function(){ rlm@46: return this.bselect.value == 'true'; rlm@46: } rlm@46: }); rlm@46: this.editors = { rlm@46: 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})), rlm@46: 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})), rlm@46: 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})), rlm@46: 'boolean' : new g.GridEditor(bfield) rlm@46: }; rlm@46: this.renderCellDelegate = this.renderCell.createDelegate(this); rlm@46: this.renderPropDelegate = this.renderProp.createDelegate(this); rlm@46: }; rlm@46: rlm@46: Ext.extend(Ext.grid.PropertyColumnModel, Ext.grid.ColumnModel, { rlm@46: nameText : 'Name', rlm@46: valueText : 'Value', rlm@46: dateFormat : 'm/j/Y', rlm@46: rlm@46: renderDate : function(dateVal){ rlm@46: return dateVal.dateFormat(this.dateFormat); rlm@46: }, rlm@46: rlm@46: renderBool : function(bVal){ rlm@46: return bVal ? 'true' : 'false'; rlm@46: }, rlm@46: rlm@46: isCellEditable : function(colIndex, rowIndex){ rlm@46: return colIndex == 1; rlm@46: }, rlm@46: rlm@46: getRenderer : function(col){ rlm@46: return col == 1 ? rlm@46: this.renderCellDelegate : this.renderPropDelegate; rlm@46: }, rlm@46: rlm@46: renderProp : function(v){ rlm@46: return this.getPropertyName(v); rlm@46: }, rlm@46: rlm@46: renderCell : function(val){ rlm@46: var rv = val; rlm@46: if(Ext.isDate(val)){ rlm@46: rv = this.renderDate(val); rlm@46: }else if(typeof val == 'boolean'){ rlm@46: rv = this.renderBool(val); rlm@46: } rlm@46: return Ext.util.Format.htmlEncode(rv); rlm@46: }, rlm@46: rlm@46: getPropertyName : function(name){ rlm@46: var pn = this.grid.propertyNames; rlm@46: return pn && pn[name] ? pn[name] : name; rlm@46: }, rlm@46: rlm@46: getCellEditor : function(colIndex, rowIndex){ rlm@46: var p = this.store.getProperty(rowIndex); rlm@46: var n = p.data['name'], val = p.data['value']; rlm@46: if(this.grid.customEditors[n]){ rlm@46: return this.grid.customEditors[n]; rlm@46: } rlm@46: if(Ext.isDate(val)){ rlm@46: return this.editors['date']; rlm@46: }else if(typeof val == 'number'){ rlm@46: return this.editors['number']; rlm@46: }else if(typeof val == 'boolean'){ rlm@46: return this.editors['boolean']; rlm@46: }else{ rlm@46: return this.editors['string']; rlm@46: } rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, { rlm@46: rlm@46: rlm@46: rlm@46: enableColumnMove:false, rlm@46: stripeRows:false, rlm@46: trackMouseOver: false, rlm@46: clicksToEdit:1, rlm@46: enableHdMenu : false, rlm@46: viewConfig : { rlm@46: forceFit:true rlm@46: }, rlm@46: rlm@46: initComponent : function(){ rlm@46: this.customEditors = this.customEditors || {}; rlm@46: this.lastEditRow = null; rlm@46: var store = new Ext.grid.PropertyStore(this); rlm@46: this.propStore = store; rlm@46: var cm = new Ext.grid.PropertyColumnModel(this, store); rlm@46: store.store.sort('name', 'ASC'); rlm@46: this.addEvents( rlm@46: rlm@46: 'beforepropertychange', rlm@46: rlm@46: 'propertychange' rlm@46: ); rlm@46: this.cm = cm; rlm@46: this.ds = store.store; rlm@46: Ext.grid.PropertyGrid.superclass.initComponent.call(this); rlm@46: rlm@46: this.selModel.on('beforecellselect', function(sm, rowIndex, colIndex){ rlm@46: if(colIndex === 0){ rlm@46: this.startEditing.defer(200, this, [rowIndex, 1]); rlm@46: return false; rlm@46: } rlm@46: }, this); rlm@46: }, rlm@46: rlm@46: onRender : function(){ rlm@46: Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments); rlm@46: rlm@46: this.getGridEl().addClass('x-props-grid'); rlm@46: }, rlm@46: rlm@46: afterRender: function(){ rlm@46: Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments); rlm@46: if(this.source){ rlm@46: this.setSource(this.source); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: setSource : function(source){ rlm@46: this.propStore.setSource(source); rlm@46: }, rlm@46: rlm@46: rlm@46: getSource : function(){ rlm@46: return this.propStore.getSource(); rlm@46: } rlm@46: }); rlm@46: Ext.reg("propertygrid", Ext.grid.PropertyGrid); rlm@46: rlm@46: rlm@46: Ext.grid.RowNumberer = function(config){ rlm@46: Ext.apply(this, config); rlm@46: if(this.rowspan){ rlm@46: this.renderer = this.renderer.createDelegate(this); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.grid.RowNumberer.prototype = { rlm@46: rlm@46: header: "", rlm@46: rlm@46: width: 23, rlm@46: rlm@46: sortable: false, rlm@46: rlm@46: rlm@46: fixed:true, rlm@46: menuDisabled:true, rlm@46: dataIndex: '', rlm@46: id: 'numberer', rlm@46: rowspan: undefined, rlm@46: rlm@46: rlm@46: renderer : function(v, p, record, rowIndex){ rlm@46: if(this.rowspan){ rlm@46: p.cellAttr = 'rowspan="'+this.rowspan+'"'; rlm@46: } rlm@46: return rowIndex+1; rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, { rlm@46: rlm@46: header: '
     
    ', rlm@46: rlm@46: width: 20, rlm@46: rlm@46: sortable: false, rlm@46: rlm@46: rlm@46: menuDisabled:true, rlm@46: fixed:true, rlm@46: dataIndex: '', rlm@46: id: 'checker', rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this); rlm@46: this.grid.on('render', function(){ rlm@46: var view = this.grid.getView(); rlm@46: view.mainBody.on('mousedown', this.onMouseDown, this); rlm@46: Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this); rlm@46: rlm@46: }, this); rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseDown : function(e, t){ rlm@46: if(e.button === 0 && t.className == 'x-grid3-row-checker'){ rlm@46: e.stopEvent(); rlm@46: var row = e.getTarget('.x-grid3-row'); rlm@46: if(row){ rlm@46: var index = row.rowIndex; rlm@46: if(this.isSelected(index)){ rlm@46: this.deselectRow(index); rlm@46: }else{ rlm@46: this.selectRow(index, true); rlm@46: } rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onHdMouseDown : function(e, t){ rlm@46: if(t.className == 'x-grid3-hd-checker'){ rlm@46: e.stopEvent(); rlm@46: var hd = Ext.fly(t.parentNode); rlm@46: var isChecked = hd.hasClass('x-grid3-hd-checker-on'); rlm@46: if(isChecked){ rlm@46: hd.removeClass('x-grid3-hd-checker-on'); rlm@46: this.clearSelections(); rlm@46: }else{ rlm@46: hd.addClass('x-grid3-hd-checker-on'); rlm@46: this.selectAll(); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: renderer : function(v, p, record){ rlm@46: return '
     
    '; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.LoadMask = function(el, config){ rlm@46: this.el = Ext.get(el); rlm@46: Ext.apply(this, config); rlm@46: if(this.store){ rlm@46: this.store.on('beforeload', this.onBeforeLoad, this); rlm@46: this.store.on('load', this.onLoad, this); rlm@46: this.store.on('loadexception', this.onLoad, this); rlm@46: this.removeMask = Ext.value(this.removeMask, false); rlm@46: }else{ rlm@46: var um = this.el.getUpdater(); rlm@46: um.showLoadIndicator = false; um.on('beforeupdate', this.onBeforeLoad, this); rlm@46: um.on('update', this.onLoad, this); rlm@46: um.on('failure', this.onLoad, this); rlm@46: this.removeMask = Ext.value(this.removeMask, true); rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.LoadMask.prototype = { rlm@46: rlm@46: rlm@46: rlm@46: msg : 'Loading...', rlm@46: rlm@46: msgCls : 'x-mask-loading', rlm@46: rlm@46: rlm@46: disabled: false, rlm@46: rlm@46: rlm@46: disable : function(){ rlm@46: this.disabled = true; rlm@46: }, rlm@46: rlm@46: rlm@46: enable : function(){ rlm@46: this.disabled = false; rlm@46: }, rlm@46: rlm@46: onLoad : function(){ rlm@46: this.el.unmask(this.removeMask); rlm@46: }, rlm@46: rlm@46: onBeforeLoad : function(){ rlm@46: if(!this.disabled){ rlm@46: this.el.mask(this.msg, this.msgCls); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: show: function(){ rlm@46: this.onBeforeLoad(); rlm@46: }, rlm@46: rlm@46: rlm@46: hide: function(){ rlm@46: this.onLoad(); rlm@46: }, rlm@46: rlm@46: destroy : function(){ rlm@46: if(this.store){ rlm@46: this.store.un('beforeload', this.onBeforeLoad, this); rlm@46: this.store.un('load', this.onLoad, this); rlm@46: this.store.un('loadexception', this.onLoad, this); rlm@46: }else{ rlm@46: var um = this.el.getUpdater(); rlm@46: um.un('beforeupdate', this.onBeforeLoad, this); rlm@46: um.un('update', this.onLoad, this); rlm@46: um.un('failure', this.onLoad, this); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.ProgressBar = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: baseCls : 'x-progress', rlm@46: rlm@46: rlm@46: waitTimer : null, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: Ext.ProgressBar.superclass.initComponent.call(this); rlm@46: this.addEvents( rlm@46: rlm@46: "update" rlm@46: ); rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(ct, position){ rlm@46: Ext.ProgressBar.superclass.onRender.call(this, ct, position); rlm@46: rlm@46: var tpl = new Ext.Template( rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
     
    ', rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
     
    ', rlm@46: '
    ', rlm@46: '
    ', rlm@46: '
    ' rlm@46: ); rlm@46: rlm@46: if(position){ rlm@46: this.el = tpl.insertBefore(position, {cls: this.baseCls}, true); rlm@46: }else{ rlm@46: this.el = tpl.append(ct, {cls: this.baseCls}, true); rlm@46: } rlm@46: if(this.id){ rlm@46: this.el.dom.id = this.id; rlm@46: } rlm@46: var inner = this.el.dom.firstChild; rlm@46: this.progressBar = Ext.get(inner.firstChild); rlm@46: rlm@46: if(this.textEl){ rlm@46: rlm@46: this.textEl = Ext.get(this.textEl); rlm@46: delete this.textTopEl; rlm@46: }else{ rlm@46: rlm@46: this.textTopEl = Ext.get(this.progressBar.dom.firstChild); rlm@46: var textBackEl = Ext.get(inner.childNodes[1]); rlm@46: this.textTopEl.setStyle("z-index", 99).addClass('x-hidden'); rlm@46: this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]); rlm@46: this.textEl.setWidth(inner.offsetWidth); rlm@46: } rlm@46: this.progressBar.setHeight(inner.offsetHeight); rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.ProgressBar.superclass.afterRender.call(this); rlm@46: if(this.value){ rlm@46: this.updateProgress(this.value, this.text); rlm@46: }else{ rlm@46: this.updateText(this.text); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: updateProgress : function(value, text){ rlm@46: this.value = value || 0; rlm@46: if(text){ rlm@46: this.updateText(text); rlm@46: } rlm@46: var w = Math.floor(value*this.el.dom.firstChild.offsetWidth); rlm@46: this.progressBar.setWidth(w); rlm@46: if(this.textTopEl){ rlm@46: rlm@46: this.textTopEl.removeClass('x-hidden').setWidth(w); rlm@46: } rlm@46: this.fireEvent('update', this, value, text); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: wait : function(o){ rlm@46: if(!this.waitTimer){ rlm@46: var scope = this; rlm@46: o = o || {}; rlm@46: this.waitTimer = Ext.TaskMgr.start({ rlm@46: run: function(i){ rlm@46: var inc = o.increment || 10; rlm@46: this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*.01); rlm@46: }, rlm@46: interval: o.interval || 1000, rlm@46: duration: o.duration, rlm@46: onStop: function(){ rlm@46: if(o.fn){ rlm@46: o.fn.apply(o.scope || this); rlm@46: } rlm@46: this.reset(); rlm@46: }, rlm@46: scope: scope rlm@46: }); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: isWaiting : function(){ rlm@46: return this.waitTimer != null; rlm@46: }, rlm@46: rlm@46: rlm@46: updateText : function(text){ rlm@46: this.text = text || ' '; rlm@46: this.textEl.update(this.text); rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setSize : function(w, h){ rlm@46: Ext.ProgressBar.superclass.setSize.call(this, w, h); rlm@46: if(this.textTopEl){ rlm@46: var inner = this.el.dom.firstChild; rlm@46: this.textEl.setSize(inner.offsetWidth, inner.offsetHeight); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: reset : function(hide){ rlm@46: this.updateProgress(0); rlm@46: if(this.textTopEl){ rlm@46: this.textTopEl.addClass('x-hidden'); rlm@46: } rlm@46: if(this.waitTimer){ rlm@46: this.waitTimer.onStop = null; rlm@46: Ext.TaskMgr.stop(this.waitTimer); rlm@46: this.waitTimer = null; rlm@46: } rlm@46: if(hide === true){ rlm@46: this.hide(); rlm@46: } rlm@46: return this; rlm@46: } rlm@46: }); rlm@46: Ext.reg('progress', Ext.ProgressBar); rlm@46: rlm@46: Ext.Slider = Ext.extend(Ext.BoxComponent, { rlm@46: rlm@46: rlm@46: vertical: false, rlm@46: rlm@46: minValue: 0, rlm@46: rlm@46: maxValue: 100, rlm@46: rlm@46: keyIncrement: 1, rlm@46: rlm@46: increment: 0, rlm@46: rlm@46: clickRange: [5,15], rlm@46: rlm@46: clickToChange : true, rlm@46: rlm@46: animate: true, rlm@46: rlm@46: rlm@46: initComponent : function(){ rlm@46: if(this.value === undefined){ rlm@46: this.value = this.minValue; rlm@46: } rlm@46: Ext.Slider.superclass.initComponent.call(this); rlm@46: this.keyIncrement = Math.max(this.increment, this.keyIncrement); rlm@46: this.addEvents( rlm@46: rlm@46: 'beforechange', rlm@46: rlm@46: 'change', rlm@46: rlm@46: 'dragstart', rlm@46: rlm@46: 'drag', rlm@46: rlm@46: 'dragend' rlm@46: ); rlm@46: rlm@46: if(this.vertical){ rlm@46: Ext.apply(this, Ext.Slider.Vertical); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onRender : function(){ rlm@46: this.autoEl = { rlm@46: cls: 'x-slider ' + (this.vertical ? 'x-slider-vert' : 'x-slider-horz'), rlm@46: cn:{cls:'x-slider-end',cn:{cls:'x-slider-inner',cn:[{cls:'x-slider-thumb'},{tag:'a', cls:'x-slider-focus', href:"#", tabIndex: '-1', hidefocus:'on'}]}} rlm@46: }; rlm@46: Ext.Slider.superclass.onRender.apply(this, arguments); rlm@46: this.endEl = this.el.first(); rlm@46: this.innerEl = this.endEl.first(); rlm@46: this.thumb = this.innerEl.first(); rlm@46: this.halfThumb = (this.vertical ? this.thumb.getHeight() : this.thumb.getWidth())/2; rlm@46: this.focusEl = this.thumb.next(); rlm@46: this.initEvents(); rlm@46: }, rlm@46: rlm@46: rlm@46: initEvents : function(){ rlm@46: this.thumb.addClassOnOver('x-slider-thumb-over'); rlm@46: this.mon(this.el, 'mousedown', this.onMouseDown, this); rlm@46: this.mon(this.el, 'keydown', this.onKeyDown, this); rlm@46: rlm@46: this.tracker = new Ext.dd.DragTracker({ rlm@46: onBeforeStart: this.onBeforeDragStart.createDelegate(this), rlm@46: onStart: this.onDragStart.createDelegate(this), rlm@46: onDrag: this.onDrag.createDelegate(this), rlm@46: onEnd: this.onDragEnd.createDelegate(this), rlm@46: tolerance: 3, rlm@46: autoStart: 300 rlm@46: }); rlm@46: this.tracker.initEl(this.thumb); rlm@46: this.on('beforedestroy', this.tracker.destroy, this.tracker); rlm@46: }, rlm@46: rlm@46: rlm@46: onMouseDown : function(e){ rlm@46: if(this.disabled) {return;} rlm@46: if(this.clickToChange && e.target != this.thumb.dom){ rlm@46: var local = this.innerEl.translatePoints(e.getXY()); rlm@46: this.onClickChange(local); rlm@46: } rlm@46: this.focus(); rlm@46: }, rlm@46: rlm@46: rlm@46: onClickChange : function(local){ rlm@46: if(local.top > this.clickRange[0] && local.top < this.clickRange[1]){ rlm@46: this.setValue(Math.round(local.left/this.getRatio())); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: onKeyDown : function(e){ rlm@46: if(this.disabled){e.preventDefault();return;} rlm@46: var k = e.getKey(); rlm@46: switch(k){ rlm@46: case e.UP: rlm@46: case e.RIGHT: rlm@46: e.stopEvent(); rlm@46: if(e.ctrlKey){ rlm@46: this.setValue(this.maxValue); rlm@46: }else{ rlm@46: this.setValue(this.value+this.keyIncrement); rlm@46: } rlm@46: break; rlm@46: case e.DOWN: rlm@46: case e.LEFT: rlm@46: e.stopEvent(); rlm@46: if(e.ctrlKey){ rlm@46: this.setValue(this.minValue); rlm@46: }else{ rlm@46: this.setValue(this.value-this.keyIncrement); rlm@46: } rlm@46: break; rlm@46: default: rlm@46: e.preventDefault(); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: doSnap : function(value){ rlm@46: if(!this.increment || this.increment == 1 || !value) { rlm@46: return value; rlm@46: } rlm@46: var newValue = value, inc = this.increment; rlm@46: var m = value % inc; rlm@46: if(m > 0){ rlm@46: if(m > (inc/2)){ rlm@46: newValue = value + (inc-m); rlm@46: }else{ rlm@46: newValue = value - m; rlm@46: } rlm@46: } rlm@46: return newValue.constrain(this.minValue, this.maxValue); rlm@46: }, rlm@46: rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.Slider.superclass.afterRender.apply(this, arguments); rlm@46: if(this.value !== undefined){ rlm@46: var v = this.normalizeValue(this.value); rlm@46: if(v !== this.value){ rlm@46: delete this.value; rlm@46: this.setValue(v, false); rlm@46: }else{ rlm@46: this.moveThumb(this.translateValue(v), false); rlm@46: } rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: getRatio : function(){ rlm@46: var w = this.innerEl.getWidth(); rlm@46: var v = this.maxValue - this.minValue; rlm@46: return w/v; rlm@46: }, rlm@46: rlm@46: rlm@46: normalizeValue : function(v){ rlm@46: if(typeof v != 'number'){ rlm@46: v = parseInt(v); rlm@46: } rlm@46: v = Math.round(v); rlm@46: v = this.doSnap(v); rlm@46: v = v.constrain(this.minValue, this.maxValue); rlm@46: return v; rlm@46: }, rlm@46: rlm@46: rlm@46: setValue : function(v, animate){ rlm@46: v = this.normalizeValue(v); rlm@46: if(v !== this.value && this.fireEvent('beforechange', this, v, this.value) !== false){ rlm@46: this.value = v; rlm@46: this.moveThumb(this.translateValue(v), animate !== false); rlm@46: this.fireEvent('change', this, v); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: translateValue : function(v){ rlm@46: return (v * this.getRatio())-this.halfThumb; rlm@46: }, rlm@46: rlm@46: rlm@46: moveThumb: function(v, animate){ rlm@46: if(!animate || this.animate === false){ rlm@46: this.thumb.setLeft(v); rlm@46: }else{ rlm@46: this.thumb.shift({left: v, stopFx: true, duration:.35}); rlm@46: } rlm@46: }, rlm@46: rlm@46: rlm@46: focus : function(){ rlm@46: this.focusEl.focus(10); rlm@46: }, rlm@46: rlm@46: rlm@46: onBeforeDragStart : function(e){ rlm@46: return !this.disabled; rlm@46: }, rlm@46: rlm@46: rlm@46: onDragStart: function(e){ rlm@46: this.thumb.addClass('x-slider-thumb-drag'); rlm@46: this.fireEvent('dragstart', this, e); rlm@46: }, rlm@46: rlm@46: rlm@46: onDrag: function(e){ rlm@46: var pos = this.innerEl.translatePoints(this.tracker.getXY()); rlm@46: this.setValue(Math.round(pos.left/this.getRatio()), false); rlm@46: this.fireEvent('drag', this, e); rlm@46: }, rlm@46: rlm@46: rlm@46: onDragEnd: function(e){ rlm@46: this.thumb.removeClass('x-slider-thumb-drag'); rlm@46: this.fireEvent('dragend', this, e); rlm@46: }, rlm@46: rlm@46: rlm@46: onResize : function(w, h){ rlm@46: this.innerEl.setWidth(w - (this.el.getPadding('l') + this.endEl.getPadding('r'))); rlm@46: }, rlm@46: rlm@46: rlm@46: getValue : function(){ rlm@46: return this.value; rlm@46: } rlm@46: }); rlm@46: Ext.reg('slider', Ext.Slider); rlm@46: rlm@46: rlm@46: Ext.Slider.Vertical = { rlm@46: onResize : function(w, h){ rlm@46: this.innerEl.setHeight(h - (this.el.getPadding('t') + this.endEl.getPadding('b'))); rlm@46: }, rlm@46: rlm@46: getRatio : function(){ rlm@46: var h = this.innerEl.getHeight(); rlm@46: var v = this.maxValue - this.minValue; rlm@46: return h/v; rlm@46: }, rlm@46: rlm@46: moveThumb: function(v, animate){ rlm@46: if(!animate || this.animate === false){ rlm@46: this.thumb.setBottom(v); rlm@46: }else{ rlm@46: this.thumb.shift({bottom: v, stopFx: true, duration:.35}); rlm@46: } rlm@46: }, rlm@46: rlm@46: onDrag: function(e){ rlm@46: var pos = this.innerEl.translatePoints(this.tracker.getXY()); rlm@46: var bottom = this.innerEl.getHeight()-pos.top; rlm@46: this.setValue(Math.round(bottom/this.getRatio()), false); rlm@46: this.fireEvent('drag', this, e); rlm@46: }, rlm@46: rlm@46: onClickChange : function(local){ rlm@46: if(local.left > this.clickRange[0] && local.left < this.clickRange[1]){ rlm@46: var bottom = this.innerEl.getHeight()-local.top; rlm@46: this.setValue(Math.round(bottom/this.getRatio())); rlm@46: } rlm@46: } rlm@46: }; rlm@46: rlm@46: Ext.StatusBar = Ext.extend(Ext.Toolbar, { rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: rlm@46: cls : 'x-statusbar', rlm@46: rlm@46: busyIconCls : 'x-status-busy', rlm@46: rlm@46: busyText : 'Loading...', rlm@46: rlm@46: autoClear : 5000, rlm@46: rlm@46: activeThreadId : 0, rlm@46: rlm@46: initComponent : function(){ rlm@46: if(this.statusAlign=='right'){ rlm@46: this.cls += ' x-status-right'; rlm@46: } rlm@46: Ext.StatusBar.superclass.initComponent.call(this); rlm@46: }, rlm@46: rlm@46: afterRender : function(){ rlm@46: Ext.StatusBar.superclass.afterRender.call(this); rlm@46: rlm@46: var right = this.statusAlign=='right', rlm@46: td = Ext.get(this.nextBlock()); rlm@46: rlm@46: if(right){ rlm@46: this.tr.appendChild(td.dom); rlm@46: }else{ rlm@46: td.insertBefore(this.tr.firstChild); rlm@46: } rlm@46: rlm@46: this.statusEl = td.createChild({ rlm@46: cls: 'x-status-text ' + (this.iconCls || this.defaultIconCls || ''), rlm@46: html: this.text || this.defaultText || '' rlm@46: }); rlm@46: this.statusEl.unselectable(); rlm@46: rlm@46: this.spacerEl = td.insertSibling({ rlm@46: tag: 'td', rlm@46: style: 'width:100%', rlm@46: cn: [{cls:'ytb-spacer'}] rlm@46: }, right ? 'before' : 'after'); rlm@46: }, rlm@46: rlm@46: rlm@46: setStatus : function(o){ rlm@46: o = o || {}; rlm@46: rlm@46: if(typeof o == 'string'){ rlm@46: o = {text:o}; rlm@46: } rlm@46: if(o.text !== undefined){ rlm@46: this.setText(o.text); rlm@46: } rlm@46: if(o.iconCls !== undefined){ rlm@46: this.setIcon(o.iconCls); rlm@46: } rlm@46: rlm@46: if(o.clear){ rlm@46: var c = o.clear, rlm@46: wait = this.autoClear, rlm@46: defaults = {useDefaults: true, anim: true}; rlm@46: rlm@46: if(typeof c == 'object'){ rlm@46: c = Ext.applyIf(c, defaults); rlm@46: if(c.wait){ rlm@46: wait = c.wait; rlm@46: } rlm@46: }else if(typeof c == 'number'){ rlm@46: wait = c; rlm@46: c = defaults; rlm@46: }else if(typeof c == 'boolean'){ rlm@46: c = defaults; rlm@46: } rlm@46: rlm@46: c.threadId = this.activeThreadId; rlm@46: this.clearStatus.defer(wait, this, [c]); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: clearStatus : function(o){ rlm@46: o = o || {}; rlm@46: rlm@46: if(o.threadId && o.threadId !== this.activeThreadId){ rlm@46: return this; rlm@46: } rlm@46: rlm@46: var text = o.useDefaults ? this.defaultText : '', rlm@46: iconCls = o.useDefaults ? this.defaultIconCls : ''; rlm@46: rlm@46: if(o.anim){ rlm@46: this.statusEl.fadeOut({ rlm@46: remove: false, rlm@46: useDisplay: true, rlm@46: scope: this, rlm@46: callback: function(){ rlm@46: this.setStatus({ rlm@46: text: text, rlm@46: iconCls: iconCls rlm@46: }); rlm@46: this.statusEl.show(); rlm@46: } rlm@46: }); rlm@46: }else{ rlm@46: this.statusEl.hide(); rlm@46: this.setStatus({ rlm@46: text: text, rlm@46: iconCls: iconCls rlm@46: }); rlm@46: this.statusEl.show(); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: setText : function(text){ rlm@46: this.activeThreadId++; rlm@46: this.text = text || ''; rlm@46: if(this.rendered){ rlm@46: this.statusEl.update(this.text); rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: getText : function(){ rlm@46: return this.text; rlm@46: }, rlm@46: rlm@46: rlm@46: setIcon : function(cls){ rlm@46: this.activeThreadId++; rlm@46: cls = cls || ''; rlm@46: rlm@46: if(this.rendered){ rlm@46: if(this.currIconCls){ rlm@46: this.statusEl.removeClass(this.currIconCls); rlm@46: this.currIconCls = null; rlm@46: } rlm@46: if(cls.length > 0){ rlm@46: this.statusEl.addClass(cls); rlm@46: this.currIconCls = cls; rlm@46: } rlm@46: }else{ rlm@46: this.currIconCls = cls; rlm@46: } rlm@46: return this; rlm@46: }, rlm@46: rlm@46: rlm@46: showBusy : function(o){ rlm@46: if(typeof o == 'string'){ rlm@46: o = {text:o}; rlm@46: } rlm@46: o = Ext.applyIf(o || {}, { rlm@46: text: this.busyText, rlm@46: iconCls: this.busyIconCls rlm@46: }); rlm@46: return this.setStatus(o); rlm@46: } rlm@46: }); rlm@46: Ext.reg('statusbar', Ext.StatusBar); rlm@46: rlm@46: Ext.debug = {}; rlm@46: rlm@46: (function(){ rlm@46: rlm@46: var cp; rlm@46: rlm@46: function createConsole(){ rlm@46: rlm@46: var scriptPanel = new Ext.debug.ScriptsPanel(); rlm@46: var logView = new Ext.debug.LogPanel(); rlm@46: var tree = new Ext.debug.DomTree(); rlm@46: rlm@46: var tabs = new Ext.TabPanel({ rlm@46: activeTab: 0, rlm@46: border: false, rlm@46: tabPosition: 'bottom', rlm@46: items: [{ rlm@46: title: 'Debug Console', rlm@46: layout:'border', rlm@46: items: [logView, scriptPanel] rlm@46: },{ rlm@46: title: 'DOM Inspector', rlm@46: layout:'border', rlm@46: items: [tree] rlm@46: }] rlm@46: }); rlm@46: rlm@46: cp = new Ext.Panel({ rlm@46: id: 'x-debug-browser', rlm@46: title: 'Console', rlm@46: collapsible: true, rlm@46: animCollapse: false, rlm@46: style: 'position:absolute;left:0;bottom:0;', rlm@46: height:200, rlm@46: logView: logView, rlm@46: layout: 'fit', rlm@46: rlm@46: tools:[{ rlm@46: id: 'close', rlm@46: handler: function(){ rlm@46: cp.destroy(); rlm@46: cp = null; rlm@46: Ext.EventManager.removeResizeListener(handleResize); rlm@46: } rlm@46: }], rlm@46: rlm@46: items: tabs rlm@46: }); rlm@46: rlm@46: cp.render(document.body); rlm@46: rlm@46: cp.resizer = new Ext.Resizable(cp.el, { rlm@46: minHeight:50, rlm@46: handles: "n", rlm@46: pinned: true, rlm@46: transparent:true, rlm@46: resizeElement : function(){ rlm@46: var box = this.proxy.getBox(); rlm@46: this.proxy.hide(); rlm@46: cp.setHeight(box.height); rlm@46: return box; rlm@46: } rlm@46: }); rlm@46: rlm@46: function handleResize(){ rlm@46: cp.setWidth(Ext.getBody().getViewSize().width); rlm@46: } rlm@46: Ext.EventManager.onWindowResize(handleResize); rlm@46: rlm@46: handleResize(); rlm@46: } rlm@46: rlm@46: rlm@46: Ext.apply(Ext, { rlm@46: log : function(){ rlm@46: if(!cp){ rlm@46: createConsole(); rlm@46: } rlm@46: cp.logView.log.apply(cp.logView, arguments); rlm@46: }, rlm@46: rlm@46: logf : function(format, arg1, arg2, etc){ rlm@46: Ext.log(String.format.apply(String, arguments)); rlm@46: }, rlm@46: rlm@46: dump : function(o){ rlm@46: if(typeof o == 'string' || typeof o == 'number' || typeof o == 'undefined' || Ext.isDate(o)){ rlm@46: Ext.log(o); rlm@46: }else if(!o){ rlm@46: Ext.log("null"); rlm@46: }else if(typeof o != "object"){ rlm@46: Ext.log('Unknown return type'); rlm@46: }else if(Ext.isArray(o)){ rlm@46: Ext.log('['+o.join(',')+']'); rlm@46: }else{ rlm@46: var b = ["{\n"]; rlm@46: for(var key in o){ rlm@46: var to = typeof o[key]; rlm@46: if(to != "function" && to != "object"){ rlm@46: b.push(String.format(" {0}: {1},\n", key, o[key])); rlm@46: } rlm@46: } rlm@46: var s = b.join(""); rlm@46: if(s.length > 3){ rlm@46: s = s.substr(0, s.length-2); rlm@46: } rlm@46: Ext.log(s + "\n}"); rlm@46: } rlm@46: }, rlm@46: rlm@46: _timers : {}, rlm@46: rlm@46: time : function(name){ rlm@46: name = name || "def"; rlm@46: Ext._timers[name] = new Date().getTime(); rlm@46: }, rlm@46: rlm@46: timeEnd : function(name, printResults){ rlm@46: var t = new Date().getTime(); rlm@46: name = name || "def"; rlm@46: var v = String.format("{0} ms", t-Ext._timers[name]); rlm@46: Ext._timers[name] = new Date().getTime(); rlm@46: if(printResults !== false){ rlm@46: Ext.log('Timer ' + (name == "def" ? v : name + ": " + v)); rlm@46: } rlm@46: return v; rlm@46: } rlm@46: }); rlm@46: rlm@46: })(); rlm@46: rlm@46: rlm@46: Ext.debug.ScriptsPanel = Ext.extend(Ext.Panel, { rlm@46: id:'x-debug-scripts', rlm@46: region: 'east', rlm@46: minWidth: 200, rlm@46: split: true, rlm@46: width: 350, rlm@46: border: false, rlm@46: layout:'anchor', rlm@46: style:'border-width:0 0 0 1px;', rlm@46: rlm@46: initComponent : function(){ rlm@46: rlm@46: this.scriptField = new Ext.form.TextArea({ rlm@46: anchor: '100% -26', rlm@46: style:'border-width:0;' rlm@46: }); rlm@46: rlm@46: this.trapBox = new Ext.form.Checkbox({ rlm@46: id: 'console-trap', rlm@46: boxLabel: 'Trap Errors', rlm@46: checked: true rlm@46: }); rlm@46: rlm@46: this.toolbar = new Ext.Toolbar([{ rlm@46: text: 'Run', rlm@46: scope: this, rlm@46: handler: this.evalScript rlm@46: },{ rlm@46: text: 'Clear', rlm@46: scope: this, rlm@46: handler: this.clear rlm@46: }, rlm@46: '->', rlm@46: this.trapBox, rlm@46: ' ', ' ' rlm@46: ]); rlm@46: rlm@46: this.items = [this.toolbar, this.scriptField]; rlm@46: rlm@46: Ext.debug.ScriptsPanel.superclass.initComponent.call(this); rlm@46: }, rlm@46: rlm@46: evalScript : function(){ rlm@46: var s = this.scriptField.getValue(); rlm@46: if(this.trapBox.getValue()){ rlm@46: try{ rlm@46: var rt = eval(s); rlm@46: Ext.dump(rt === undefined? '(no return)' : rt); rlm@46: }catch(e){ rlm@46: Ext.log(e.message || e.descript); rlm@46: } rlm@46: }else{ rlm@46: var rt = eval(s); rlm@46: Ext.dump(rt === undefined? '(no return)' : rt); rlm@46: } rlm@46: }, rlm@46: rlm@46: clear : function(){ rlm@46: this.scriptField.setValue(''); rlm@46: this.scriptField.focus(); rlm@46: } rlm@46: rlm@46: }); rlm@46: rlm@46: Ext.debug.LogPanel = Ext.extend(Ext.Panel, { rlm@46: autoScroll: true, rlm@46: region: 'center', rlm@46: border: false, rlm@46: style:'border-width:0 1px 0 0', rlm@46: rlm@46: log : function(){ rlm@46: var markup = [ '
    ', rlm@46: Ext.util.Format.htmlEncode(Array.prototype.join.call(arguments, ', ')).replace(/\n/g, '
    ').replace(/\s/g, ' '), rlm@46: '
    '].join(''); rlm@46: rlm@46: this.body.insertHtml('beforeend', markup); rlm@46: this.body.scrollTo('top', 100000); rlm@46: }, rlm@46: rlm@46: clear : function(){ rlm@46: this.body.update(''); rlm@46: this.body.dom.scrollTop = 0; rlm@46: } rlm@46: }); rlm@46: rlm@46: Ext.debug.DomTree = Ext.extend(Ext.tree.TreePanel, { rlm@46: enableDD:false , rlm@46: lines:false, rlm@46: rootVisible:false, rlm@46: animate:false, rlm@46: hlColor:'ffff9c', rlm@46: autoScroll: true, rlm@46: region:'center', rlm@46: border:false, rlm@46: rlm@46: initComponent : function(){ rlm@46: rlm@46: rlm@46: Ext.debug.DomTree.superclass.initComponent.call(this); rlm@46: rlm@46: var styles = false, hnode; rlm@46: var nonSpace = /^\s*$/; rlm@46: var html = Ext.util.Format.htmlEncode; rlm@46: var ellipsis = Ext.util.Format.ellipsis; rlm@46: var styleRe = /\s?([a-z\-]*)\:([^;]*)(?:[;\s\n\r]*)/gi; rlm@46: rlm@46: function findNode(n){ rlm@46: if(!n || n.nodeType != 1 || n == document.body || n == document){ rlm@46: return false; rlm@46: } rlm@46: var pn = [n], p = n; rlm@46: while((p = p.parentNode) && p.nodeType == 1 && p.tagName.toUpperCase() != 'HTML'){ rlm@46: pn.unshift(p); rlm@46: } rlm@46: var cn = hnode; rlm@46: for(var i = 0, len = pn.length; i < len; i++){ rlm@46: cn.expand(); rlm@46: cn = cn.findChild('htmlNode', pn[i]); rlm@46: if(!cn){ return false; rlm@46: } rlm@46: } rlm@46: cn.select(); rlm@46: var a = cn.ui.anchor; rlm@46: treeEl.dom.scrollTop = Math.max(0 ,a.offsetTop-10); rlm@46: cn.highlight(); rlm@46: return true; rlm@46: } rlm@46: rlm@46: function nodeTitle(n){ rlm@46: var s = n.tagName; rlm@46: if(n.id){ rlm@46: s += '#'+n.id; rlm@46: }else if(n.className){ rlm@46: s += '.'+n.className; rlm@46: } rlm@46: return s; rlm@46: } rlm@46: rlm@46: function onNodeSelect(t, n, last){ rlm@46: return; rlm@46: if(last && last.unframe){ rlm@46: last.unframe(); rlm@46: } rlm@46: var props = {}; rlm@46: if(n && n.htmlNode){ rlm@46: if(frameEl.pressed){ rlm@46: n.frame(); rlm@46: } rlm@46: if(inspecting){ rlm@46: return; rlm@46: } rlm@46: addStyle.enable(); rlm@46: reload.setDisabled(n.leaf); rlm@46: var dom = n.htmlNode; rlm@46: stylePanel.setTitle(nodeTitle(dom)); rlm@46: if(styles && !showAll.pressed){ rlm@46: var s = dom.style ? dom.style.cssText : ''; rlm@46: if(s){ rlm@46: var m; rlm@46: while ((m = styleRe.exec(s)) != null){ rlm@46: props[m[1].toLowerCase()] = m[2]; rlm@46: } rlm@46: } rlm@46: }else if(styles){ rlm@46: var cl = Ext.debug.cssList; rlm@46: var s = dom.style, fly = Ext.fly(dom); rlm@46: if(s){ rlm@46: for(var i = 0, len = cl.length; i' + ellipsis(html(String(c.nodeValue)), 35) + '', rlm@46: cls: 'x-tree-noicon' rlm@46: })); rlm@46: } rlm@46: } rlm@46: cb(); rlm@46: }; rlm@46: rlm@46: rlm@46: this.root = this.setRootNode(new Ext.tree.TreeNode('Ext')); rlm@46: rlm@46: hnode = this.root.appendChild(new Ext.debug.HtmlNode( rlm@46: document.getElementsByTagName('html')[0] rlm@46: )); rlm@46: rlm@46: } rlm@46: }); rlm@46: rlm@46: rlm@46: Ext.debug.HtmlNode = function(){ rlm@46: var html = Ext.util.Format.htmlEncode; rlm@46: var ellipsis = Ext.util.Format.ellipsis; rlm@46: var nonSpace = /^\s*$/; rlm@46: rlm@46: var attrs = [ rlm@46: {n: 'id', v: 'id'}, rlm@46: {n: 'className', v: 'class'}, rlm@46: {n: 'name', v: 'name'}, rlm@46: {n: 'type', v: 'type'}, rlm@46: {n: 'src', v: 'src'}, rlm@46: {n: 'href', v: 'href'} rlm@46: ]; rlm@46: rlm@46: function hasChild(n){ rlm@46: for(var i = 0, c; c = n.childNodes[i]; i++){ rlm@46: if(c.nodeType == 1){ rlm@46: return true; rlm@46: } rlm@46: } rlm@46: return false; rlm@46: } rlm@46: rlm@46: function renderNode(n, leaf){ rlm@46: var tag = n.tagName.toLowerCase(); rlm@46: var s = '<' + tag; rlm@46: for(var i = 0, len = attrs.length; i < len; i++){ rlm@46: var a = attrs[i]; rlm@46: var v = n[a.n]; rlm@46: if(v && !nonSpace.test(v)){ rlm@46: s += ' ' + a.v + '="' + html(v) +'"'; rlm@46: } rlm@46: } rlm@46: var style = n.style ? n.style.cssText : ''; rlm@46: if(style){ rlm@46: s += ' style="' + html(style.toLowerCase()) +'"'; rlm@46: } rlm@46: if(leaf && n.childNodes.length > 0){ rlm@46: s+='>' + ellipsis(html(String(n.innerHTML)), 35) + '</'+tag+'>'; rlm@46: }else if(leaf){ rlm@46: s += ' />'; rlm@46: }else{ rlm@46: s += '>'; rlm@46: } rlm@46: return s; rlm@46: } rlm@46: rlm@46: var HtmlNode = function(n){ rlm@46: var leaf = !hasChild(n); rlm@46: this.htmlNode = n; rlm@46: this.tagName = n.tagName.toLowerCase(); rlm@46: var attr = { rlm@46: text : renderNode(n, leaf), rlm@46: leaf : leaf, rlm@46: cls: 'x-tree-noicon' rlm@46: }; rlm@46: HtmlNode.superclass.constructor.call(this, attr); rlm@46: this.attributes.htmlNode = n; if(!leaf){ rlm@46: this.on('expand', this.onExpand, this); rlm@46: this.on('collapse', this.onCollapse, this); rlm@46: } rlm@46: }; rlm@46: rlm@46: rlm@46: Ext.extend(HtmlNode, Ext.tree.AsyncTreeNode, { rlm@46: cls: 'x-tree-noicon', rlm@46: preventHScroll: true, rlm@46: refresh : function(highlight){ rlm@46: var leaf = !hasChild(this.htmlNode); rlm@46: this.setText(renderNode(this.htmlNode, leaf)); rlm@46: if(highlight){ rlm@46: Ext.fly(this.ui.textNode).highlight(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onExpand : function(){ rlm@46: if(!this.closeNode && this.parentNode){ rlm@46: this.closeNode = this.parentNode.insertBefore(new Ext.tree.TreeNode({ rlm@46: text:'</' + this.tagName + '>', rlm@46: cls: 'x-tree-noicon' rlm@46: }), this.nextSibling); rlm@46: }else if(this.closeNode){ rlm@46: this.closeNode.ui.show(); rlm@46: } rlm@46: }, rlm@46: rlm@46: onCollapse : function(){ rlm@46: if(this.closeNode){ rlm@46: this.closeNode.ui.hide(); rlm@46: } rlm@46: }, rlm@46: rlm@46: render : function(bulkRender){ rlm@46: HtmlNode.superclass.render.call(this, bulkRender); rlm@46: }, rlm@46: rlm@46: highlightNode : function(){ rlm@46: }, rlm@46: rlm@46: highlight : function(){ rlm@46: }, rlm@46: rlm@46: frame : function(){ rlm@46: this.htmlNode.style.border = '1px solid #0000ff'; rlm@46: }, rlm@46: rlm@46: unframe : function(){ rlm@46: this.htmlNode.style.border = ''; rlm@46: } rlm@46: }); rlm@46: rlm@46: return HtmlNode; rlm@46: }(); rlm@46: rlm@46: rlm@46: