📄 main.js.bak
字号:
// node text created from config of el configToText : function(c) { var txt = []; c = c || {}; if (c.xtype) { txt.push(c.xtype); } if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); } if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); } if (c.layout) { txt.push('<i>' + c.layout + '</i>'); } if (c.title) { txt.push('<b>' + c.title + '</b>'); } if (c.text) { txt.push('<b>' + c.text + '</b>'); } if (c.region) { txt.push('<i>(' + c.region + ')</i>'); } return (txt.length == 0 ? "Element" : txt.join(" ")); }, // return type of attribute attrType : function(name) { if (!Main.FIELDS[name]) { return 'unknown'; } return Main.FIELDS[name].type; }, // return a cloned config cloneConfig : function(config) { if (!config) { return null; } var newConfig = {}; for (i in config) { if (typeof config[i] == 'object') { newConfig[i] = this.cloneConfig(config[i]); } else if (typeof config[i] != 'function') { newConfig[i] = config[i]; } } return newConfig; }, // erase all resetAll : function() { var w = this.viewport.layout.center.getSize().width - 50; var node = this.setConfig({items:[]}); this.setCurrentNode(node, true); }, // get a new ID getNewId : function() { return "form-gen-" + (this.idCounter++); }, // return true if config can be added to node, or an error message if it cannot canAppend : function(config, node) { if (node == this.treePanel.root && this.treePanel.root.hasChildNodes()) { return "Only one element can be directly under the GUI Builder"; } var xtype = node.elConfig.xtype; if (xtype && ['panel','viewport','form','window','tabpanel','toolbar','fieldset'].indexOf(xtype) == -1) { return 'You cannot add element under xtype "'+xtype+'"'; } return true; }, // add a config to the tree appendConfig : function(config, appendTo, doUpdate, markUndo) { if (!appendTo) { appendTo = this.treePanel.getSelectedNode() || this.treePanel.root; } var canAppend = this.canAppend(config,appendTo); if (canAppend !== true) { Ext.Msg.alert("Unable to add element", canAppend); return false; } var items = config.items; delete config.items; var id = config.id||(config._node ? config._node.id : this.getNewId()); var newNode = new Ext.tree.TreeNode({id:id,text:this.configToText(config)}); for(var k in config) { if (config[k]===null) { delete config[k]; }} newNode.elConfig = config; if (markUndo === true) { this.markUndo("Add " + newNode.text); } appendTo.appendChild(newNode); if (items && items.length) { for (var i = 0; i < items.length; i++) { this.appendConfig(items[i], newNode, false); } } if (doUpdate !== false) { this.updateForm(false, newNode); } return newNode; }, // remove a node removeNode : function(node) { if (!node || node == this.treePanel.root) { return; } this.markUndo("Remove " + node.text); var nextNode = node.nextSibling || node.parentNode; var pNode = node.parentNode; pNode.removeChild(node); this.updateForm(false, pNode); this.setCurrentNode(nextNode, true); }, // update the form setFormConfig : function(config, el) { el = el || this.builderPanel; // empty the form if (el.items) { while (el.items.first()) { el.remove(el.items.first(), true); } } if (el.getLayoutTarget) { el.getLayoutTarget().update(); } else { el.update(); } // adding items var start = new Date().getTime(); if (config.items) { for (var i=0;i<config.items.length;i++) { el.add(config.items[i]); } } el.doLayout(); var time = new Date().getTime() - start; return time; }, // show a window with the json config editConfig : function() { var size = this.viewport.getSize(); if (!this.jsonWindow) { var tf = new Ext.form.TextArea(); this.jsonWindow = new Ext.Window({ title : "Form Config", width : 400, height : size.height - 50, autoScroll : true, layout : 'fit', items : [tf], modal : true, closeAction : 'hide' }); this.jsonWindow.tf = tf; this.jsonWindow.addButton({ text : "Close", scope : this.jsonWindow, handler : function() { this.hide(); } }); this.jsonWindow.addButton({ text : "Apply", scope : this, handler : function() { var config = null; try { this.jsonWindow.el.mask("Please wait..."); config = Ext.decode(tf.getValue()); } catch (e) { config = null; this.jsonWindow.el.unmask(); Ext.Msg.alert("Error", "JSON is invalid : " + e.name + "<br/>" + e.message); return; } if (!config) { this.jsonWindow.el.unmask(); Ext.Msg.alert("Error", "Config seems invalid"); return; } else { this.markUndo("JSON edit"); try { this.setConfig({items:[config]}); } catch(e) { this.jsonWindow.el.unmask(); Ext.Msg.confirm("Error", "Error while adding : " + e.name + "<br/>" + e.message + '<br/>' + 'Do you wish to revert to previous ?', function(b) { if (b == 'yes') { this.undo(); } }, this); } } this.jsonWindow.el.unmask(); this.jsonWindow.hide(); } }); } var cleanConfig = this.getTreeConfig(); cleanConfig = (cleanConfig.items?cleanConfig.items[0]||{}:{}); cleanConfig = Main.JSON.encode(cleanConfig); this.jsonWindow.tf.setValue(cleanConfig); this.jsonWindow.show(); }, // remove all nodes removeAll : function() { var root = this.treePanel.root; while(root.firstChild){ root.removeChild(root.firstChild); } }, // set config (remove then append a whole new config) setConfig : function(config) { if (!config || !config.items) { return false; } // delete all items this.removeAll(); // add all items var root = this.treePanel.root; var node = null; for (var i = 0; i < config.items.length; i++) { try { node = this.appendConfig(config.items[i], root); } catch(e) { Ext.Msg.alert("Error", "Error while adding : " + e.name + "<br/>" + e.message); } } this.updateForm(true, root); return node || root; }};// modified Ext.util.JSON to display a readable configMain.JSON = new (function(){ var useHasOwn = {}.hasOwnProperty ? true : false; var pad = function(n) { return n < 10 ? "0" + n : n; }; var m = { "\b": '\\b', "\t": '\\t', "\n": '\\n', "\f": '\\f', "\r": '\\r', '"' : '\\"', "\\": '\\\\' }; var encodeString = function(s){ if (/["\\\x00-\x1f]/.test(s)) { return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if(c){ return c; } c = b.charCodeAt(); return "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"'; } return '"' + s + '"'; }; var indentStr = function(n) { var str = "", i = 0; while (i<n) { str += " "; i++; } return str; }; var encodeArray = function(o, indent){ indent = indent || 0; var a = ["["], b, i, l = o.length, v; for (i = 0; i < l; i += 1) { v = o[i]; switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if (b) { a.push(','); } a.push(v === null ? "null" : Main.JSON.encode(v, indent + 1)); b = true; } } a.push("]"); return a.join(""); }; var encodeDate = function(o){ return '"' + o.getFullYear() + "-" + pad(o.getMonth() + 1) + "-" + pad(o.getDate()) + "T" + pad(o.getHours()) + ":" + pad(o.getMinutes()) + ":" + pad(o.getSeconds()) + '"'; }; this.encode = function(o, indent){ indent = indent || 0; if(typeof o == "undefined" || o === null){ return "null"; }else if(o instanceof Array){ return encodeArray(o, indent); }else if(o instanceof Date){ return encodeDate(o); }else if(typeof o == "string"){ return encodeString(o); }else if(typeof o == "number"){ return isFinite(o) ? String(o) : "null"; }else if(typeof o == "boolean"){ return String(o); }else { var a = ["{\n"], b, i, v; if (o.items instanceof Array) { var items = o.items; delete o.items; o.items = items; } for (i in o) { if (i === "_node") { continue; } if(!useHasOwn || o.hasOwnProperty(i)) { v = o[i]; if (i === "id" && /^form-gen-/.test(o[i])) { continue; } if (i === "id" && /^ext-comp-/.test(o[i])) { continue; } switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if(b){ a.push(',\n'); } a.push(indentStr(indent), i, ":", v === null ? "null" : this.encode(v, indent + 1)); b = true; } } } a.push("\n" + indentStr(indent-1) + "}"); return a.join(""); } };})();// parse DocRefsvar fields = {};var fileName;var infos;var type;var desc;for (fileName in DocRefs) { for (key in DocRefs[fileName]) { infos = DocRefs[fileName][key]; if (infos.type == "Function") { continue; } desc = "<i>"+fileName+"</i><br/><b>"+infos.type+"</b> "+infos.desc; if (!fields[key]) { fields[key] = { desc:desc }; if (infos.type == "Boolean") { type = "boolean"; } else if (infos.type == "Number") { type = "number"; } else if (infos.type.match(/Object/)) { type = "object"; } else { type = "string"; } fields[key].type = type; } else { fields[key].desc += "<hr/>" + desc; } }}Ext.apply(fields, { xtype : {desc:"",type:"string",values:'component box viewport panel window dataview colorpalette datepicker tabpanel button splitbutton cycle toolbar tbitem tbseparator tbspacer tbfill tbtext tbbutton tbsplit paging editor treepanel field textfield trigger textarea numberfield datefield combo checkbox radio hidden form fieldset htmleditor timefield grid editorgrid progress'.split(' ')}, region : {desc:"",type:"string",values:'center west north south east'.split(' ')}, hideMode : {desc:"",type:"string",values:'visibility display offsets'.split(' ')}, msgTarget : {desc:"",type:"string",values:'qtip title under side'.split(' ')}, shadow : {desc:"",type:"string",values:'sides frame drop'.split(' ')}, tabPosition : {desc:"",type:"string",values:'top bottom'.split(' ')}, columnWidth : {desc:"Size of column (0 to 1 for percentage, >1 for fixed width",type:"number"}, fieldLabel : {desc:"Label of the field",type:"string"}, x : {desc:"X position in pixels (for absolute layouts",type:"number"}, y : {desc:"Y position in pixels (for absolute layouts",type:"number"}, anchor : {desc:"Anchor size (width) in %",type:"string"}});fields.layout.values = [];for (i in Ext.Container.LAYOUTS) { fields.layout.values.push(i); }fields.vtype.values = [];for (i in Ext.form.VTypes) { fields.vtype.values.push(i); }fields.defaultType.values = fields.defaults.xtype;Main.FIELDS = fields;// custom editors for attributesMain.getCustomEditors = function() { var g = Ext.grid; var f = Ext.form; var cmEditors = new g.PropertyColumnModel().editors; var eds = {}; var fields = Main.FIELDS; for (i in fields) { if (fields[i].values) { var values = fields[i].values; var data = []; for (j=0;j<values.length;j++) { data.push([values[j],values[j]]); } eds[i] = new g.GridEditor(new f.SimpleCombo({forceSelection:false,data:data,editable:true})); } else if (fields[i].type == "boolean") { eds[i] = cmEditors['boolean']; } else if (fields[i].type == "number") { eds[i] = cmEditors['number']; } else if (fields[i].type == "string") { eds[i] = cmEditors['string']; } } return eds;};main = new Main();Ext.onReady(main.init, main);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -