ext-all-debug.js
资源名称:demo.zip [点击查看]
上传用户:chliyg
上传日期:2016-05-15
资源大小:3196k
文件大小:951k
源码类别:
Jsp/Servlet
开发平台:
Java
- buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
- } else {
- buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
- }
- }
- p = p.parentNode;
- }
- this.childIndent = buf.join("");
- }
- return this.childIndent;
- },
- renderIndent : function(){
- if(this.rendered){
- var indent = "";
- var p = this.node.parentNode;
- if(p){
- indent = p.ui.getChildIndent();
- }
- if(this.indentMarkup != indent){ this.indentNode.innerHTML = indent;
- this.indentMarkup = indent;
- }
- this.updateExpandIcon();
- }
- },
- destroy : function(){
- if(this.elNode){
- Ext.dd.Registry.unregister(this.elNode.id);
- }
- delete this.elNode;
- delete this.ctNode;
- delete this.indentNode;
- delete this.ecNode;
- delete this.iconNode;
- delete this.checkbox;
- delete this.anchor;
- delete this.textNode;
- Ext.removeNode(this.ctNode);
- }
- };
- Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
- render : function(){
- if(!this.rendered){
- var targetNode = this.node.ownerTree.innerCt.dom;
- this.node.expanded = true;
- targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
- this.wrap = this.ctNode = targetNode.firstChild;
- }
- },
- collapse : Ext.emptyFn,
- expand : Ext.emptyFn
- });
- Ext.tree.TreeLoader = function(config){
- this.baseParams = {};
- Ext.apply(this, config);
- this.addEvents(
- "beforeload",
- "load",
- "loadexception"
- );
- Ext.tree.TreeLoader.superclass.constructor.call(this);
- };
- Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
- uiProviders : {},
- clearOnLoad : true,
- load : function(node, callback){
- if(this.clearOnLoad){
- while(node.firstChild){
- node.removeChild(node.firstChild);
- }
- }
- if(this.doPreload(node)){ if(typeof callback == "function"){
- callback();
- }
- }else if(this.dataUrl||this.url){
- this.requestData(node, callback);
- }
- },
- doPreload : function(node){
- if(node.attributes.children){
- if(node.childNodes.length < 1){ var cs = node.attributes.children;
- node.beginUpdate();
- for(var i = 0, len = cs.length; i < len; i++){
- var cn = node.appendChild(this.createNode(cs[i]));
- if(this.preloadChildren){
- this.doPreload(cn);
- }
- }
- node.endUpdate();
- }
- return true;
- }else {
- return false;
- }
- },
- getParams: function(node){
- var buf = [], bp = this.baseParams;
- for(var key in bp){
- if(typeof bp[key] != "function"){
- buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
- }
- }
- buf.push("node=", encodeURIComponent(node.id));
- return buf.join("");
- },
- requestData : function(node, callback){
- if(this.fireEvent("beforeload", this, node, callback) !== false){
- this.transId = Ext.Ajax.request({
- method:this.requestMethod,
- url: this.dataUrl||this.url,
- success: this.handleResponse,
- failure: this.handleFailure,
- scope: this,
- argument: {callback: callback, node: node},
- params: this.getParams(node)
- });
- }else{
- if(typeof callback == "function"){
- callback();
- }
- }
- },
- isLoading : function(){
- return !!this.transId;
- },
- abort : function(){
- if(this.isLoading()){
- Ext.Ajax.abort(this.transId);
- }
- },
- createNode : function(attr){
- if(this.baseAttrs){
- Ext.applyIf(attr, this.baseAttrs);
- }
- if(this.applyLoader !== false){
- attr.loader = this;
- }
- if(typeof attr.uiProvider == 'string'){
- attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
- }
- if(attr.nodeType){
- return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
- }else{
- return attr.leaf ?
- new Ext.tree.TreeNode(attr) :
- new Ext.tree.AsyncTreeNode(attr);
- }
- },
- processResponse : function(response, node, callback){
- var json = response.responseText;
- try {
- var o = eval("("+json+")");
- node.beginUpdate();
- for(var i = 0, len = o.length; i < len; i++){
- var n = this.createNode(o[i]);
- if(n){
- node.appendChild(n);
- }
- }
- node.endUpdate();
- if(typeof callback == "function"){
- callback(this, node);
- }
- }catch(e){
- this.handleFailure(response);
- }
- },
- handleResponse : function(response){
- this.transId = false;
- var a = response.argument;
- this.processResponse(response, a.node, a.callback);
- this.fireEvent("load", this, a.node, response);
- },
- handleFailure : function(response){
- this.transId = false;
- var a = response.argument;
- this.fireEvent("loadexception", this, a.node, response);
- if(typeof a.callback == "function"){
- a.callback(this, a.node);
- }
- }
- });
- Ext.tree.TreeFilter = function(tree, config){
- this.tree = tree;
- this.filtered = {};
- Ext.apply(this, config);
- };
- Ext.tree.TreeFilter.prototype = {
- clearBlank:false,
- reverse:false,
- autoClear:false,
- remove:false,
- filter : function(value, attr, startNode){
- attr = attr || "text";
- var f;
- if(typeof value == "string"){
- var vlen = value.length;
- if(vlen == 0 && this.clearBlank){
- this.clear();
- return;
- }
- value = value.toLowerCase();
- f = function(n){
- return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
- };
- }else if(value.exec){ f = function(n){
- return value.test(n.attributes[attr]);
- };
- }else{
- throw 'Illegal filter type, must be string or regex';
- }
- this.filterBy(f, null, startNode);
- },
- filterBy : function(fn, scope, startNode){
- startNode = startNode || this.tree.root;
- if(this.autoClear){
- this.clear();
- }
- var af = this.filtered, rv = this.reverse;
- var f = function(n){
- if(n == startNode){
- return true;
- }
- if(af[n.id]){
- return false;
- }
- var m = fn.call(scope || n, n);
- if(!m || rv){
- af[n.id] = n;
- n.ui.hide();
- return false;
- }
- return true;
- };
- startNode.cascade(f);
- if(this.remove){
- for(var id in af){
- if(typeof id != "function"){
- var n = af[id];
- if(n && n.parentNode){
- n.parentNode.removeChild(n);
- }
- }
- }
- }
- },
- clear : function(){
- var t = this.tree;
- var af = this.filtered;
- for(var id in af){
- if(typeof id != "function"){
- var n = af[id];
- if(n){
- n.ui.show();
- }
- }
- }
- this.filtered = {};
- }
- };
- Ext.tree.TreeSorter = function(tree, config){
- Ext.apply(this, config);
- tree.on("beforechildrenrendered", this.doSort, this);
- tree.on("append", this.updateSort, this);
- tree.on("insert", this.updateSort, this);
- tree.on("textchange", this.updateSortParent, this);
- var dsc = this.dir && this.dir.toLowerCase() == "desc";
- var p = this.property || "text";
- var sortType = this.sortType;
- var fs = this.folderSort;
- var cs = this.caseSensitive === true;
- var leafAttr = this.leafAttr || 'leaf';
- this.sortFn = function(n1, n2){
- if(fs){
- if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
- return 1;
- }
- if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
- return -1;
- }
- }
- var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
- var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
- if(v1 < v2){
- return dsc ? +1 : -1;
- }else if(v1 > v2){
- return dsc ? -1 : +1;
- }else{
- return 0;
- }
- };
- };
- Ext.tree.TreeSorter.prototype = {
- doSort : function(node){
- node.sort(this.sortFn);
- },
- compareNodes : function(n1, n2){
- return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
- },
- updateSort : function(tree, node){
- if(node.childrenRendered){
- this.doSort.defer(1, this, [node]);
- }
- },
- updateSortParent : function(node){
- var p = node.parentNode;
- if(p && p.childrenRendered){
- this.doSort.defer(1, this, [p]);
- }
- }
- };
- if(Ext.dd.DropZone){
- Ext.tree.TreeDropZone = function(tree, config){
- this.allowParentInsert = false;
- this.allowContainerDrop = false;
- this.appendOnly = false;
- Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
- this.tree = tree;
- this.dragOverData = {};
- this.lastInsertClass = "x-tree-no-status";
- };
- Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
- ddGroup : "TreeDD",
- expandDelay : 1000,
- expandNode : function(node){
- if(node.hasChildNodes() && !node.isExpanded()){
- node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
- }
- },
- queueExpand : function(node){
- this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
- },
- cancelExpand : function(){
- if(this.expandProcId){
- clearTimeout(this.expandProcId);
- this.expandProcId = false;
- }
- },
- isValidDropPoint : function(n, pt, dd, e, data){
- if(!n || !data){ return false; }
- var targetNode = n.node;
- var dropNode = data.node;
- if(!(targetNode && targetNode.isTarget && pt)){
- return false;
- }
- if(pt == "append" && targetNode.allowChildren === false){
- return false;
- }
- if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
- return false;
- }
- if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
- return false;
- }
- var overEvent = this.dragOverData;
- overEvent.tree = this.tree;
- overEvent.target = targetNode;
- overEvent.data = data;
- overEvent.point = pt;
- overEvent.source = dd;
- overEvent.rawEvent = e;
- overEvent.dropNode = dropNode;
- overEvent.cancel = false;
- var result = this.tree.fireEvent("nodedragover", overEvent);
- return overEvent.cancel === false && result !== false;
- },
- getDropPoint : function(e, n, dd){
- var tn = n.node;
- if(tn.isRoot){
- return tn.allowChildren !== false ? "append" : false; }
- var dragEl = n.ddel;
- var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
- var y = Ext.lib.Event.getPageY(e);
- var noAppend = tn.allowChildren === false || tn.isLeaf();
- if(this.appendOnly || tn.parentNode.allowChildren === false){
- return noAppend ? false : "append";
- }
- var noBelow = false;
- if(!this.allowParentInsert){
- noBelow = tn.hasChildNodes() && tn.isExpanded();
- }
- var q = (b - t) / (noAppend ? 2 : 3);
- if(y >= t && y < (t + q)){
- return "above";
- }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
- return "below";
- }else{
- return "append";
- }
- },
- onNodeEnter : function(n, dd, e, data){
- this.cancelExpand();
- },
- onNodeOver : function(n, dd, e, data){
- var pt = this.getDropPoint(e, n, dd);
- var node = n.node;
- if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
- this.queueExpand(node);
- }else if(pt != "append"){
- this.cancelExpand();
- }
- var returnCls = this.dropNotAllowed;
- if(this.isValidDropPoint(n, pt, dd, e, data)){
- if(pt){
- var el = n.ddel;
- var cls;
- if(pt == "above"){
- returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
- cls = "x-tree-drag-insert-above";
- }else if(pt == "below"){
- returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
- cls = "x-tree-drag-insert-below";
- }else{
- returnCls = "x-tree-drop-ok-append";
- cls = "x-tree-drag-append";
- }
- if(this.lastInsertClass != cls){
- Ext.fly(el).replaceClass(this.lastInsertClass, cls);
- this.lastInsertClass = cls;
- }
- }
- }
- return returnCls;
- },
- onNodeOut : function(n, dd, e, data){
- this.cancelExpand();
- this.removeDropIndicators(n);
- },
- onNodeDrop : function(n, dd, e, data){
- var point = this.getDropPoint(e, n, dd);
- var targetNode = n.node;
- targetNode.ui.startDrop();
- if(!this.isValidDropPoint(n, point, dd, e, data)){
- targetNode.ui.endDrop();
- return false;
- }
- var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
- var dropEvent = {
- tree : this.tree,
- target: targetNode,
- data: data,
- point: point,
- source: dd,
- rawEvent: e,
- dropNode: dropNode,
- cancel: !dropNode,
- dropStatus: false
- };
- var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
- if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
- targetNode.ui.endDrop();
- return dropEvent.dropStatus;
- }
- targetNode = dropEvent.target;
- if(point == "append" && !targetNode.isExpanded()){
- targetNode.expand(false, null, function(){
- this.completeDrop(dropEvent);
- }.createDelegate(this));
- }else{
- this.completeDrop(dropEvent);
- }
- return true;
- },
- completeDrop : function(de){
- var ns = de.dropNode, p = de.point, t = de.target;
- if(!Ext.isArray(ns)){
- ns = [ns];
- }
- var n;
- for(var i = 0, len = ns.length; i < len; i++){
- n = ns[i];
- if(p == "above"){
- t.parentNode.insertBefore(n, t);
- }else if(p == "below"){
- t.parentNode.insertBefore(n, t.nextSibling);
- }else{
- t.appendChild(n);
- }
- }
- n.ui.focus();
- if(Ext.enableFx && this.tree.hlDrop){
- n.ui.highlight();
- }
- t.ui.endDrop();
- this.tree.fireEvent("nodedrop", de);
- },
- afterNodeMoved : function(dd, data, e, targetNode, dropNode){
- if(Ext.enableFx && this.tree.hlDrop){
- dropNode.ui.focus();
- dropNode.ui.highlight();
- }
- this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
- },
- getTree : function(){
- return this.tree;
- },
- removeDropIndicators : function(n){
- if(n && n.ddel){
- var el = n.ddel;
- Ext.fly(el).removeClass([
- "x-tree-drag-insert-above",
- "x-tree-drag-insert-below",
- "x-tree-drag-append"]);
- this.lastInsertClass = "_noclass";
- }
- },
- beforeDragDrop : function(target, e, id){
- this.cancelExpand();
- return true;
- },
- afterRepair : function(data){
- if(data && Ext.enableFx){
- data.node.ui.highlight();
- }
- this.hideProxy();
- }
- });
- }
- if(Ext.dd.DragZone){
- Ext.tree.TreeDragZone = function(tree, config){
- Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
- this.tree = tree;
- };
- Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
- ddGroup : "TreeDD",
- onBeforeDrag : function(data, e){
- var n = data.node;
- return n && n.draggable && !n.disabled;
- },
- onInitDrag : function(e){
- var data = this.dragData;
- this.tree.getSelectionModel().select(data.node);
- this.tree.eventModel.disable();
- this.proxy.update("");
- data.node.ui.appendDDGhost(this.proxy.ghost.dom);
- this.tree.fireEvent("startdrag", this.tree, data.node, e);
- },
- getRepairXY : function(e, data){
- return data.node.ui.getDDRepairXY();
- },
- onEndDrag : function(data, e){
- this.tree.eventModel.enable.defer(100, this.tree.eventModel);
- this.tree.fireEvent("enddrag", this.tree, data.node, e);
- },
- onValidDrop : function(dd, e, id){
- this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
- this.hideProxy();
- },
- beforeInvalidDrop : function(e, id){
- var sm = this.tree.getSelectionModel();
- sm.clearSelections();
- sm.select(this.dragData.node);
- },
- afterRepair : function(){
- if (Ext.enableFx && this.tree.hlDrop) {
- Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
- }
- this.dragging = false;
- }
- });
- } Ext.tree.TreeEditor = function(tree, fc, config){ fc = fc || {}; var field = fc.events ? fc : new Ext.form.TextField(fc); Ext.tree.TreeEditor.superclass.constructor.call(this, field, config); this.tree = tree; if(!tree.rendered){ tree.on('render', this.initEditor, this); }else{ this.initEditor(tree); } }; Ext.extend(Ext.tree.TreeEditor, Ext.Editor, { alignment: "l-l", autoSize: false, hideEl : false, cls: "x-small-editor x-tree-editor", shim:false, shadow:"frame", maxWidth: 250, editDelay : 350, initEditor : function(tree){ tree.on('beforeclick', this.beforeNodeClick, this); tree.on('dblclick', this.onNodeDblClick, this); this.on('complete', this.updateNode, this); this.on('beforestartedit', this.fitToTree, this); this.on('startedit', this.bindScroll, this, {delay:10}); this.on('specialkey', this.onSpecialKey, this); }, fitToTree : function(ed, el){ var td = this.tree.getTreeEl().dom, nd = el.dom; if(td.scrollLeft > nd.offsetLeft){ td.scrollLeft = nd.offsetLeft; } var w = Math.min( this.maxWidth, (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - 5); this.setSize(w, ''); }, triggerEdit : function(node, defer){ this.completeEdit(); if(node.attributes.editable !== false){ this.editNode = node; if(this.tree.autoScroll){ node.ui.getEl().scrollIntoView(this.tree.body); } this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, node.text]); return false; } }, bindScroll : function(){ this.tree.getTreeEl().on('scroll', this.cancelEdit, this); }, beforeNodeClick : function(node, e){ clearTimeout(this.autoEditTimer); if(this.tree.getSelectionModel().isSelected(node)){ e.stopEvent(); return this.triggerEdit(node); } }, onNodeDblClick : function(node, e){ clearTimeout(this.autoEditTimer); }, updateNode : function(ed, value){ this.tree.getTreeEl().un('scroll', this.cancelEdit, this); this.editNode.setText(value); }, onHide : function(){ Ext.tree.TreeEditor.superclass.onHide.call(this); if(this.editNode){ this.editNode.ui.focus.defer(50, this.editNode.ui); } }, onSpecialKey : function(field, e){ var k = e.getKey(); if(k == e.ESC){ e.stopEvent(); this.cancelEdit(); }else if(k == e.ENTER && !e.hasModifier()){ e.stopEvent(); this.completeEdit(); } } }); Ext.menu.Menu = function(config){ if(Ext.isArray(config)){ config = {items:config}; } Ext.apply(this, config); this.id = this.id || Ext.id(); this.addEvents( 'beforeshow', 'beforehide', 'show', 'hide', 'click', 'mouseover', 'mouseout', 'itemclick' ); Ext.menu.MenuMgr.register(this); Ext.menu.Menu.superclass.constructor.call(this); var mis = this.items; this.items = new Ext.util.MixedCollection(); if(mis){ this.add.apply(this, mis); } }; Ext.extend(Ext.menu.Menu, Ext.util.Observable, { minWidth : 120, shadow : "sides", subMenuAlign : "tl-tr?", defaultAlign : "tl-bl?", allowOtherMenus : false, ignoreParentClicks : false, hidden:true, createEl : function(){ return new Ext.Layer({ cls: "x-menu", shadow:this.shadow, constrain: false, parentEl: this.parentEl || document.body, zindex:15000 }); }, render : function(){ if(this.el){ return; } var el = this.el = this.createEl(); if(!this.keyNav){ this.keyNav = new Ext.menu.MenuNav(this); } if(this.plain){ el.addClass("x-menu-plain"); } if(this.cls){ el.addClass(this.cls); } this.focusEl = el.createChild({ tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1" }); var ul = el.createChild({tag: "ul", cls: "x-menu-list"}); ul.on("click", this.onClick, this); ul.on("mouseover", this.onMouseOver, this); ul.on("mouseout", this.onMouseOut, this); this.items.each(function(item){ var li = document.createElement("li"); li.className = "x-menu-list-item"; ul.dom.appendChild(li); item.render(li, this); }, this); this.ul = ul; this.autoWidth(); }, autoWidth : function(){ var el = this.el, ul = this.ul; if(!el){ return; } var w = this.width; if(w){ el.setWidth(w); }else if(Ext.isIE){ el.setWidth(this.minWidth); var t = el.dom.offsetWidth; el.setWidth(ul.getWidth()+el.getFrameWidth("lr")); } }, delayAutoWidth : function(){ if(this.el){ if(!this.awTask){ this.awTask = new Ext.util.DelayedTask(this.autoWidth, this); } this.awTask.delay(20); } }, findTargetItem : function(e){ var t = e.getTarget(".x-menu-list-item", this.ul, true); if(t && t.menuItemId){ return this.items.get(t.menuItemId); } }, onClick : function(e){ var t; if(t = this.findTargetItem(e)){ if(t.menu && this.ignoreParentClicks){ t.expandMenu(); }else{ t.onClick(e); this.fireEvent("click", this, t, e); } } }, setActiveItem : function(item, autoExpand){ if(item != this.activeItem){ if(this.activeItem){ this.activeItem.deactivate(); } this.activeItem = item; item.activate(autoExpand); }else if(autoExpand){ item.expandMenu(); } }, tryActivate : function(start, step){ var items = this.items; for(var i = start, len = items.length; i >= 0 && i < len; i+= step){ var item = items.get(i); if(!item.disabled && item.canActivate){ this.setActiveItem(item, false); return item; } } return false; }, onMouseOver : function(e){ var t; if(t = this.findTargetItem(e)){ if(t.canActivate && !t.disabled){ this.setActiveItem(t, true); } } this.over = true; this.fireEvent("mouseover", this, e, t); }, onMouseOut : function(e){ var t; if(t = this.findTargetItem(e)){ if(t == this.activeItem && t.shouldDeactivate(e)){ this.activeItem.deactivate(); delete this.activeItem; } } this.over = false; this.fireEvent("mouseout", this, e, t); }, isVisible : function(){ return this.el && !this.hidden; }, show : function(el, pos, parentMenu){ this.parentMenu = parentMenu; if(!this.el){ this.render(); } this.fireEvent("beforeshow", this); this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false); }, showAt : function(xy, parentMenu, _e){ this.parentMenu = parentMenu; if(!this.el){ this.render(); } if(_e !== false){ this.fireEvent("beforeshow", this); xy = this.el.adjustForConstraints(xy); } this.el.setXY(xy); this.el.show(); this.hidden = false; this.focus(); this.fireEvent("show", this); }, focus : function(){ if(!this.hidden){ this.doFocus.defer(50, this); } }, doFocus : function(){ if(!this.hidden){ this.focusEl.focus(); } }, hide : function(deep){ if(this.el && this.isVisible()){ this.fireEvent("beforehide", this); if(this.activeItem){ this.activeItem.deactivate(); this.activeItem = null; } this.el.hide(); this.hidden = true; this.fireEvent("hide", this); } if(deep === true && this.parentMenu){ this.parentMenu.hide(true); } }, add : function(){ var a = arguments, l = a.length, item; for(var i = 0; i < l; i++){ var el = a[i]; if(el.render){ item = this.addItem(el); }else if(typeof el == "string"){ if(el == "separator" || el == "-"){ item = this.addSeparator(); }else{ item = this.addText(el); } }else if(el.tagName || el.el){ item = this.addElement(el); }else if(typeof el == "object"){ Ext.applyIf(el, this.defaults); item = this.addMenuItem(el); } } return item; }, getEl : function(){ if(!this.el){ this.render(); } return this.el; }, addSeparator : function(){ return this.addItem(new Ext.menu.Separator()); }, addElement : function(el){ return this.addItem(new Ext.menu.BaseItem(el)); }, addItem : function(item){ this.items.add(item); if(this.ul){ var li = document.createElement("li"); li.className = "x-menu-list-item"; this.ul.dom.appendChild(li); item.render(li, this); this.delayAutoWidth(); } return item; }, addMenuItem : function(config){ if(!(config instanceof Ext.menu.Item)){ if(typeof config.checked == "boolean"){ config = new Ext.menu.CheckItem(config); }else{ config = new Ext.menu.Item(config); } } return this.addItem(config); }, addText : function(text){ return this.addItem(new Ext.menu.TextItem(text)); }, insert : function(index, item){ this.items.insert(index, item); if(this.ul){ var li = document.createElement("li"); li.className = "x-menu-list-item"; this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]); item.render(li, this); this.delayAutoWidth(); } return item; }, remove : function(item){ this.items.removeKey(item.id); item.destroy(); }, removeAll : function(){ if(this.items){ var f; while(f = this.items.first()){ this.remove(f); } } }, destroy : function(){ this.beforeDestroy(); Ext.menu.MenuMgr.unregister(this); if (this.keyNav) { this.keyNav.disable(); } this.removeAll(); if (this.ul) { this.ul.removeAllListeners(); } if (this.el) { this.el.destroy(); } }, beforeDestroy : Ext.emptyFn }); Ext.menu.MenuNav = function(menu){ Ext.menu.MenuNav.superclass.constructor.call(this, menu.el); this.scope = this.menu = menu; }; Ext.extend(Ext.menu.MenuNav, Ext.KeyNav, { doRelay : function(e, h){ var k = e.getKey(); if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){ this.menu.tryActivate(0, 1); return false; } return h.call(this.scope || this, e, this.menu); }, up : function(e, m){ if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){ m.tryActivate(m.items.length-1, -1); } }, down : function(e, m){ if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){ m.tryActivate(0, 1); } }, right : function(e, m){ if(m.activeItem){ m.activeItem.expandMenu(true); } }, left : function(e, m){ m.hide(); if(m.parentMenu && m.parentMenu.activeItem){ m.parentMenu.activeItem.activate(); } }, enter : function(e, m){ if(m.activeItem){ e.stopPropagation(); m.activeItem.onClick(e); m.fireEvent("click", this, m.activeItem); return true; } } }); Ext.menu.MenuMgr = function(){ var menus, active, groups = {}, attached = false, lastShow = new Date(); function init(){ menus = {}; active = new Ext.util.MixedCollection(); Ext.getDoc().addKeyListener(27, function(){ if(active.length > 0){ hideAll(); } }); } function hideAll(){ if(active && active.length > 0){ var c = active.clone(); c.each(function(m){ m.hide(); }); } } function onHide(m){ active.remove(m); if(active.length < 1){ Ext.getDoc().un("mousedown", onMouseDown); attached = false; } } function onShow(m){ var last = active.last(); lastShow = new Date(); active.add(m); if(!attached){ Ext.getDoc().on("mousedown", onMouseDown); attached = true; } if(m.parentMenu){ m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3); m.parentMenu.activeChild = m; }else if(last && last.isVisible()){ m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3); } } function onBeforeHide(m){ if(m.activeChild){ m.activeChild.hide(); } if(m.autoHideTimer){ clearTimeout(m.autoHideTimer); delete m.autoHideTimer; } } function onBeforeShow(m){ var pm = m.parentMenu; if(!pm && !m.allowOtherMenus){ hideAll(); }else if(pm && pm.activeChild){ pm.activeChild.hide(); } } function onMouseDown(e){ if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){ hideAll(); } } function onBeforeCheck(mi, state){ if(state){ var g = groups[mi.group]; for(var i = 0, l = g.length; i < l; i++){ if(g[i] != mi){ g[i].setChecked(false); } } } } return { hideAll : function(){ hideAll(); }, register : function(menu){ if(!menus){ init(); } menus[menu.id] = menu; menu.on("beforehide", onBeforeHide); menu.on("hide", onHide); menu.on("beforeshow", onBeforeShow); menu.on("show", onShow); var g = menu.group; if(g && menu.events["checkchange"]){ if(!groups[g]){ groups[g] = []; } groups[g].push(menu); menu.on("checkchange", onCheck); } }, get : function(menu){ if(typeof menu == "string"){ if(!menus){ return null; } return menus[menu]; }else if(menu.events){ return menu; }else if(typeof menu.length == 'number'){ return new Ext.menu.Menu({items:menu}); }else{ return new Ext.menu.Menu(menu); } }, unregister : function(menu){ delete menus[menu.id]; menu.un("beforehide", onBeforeHide); menu.un("hide", onHide); menu.un("beforeshow", onBeforeShow); menu.un("show", onShow); var g = menu.group; if(g && menu.events["checkchange"]){ groups[g].remove(menu); menu.un("checkchange", onCheck); } }, registerCheckable : function(menuItem){ var g = menuItem.group; if(g){ if(!groups[g]){ groups[g] = []; } groups[g].push(menuItem); menuItem.on("beforecheckchange", onBeforeCheck); } }, unregisterCheckable : function(menuItem){ var g = menuItem.group; if(g){ groups[g].remove(menuItem); menuItem.un("beforecheckchange", onBeforeCheck); } }, getCheckedItem : function(groupId){ var g = groups[groupId]; if(g){ for(var i = 0, l = g.length; i < l; i++){ if(g[i].checked){ return g[i]; } } } return null; }, setCheckedItem : function(groupId, itemId){ var g = groups[groupId]; if(g){ for(var i = 0, l = g.length; i < l; i++){ if(g[i].id == itemId){ g[i].setChecked(true); } } } return null; } }; }(); Ext.menu.BaseItem = function(config){ Ext.menu.BaseItem.superclass.constructor.call(this, config); this.addEvents( 'click', 'activate', 'deactivate' ); if(this.handler){ this.on("click", this.handler, this.scope); } }; Ext.extend(Ext.menu.BaseItem, Ext.Component, { canActivate : false, activeClass : "x-menu-item-active", hideOnClick : true, hideDelay : 100, ctype: "Ext.menu.BaseItem", actionMode : "container", render : function(container, parentMenu){ this.parentMenu = parentMenu; Ext.menu.BaseItem.superclass.render.call(this, container); this.container.menuItemId = this.id; }, onRender : function(container, position){ this.el = Ext.get(this.el); container.dom.appendChild(this.el.dom); }, setHandler : function(handler, scope){ if(this.handler){ this.un("click", this.handler, this.scope); } this.on("click", this.handler = handler, this.scope = scope); }, onClick : function(e){ if(!this.disabled && this.fireEvent("click", this, e) !== false && this.parentMenu.fireEvent("itemclick", this, e) !== false){ this.handleClick(e); }else{ e.stopEvent(); } }, activate : function(){ if(this.disabled){ return false; } var li = this.container; li.addClass(this.activeClass); this.region = li.getRegion().adjust(2, 2, -2, -2); this.fireEvent("activate", this); return true; }, deactivate : function(){ this.container.removeClass(this.activeClass); this.fireEvent("deactivate", this); }, shouldDeactivate : function(e){ return !this.region || !this.region.contains(e.getPoint()); }, handleClick : function(e){ if(this.hideOnClick){ this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]); } }, expandMenu : function(autoActivate){ }, hideMenu : function(){ } }); Ext.menu.TextItem = function(cfg){ if(typeof cfg == 'string'){ cfg = {text: cfg} } Ext.menu.TextItem.superclass.constructor.call(this, cfg); }; Ext.extend(Ext.menu.TextItem, Ext.menu.BaseItem, { hideOnClick : false, itemCls : "x-menu-text", onRender : function(){ var s = document.createElement("span"); s.className = this.itemCls; s.innerHTML = this.text; this.el = s; Ext.menu.TextItem.superclass.onRender.apply(this, arguments); } }); Ext.menu.Separator = function(config){ Ext.menu.Separator.superclass.constructor.call(this, config); }; Ext.extend(Ext.menu.Separator, Ext.menu.BaseItem, { itemCls : "x-menu-sep", hideOnClick : false, onRender : function(li){ var s = document.createElement("span"); s.className = this.itemCls; s.innerHTML = " "; this.el = s; li.addClass("x-menu-sep-li"); Ext.menu.Separator.superclass.onRender.apply(this, arguments); } }); Ext.menu.Item = function(config){ Ext.menu.Item.superclass.constructor.call(this, config); if(this.menu){ this.menu = Ext.menu.MenuMgr.get(this.menu); } }; Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, { itemCls : "x-menu-item", canActivate : true, showDelay: 200, hideDelay: 200, ctype: "Ext.menu.Item", onRender : function(container, position){ var el = document.createElement("a"); el.hideFocus = true; el.unselectable = "on"; el.href = this.href || "#"; if(this.hrefTarget){ el.target = this.hrefTarget; } el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : ""); el.innerHTML = String.format( '<img src="{0}" class="x-menu-item-icon {2}" />{1}', this.icon || Ext.BLANK_IMAGE_URL, this.itemText||this.text, this.iconCls || ''); this.el = el; Ext.menu.Item.superclass.onRender.call(this, container, position); }, setText : function(text){ this.text = text; if(this.rendered){ this.el.update(String.format( '<img src="{0}" class="x-menu-item-icon {2}">{1}', this.icon || Ext.BLANK_IMAGE_URL, this.text, this.iconCls || '')); this.parentMenu.autoWidth(); } }, setIconClass : function(cls){ var oldCls = this.iconCls; this.iconCls = cls; if(this.rendered){ this.el.child('img.x-menu-item-icon').replaceClass(oldCls, this.iconCls); } }, handleClick : function(e){ if(!this.href){ e.stopEvent(); } Ext.menu.Item.superclass.handleClick.apply(this, arguments); }, activate : function(autoExpand){ if(Ext.menu.Item.superclass.activate.apply(this, arguments)){ this.focus(); if(autoExpand){ this.expandMenu(); } } return true; }, shouldDeactivate : function(e){ if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){ if(this.menu && this.menu.isVisible()){ return !this.menu.getEl().getRegion().contains(e.getPoint()); } return true; } return false; }, deactivate : function(){ Ext.menu.Item.superclass.deactivate.apply(this, arguments); this.hideMenu(); }, expandMenu : function(autoActivate){ if(!this.disabled && this.menu){ clearTimeout(this.hideTimer); delete this.hideTimer; if(!this.menu.isVisible() && !this.showTimer){ this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]); }else if (this.menu.isVisible() && autoActivate){ this.menu.tryActivate(0, 1); } } }, deferExpand : function(autoActivate){ delete this.showTimer; this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu); if(autoActivate){ this.menu.tryActivate(0, 1); } }, hideMenu : function(){ clearTimeout(this.showTimer); delete this.showTimer; if(!this.hideTimer && this.menu && this.menu.isVisible()){ this.hideTimer = this.deferHide.defer(this.hideDelay, this); } }, deferHide : function(){ delete this.hideTimer; if(this.menu.over){ this.parentMenu.setActiveItem(this, false); }else{ this.menu.hide(); } } }); Ext.menu.CheckItem = function(config){ Ext.menu.CheckItem.superclass.constructor.call(this, config); this.addEvents( "beforecheckchange" , "checkchange" ); if(this.checkHandler){ this.on('checkchange', this.checkHandler, this.scope); } Ext.menu.MenuMgr.registerCheckable(this); }; Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, { itemCls : "x-menu-item x-menu-check-item", groupClass : "x-menu-group-item", checked: false, ctype: "Ext.menu.CheckItem", onRender : function(c){ Ext.menu.CheckItem.superclass.onRender.apply(this, arguments); if(this.group){ this.el.addClass(this.groupClass); } if(this.checked){ this.checked = false; this.setChecked(true, true); } }, destroy : function(){ Ext.menu.MenuMgr.unregisterCheckable(this); Ext.menu.CheckItem.superclass.destroy.apply(this, arguments); }, setChecked : function(state, suppressEvent){ if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){ if(this.container){ this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked"); } this.checked = state; if(suppressEvent !== true){ this.fireEvent("checkchange", this, state); } } }, handleClick : function(e){ if(!this.disabled && !(this.checked && this.group)){ this.setChecked(!this.checked); } Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments); } }); Ext.menu.Adapter = function(component, config){ Ext.menu.Adapter.superclass.constructor.call(this, config); this.component = component; }; Ext.extend(Ext.menu.Adapter, Ext.menu.BaseItem, { canActivate : true, onRender : function(container, position){ this.component.render(container); this.el = this.component.getEl(); }, activate : function(){ if(this.disabled){ return false; } this.component.focus(); this.fireEvent("activate", this); return true; }, deactivate : function(){ this.fireEvent("deactivate", this); }, disable : function(){ this.component.disable(); Ext.menu.Adapter.superclass.disable.call(this); }, enable : function(){ this.component.enable(); Ext.menu.Adapter.superclass.enable.call(this); } }); Ext.menu.DateItem = function(config){ Ext.menu.DateItem.superclass.constructor.call(this, new Ext.DatePicker(config), config); this.picker = this.component; this.addEvents('select'); this.picker.on("render", function(picker){ picker.getEl().swallowEvent("click"); picker.container.addClass("x-menu-date-item"); }); this.picker.on("select", this.onSelect, this); }; Ext.extend(Ext.menu.DateItem, Ext.menu.Adapter, { onSelect : function(picker, date){ this.fireEvent("select", this, date, picker); Ext.menu.DateItem.superclass.handleClick.call(this); } }); Ext.menu.ColorItem = function(config){ Ext.menu.ColorItem.superclass.constructor.call(this, new Ext.ColorPalette(config), config); this.palette = this.component; this.relayEvents(this.palette, ["select"]); if(this.selectHandler){ this.on('select', this.selectHandler, this.scope); } }; Ext.extend(Ext.menu.ColorItem, Ext.menu.Adapter); Ext.menu.DateMenu = function(config){ Ext.menu.DateMenu.superclass.constructor.call(this, config); this.plain = true; var di = new Ext.menu.DateItem(config); this.add(di); this.picker = di.picker; this.relayEvents(di, ["select"]); this.on('beforeshow', function(){ if(this.picker){ this.picker.hideMonthPicker(true); } }, this); }; Ext.extend(Ext.menu.DateMenu, Ext.menu.Menu, { cls:'x-date-menu', beforeDestroy : function() { this.picker.destroy(); } }); Ext.menu.ColorMenu = function(config){ Ext.menu.ColorMenu.superclass.constructor.call(this, config); this.plain = true; var ci = new Ext.menu.ColorItem(config); this.add(ci); this.palette = ci.palette; this.relayEvents(ci, ["select"]); }; Ext.extend(Ext.menu.ColorMenu, Ext.menu.Menu); Ext.form.Field = Ext.extend(Ext.BoxComponent, { invalidClass : "x-form-invalid", invalidText : "The value in this field is invalid", focusClass : "x-form-focus", validationEvent : "keyup", validateOnBlur : true, validationDelay : 250, defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"}, fieldClass : "x-form-field", msgTarget : 'qtip', msgFx : 'normal', readOnly : false, disabled : false, isFormField : true, hasFocus : false, initComponent : function(){ Ext.form.Field.superclass.initComponent.call(this); this.addEvents( 'focus', 'blur', 'specialkey', 'change', 'invalid', 'valid' ); }, getName: function(){ return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || ''); }, onRender : function(ct, position){ Ext.form.Field.superclass.onRender.call(this, ct, position); if(!this.el){ var cfg = this.getAutoCreate(); if(!cfg.name){ cfg.name = this.name || this.id; } if(this.inputType){ cfg.type = this.inputType; } this.el = ct.createChild(cfg, position); } var type = this.el.dom.type; if(type){ if(type == 'password'){ type = 'text'; } this.el.addClass('x-form-'+type); } if(this.readOnly){ this.el.dom.readOnly = true; } if(this.tabIndex !== undefined){ this.el.dom.setAttribute('tabIndex', this.tabIndex); } this.el.addClass([this.fieldClass, this.cls]); }, initValue : function(){ if(this.value !== undefined){ this.setValue(this.value); }else if(this.el.dom.value.length > 0 && this.el.dom.value != this.emptyText){ this.setValue(this.el.dom.value); } this.originalValue = this.getValue(); }, isDirty : function() { if(this.disabled) { return false; } return String(this.getValue()) !== String(this.originalValue); }, afterRender : function(){ Ext.form.Field.superclass.afterRender.call(this); this.initEvents(); this.initValue(); }, fireKey : function(e){ if(e.isSpecialKey()){ this.fireEvent("specialkey", this, e); } }, reset : function(){ this.setValue(this.originalValue); this.clearInvalid(); }, initEvents : function(){ this.el.on(Ext.isIE || Ext.isSafari3 ? "keydown" : "keypress", this.fireKey, this); this.el.on("focus", this.onFocus, this); var o = this.inEditor && Ext.isWindows && Ext.isGecko ? {buffer:10} : null; this.el.on("blur", this.onBlur, this, o); this.originalValue = this.getValue(); }, onFocus : function(){ if(!Ext.isOpera && this.focusClass){ this.el.addClass(this.focusClass); } if(!this.hasFocus){ this.hasFocus = true; this.startValue = this.getValue(); this.fireEvent("focus", this); } }, beforeBlur : Ext.emptyFn, onBlur : function(){ this.beforeBlur(); if(!Ext.isOpera && this.focusClass){ this.el.removeClass(this.focusClass); } this.hasFocus = false; if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){ this.validate(); } var v = this.getValue(); if(String(v) !== String(this.startValue)){ this.fireEvent('change', this, v, this.startValue); } this.fireEvent("blur", this); }, isValid : function(preventMark){ if(this.disabled){ return true; } var restore = this.preventMark; this.preventMark = preventMark === true; var v = this.validateValue(this.processValue(this.getRawValue())); this.preventMark = restore; return v; }, validate : function(){ if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){ this.clearInvalid(); return true; } return false; }, processValue : function(value){ return value; }, validateValue : function(value){ return true; }, markInvalid : function(msg){ if(!this.rendered || this.preventMark){ return; } this.el.addClass(this.invalidClass); msg = msg || this.invalidText; switch(this.msgTarget){ case 'qtip': this.el.dom.qtip = msg; this.el.dom.qclass = 'x-form-invalid-tip'; if(Ext.QuickTips){ Ext.QuickTips.enable(); } break; case 'title': this.el.dom.title = msg; break; case 'under': if(!this.errorEl){ var elp = this.getErrorCt(); if(!elp){ this.el.dom.title = msg; break; } this.errorEl = elp.createChild({cls:'x-form-invalid-msg'}); this.errorEl.setWidth(elp.getWidth(true)-20); } this.errorEl.update(msg); Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this); break; case 'side': if(!this.errorIcon){ var elp = this.getErrorCt(); if(!elp){ this.el.dom.title = msg; break; } this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'}); } this.alignErrorIcon(); this.errorIcon.dom.qtip = msg; this.errorIcon.dom.qclass = 'x-form-invalid-tip'; this.errorIcon.show(); this.on('resize', this.alignErrorIcon, this); break; default: var t = Ext.getDom(this.msgTarget); t.innerHTML = msg; t.style.display = this.msgDisplay; break; } this.fireEvent('invalid', this, msg); }, getErrorCt : function(){ return this.el.findParent('.x-form-element', 5, true) || this.el.findParent('.x-form-field-wrap', 5, true); }, alignErrorIcon : function(){ this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]); }, clearInvalid : function(){ if(!this.rendered || this.preventMark){ return; } this.el.removeClass(this.invalidClass); switch(this.msgTarget){ case 'qtip': this.el.dom.qtip = ''; break; case 'title': this.el.dom.title = ''; break; case 'under': if(this.errorEl){ Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this); } break; case 'side': if(this.errorIcon){ this.errorIcon.dom.qtip = ''; this.errorIcon.hide(); this.un('resize', this.alignErrorIcon, this); } break; default: var t = Ext.getDom(this.msgTarget); t.innerHTML = ''; t.style.display = 'none'; break; } this.fireEvent('valid', this); }, getRawValue : function(){ var v = this.rendered ? this.el.getValue() : Ext.value(this.value, ''); if(v === this.emptyText){ v = ''; } return v; }, getValue : function(){ if(!this.rendered) { return this.value; } var v = this.el.getValue(); if(v === this.emptyText || v === undefined){ v = ''; } return v; }, setRawValue : function(v){ return this.el.dom.value = (v === null || v === undefined ? '' : v); }, setValue : function(v){ this.value = v; if(this.rendered){ this.el.dom.value = (v === null || v === undefined ? '' : v); this.validate(); } }, adjustSize : function(w, h){ var s = Ext.form.Field.superclass.adjustSize.call(this, w, h); s.width = this.adjustWidth(this.el.dom.tagName, s.width); return s; }, adjustWidth : function(tag, w){ tag = tag.toLowerCase(); if(typeof w == 'number' && !Ext.isSafari){ if(Ext.isIE && (tag == 'input' || tag == 'textarea')){ if(tag == 'input' && !Ext.isStrict){ return this.inEditor ? w : w - 3; } if(tag == 'input' && Ext.isStrict){ return w - (Ext.isIE6 ? 4 : 1); } if(tag == 'textarea' && Ext.isStrict){ return w-2; } }else if(Ext.isOpera && Ext.isStrict){ if(tag == 'input'){ return w + 2; } if(tag == 'textarea'){ return w-2; } } } return w; } }); Ext.form.MessageTargets = { 'qtip' : { mark: function(f){ this.el.dom.qtip = msg; this.el.dom.qclass = 'x-form-invalid-tip'; if(Ext.QuickTips){ Ext.QuickTips.enable(); } }, clear: function(f){ this.el.dom.qtip = ''; } }, 'title' : { mark: function(f){ this.el.dom.title = msg; }, clear: function(f){ this.el.dom.title = ''; } }, 'under' : { mark: function(f){ if(!this.errorEl){ var elp = this.getErrorCt(); if(!elp){ this.el.dom.title = msg; return; } this.errorEl = elp.createChild({cls:'x-form-invalid-msg'}); this.errorEl.setWidth(elp.getWidth(true)-20); } this.errorEl.update(msg); Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this); }, clear: function(f){ if(this.errorEl){ Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this); }else{ this.el.dom.title = ''; } } }, 'side' : { mark: function(f){ if(!this.errorIcon){ var elp = this.getErrorCt(); if(!elp){ this.el.dom.title = msg; return; } this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'}); } this.alignErrorIcon(); this.errorIcon.dom.qtip = msg; this.errorIcon.dom.qclass = 'x-form-invalid-tip'; this.errorIcon.show(); this.on('resize', this.alignErrorIcon, this); }, clear: function(f){ if(this.errorIcon){ this.errorIcon.dom.qtip = ''; this.errorIcon.hide(); this.un('resize', this.alignErrorIcon, this); }else{ this.el.dom.title = ''; } } }, 'around' : { mark: function(f){ }, clear: function(f){ } } }; Ext.form.Field.msgFx = { normal : { show: function(msgEl, f){ msgEl.setDisplayed('block'); }, hide : function(msgEl, f){ msgEl.setDisplayed(false).update(''); } }, slide : { show: function(msgEl, f){ msgEl.slideIn('t', {stopFx:true}); }, hide : function(msgEl, f){ msgEl.slideOut('t', {stopFx:true,useDisplay:true}); } }, slideRight : { show: function(msgEl, f){ msgEl.fixDisplay(); msgEl.alignTo(f.el, 'tl-tr'); msgEl.slideIn('l', {stopFx:true}); }, hide : function(msgEl, f){ msgEl.slideOut('l', {stopFx:true,useDisplay:true}); } } }; Ext.reg('field', Ext.form.Field); Ext.form.TextField = Ext.extend(Ext.form.Field, { grow : false, growMin : 30, growMax : 800, vtype : null, maskRe : null, disableKeyFilter : false, allowBlank : true, minLength : 0, maxLength : Number.MAX_VALUE, minLengthText : "The minimum length for this field is {0}", maxLengthText : "The maximum length for this field is {0}", selectOnFocus : false, blankText : "This field is required", validator : null, regex : null, regexText : "", emptyText : null, emptyClass : 'x-form-empty-field', initComponent : function(){ Ext.form.TextField.superclass.initComponent.call(this); this.addEvents( 'autosize', 'keydown', 'keyup', 'keypress' ); }, initEvents : function(){ Ext.form.TextField.superclass.initEvents.call(this); if(this.validationEvent == 'keyup'){ this.validationTask = new Ext.util.DelayedTask(this.validate, this); this.el.on('keyup', this.filterValidation, this); } else if(this.validationEvent !== false){ this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay}); } if(this.selectOnFocus || this.emptyText){ this.on("focus", this.preFocus, this); this.el.on('mousedown', function(){ if(!this.hasFocus){ this.el.on('mouseup', function(e){ e.preventDefault(); }, this, {single:true}); } }, this); if(this.emptyText){ this.on('blur', this.postBlur, this); this.applyEmptyText(); } } if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){ this.el.on("keypress", this.filterKeys, this); } if(this.grow){ this.el.on("keyup", this.onKeyUpBuffered, this, {buffer:50}); this.el.on("click", this.autoSize, this); } if(this.enableKeyEvents){ this.el.on("keyup", this.onKeyUp, this); this.el.on("keydown", this.onKeyDown, this); this.el.on("keypress", this.onKeyPress, this); } }, processValue : function(value){ if(this.stripCharsRe){ var newValue = value.replace(this.stripCharsRe, ''); if(newValue !== value){ this.setRawValue(newValue); return newValue; } } return value; }, filterValidation : function(e){ if(!e.isNavKeyPress()){ this.validationTask.delay(this.validationDelay); } }, onKeyUpBuffered : function(e){ if(!e.isNavKeyPress()){ this.autoSize(); } }, onKeyUp : function(e){ this.fireEvent('keyup', this, e); }, onKeyDown : function(e){ this.fireEvent('keydown', this, e); }, onKeyPress : function(e){ this.fireEvent('keypress', this, e); }, reset : function(){ Ext.form.TextField.superclass.reset.call(this); this.applyEmptyText(); }, applyEmptyText : function(){ if(this.rendered && this.emptyText && this.getRawValue().length < 1){ this.setRawValue(this.emptyText); this.el.addClass(this.emptyClass); } }, preFocus : function(){ if(this.emptyText){ if(this.el.dom.value == this.emptyText){ this.setRawValue(''); } this.el.removeClass(this.emptyClass); } if(this.selectOnFocus){ this.el.dom.select(); } }, postBlur : function(){ this.applyEmptyText(); }, filterKeys : function(e){ if(e.ctrlKey){ return; } var k = e.getKey(); if(Ext.isGecko && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){ return; } var c = e.getCharCode(), cc = String.fromCharCode(c); if(!Ext.isGecko && e.isSpecialKey() && !cc){ return; } if(!this.maskRe.test(cc)){ e.stopEvent(); } }, setValue : function(v){ if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){ this.el.removeClass(this.emptyClass); } Ext.form.TextField.superclass.setValue.apply(this, arguments); this.applyEmptyText(); this.autoSize(); }, validateValue : function(value){ if(value.length < 1 || value === this.emptyText){ if(this.allowBlank){ this.clearInvalid(); return true; }else{ this.markInvalid(this.blankText); return false; } } if(value.length < this.minLength){ this.markInvalid(String.format(this.minLengthText, this.minLength)); return false; } if(value.length > this.maxLength){ this.markInvalid(String.format(this.maxLengthText, this.maxLength)); return false; } if(this.vtype){ var vt = Ext.form.VTypes; if(!vt[this.vtype](value, this)){ this.markInvalid(this.vtypeText || vt[this.vtype +'Text']); return false; } } if(typeof this.validator == "function"){ var msg = this.validator(value); if(msg !== true){ this.markInvalid(msg); return false; } } if(this.regex && !this.regex.test(value)){ this.markInvalid(this.regexText); return false; } return true; }, selectText : function(start, end){ var v = this.getRawValue(); if(v.length > 0){ start = start === undefined ? 0 : start; end = end === undefined ? v.length : end; var d = this.el.dom; if(d.setSelectionRange){ d.setSelectionRange(start, end); }else if(d.createTextRange){ var range = d.createTextRange(); range.moveStart("character", start); range.moveEnd("character", end-v.length); range.select(); } } }, autoSize : function(){ if(!this.grow || !this.rendered){ return; } if(!this.metrics){ this.metrics = Ext.util.TextMetrics.createInstance(this.el); } var el = this.el; var v = el.dom.value; var d = document.createElement('div'); d.appendChild(document.createTextNode(v)); v = d.innerHTML; d = null; v += " "; var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + 10, this.growMin)); this.el.setWidth(w); this.fireEvent("autosize", this, w); } }); Ext.reg('textfield', Ext.form.TextField); Ext.form.TriggerField = Ext.extend(Ext.form.TextField, { defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"}, hideTrigger:false, autoSize: Ext.emptyFn, monitorTab : true, deferHeight : true, mimicing : false, onResize : function(w, h){ Ext.form.TriggerField.superclass.onResize.call(this, w, h); if(typeof w == 'number'){ this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth())); } this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth()); }, adjustSize : Ext.BoxComponent.prototype.adjustSize, getResizeEl : function(){ return this.wrap; }, getPositionEl : function(){ return this.wrap; }, alignErrorIcon : function(){ if(this.wrap){ this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]); } }, onRender : function(ct, position){ Ext.form.TriggerField.superclass.onRender.call(this, ct, position); this.wrap = this.el.wrap({cls: "x-form-field-wrap"}); this.trigger = this.wrap.createChild(this.triggerConfig || {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}); if(this.hideTrigger){ this.trigger.setDisplayed(false); } this.initTrigger(); if(!this.width){ this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth()); } }, afterRender : function(){ Ext.form.TriggerField.superclass.afterRender.call(this); var y; if(Ext.isIE && this.el.getY() != (y = this.trigger.getY())){ this.el.position(); this.el.setY(y); } }, initTrigger : function(){ this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true}); this.trigger.addClassOnOver('x-form-trigger-over'); this.trigger.addClassOnClick('x-form-trigger-click'); }, onDestroy : function(){ if(this.trigger){ this.trigger.removeAllListeners(); this.trigger.remove(); } if(this.wrap){ this.wrap.remove(); } Ext.form.TriggerField.superclass.onDestroy.call(this); }, onFocus : function(){ Ext.form.TriggerField.superclass.onFocus.call(this); if(!this.mimicing){ this.wrap.addClass('x-trigger-wrap-focus'); this.mimicing = true; Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {delay: 10}); if(this.monitorTab){ this.el.on("keydown", this.checkTab, this); } } }, checkTab : function(e){ if(e.getKey() == e.TAB){ this.triggerBlur(); } }, onBlur : function(){ }, mimicBlur : function(e){ if(!this.wrap.contains(e.target) && this.validateBlur(e)){ this.triggerBlur(); } }, triggerBlur : function(){ this.mimicing = false; Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this); if(this.monitorTab){ this.el.un("keydown", this.checkTab, this); } this.beforeBlur(); this.wrap.removeClass('x-trigger-wrap-focus'); Ext.form.TriggerField.superclass.onBlur.call(this); }, beforeBlur : Ext.emptyFn, validateBlur : function(e){ return true; }, onDisable : function(){ Ext.form.TriggerField.superclass.onDisable.call(this); if(this.wrap){ this.wrap.addClass(this.disabledClass); this.el.removeClass(this.disabledClass); } }, onEnable : function(){ Ext.form.TriggerField.superclass.onEnable.call(this); if(this.wrap){ this.wrap.removeClass(this.disabledClass); } }, onShow : function(){ if(this.wrap){ this.wrap.dom.style.display = ''; this.wrap.dom.style.visibility = 'visible'; } }, onHide : function(){ this.wrap.dom.style.display = 'none'; }, onTriggerClick : Ext.emptyFn }); Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, { initComponent : function(){ Ext.form.TwinTriggerField.superclass.initComponent.call(this); this.triggerConfig = { tag:'span', cls:'x-form-twin-triggers', cn:[ {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class}, {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class} ]}; }, getTrigger : function(index){ return this.triggers[index]; }, initTrigger : function(){ var ts = this.trigger.select('.x-form-trigger', true); this.wrap.setStyle('overflow', 'hidden'); var triggerField = this; ts.each(function(t, all, index){ t.hide = function(){ var w = triggerField.wrap.getWidth(); this.dom.style.display = 'none'; triggerField.el.setWidth(w-triggerField.trigger.getWidth()); }; t.show = function(){ var w = triggerField.wrap.getWidth(); this.dom.style.display = ''; triggerField.el.setWidth(w-triggerField.trigger.getWidth()); }; var triggerIndex = 'Trigger'+(index+1); if(this['hide'+triggerIndex]){ t.dom.style.display = 'none'; } t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true}); t.addClassOnOver('x-form-trigger-over'); t.addClassOnClick('x-form-trigger-click'); }, this); this.triggers = ts.elements; }, onTrigger1Click : Ext.emptyFn, onTrigger2Click : Ext.emptyFn }); Ext.reg('trigger', Ext.form.TriggerField); Ext.form.TextArea = Ext.extend(Ext.form.TextField, { growMin : 60, growMax: 1000, growAppend : ' n ', growPad : 0, enterIsSpecial : false, preventScrollbars: false, onRender : function(ct, position){ if(!this.el){ this.defaultAutoCreate = { tag: "textarea", style:"width:100px;height:60px;", autocomplete: "off" }; } Ext.form.TextArea.superclass.onRender.call(this, ct, position); if(this.grow){ this.textSizeEl = Ext.DomHelper.append(document.body, { tag: "pre", cls: "x-form-grow-sizer" }); if(this.preventScrollbars){ this.el.setStyle("overflow", "hidden"); } this.el.setHeight(this.growMin); } }, onDestroy : function(){ if(this.textSizeEl){ Ext.removeNode(this.textSizeEl); } Ext.form.TextArea.superclass.onDestroy.call(this); }, fireKey : function(e){ if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){ this.fireEvent("specialkey", this, e); } }, onKeyUp : function(e){ if(!e.isNavKeyPress() || e.getKey() == e.ENTER){ this.autoSize(); } Ext.form.TextArea.superclass.onKeyUp.call(this, e); }, autoSize : function(){ if(!this.grow || !this.textSizeEl){ return; } var el = this.el; var v = el.dom.value; var ts = this.textSizeEl; ts.innerHTML = ''; ts.appendChild(document.createTextNode(v)); v = ts.innerHTML; Ext.fly(ts).setWidth(this.el.getWidth()); if(v.length < 1){ v = "  "; }else{ if(Ext.isIE){ v = v.replace(/n/g, '<p> </p>'); } v += this.growAppend; } ts.innerHTML = v; var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin)+this.growPad); if(h != this.lastHeight){ this.lastHeight = h; this.el.setHeight(h); this.fireEvent("autosize", this, h); } } }); Ext.reg('textarea', Ext.form.TextArea); Ext.form.NumberField = Ext.extend(Ext.form.TextField, { fieldClass: "x-form-field x-form-num-field", allowDecimals : true, decimalSeparator : ".", decimalPrecision : 2, allowNegative : true, minValue : Number.NEGATIVE_INFINITY, maxValue : Number.MAX_VALUE, minText : "The minimum value for this field is {0}", maxText : "The maximum value for this field is {0}", nanText : "{0} is not a valid number", baseChars : "0123456789", initEvents : function(){ Ext.form.NumberField.superclass.initEvents.call(this); var allowed = this.baseChars+''; if(this.allowDecimals){ allowed += this.decimalSeparator; } if(this.allowNegative){ allowed += "-"; } this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi'); var keyPress = function(e){ var k = e.getKey(); if(!Ext.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){ return; } var c = e.getCharCode(); if(allowed.indexOf(String.fromCharCode(c)) === -1){ e.stopEvent(); } }; this.el.on("keypress", keyPress, this); }, validateValue : function(value){ if(!Ext.form.NumberField.superclass.validateValue.call(this, value)){ return false; } if(value.length < 1){ return true; } value = String(value).replace(this.decimalSeparator, "."); if(isNaN(value)){ this.markInvalid(String.format(this.nanText, value)); return false; } var num = this.parseValue(value); if(num < this.minValue){ this.markInvalid(String.format(this.minText, this.minValue)); return false; } if(num > this.maxValue){ this.markInvalid(String.format(this.maxText, this.maxValue)); return false; } return true; }, getValue : function(){ return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this))); }, setValue : function(v){ v = typeof v == 'number' ? v : parseFloat(String(v).replace(this.decimalSeparator, ".")); v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator); Ext.form.NumberField.superclass.setValue.call(this, v); }, parseValue : function(value){ value = parseFloat(String(value).replace(this.decimalSeparator, ".")); return isNaN(value) ? '' : value; }, fixPrecision : function(value){ var nan = isNaN(value); if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){ return nan ? '' : value; } return parseFloat(parseFloat(value).toFixed(this.decimalPrecision)); }, beforeBlur : function(){ var v = this.parseValue(this.getRawValue()); if(v){ this.setValue(this.fixPrecision(v)); } } }); Ext.reg('numberfield', Ext.form.NumberField); Ext.form.DateField = Ext.extend(Ext.form.TriggerField, { format : "m/d/Y", 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", disabledDaysText : "Disabled", disabledDatesText : "Disabled", minText : "The date in this field must be equal to or after {0}", maxText : "The date in this field must be equal to or before {0}", invalidText : "{0} is not a valid date - it must be in the format {1}", triggerClass : 'x-form-date-trigger', showToday : true, defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"}, initComponent : function(){ Ext.form.DateField.superclass.initComponent.call(this); if(typeof this.minValue == "string"){ this.minValue = this.parseDate(this.minValue); } if(typeof this.maxValue == "string"){ this.maxValue = this.parseDate(this.maxValue); } this.ddMatch = null; this.initDisabledDays(); }, initDisabledDays : function(){ if(this.disabledDates){ var dd = this.disabledDates; var re = "(?:"; for(var i = 0; i < dd.length; i++){ re += dd[i]; if(i != dd.length-1) re += "|"; } this.disabledDatesRE = new RegExp(re + ")"); } }, setDisabledDates : function(dd){ this.disabledDates = dd; this.initDisabledDays(); if(this.menu){ this.menu.picker.setDisabledDates(this.disabledDatesRE); } }, setDisabledDays : function(dd){ this.disabledDays = dd; if(this.menu){ this.menu.picker.setDisabledDays(dd); } }, setMinValue : function(dt){ this.minValue = (typeof dt == "string" ? this.parseDate(dt) : dt); if(this.menu){ this.menu.picker.setMinDate(this.minValue); } }, setMaxValue : function(dt){ this.maxValue = (typeof dt == "string" ? this.parseDate(dt) : dt); if(this.menu){ this.menu.picker.setMaxDate(this.maxValue); } }, validateValue : function(value){ value = this.formatDate(value); if(!Ext.form.DateField.superclass.validateValue.call(this, value)){ return false; } if(value.length < 1){ return true; } var svalue = value; value = this.parseDate(value); if(!value){ this.markInvalid(String.format(this.invalidText, svalue, this.format)); return false; } var time = value.getTime(); if(this.minValue && time < this.minValue.getTime()){ this.markInvalid(String.format(this.minText, this.formatDate(this.minValue))); return false; } if(this.maxValue && time > this.maxValue.getTime()){ this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue))); return false; } if(this.disabledDays){ var day = value.getDay(); for(var i = 0; i < this.disabledDays.length; i++) { if(day === this.disabledDays[i]){ this.markInvalid(this.disabledDaysText); return false; } } } var fvalue = this.formatDate(value); if(this.ddMatch && this.ddMatch.test(fvalue)){ this.markInvalid(String.format(this.disabledDatesText, fvalue)); return false; } return true; }, validateBlur : function(){ return !this.menu || !this.menu.isVisible(); }, getValue : function(){ return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || ""; }, setValue : function(date){ Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date))); }, parseDate : function(value){ if(!value || Ext.isDate(value)){ return value; } var v = Date.parseDate(value, this.format); if(!v && this.altFormats){ if(!this.altFormatsArray){ this.altFormatsArray = this.altFormats.split("|"); } for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){ v = Date.parseDate(value, this.altFormatsArray[i]); } } return v; }, onDestroy : function(){ if(this.menu) { this.menu.destroy(); } if(this.wrap){ this.wrap.remove(); } Ext.form.DateField.superclass.onDestroy.call(this); }, formatDate : function(date){ return Ext.isDate(date) ? date.dateFormat(this.format) : date; }, menuListeners : { select: function(m, d){ this.setValue(d); }, show : function(){ this.onFocus(); }, hide : function(){ this.focus.defer(10, this); var ml = this.menuListeners; this.menu.un("select", ml.select, this); this.menu.un("show", ml.show, this); this.menu.un("hide", ml.hide, this); } }, onTriggerClick : function(){ if(this.disabled){ return; } if(this.menu == null){ this.menu = new Ext.menu.DateMenu(); } Ext.apply(this.menu.picker, { minDate : this.minValue, maxDate : this.maxValue, disabledDatesRE : this.ddMatch, disabledDatesText : this.disabledDatesText, disabledDays : this.disabledDays, disabledDaysText : this.disabledDaysText, format : this.format, showToday : this.showToday, minText : String.format(this.minText, this.formatDate(this.minValue)), maxText : String.format(this.maxText, this.formatDate(this.maxValue)) }); this.menu.on(Ext.apply({}, this.menuListeners, { scope:this })); this.menu.picker.setValue(this.getValue() || new Date()); this.menu.show(this.el, "tl-bl?"); }, beforeBlur : function(){ var v = this.parseDate(this.getRawValue()); if(v){ this.setValue(v); } } }); Ext.reg('datefield', Ext.form.DateField); Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, { defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"}, listClass: '', selectedClass: 'x-combo-selected', triggerClass : 'x-form-arrow-trigger', shadow:'sides', listAlign: 'tl-bl?', maxHeight: 300, minHeight: 90, triggerAction: 'query', minChars : 4, typeAhead: false, queryDelay: 500, pageSize: 0, selectOnFocus:false, queryParam: 'query', loadingText: 'Loading...', resizable: false, handleHeight : 8, editable: true, allQuery: '', mode: 'remote', minListWidth : 70, forceSelection:false, typeAheadDelay : 250, lazyInit : true, initComponent : function(){ Ext.form.ComboBox.superclass.initComponent.call(this); this.addEvents( 'expand', 'collapse', 'beforeselect', 'select', 'beforequery' ); if(this.transform){ this.allowDomMove = false; var s = Ext.getDom(this.transform); if(!this.hiddenName){ this.hiddenName = s.name; } if(!this.store){ this.mode = 'local'; var d = [], opts = s.options; for(var i = 0, len = opts.length;i < len; i++){ var o = opts[i]; var value = (Ext.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text; if(o.selected) { this.value = value; } d.push([value, o.text]); } this.store = new Ext.data.SimpleStore({ 'id': 0, fields: ['value', 'text'], data : d }); this.valueField = 'value'; this.displayField = 'text'; } s.name = Ext.id(); if(!this.lazyRender){ this.target = true; this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate); Ext.removeNode(s); this.render(this.el.parentNode); }else{ Ext.removeNode(s); } } else if(Ext.isArray(this.store)){ if (Ext.isArray(this.store[0])){ this.store = new Ext.data.SimpleStore({ fields: ['value','text'], data: this.store }); this.valueField = 'value'; }else{ this.store = new Ext.data.SimpleStore({ fields: ['text'], data: this.store, expandData: true }); this.valueField = 'text'; } this.displayField = 'text'; this.mode = 'local'; } this.selectedIndex = -1; if(this.mode == 'local'){ if(this.initialConfig.queryDelay === undefined){ this.queryDelay = 10; } if(this.initialConfig.minChars === undefined){ this.minChars = 0; } } }, onRender : function(ct, position){ Ext.form.ComboBox.superclass.onRender.call(this, ct, position); if(this.hiddenName){ this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)}, 'before', true); this.el.dom.removeAttribute('name'); } if(Ext.isGecko){ this.el.dom.setAttribute('autocomplete', 'off'); } if(!this.lazyInit){ this.initList(); }else{ this.on('focus', this.initList, this, {single: true}); } if(!this.editable){ this.editable = true; this.setEditable(false); } }, initValue : function(){ Ext.form.ComboBox.superclass.initValue.call(this); if(this.hiddenField){ this.hiddenField.value = this.hiddenValue !== undefined ? this.hiddenValue : this.value !== undefined ? this.value : ''; } }, initList : function(){ if(!this.list){ var cls = 'x-combo-list'; this.list = new Ext.Layer({ shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false }); var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth); this.list.setWidth(lw); this.list.swallowEvent('mousewheel'); this.assetHeight = 0; if(this.title){ this.header = this.list.createChild({cls:cls+'-hd', html: this.title}); this.assetHeight += this.header.getHeight(); } this.innerList = this.list.createChild({cls:cls+'-inner'}); this.innerList.on('mouseover', this.onViewOver, this); this.innerList.on('mousemove', this.onViewMove, this); this.innerList.setWidth(lw - this.list.getFrameWidth('lr')); if(this.pageSize){ this.footer = this.list.createChild({cls:cls+'-ft'}); this.pageTb = new Ext.PagingToolbar({ store:this.store, pageSize: this.pageSize, renderTo:this.footer }); this.assetHeight += this.footer.getHeight(); } if(!this.tpl){ this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>'; } this.view = new Ext.DataView({ applyTo: this.innerList, tpl: this.tpl, singleSelect: true, selectedClass: this.selectedClass, itemSelector: this.itemSelector || '.' + cls + '-item' }); this.view.on('click', this.onViewClick, this); this.bindStore(this.store, true); if(this.resizable){ this.resizer = new Ext.Resizable(this.list, { pinned:true, handles:'se' }); this.resizer.on('resize', function(r, w, h){ this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight; this.listWidth = w; this.innerList.setWidth(w - this.list.getFrameWidth('lr')); this.restrictHeight(); }, this); this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px'); } } }, bindStore : function(store, initial){ if(this.store && !initial){ this.store.un('beforeload', this.onBeforeLoad, this); this.store.un('load', this.onLoad, this); this.store.un('loadexception', this.collapse, this); if(!store){ this.store = null; if(this.view){ this.view.setStore(null); } } } if(store){ this.store = Ext.StoreMgr.lookup(store); this.store.on('beforeload', this.onBeforeLoad, this); this.store.on('load', this.onLoad, this); this.store.on('loadexception', this.collapse, this); if(this.view){ this.view.setStore(store); } } }, initEvents : function(){ Ext.form.ComboBox.superclass.initEvents.call(this); this.keyNav = new Ext.KeyNav(this.el, { "up" : function(e){ this.inKeyMode = true; this.selectPrev(); }, "down" : function(e){ if(!this.isExpanded()){ this.onTriggerClick(); }else{ this.inKeyMode = true; this.selectNext(); } }, "enter" : function(e){ this.onViewClick(); this.delayedCheck = true; this.unsetDelayCheck.defer(10, this); }, "esc" : function(e){ this.collapse(); }, "tab" : function(e){ this.onViewClick(false); return true; }, scope : this, doRelay : function(foo, bar, hname){ if(hname == 'down' || this.scope.isExpanded()){ return Ext.KeyNav.prototype.doRelay.apply(this, arguments); } return true; }, forceKeyDown : true }); this.queryDelay = Math.max(this.queryDelay || 10, this.mode == 'local' ? 10 : 250); this.dqTask = new Ext.util.DelayedTask(this.initQuery, this); if(this.typeAhead){ this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this); } if(this.editable !== false){ this.el.on("keyup", this.onKeyUp, this); } if(this.forceSelection){ this.on('blur', this.doForce, this); } }, onDestroy : function(){ if(this.view){ this.view.el.removeAllListeners(); this.view.el.remove(); this.view.purgeListeners(); } if(this.list){ this.list.destroy(); } this.bindStore(null); Ext.form.ComboBox.superclass.onDestroy.call(this); }, unsetDelayCheck : function(){ delete this.delayedCheck; }, fireKey : function(e){ if(e.isNavKeyPress() && !this.isExpanded() && !this.delayedCheck){ this.fireEvent("specialkey", this, e); } }, onResize: function(w, h){ Ext.form.ComboBox.superclass.onResize.apply(this, arguments); if(this.list && this.listWidth === undefined){ var lw = Math.max(w, this.minListWidth); this.list.setWidth(lw); this.innerList.setWidth(lw - this.list.getFrameWidth('lr')); } }, onEnable: function(){ Ext.form.ComboBox.superclass.onEnable.apply(this, arguments); if(this.hiddenField){ this.hiddenField.disabled = false; } }, onDisable: function(){ Ext.form.ComboBox.superclass.onDisable.apply(this, arguments); if(this.hiddenField){ this.hiddenField.disabled = true; } }, setEditable : function(value){ if(value == this.editable){ return; } this.editable = value; if(!value){ this.el.dom.setAttribute('readOnly', true); this.el.on('mousedown', this.onTriggerClick, this); this.el.addClass('x-combo-noedit'); }else{ this.el.dom.setAttribute('readOnly', false); this.el.un('mousedown', this.onTriggerClick, this); this.el.removeClass('x-combo-noedit'); } }, onBeforeLoad : function(){ if(!this.hasFocus){ return; } this.innerList.update(this.loadingText ? '<div class="loading-indicator">'+this.loadingText+'</div>' : ''); this.restrictHeight(); this.selectedIndex = -1; }, onLoad : function(){ if(!this.hasFocus){ return; } if(this.store.getCount() > 0){ this.expand(); this.restrictHeight(); if(this.lastQuery == this.allQuery){ if(this.editable){ this.el.dom.select(); } if(!this.selectByValue(this.value, true)){ this.select(0, true); } }else{ this.selectNext(); if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){ this.taTask.delay(this.typeAheadDelay); } } }else{ this.onEmptyResults(); } }, onTypeAhead : function(){ if(this.store.getCount() > 0){ var r = this.store.getAt(0); var newValue = r.data[this.displayField]; var len = newValue.length; var selStart = this.getRawValue().length; if(selStart != len){ this.setRawValue(newValue); this.selectText(selStart, newValue.length); } } }, onSelect : function(record, index){ if(this.fireEvent('beforeselect', this, record, index) !== false){ this.setValue(record.data[this.valueField || this.displayField]); this.collapse(); this.fireEvent('select', this, record, index); } }, getValue : function(){ if(this.valueField){ return typeof this.value != 'undefined' ? this.value : ''; }else{ return Ext.form.ComboBox.superclass.getValue.call(this); } }, clearValue : function(){ if(this.hiddenField){ this.hiddenField.value = ''; } this.setRawValue(''); this.lastSelectionText = ''; this.applyEmptyText(); this.value = ''; }, setValue : function(v){ var text = v; if(this.valueField){ var r = this.findRecord(this.valueField, v); if(r){ text = r.data[this.displayField]; }else if(this.valueNotFoundText !== undefined){ text = this.valueNotFoundText; } } this.lastSelectionText = text; if(this.hiddenField){ this.hiddenField.value = v; } Ext.form.ComboBox.superclass.setValue.call(this, text); this.value = v; }, findRecord : function(prop, value){ var record; if(this.store.getCount() > 0){ this.store.each(function(r){ if(r.data[prop] == value){ record = r; return false; } }); } return record; }, onViewMove : function(e, t){ this.inKeyMode = false; }, onViewOver : function(e, t){ if(this.inKeyMode){ return; } var item = this.view.findItemFromChild(t); if(item){ var index = this.view.indexOf(item); this.select(index, false); } }, onViewClick : function(doFocus){ var index = this.view.getSelectedIndexes()[0]; var r = this.store.getAt(index); if(r){ this.onSelect(r, index); } if(doFocus !== false){ this.el.focus(); } }, restrictHeight : function(){ this.innerList.dom.style.height = ''; var inner = this.innerList.dom; var pad = this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight; var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight); var ha = this.getPosition()[1]-Ext.getBody().getScroll().top; var hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height; var space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5; h = Math.min(h, space, this.maxHeight); this.innerList.setHeight(h); this.list.beginUpdate(); this.list.setHeight(h+pad); this.list.alignTo(this.wrap, this.listAlign); this.list.endUpdate(); }, onEmptyResults : function(){ this.collapse(); }, isExpanded : function(){ return this.list && this.list.isVisible(); }, selectByValue : function(v, scrollIntoView){ if(v !== undefined && v !== null){ var r = this.findRecord(this.valueField || this.displayField, v); if(r){ this.select(this.store.indexOf(r), scrollIntoView); return true; } } return false; }, select : function(index, scrollIntoView){ this.selectedIndex = index; this.view.select(index); if(scrollIntoView !== false){ var el = this.view.getNode(index); if(el){ this.innerList.scrollChildIntoView(el, false); } } }, selectNext : function(){ var ct = this.store.getCount(); if(ct > 0){ if(this.selectedIndex == -1){ this.select(0); }else if(this.selectedIndex < ct-1){ this.select(this.selectedIndex+1); } } }, selectPrev : function(){ var ct = this.store.getCount(); if(ct > 0){ if(this.selectedIndex == -1){ this.select(0); }else if(this.selectedIndex != 0){ this.select(this.selectedIndex-1); } } }, onKeyUp : function(e){ if(this.editable !== false && !e.isSpecialKey()){ this.lastKey = e.getKey(); this.dqTask.delay(this.queryDelay); } }, validateBlur : function(){ return !this.list || !this.list.isVisible(); }, initQuery : function(){ this.doQuery(this.getRawValue()); }, doForce : function(){ if(this.el.dom.value.length > 0){ this.el.dom.value = this.lastSelectionText === undefined ? '' : this.lastSelectionText; this.applyEmptyText(); } }, doQuery : function(q, forceAll){ if(q === undefined || q === null){ q = ''; } var qe = { query: q, forceAll: forceAll, combo: this, cancel:false }; if(this.fireEvent('beforequery', qe)===false || qe.cancel){ return false; } q = qe.query; forceAll = qe.forceAll; if(forceAll === true || (q.length >= this.minChars)){ if(this.lastQuery !== q){ this.lastQuery = q; if(this.mode == 'local'){ this.selectedIndex = -1; if(forceAll){ this.store.clearFilter(); }else{ this.store.filter(this.displayField, q); } this.onLoad(); }else{ this.store.baseParams[this.queryParam] = q; this.store.load({ params: this.getParams(q) }); this.expand(); } }else{ this.selectedIndex = -1; this.onLoad(); } } }, getParams : function(q){ var p = {}; if(this.pageSize){ p.start = 0; p.limit = this.pageSize; } return p; }, collapse : function(){ if(!this.isExpanded()){ return; } this.list.hide(); Ext.getDoc().un('mousewheel', this.collapseIf, this); Ext.getDoc().un('mousedown', this.collapseIf, this); this.fireEvent('collapse', this); }, collapseIf : function(e){ if(!e.within(this.wrap) && !e.within(this.list)){ this.collapse(); } }, expand : function(){ if(this.isExpanded() || !this.hasFocus){ return; } this.list.alignTo(this.wrap, this.listAlign); this.list.show(); this.innerList.setOverflow('auto'); Ext.getDoc().on('mousewheel', this.collapseIf, this); Ext.getDoc().on('mousedown', this.collapseIf, this); this.fireEvent('expand', this); }, onTriggerClick : function(){ if(this.disabled){ return; } if(this.isExpanded()){ this.collapse(); this.el.focus(); }else { this.onFocus({}); if(this.triggerAction == 'all') { this.doQuery(this.allQuery, true); } else { this.doQuery(this.getRawValue()); } this.el.focus(); } } }); Ext.reg('combo', Ext.form.ComboBox); Ext.form.Checkbox = Ext.extend(Ext.form.Field, { checkedCls: 'x-form-check-checked', focusCls: 'x-form-check-focus', overCls: 'x-form-check-over', mouseDownCls: 'x-form-check-down', tabIndex: 0, checked: false, defaultAutoCreate: {tag: 'input', type: 'checkbox', autocomplete: 'off'}, baseCls: 'x-form-check', initComponent : function(){ Ext.form.Checkbox.superclass.initComponent.call(this); this.addEvents( 'check' ); }, initEvents : function(){ Ext.form.Checkbox.superclass.initEvents.call(this); this.initCheckEvents(); }, initCheckEvents : function(){ this.innerWrap.removeAllListeners(); this.innerWrap.addClassOnOver(this.overCls); this.innerWrap.addClassOnClick(this.mouseDownCls); this.innerWrap.on('click', this.onClick, this); this.innerWrap.on('keyup', this.onKeyUp, this); }, onRender : function(ct, position){ Ext.form.Checkbox.superclass.onRender.call(this, ct, position); if(this.inputValue !== undefined){ this.el.dom.value = this.inputValue; } this.el.addClass('x-hidden'); this.innerWrap = this.el.wrap({ tabIndex: this.tabIndex, cls: this.baseCls+'-wrap-inner' }); this.wrap = this.innerWrap.wrap({cls: this.baseCls+'-wrap'}); if(this.boxLabel){ this.labelEl = this.innerWrap.createChild({ tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel }); } this.imageEl = this.innerWrap.createChild({ tag: 'img', src: Ext.BLANK_IMAGE_URL, cls: this.baseCls }, this.el); if(this.checked){ this.setValue(true); }else{ this.checked = this.el.dom.checked; } this.originalValue = this.checked; }, onDestroy : function(){ if(this.rendered){ Ext.destroy(this.imageEl, this.labelEl, this.innerWrap, this.wrap); } Ext.form.Checkbox.superclass.onDestroy.call(this); }, onFocus: function(e) { Ext.form.Checkbox.superclass.onFocus.call(this, e); this.el.addClass(this.focusCls); }, onBlur: function(e) { Ext.form.Checkbox.superclass.onBlur.call(this, e); this.el.removeClass(this.focusCls); }, onResize : function(){ Ext.form.Checkbox.superclass.onResize.apply(this, arguments); if(!this.boxLabel && !this.fieldLabel){ this.el.alignTo(this.wrap, 'c-c'); } }, onKeyUp : function(e){ if(e.getKey() == Ext.EventObject.SPACE){ this.onClick(e); } }, onClick : function(e){ if (!this.disabled && !this.readOnly) { this.toggleValue(); } e.stopEvent(); }, onEnable : function(){ Ext.form.Checkbox.superclass.onEnable.call(this); this.initCheckEvents(); }, onDisable : function(){ Ext.form.Checkbox.superclass.onDisable.call(this); this.innerWrap.removeAllListeners(); }, toggleValue : function(){ this.setValue(!this.checked); }, getResizeEl : function(){ if(!this.resizeEl){ this.resizeEl = Ext.isSafari ? this.wrap : (this.wrap.up('.x-form-element', 5) || this.wrap); } return this.resizeEl; }, getPositionEl : function(){ return this.wrap; }, getActionEl : function(){ return this.wrap; }, markInvalid : Ext.emptyFn, clearInvalid : Ext.emptyFn, initValue : Ext.emptyFn, getValue : function(){ if(this.rendered){ return this.el.dom.checked; } return false; }, setValue : function(v) { var checked = this.checked; this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); if(this.el && this.el.dom){ this.el.dom.checked = this.checked; this.el.dom.defaultChecked = this.checked; } this.wrap[this.checked? 'addClass' : 'removeClass'](this.checkedCls); if(checked != this.checked){ this.fireEvent("check", this, this.checked); if(this.handler){ this.handler.call(this.scope || this, this, this.checked); } } } }); Ext.reg('checkbox', Ext.form.Checkbox); Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, { columns : 'auto', vertical : false, allowBlank : true, blankText : "You must select at least one item in this group", defaultType : 'checkbox', groupCls: 'x-form-check-group', onRender : function(ct, position){ if(!this.el){ var panelCfg = { cls: this.groupCls, layout: 'column', border: false, renderTo: ct }; var colCfg = { defaultType: this.defaultType, layout: 'form', border: false, defaults: { hideLabel: true, anchor: '100%' } } if(this.items[0].items){ Ext.apply(panelCfg, { layoutConfig: {columns: this.items.length}, defaults: this.defaults, items: this.items }) for(var i=0, len=this.items.length; i<len; i++){ Ext.applyIf(this.items[i], colCfg); }; }else{ var numCols, cols = []; if(typeof this.columns == 'string'){ this.columns = this.items.length; } if(!Ext.isArray(this.columns)){ var cs = []; for(var i=0; i<this.columns; i++){ cs.push((100/this.columns)*.01); } this.columns = cs; } numCols = this.columns.length; for(var i=0; i<numCols; i++){ var cc = Ext.apply({items:[]}, colCfg); cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] = this.columns[i]; if(this.defaults){ cc.defaults = Ext.apply(cc.defaults || {}, this.defaults) } cols.push(cc); }; if(this.vertical){ var rows = Math.ceil(this.items.length / numCols), ri = 0; for(var i=0, len=this.items.length; i<len; i++){ if(i>0 && i%rows==0){ ri++; } if(this.items[i].fieldLabel){ this.items[i].hideLabel = false; } cols[ri].items.push(this.items[i]); }; }else{ for(var i=0, len=this.items.length; i<len; i++){ var ci = i % numCols; if(this.items[i].fieldLabel){ this.items[i].hideLabel = false; } cols[ci].items.push(this.items[i]); }; } Ext.apply(panelCfg, { layoutConfig: {columns: numCols}, items: cols }); } this.panel = new Ext.Panel(panelCfg); this.el = this.panel.getEl(); if(this.forId && this.itemCls){ var l = this.el.up(this.itemCls).child('label', true); if(l){ l.setAttribute('htmlFor', this.forId); } } var fields = this.panel.findBy(function(c){ return c.isFormField; }, this); this.items = new Ext.util.MixedCollection(); this.items.addAll(fields); } Ext.form.CheckboxGroup.superclass.onRender.call(this, ct, position); }, validateValue : function(value){ if(!this.allowBlank){ var blank = true; this.items.each(function(f){ if(f.checked){ return blank = false; } }, this); if(blank){ this.markInvalid(this.blankText); return false; } } return true; }, onDisable : function(){ this.items.each(function(item){ item.disable(); }) }, onEnable : function(){ this.items.each(function(item){ item.enable(); }) }, onResize : function(w, h){ this.panel.setSize(w, h); this.panel.doLayout(); }, reset : function(){ Ext.form.CheckboxGroup.superclass.reset.call(this); this.items.each(function(c){ if(c.reset){ c.reset(); } }, this); }, initValue : Ext.emptyFn, getValue : Ext.emptyFn, getRawValue : Ext.emptyFn, setValue : Ext.emptyFn, setRawValue : Ext.emptyFn }); Ext.reg('checkboxgroup', Ext.form.CheckboxGroup); Ext.form.Radio = Ext.extend(Ext.form.Checkbox, { inputType: 'radio', baseCls: 'x-form-radio', getGroupValue : function(){ var c = this.getParent().child('input[name='+this.el.dom.name+']:checked', true); return c ? c.value : null; }, getParent : function(){ return this.el.up('form') || Ext.getBody(); }, toggleValue : function() { if(!this.checked){ var els = this.getParent().select('input[name='+this.el.dom.name+']'); els.each(function(el){ if(el.dom.id == this.id){ this.setValue(true); }else{ Ext.getCmp(el.dom.id).setValue(false); } }, this); } }, setValue : function(v){ if(typeof v=='boolean') { Ext.form.Radio.superclass.setValue.call(this, v); }else{ var r = this.getParent().child('input[name='+this.el.dom.name+'][value='+v+']', true); if(r && !r.checked){ Ext.getCmp(r.id).toggleValue(); }; } }, markInvalid : Ext.emptyFn, clearInvalid : Ext.emptyFn }); Ext.reg('radio', Ext.form.Radio); Ext.form.RadioGroup = Ext.extend(Ext.form.CheckboxGroup, { allowBlank : true, blankText : "You must select one item in this group", defaultType : 'radio', groupCls: 'x-form-radio-group' }); Ext.reg('radiogroup', Ext.form.RadioGroup);
- Ext.form.Hidden = Ext.extend(Ext.form.Field, {
- inputType : 'hidden',
- onRender : function(){
- Ext.form.Hidden.superclass.onRender.apply(this, arguments);
- },
- initEvents : function(){
- this.originalValue = this.getValue();
- },
- setSize : Ext.emptyFn,
- setWidth : Ext.emptyFn,
- setHeight : Ext.emptyFn,
- setPosition : Ext.emptyFn,
- setPagePosition : Ext.emptyFn,
- markInvalid : Ext.emptyFn,
- clearInvalid : Ext.emptyFn
- });
- Ext.reg('hidden', Ext.form.Hidden); Ext.form.BasicForm = function(el, config){ Ext.apply(this, config); this.items = new Ext.util.MixedCollection(false, function(o){ return o.id || (o.id = Ext.id()); }); this.addEvents( 'beforeaction', 'actionfailed', 'actioncomplete' ); if(el){ this.initEl(el); } Ext.form.BasicForm.superclass.constructor.call(this); }; Ext.extend(Ext.form.BasicForm, Ext.util.Observable, { timeout: 30, activeAction : null, trackResetOnLoad : false, initEl : function(el){ this.el = Ext.get(el); this.id = this.el.id || Ext.id(); if(!this.standardSubmit){ this.el.on('submit', this.onSubmit, this); } this.el.addClass('x-form'); }, getEl: function(){ return this.el; }, onSubmit : function(e){ e.stopEvent(); }, destroy: function() { this.items.each(function(f){ Ext.destroy(f); }); if(this.el){ this.el.removeAllListeners(); this.el.remove(); } this.purgeListeners(); }, isValid : function(){ var valid = true; this.items.each(function(f){ if(!f.validate()){ valid = false; } }); return valid; }, isDirty : function(){ var dirty = false; this.items.each(function(f){ if(f.isDirty()){ dirty = true; return false; } }); return dirty; }, doAction : function(action, options){ if(typeof action == 'string'){ action = new Ext.form.Action.ACTION_TYPES[action](this, options); } if(this.fireEvent('beforeaction', this, action) !== false){ this.beforeAction(action); action.run.defer(100, action); } return this; }, submit : function(options){ if(this.standardSubmit){ var v = this.isValid(); if(v){ this.el.dom.submit(); } return v; } this.doAction('submit', options); return this; }, load : function(options){ this.doAction('load', options); return this; }, updateRecord : function(record){ record.beginEdit(); var fs = record.fields; fs.each(function(f){ var field = this.findField(f.name); if(field){ record.set(f.name, field.getValue()); } }, this); record.endEdit(); return this; }, loadRecord : function(record){ this.setValues(record.data); return this; }, beforeAction : function(action){ var o = action.options; if(o.waitMsg){ if(this.waitMsgTarget === true){ this.el.mask(o.waitMsg, 'x-mask-loading'); }else if(this.waitMsgTarget){ this.waitMsgTarget = Ext.get(this.waitMsgTarget); this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading'); }else{ Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...'); } } }, afterAction : function(action, success){ this.activeAction = null; var o = action.options; if(o.waitMsg){ if(this.waitMsgTarget === true){ this.el.unmask(); }else if(this.waitMsgTarget){ this.waitMsgTarget.unmask(); }else{ Ext.MessageBox.updateProgress(1); Ext.MessageBox.hide(); } } if(success){ if(o.reset){ this.reset(); } Ext.callback(o.success, o.scope, [this, action]); this.fireEvent('actioncomplete', this, action); }else{ Ext.callback(o.failure, o.scope, [this, action]); this.fireEvent('actionfailed', this, action); } }, findField : function(id){ var field = this.items.get(id); if(!field){ this.items.each(function(f){ if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){ field = f; return false; } }); } return field || null; }, markInvalid : function(errors){ if(Ext.isArray(errors)){ for(var i = 0, len = errors.length; i < len; i++){ var fieldError = errors[i]; var f = this.findField(fieldError.id); if(f){ f.markInvalid(fieldError.msg); } } }else{ var field, id; for(id in errors){ if(typeof errors[id] != 'function' && (field = this.findField(id))){ field.markInvalid(errors[id]); } } } return this; }, setValues : function(values){ if(Ext.isArray(values)){ for(var i = 0, len = values.length; i < len; i++){ var v = values[i]; var f = this.findField(v.id); if(f){ f.setValue(v.value); if(this.trackResetOnLoad){ f.originalValue = f.getValue(); } } } }else{ var field, id; for(id in values){ if(typeof values[id] != 'function' && (field = this.findField(id))){ field.setValue(values[id]); if(this.trackResetOnLoad){ field.originalValue = field.getValue(); } } } } return this; }, getValues : function(asString){ var fs = Ext.lib.Ajax.serializeForm(this.el.dom); if(asString === true){ return fs; } return Ext.urlDecode(fs); }, clearInvalid : function(){ this.items.each(function(f){ f.clearInvalid(); }); return this; }, reset : function(){ this.items.each(function(f){ f.reset(); }); return this; }, add : function(){ this.items.addAll(Array.prototype.slice.call(arguments, 0)); return this; }, remove : function(field){ this.items.remove(field); return this; }, render : function(){ this.items.each(function(f){ if(f.isFormField && !f.rendered && document.getElementById(f.id)){ f.applyToMarkup(f.id); } }); return this; }, applyToFields : function(o){ this.items.each(function(f){ Ext.apply(f, o); }); return this; }, applyIfToFields : function(o){ this.items.each(function(f){ Ext.applyIf(f, o); }); return this; } }); Ext.BasicForm = Ext.form.BasicForm; Ext.FormPanel = Ext.extend(Ext.Panel, { buttonAlign:'center', minButtonWidth:75, labelAlign:'left', monitorValid : false, monitorPoll : 200, layout: 'form', initComponent :function(){ this.form = this.createForm(); this.bodyCfg = { tag: 'form', cls: this.baseCls + '-body', method : this.method || 'POST', id : this.formId || Ext.id() }; if(this.fileUpload) { this.bodyCfg.enctype = 'multipart/form-data'; } Ext.FormPanel.superclass.initComponent.call(this); this.addEvents( 'clientvalidation' ); this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']); }, createForm: function(){ delete this.initialConfig.listeners; return new Ext.form.BasicForm(null, this.initialConfig); }, initFields : function(){ var f = this.form; var formPanel = this; var fn = function(c){ if(c.isFormField){ f.add(c); }else if(c.doLayout && c != formPanel){ Ext.applyIf(c, { labelAlign: c.ownerCt.labelAlign, labelWidth: c.ownerCt.labelWidth, itemCls: c.ownerCt.itemCls }); if(c.items){ c.items.each(fn); } } } this.items.each(fn); }, getLayoutTarget : function(){ return this.form.el; }, getForm : function(){ return this.form; }, onRender : function(ct, position){ this.initFields(); Ext.FormPanel.superclass.onRender.call(this, ct, position); this.form.initEl(this.body); }, beforeDestroy: function(){ Ext.FormPanel.superclass.beforeDestroy.call(this); this.stopMonitoring(); Ext.destroy(this.form); }, initEvents : function(){ Ext.FormPanel.superclass.initEvents.call(this); this.items.on('remove', this.onRemove, this); this.items.on('add', this.onAdd, this); if(this.monitorValid){ this.startMonitoring(); } }, onAdd : function(ct, c) { if (c.isFormField) { this.form.add(c); } }, onRemove : function(c) { if (c.isFormField) { Ext.destroy(c.container.up('.x-form-item')); this.form.remove(c); } }, startMonitoring : function(){ if(!this.bound){ this.bound = true; Ext.TaskMgr.start({ run : this.bindHandler, interval : this.monitorPoll || 200, scope: this }); } }, stopMonitoring : function(){ this.bound = false; }, load : function(){ this.form.load.apply(this.form, arguments); }, onDisable : function(){ Ext.FormPanel.superclass.onDisable.call(this); if(this.form){ this.form.items.each(function(){ this.disable(); }); } }, onEnable : function(){ Ext.FormPanel.superclass.onEnable.call(this); if(this.form){ this.form.items.each(function(){ this.enable(); }); } }, bindHandler : function(){ if(!this.bound){ return false; } var valid = true; this.form.items.each(function(f){ if(!f.isValid(true)){ valid = false; return false; } }); if(this.buttons){ for(var i = 0, len = this.buttons.length; i < len; i++){ var btn = this.buttons[i]; if(btn.formBind === true && btn.disabled === valid){ btn.setDisabled(!valid); } } } this.fireEvent('clientvalidation', this, valid); } }); Ext.reg('form', Ext.FormPanel); Ext.form.FormPanel = Ext.FormPanel;
- Ext.form.FieldSet = Ext.extend(Ext.Panel, {
- baseCls:'x-fieldset',
- layout: 'form',
- onRender : function(ct, position){
- if(!this.el){
- this.el = document.createElement('fieldset');
- this.el.id = this.id;
- if (this.title || this.header || this.checkboxToggle) {
- this.el.appendChild(document.createElement('legend')).className = 'x-fieldset-header';
- }
- }
- Ext.form.FieldSet.superclass.onRender.call(this, ct, position);
- if(this.checkboxToggle){
- var o = typeof this.checkboxToggle == 'object' ?
- this.checkboxToggle :
- {tag: 'input', type: 'checkbox', name: this.checkboxName || this.id+'-checkbox'};
- this.checkbox = this.header.insertFirst(o);
- this.checkbox.dom.checked = !this.collapsed;
- this.checkbox.on('click', this.onCheckClick, this);
- }
- },
- onCollapse : function(doAnim, animArg){
- if(this.checkbox){
- this.checkbox.dom.checked = false;
- }
- this.afterCollapse();
- },
- onExpand : function(doAnim, animArg){
- if(this.checkbox){
- this.checkbox.dom.checked = true;
- }
- this.afterExpand();
- },
- onCheckClick : function(){
- this[this.checkbox.dom.checked ? 'expand' : 'collapse']();
- }
- });
- Ext.reg('fieldset', Ext.form.FieldSet);
- Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, {
- enableFormat : true,
- enableFontSize : true,
- enableColors : true,
- enableAlignments : true,
- enableLists : true,
- enableSourceEdit : true,
- enableLinks : true,
- enableFont : true,
- createLinkText : 'Please enter the URL for the link:',
- defaultLinkValue : 'http:/'+'/',
- fontFamilies : [
- 'Arial',
- 'Courier New',
- 'Tahoma',
- 'Times New Roman',
- 'Verdana'
- ],
- defaultFont: 'tahoma',
- validationEvent : false,
- deferHeight: true,
- initialized : false,
- activated : false,
- sourceEditMode : false,
- onFocus : Ext.emptyFn,
- iframePad:3,
- hideMode:'offsets',
- defaultAutoCreate : {
- tag: "textarea",
- style:"width:500px;height:300px;",
- autocomplete: "off"
- },
- initComponent : function(){
- this.addEvents(
- 'initialize',
- 'activate',
- 'beforesync',
- 'beforepush',
- 'sync',
- 'push',
- 'editmodechange'
- )
- },
- createFontOptions : function(){
- var buf = [], fs = this.fontFamilies, ff, lc;
- for(var i = 0, len = fs.length; i< len; i++){
- ff = fs[i];
- lc = ff.toLowerCase();
- buf.push(
- '<option value="',lc,'" style="font-family:',ff,';"',
- (this.defaultFont == lc ? ' selected="true">' : '>'),
- ff,
- '</option>'
- );
- }
- return buf.join('');
- },
- createToolbar : function(editor){
- var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled();
- function btn(id, toggle, handler){
- return {
- itemId : id,
- cls : 'x-btn-icon x-edit-'+id,
- enableToggle:toggle !== false,
- scope: editor,
- handler:handler||editor.relayBtnCmd,
- clickEvent:'mousedown',
- tooltip: tipsEnabled ? editor.buttonTips[id] || undefined : undefined,
- tabIndex:-1
- };
- }
- var tb = new Ext.Toolbar({
- renderTo:this.wrap.dom.firstChild
- });
- tb.el.on('click', function(e){
- e.preventDefault();
- });
- if(this.enableFont && !Ext.isSafari2){
- this.fontSelect = tb.el.createChild({
- tag:'select',
- cls:'x-font-select',
- html: this.createFontOptions()
- });
- this.fontSelect.on('change', function(){
- var font = this.fontSelect.dom.value;
- this.relayCmd('fontname', font);
- this.deferFocus();
- }, this);
- tb.add(
- this.fontSelect.dom,
- '-'
- );
- };
- if(this.enableFormat){
- tb.add(
- btn('bold'),
- btn('italic'),
- btn('underline')
- );
- };
- if(this.enableFontSize){
- tb.add(
- '-',
- btn('increasefontsize', false, this.adjustFont),
- btn('decreasefontsize', false, this.adjustFont)
- );
- };
- if(this.enableColors){
- tb.add(
- '-', {
- itemId:'forecolor',
- cls:'x-btn-icon x-edit-forecolor',
- clickEvent:'mousedown',
- tooltip: tipsEnabled ? editor.buttonTips['forecolor'] || undefined : undefined,
- tabIndex:-1,
- menu : new Ext.menu.ColorMenu({
- allowReselect: true,
- focus: Ext.emptyFn,
- value:'000000',
- plain:true,
- selectHandler: function(cp, color){
- this.execCmd('forecolor', Ext.isSafari || Ext.isIE ? '#'+color : color);
- this.deferFocus();
- },
- scope: this,
- clickEvent:'mousedown'
- })
- }, {
- itemId:'backcolor',
- cls:'x-btn-icon x-edit-backcolor',
- clickEvent:'mousedown',
- tooltip: tipsEnabled ? editor.buttonTips['backcolor'] || undefined : undefined,
- tabIndex:-1,
- menu : new Ext.menu.ColorMenu({
- focus: Ext.emptyFn,
- value:'FFFFFF',
- plain:true,
- allowReselect: true,
- selectHandler: function(cp, color){
- if(Ext.isGecko){
- this.execCmd('useCSS', false);
- this.execCmd('hilitecolor', color);
- this.execCmd('useCSS', true);
- this.deferFocus();
- }else{
- this.execCmd(Ext.isOpera ? 'hilitecolor' : 'backcolor', Ext.isSafari || Ext.isIE ? '#'+color : color);
- this.deferFocus();
- }
- },
- scope:this,
- clickEvent:'mousedown'
- })
- }
- );
- };
- if(this.enableAlignments){
- tb.add(
- '-',
- btn('justifyleft'),
- btn('justifycenter'),
- btn('justifyright')
- );
- };
- if(!Ext.isSafari2){
- if(this.enableLinks){
- tb.add(
- '-',
- btn('createlink', false, this.createLink)
- );
- };
- if(this.enableLists){
- tb.add(
- '-',
- btn('insertorderedlist'),
- btn('insertunorderedlist')
- );
- }
- if(this.enableSourceEdit){
- tb.add(
- '-',
- btn('sourceedit', true, function(btn){
- this.toggleSourceEdit(btn.pressed);
- })
- );
- }
- }
- this.tb = tb;
- },
- getDocMarkup : function(){
- return '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
- },
- getEditorBody : function(){
- return this.doc.body || this.doc.documentElement;
- },
- getDoc : function(){
- return Ext.isIE ? this.getWin().document : (this.iframe.contentDocument || this.getWin().document);
- },
- getWin : function(){
- return Ext.isIE ? this.iframe.contentWindow : window.frames[this.iframe.name];
- },
- onRender : function(ct, position){
- Ext.form.HtmlEditor.superclass.onRender.call(this, ct, position);
- this.el.dom.style.border = '0 none';
- this.el.dom.setAttribute('tabIndex', -1);
- this.el.addClass('x-hidden');
- if(Ext.isIE){ this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
- }
- this.wrap = this.el.wrap({
- cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
- });
- this.createToolbar(this);
- this.tb.items.each(function(item){
- if(item.itemId != 'sourceedit'){
- item.disable();
- }
- });
- var iframe = document.createElement('iframe');
- iframe.name = Ext.id();
- iframe.frameBorder = '0';
- iframe.src = Ext.isIE ? Ext.SSL_SECURE_URL : "javascript:;";
- this.wrap.dom.appendChild(iframe);
- this.iframe = iframe;
- this.initFrame();
- if(this.autoMonitorDesignMode !== false){
- this.monitorTask = Ext.TaskMgr.start({
- run: this.checkDesignMode,
- scope: this,
- interval:100
- });
- }
- if(!this.width){
- var sz = this.el.getSize();
- this.setSize(sz.width, this.height || sz.height);
- }
- },
- initFrame : function(){
- this.doc = this.getDoc();
- this.win = this.getWin();
- this.doc.open();
- this.doc.write(this.getDocMarkup());
- this.doc.close();
- var task = { run : function(){
- if(this.doc.body || this.doc.readyState == 'complete'){
- Ext.TaskMgr.stop(task);
- this.doc.designMode="on";
- this.initEditor.defer(10, this);
- }
- },
- interval : 10,
- duration:10000,
- scope: this
- };
- Ext.TaskMgr.start(task);
- },
- checkDesignMode : function(){
- if(this.wrap && this.wrap.dom.offsetWidth){
- var doc = this.getDoc();
- if(!doc){
- return;
- }
- if(!doc.editorInitialized || String(doc.designMode).toLowerCase() != 'on'){
- this.initFrame();
- }
- }
- },
- onResize : function(w, h){
- Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments);
- if(this.el && this.iframe){
- if(typeof w == 'number'){
- var aw = w - this.wrap.getFrameWidth('lr');
- this.el.setWidth(this.adjustWidth('textarea', aw));
- this.iframe.style.width = aw + 'px';
- }
- if(typeof h == 'number'){
- var ah = h - this.wrap.getFrameWidth('tb') - this.tb.el.getHeight();
- this.el.setHeight(this.adjustWidth('textarea', ah));
- this.iframe.style.height = ah + 'px';
- if(this.doc){
- this.getEditorBody().style.height = (ah - (this.iframePad*2)) + 'px';
- }
- }
- }
- },
- toggleSourceEdit : function(sourceEditMode){
- if(sourceEditMode === undefined){
- sourceEditMode = !this.sourceEditMode;
- }
- this.sourceEditMode = sourceEditMode === true;
- var btn = this.tb.items.get('sourceedit');
- if(btn.pressed !== this.sourceEditMode){
- btn.toggle(this.sourceEditMode);
- return;
- }
- if(this.sourceEditMode){
- this.tb.items.each(function(item){
- if(item.itemId != 'sourceedit'){
- item.disable();
- }
- });
- this.syncValue();
- this.iframe.className = 'x-hidden';
- this.el.removeClass('x-hidden');
- this.el.dom.removeAttribute('tabIndex');
- this.el.focus();
- }else{
- if(this.initialized){
- this.tb.items.each(function(item){
- item.enable();
- });
- }
- this.pushValue();
- this.iframe.className = '';
- this.el.addClass('x-hidden');
- this.el.dom.setAttribute('tabIndex', -1);
- this.deferFocus();
- }
- var lastSize = this.lastSize;
- if(lastSize){
- delete this.lastSize;
- this.setSize(lastSize);
- }
- this.fireEvent('editmodechange', this, this.sourceEditMode);
- },
- createLink : function(){
- var url = prompt(this.createLinkText, this.defaultLinkValue);
- if(url && url != 'http:/'+'/'){
- this.relayCmd('createlink', url);
- }
- },
- adjustSize : Ext.BoxComponent.prototype.adjustSize,
- getResizeEl : function(){
- return this.wrap;
- },
- getPositionEl : function(){
- return this.wrap;
- },
- initEvents : function(){
- this.originalValue = this.getValue();
- },
- markInvalid : Ext.emptyFn,
- clearInvalid : Ext.emptyFn,
- setValue : function(v){
- Ext.form.HtmlEditor.superclass.setValue.call(this, v);
- this.pushValue();
- },
- cleanHtml : function(html){
- html = String(html);
- if(html.length > 5){
- if(Ext.isSafari){ html = html.replace(/sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
- }
- }
- if(html == ' '){
- html = '';
- }
- return html;
- },
- syncValue : function(){
- if(this.initialized){
- var bd = this.getEditorBody();
- var html = bd.innerHTML;
- if(Ext.isSafari){
- var bs = bd.getAttribute('style'); var m = bs.match(/text-align:(.*?);/i);
- if(m && m[1]){
- html = '<div style="'+m[0]+'">' + html + '</div>';
- }
- }
- html = this.cleanHtml(html);
- if(this.fireEvent('beforesync', this, html) !== false){
- this.el.dom.value = html;
- this.fireEvent('sync', this, html);
- }
- }
- },
- pushValue : function(){
- if(this.initialized){
- var v = this.el.dom.value;
- if(!this.activated && v.length < 1){
- v = ' ';
- }
- if(this.fireEvent('beforepush', this, v) !== false){
- this.getEditorBody().innerHTML = v;
- this.fireEvent('push', this, v);
- }
- }
- },
- deferFocus : function(){
- this.focus.defer(10, this);
- },
- focus : function(){
- if(this.win && !this.sourceEditMode){
- this.win.focus();
- }else{
- this.el.focus();
- }
- },
- initEditor : function(){
- var dbody = this.getEditorBody();
- var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
- ss['background-attachment'] = 'fixed'; dbody.bgProperties = 'fixed';
- Ext.DomHelper.applyStyles(dbody, ss);
- if(this.doc){
- try{
- Ext.EventManager.removeAll(this.doc);
- }catch(e){}
- }
- this.doc = this.getDoc();
- Ext.EventManager.on(this.doc, {
- 'mousedown': this.onEditorEvent,
- 'dblclick': this.onEditorEvent,
- 'click': this.onEditorEvent,
- 'keyup': this.onEditorEvent,
- buffer:100,
- scope: this
- });
- if(Ext.isGecko){
- Ext.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
- }
- if(Ext.isIE || Ext.isSafari || Ext.isOpera){
- Ext.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
- }
- this.initialized = true;
- this.fireEvent('initialize', this);
- this.doc.editorInitialized = true;
- this.pushValue();
- },
- onDestroy : function(){
- if(this.monitorTask){
- Ext.TaskMgr.stop(this.monitorTask);
- }
- if(this.rendered){
- this.tb.items.each(function(item){
- if(item.menu){
- item.menu.removeAll();
- if(item.menu.el){
- item.menu.el.destroy();
- }
- }
- item.destroy();
- });
- this.wrap.dom.innerHTML = '';
- this.wrap.remove();
- }
- },
- onFirstFocus : function(){
- this.activated = true;
- this.tb.items.each(function(item){
- item.enable();
- });
- if(Ext.isGecko){ this.win.focus();
- var s = this.win.getSelection();
- if(!s.focusNode || s.focusNode.nodeType != 3){
- var r = s.getRangeAt(0);
- r.selectNodeContents(this.getEditorBody());
- r.collapse(true);
- this.deferFocus();
- }
- try{
- this.execCmd('useCSS', true);
- this.execCmd('styleWithCSS', false);
- }catch(e){}
- }
- this.fireEvent('activate', this);
- },
- adjustFont: function(btn){
- var adjust = btn.itemId == 'increasefontsize' ? 1 : -1;
- var v = parseInt(this.doc.queryCommandValue('FontSize') || 2, 10);
- if(Ext.isSafari3 || Ext.isAir){
- if(v <= 10){
- v = 1 + adjust;
- }else if(v <= 13){
- v = 2 + adjust;
- }else if(v <= 16){
- v = 3 + adjust;
- }else if(v <= 18){
- v = 4 + adjust;
- }else if(v <= 24){
- v = 5 + adjust;
- }else {
- v = 6 + adjust;
- }
- v = v.constrain(1, 6);
- }else{
- if(Ext.isSafari){ adjust *= 2;
- }
- v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0);
- }
- this.execCmd('FontSize', v);
- },
- onEditorEvent : function(e){
- this.updateToolbar();
- },
- updateToolbar: function(){
- if(!this.activated){
- this.onFirstFocus();
- return;
- }
- var btns = this.tb.items.map, doc = this.doc;
- if(this.enableFont && !Ext.isSafari2){
- var name = (this.doc.queryCommandValue('FontName')||this.defaultFont).toLowerCase();
- if(name != this.fontSelect.dom.value){
- this.fontSelect.dom.value = name;
- }
- }
- if(this.enableFormat){
- btns.bold.toggle(doc.queryCommandState('bold'));
- btns.italic.toggle(doc.queryCommandState('italic'));
- btns.underline.toggle(doc.queryCommandState('underline'));
- }
- if(this.enableAlignments){
- btns.justifyleft.toggle(doc.queryCommandState('justifyleft'));
- btns.justifycenter.toggle(doc.queryCommandState('justifycenter'));
- btns.justifyright.toggle(doc.queryCommandState('justifyright'));
- }
- if(!Ext.isSafari2 && this.enableLists){
- btns.insertorderedlist.toggle(doc.queryCommandState('insertorderedlist'));
- btns.insertunorderedlist.toggle(doc.queryCommandState('insertunorderedlist'));
- }
- Ext.menu.MenuMgr.hideAll();
- this.syncValue();
- },
- relayBtnCmd : function(btn){
- this.relayCmd(btn.itemId);
- },
- relayCmd : function(cmd, value){
- (function(){
- this.focus();
- this.execCmd(cmd, value);
- this.updateToolbar();
- }).defer(10, this);
- },
- execCmd : function(cmd, value){
- this.doc.execCommand(cmd, false, value === undefined ? null : value);
- this.syncValue();
- },
- applyCommand : function(e){
- if(e.ctrlKey){
- var c = e.getCharCode(), cmd;
- if(c > 0){
- c = String.fromCharCode(c);
- switch(c){
- case 'b':
- cmd = 'bold';
- break;
- case 'i':
- cmd = 'italic';
- break;
- case 'u':
- cmd = 'underline';
- break;
- }
- if(cmd){
- this.win.focus();
- this.execCmd(cmd);
- this.deferFocus();
- e.preventDefault();
- }
- }
- }
- },
- insertAtCursor : function(text){
- if(!this.activated){
- return;
- }
- if(Ext.isIE){
- this.win.focus();
- var r = this.doc.selection.createRange();
- if(r){
- r.collapse(true);
- r.pasteHTML(text);
- this.syncValue();
- this.deferFocus();
- }
- }else if(Ext.isGecko || Ext.isOpera){
- this.win.focus();
- this.execCmd('InsertHTML', text);
- this.deferFocus();
- }else if(Ext.isSafari){
- this.execCmd('InsertText', text);
- this.deferFocus();
- }
- },
- fixKeys : function(){ if(Ext.isIE){
- return function(e){
- var k = e.getKey(), r;
- if(k == e.TAB){
- e.stopEvent();
- r = this.doc.selection.createRange();
- if(r){
- r.collapse(true);
- r.pasteHTML(' ');
- this.deferFocus();
- }
- }else if(k == e.ENTER){
- r = this.doc.selection.createRange();
- if(r){
- var target = r.parentElement();
- if(!target || target.tagName.toLowerCase() != 'li'){
- e.stopEvent();
- r.pasteHTML('<br />');
- r.collapse(false);
- r.select();
- }
- }
- }
- };
- }else if(Ext.isOpera){
- return function(e){
- var k = e.getKey();
- if(k == e.TAB){
- e.stopEvent();
- this.win.focus();
- this.execCmd('InsertHTML',' ');
- this.deferFocus();
- }
- };
- }else if(Ext.isSafari){
- return function(e){
- var k = e.getKey();
- if(k == e.TAB){
- e.stopEvent();
- this.execCmd('InsertText','t');
- this.deferFocus();
- }
- };
- }
- }(),
- getToolbar : function(){
- return this.tb;
- },
- buttonTips : {
- bold : {
- title: 'Bold (Ctrl+B)',
- text: 'Make the selected text bold.',
- cls: 'x-html-editor-tip'
- },
- italic : {
- title: 'Italic (Ctrl+I)',
- text: 'Make the selected text italic.',
- cls: 'x-html-editor-tip'
- },
- underline : {
- title: 'Underline (Ctrl+U)',
- text: 'Underline the selected text.',
- cls: 'x-html-editor-tip'
- },
- increasefontsize : {
- title: 'Grow Text',
- text: 'Increase the font size.',
- cls: 'x-html-editor-tip'
- },
- decreasefontsize : {
- title: 'Shrink Text',
- text: 'Decrease the font size.',
- cls: 'x-html-editor-tip'
- },
- backcolor : {
- title: 'Text Highlight Color',
- text: 'Change the background color of the selected text.',
- cls: 'x-html-editor-tip'
- },
- forecolor : {
- title: 'Font Color',
- text: 'Change the color of the selected text.',
- cls: 'x-html-editor-tip'
- },
- justifyleft : {
- title: 'Align Text Left',
- text: 'Align text to the left.',
- cls: 'x-html-editor-tip'
- },
- justifycenter : {
- title: 'Center Text',
- text: 'Center text in the editor.',
- cls: 'x-html-editor-tip'
- },
- justifyright : {
- title: 'Align Text Right',
- text: 'Align text to the right.',
- cls: 'x-html-editor-tip'
- },
- insertunorderedlist : {
- title: 'Bullet List',
- text: 'Start a bulleted list.',
- cls: 'x-html-editor-tip'
- },
- insertorderedlist : {
- title: 'Numbered List',
- text: 'Start a numbered list.',
- cls: 'x-html-editor-tip'
- },
- createlink : {
- title: 'Hyperlink',
- text: 'Make the selected text a hyperlink.',
- cls: 'x-html-editor-tip'
- },
- sourceedit : {
- title: 'Source Edit',
- text: 'Switch to source editing mode.',
- cls: 'x-html-editor-tip'
- }
- }
- });
- Ext.reg('htmleditor', Ext.form.HtmlEditor);
- Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
- minValue : null,
- maxValue : null,
- minText : "The time in this field must be equal to or after {0}",
- maxText : "The time in this field must be equal to or before {0}",
- invalidText : "{0} is not a valid time",
- format : "g:i A",
- 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",
- increment: 15,
- mode: 'local',
- triggerAction: 'all',
- typeAhead: false,
- initDate: '1/1/2008',
- initComponent : function(){
- Ext.form.TimeField.superclass.initComponent.call(this);
- if(typeof this.minValue == "string"){
- this.minValue = this.parseDate(this.minValue);
- }
- if(typeof this.maxValue == "string"){
- this.maxValue = this.parseDate(this.maxValue);
- }
- if(!this.store){
- var min = this.parseDate(this.minValue);
- if(!min){
- min = new Date(this.initDate).clearTime();
- }
- var max = this.parseDate(this.maxValue);
- if(!max){
- max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
- }
- var times = [];
- while(min <= max){
- times.push([min.dateFormat(this.format)]);
- min = min.add('mi', this.increment);
- }
- this.store = new Ext.data.SimpleStore({
- fields: ['text'],
- data : times
- });
- this.displayField = 'text';
- }
- },
- getValue : function(){
- var v = Ext.form.TimeField.superclass.getValue.call(this);
- return this.formatDate(this.parseDate(v)) || '';
- },
- setValue : function(value){
- Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
- },
- validateValue : Ext.form.DateField.prototype.validateValue,
- parseDate : Ext.form.DateField.prototype.parseDate,
- formatDate : Ext.form.DateField.prototype.formatDate,
- beforeBlur : function(){
- var v = this.parseDate(this.getRawValue());
- if(v){
- this.setValue(v.dateFormat(this.format));
- }
- }