MWF.xApplication = MWF.xApplication || {}; MWF.xApplication.cms = MWF.xApplication.cms || {}; MWF.xApplication.cms.DictionaryDesigner = MWF.xApplication.cms.DictionaryDesigner || {}; MWF.CMSDD = MWF.xApplication.cms.DictionaryDesigner; MWF.require("MWF.widget.Common", null, false); MWF.xDesktop.requireApp("cms.DictionaryDesigner", "lp."+MWF.language, null, false); MWF.xDesktop.requireApp("Selector", "package", null, false); MWF.require("MWF.widget.JavascriptEditor", null, false); MWF.xApplication.cms.DictionaryDesigner.Dictionary = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default", "isView": false, "showTab": true, "types": ["object", "array", "string", "number", "boolean"] }, initialize: function(designer, data, options){ this.setOptions(options); this.path = "../x_component_cms_DictionaryDesigner/$Dictionary/"; this.cssPath = "../x_component_cms_DictionaryDesigner/$Dictionary/"+this.options.style+"/css.wcss"; this._loadCss(); this.designer = designer; this.data = data; if (!this.data.data) this.data.data = {}; this.node = this.designer.designNode; this.tab = this.designer.tab; this.areaNode = new Element("div", {"styles": {"overflow": "auto"}}); //MWF.require("MWF.widget.ScrollBar", function(){ // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100}); //}.bind(this)); this.propertyListNode = this.designer.propertyDomArea; //this.propertyNode = this.designer.propertyContentArea; if(this.designer.application) this.data.applicationName = this.designer.application.name; if(this.designer.application) this.data.application = this.designer.application.id; this.isNewDictionary = (this.data.id) ? false : true; this.items = []; this.autoSave(); this.designer.addEvent("queryClose", function(){ if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); }.bind(this)); }, loadTab: function(callback){ var _self = this; MWF.require("MWF.widget.Tab", null, false); this.designTabNode = new Element("div").inject(this.areaNode); this.designTab = new MWF.widget.Tab(this.designTabNode, {"style": "design"}); this.designTab.load(); this.designTabPageAreaNode = Element("div"); this.designNode = new Element("div", {"styles": {"overflow": "auto","background-color":"#fff"}}).inject(this.designTabPageAreaNode); this.designTabScriptAreaNode = Element("div", {"styles": { "height": "100%" }}); this.scriptNode = new Element("div.scriptNode", {"styles": {"background-color":"#fff"}}).inject(this.designTabScriptAreaNode); this.designPage = this.designTab.addTab(this.designTabPageAreaNode, this.designer.lp.design); this.scriptPage = this.designTab.addTab(this.designTabScriptAreaNode, "JSON"); this.designPage.showTabIm = function(callback){ if( _self.scriptEditor && _self.isChanged){ if( _self.getEditorValidData() !== false ){ if (!this.isShow){ this.tab.pages.each(function(page){ if (page.isShow) page.hideIm(); }); this.showIm(callback); } } }else{ if (!this.isShow){ this.tab.pages.each(function(page){ if (page.isShow) page.hideIm(); }); this.showIm(callback); } } } // this.setScriptPageEvent(); this.designPage.showTabIm(); this.scriptPage.addEvent("postShow", function(){ if (this.scriptEditor){ var value = JSON.stringify(this.data.data, null, "\t"); if (value) this.scriptEditor.setValue(value); this.scriptEditor.focus(); }else{ this.loadScriptEditor(); } this.fireEvent("resize"); }.bind(this)); this.designPage.addEvent("postShow", function(){ if( this.scriptEditor && this.isChanged){ var data = this.getEditorValidData(); if( data !== false ){ this.data.data = data; this.reload(); this.isChanged = false; } } this.fireEvent("resize"); }.bind(this)); }, getEditorValidData : function( silence ){ if( !this.scriptEditor.validated() ){ if(!silence)this.designer.notice( this.designer.lp.notice.editorNotValidated, "error", this.node, {"x": "left", "y": "bottom"}); return false; } try{ var value = this.scriptEditor.getValue(); var v = JSON.parse(value); if( !this.checkValid(v, silence) ){ return false; } return v; }catch (e) { if(!silence)this.designer.notice( this.designer.lp.notice.jsonParseError, "error", this.node, {"x": "left", "y": "bottom"}); return false; } }, checkValid: function( obj, silence ){ if( typeOf(obj) !== "object" ){ return true; } for (var key in obj) { if( !key || key.trim() === "" ){ if(!silence)this.designer.notice(this.designer.lp.notice.emptyObjectKey, "error", this.node, {"x": "left", "y": "bottom"}); return false; } if (!isNaN(parseFloat(key))){ if(!silence)this.designer.notice(this.designer.lp.notice.numberObjectKey, "error", this.node, {"x": "left", "y": "bottom"}); return false; } if( typeOf(obj[key]) === "object" ){ if( !this.checkValid( obj[key] ) )return false; } } return true; }, loadScriptEditor:function(){ var value = JSON.stringify(this.data.data, null, "\t"); this.scriptEditor = new MWF.widget.JavascriptEditor(this.scriptNode, {"option": {"value": value, "mode" : "json" }}); this.scriptEditor.load(function(){ if (value) this.scriptEditor.setValue(value); this.scriptEditor.addEditorEvent("change", function(e){ if (!this.isChanged){ this.isChanged = true; } }.bind(this)); }.bind(this)); }, autoSave: function(){ this.autoSaveTimerID = window.setInterval(function(){ if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck"); if (this.autoSaveCheckNode){ if (this.autoSaveCheckNode.get("checked")){ this.save(); } } }.bind(this), 60000); }, createTitle: function(){ this.itemsNode = new Element("div", {"styles": this.css.itemsNode}).inject(this.designNode); this.typesNode = new Element("div", {"styles": this.css.typesNode}).inject(this.designNode); this.valuesNode = new Element("div", {"styles": this.css.valuesNode}).inject(this.designNode); this.itemTitleNode = new Element("div", {"styles": this.css.itemTitleNode}).inject(this.itemsNode); this.typeTitleNode = new Element("div", {"styles": this.css.typeTitleNode}).inject(this.typesNode); this.valueTitleNode = new Element("div", {"styles": this.css.valueTitleNode}).inject(this.valuesNode); this.itemResizeNode = new Element("div", {"styles": this.css.itemResizeNode}).inject(this.itemTitleNode); this.typeResizeNode = new Element("div", {"styles": this.css.typeResizeNode}).inject(this.typeTitleNode); // this.addTopItemNode = new Element("div", {"styles": this.css.addTopItemNode}).inject(this.itemTitleNode); this.itemTitleTextNode = new Element("div", {"styles": this.css.itemTitleTextNode, "text": this.designer.lp.item}).inject(this.itemTitleNode); this.typeTitleTextNode = new Element("div", {"styles": this.css.typeTitleTextNode, "text": this.designer.lp.type}).inject(this.typeTitleNode); this.valueTitleTextNode = new Element("div", {"styles": this.css.valueTitleTextNode, "text": this.designer.lp.value}).inject(this.valueTitleNode); // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this)); }, load : function(){ this.loadTab(); this.setAreaNodeSize(); this.designer.addEvent("resize", this.setAreaNodeSize.bind(this)); this.page = this.tab.addTab(this.areaNode, this.data.name || this.designer.lp.newDictionary, (!this.data.isNewDictionary && this.data.id!=this.designer.options.id)); this.page.dictionary = this; this.page.addEvent("show", function(){ this.designer.dictionaryListAreaNode.getChildren().each(function(node){ var dictionary = node.retrieve("dictionary"); if (dictionary.id==this.data.id){ if (this.designer.currentListDictionaryItem){ this.designer.currentListDictionaryItem.setStyles(this.designer.css.listDictionaryItem); } node.setStyles(this.designer.css.listDictionaryItem_current); this.designer.currentListDictionaryItem = node; this.lisNode = node; } }.bind(this)); this.setPropertyContent(); }.bind(this)); this.page.addEvent("queryClose", function(){ if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); this.saveSilence(); if (this.lisNode) this.lisNode.setStyles(this.designer.css.listScriptItem); }.bind(this)); this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer)); this.createTitle(); this.createRootItem(); if (this.options.showTab) this.page.showTabIm(); }, setPropertyContent: function(){ this.designer.propertyIdNode.set("text", this.data.id); this.designer.propertyNameNode.set("value", this.data.name); this.designer.propertyAliasNode.set("value", this.data.alias); this.designer.propertyDescriptionNode.set("value", this.data.description); this.designer.jsonDomNode.empty(); MWF.require("MWF.widget.JsonParse", function(){ this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode); window.setTimeout(function(){ this.jsonParse.load(); }.bind(this), 1); }.bind(this)); }, setAreaNodeSize: function(){ var size = this.node.getSize(); var tabSize = this.tab.tabNodeContainer.getSize(); var searchY = 0; if (this.searchNode) searchY = this.searchNode.getSize().y; var y = size.y - tabSize.y - searchY; this.areaNode.setStyle("height", ""+y+"px"); this.designNode.setStyle("height", ""+(y-18)+"px"); this.scriptNode.setStyle("height", ""+(y-18)+"px"); if (this.scriptEditor) if (this.scriptEditor.editor) this.scriptEditor.editor.resize(); }, reload : function(){ this.items = []; this.designNode.empty(); this.createTitle(); this.createRootItem(); }, createRootItem: function() { this.items.push(new MWF.xApplication.cms.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true)); }, saveSilence: function(){ if (!this.isSave){ if( this.scriptPage.isShow ){ if( this.scriptEditor ){ var data = this.getEditorValidData( true ); if( data !== false ){ this.data.data = data; }else{ return false; } } } var name = this.designer.propertyNameNode.get("value"); var alias = this.designer.propertyAliasNode.get("value"); var description = this.designer.propertyDescriptionNode.get("value"); if (!name){ this.designer.notice(this.designer.lp.notice.inputName, "error"); return false; } if (!alias){ this.designer.notice(this.designer.lp.notice.inputAlias, "error"); return false; } this.data.name = name; this.data.alias = alias; this.data.description = description; this.isSave = true; this.designer.actions.saveDictionary(this.data, function(json){ this.isSave = false; this.data.id = json.data.id; if (callback) callback(); }.bind(this), function(xhr, text, error){ this.isSave = false; // //var errorText = error+":"+text; //if (xhr) errorText = xhr.responseText; //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText); }.bind(this)); } }, save: function(callback){ if (!this.isSave){ if (this.designer.tab.showPage==this.page){ if( this.scriptPage.isShow ){ if( this.scriptEditor ){ var data = this.getEditorValidData(); if( data !== false ){ this.data.data = data; }else{ return false; } } } var name = this.designer.propertyNameNode.get("value"); var alias = this.designer.propertyAliasNode.get("value"); var description = this.designer.propertyDescriptionNode.get("value"); if (!name){ this.designer.notice(this.designer.lp.notice.inputName, "error"); return false; } if (!alias){ this.designer.notice(this.designer.lp.notice.inputAlias, "error"); return false; } this.data.name = name; this.data.alias = alias; this.data.description = description; this.data.appId = this.data.application; } this.isSave = true; this.designer.actions.saveDictionary(this.data, function(json){ this.isSave = false; this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"}); this.data.isNewDictionary = false; this.isNewDictionary = false; this.data.id = json.data.id; this.page.textNode.set("text", this.data.name); if (this.lisNode) { this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")"); } if (callback) callback(); }.bind(this), function(xhr, text, error){ this.isSave = false; var errorText = error+":"+text; if (xhr) errorText = xhr.responseText; MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText); }.bind(this)); }else{ MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave); } }, loadSearch: function(){ if (!this.searchNode){ this.createSearchNode(); }else{ if (this.searchNode.getStyle("display")=="none"){ this.searchNode.setStyle("display", "block"); }else{ this.searchNode.setStyle("display", "none"); } } this.setAreaNodeSize(); }, createSearchNode: function(){ this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.designNode, "before"); this.searchInputNode = new Element("div", {"styles": this.css.searchInputNode}).inject(this.searchNode); this.searchInput = new Element("input", {"styles": this.css.searchInput}).inject(this.searchInputNode); this.searchAction = new Element("div", {"styles": this.css.searchAction, "text": this.designer.lp.search}).inject(this.searchNode); var lineNode = new Element("div", {"styles": this.css.searchLineNode,}).inject(this.searchNode); this.nextAction = new Element("div", {"styles": this.css.searchNextAction, "text": this.designer.lp.next}).inject(this.searchNode); this.searchAction.addEvent("click", function(){ this.searchDictionary(); }.bind(this)); this.nextAction.addEvent("click", function(){ this.searchDictionaryNext(); }.bind(this)); }, searchDictionary: function(){ var key = this.searchInput.get("value"); if (key){ this.currentSearchItem = null; if (!this.getSearchItem(key)){ } } }, searchDictionaryNext: function(){ var key = this.searchInput.get("value"); if (key){ if (!this.getSearchItem(key, null, this.currentSearchItem)){ if (!this.getSearchItem(key)){ } } } }, getSearchItem: function(key, rootItem, item){ var fromItem = rootItem || this.items[0]; var flag = true; if (item){ if (item.type=="object"){ if (!item.exp) item.expOrColChildren(); if (this.getSearchItem(key, item)) return true; } fromItem = item.parent; flag = false; } if (fromItem.type=="object") { if (!fromItem.exp) fromItem.expOrColChildren(); for (var i=0; isize.y){ this.typeSelectNode.position({ relativeTo: this.typeNode, position: 'bottomLeft', edge: 'bottomLeft' }); }; this.closeTypeSelectNodeFun = this.closeTypeSelectNode.bind(this); $(document.body).addEvent("mousedown", this.closeTypeSelectNodeFun); }, closeTypeSelectNode: function(){ this.typeSelectNode.setStyle("display", "none"); $(document.body).removeEvent("mousedown", this.closeTypeSelectNodeFun); }, createTypeSelectNode: function(){ var _self = this; this.typeSelectNode = new Element("div", {"styles": this.css.typeSelectNode}); var types = this.dictionary.options.types; if (!this.parent){ types = ["object", "array"]; this.typeSelectNode.setStyle("height", "50px"); } types.each(function(type){ var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.typeSelectNode); itemNode.set("text", type); if (this.type==type) itemNode.setStyles(this.css.typeSelectItemNode_over); itemNode.addEvents({ "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);}, "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);}, "mousedown": function(e){_self.selectedType(this, e);} }) }.bind(this)); this.typeSelectNode.inject(this.dictionary.node); }, selectedType: function(itemNode, e){ e.target = null; var type = itemNode.get("text"); if (this.type!=type){ var _self = this; switch(type){ case "array": if (this.value!="New Item Value" && this.value!="New Element Value"){ this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeType, 300, 120, function(){ if (_self.type=="object"){ _self.changeTypeObjectToArray(type); }else{ _self.changeTypePrimitiveToArray(type); } this.close(); _self.dictionary.jsonParse.loadObjectTree(); }, function(){ this.close(); }); }else{ if (this.type=="object"){ this.changeTypeObjectToArray(type); }else{ this.changeTypePrimitiveToArray(type); } this.dictionary.jsonParse.loadObjectTree(); } break; case "object": if (this.value!="New Item Value" && this.value!="New Element Value") { this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeType, 300, 120, function () { if (_self.type == "array") { _self.changeTypeArrayToObject(type); } else { _self.changeTypePrimitiveToObject(type); } this.close(); _self.dictionary.jsonParse.loadObjectTree(); }, function () { this.close(); }); }else{ if (this.type == "array") { this.changeTypeArrayToObject(type); } else { this.changeTypePrimitiveToObject(type); } this.dictionary.jsonParse.loadObjectTree(); } break; default: if (this.value!="New Item Value" && this.value!="New Element Value") { this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeTypeDeleteChildren, 300, 120, function () { if (_self.type == "array") { _self.changeTypeArrayToPrimitive(type); } else if (_self.type == "object") { _self.changeTypeObjectToPrimitive(type); } else { _self.changeTypePrimitiveToPrimitive(type); } this.close(); _self.dictionary.jsonParse.loadObjectTree(); }, function () { this.close(); }); }else{ if (this.type == "array") { this.changeTypeArrayToPrimitive(type); } else if (_self.type == "object") { this.changeTypeObjectToPrimitive(type); } else { this.changeTypePrimitiveToPrimitive(type); } this.dictionary.jsonParse.loadObjectTree(); } break; } } }, deleteAllChildren: function(){ this.children.each(function(item){ item.destroyAllNodes(); }); }, changeTypeObjectToPrimitive: function(type){ this.deleteAllChildren(); this.children = []; this.childrenItemCreated = false; var value; switch(type){ case "string": value = ""; break; case "number": value = 0; break; case "boolean": value = true; break; } delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.exp = false; this.setNodeText(); this.resetNodes(); }, changeTypeArrayToPrimitive: function(type){ this.changeTypeObjectToPrimitive(type); }, changeTypePrimitiveToPrimitive: function(type){ switch(type){ case "string": value = this.value.toString(); break; case "number": value = this.value.toFloat(); if (isNaN(value)) value = 0; break; case "boolean": value = true; if (this.value=="false") value = false; break; } delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.exp = false; this.setNodeText(); this.resetNodes(); }, changeTypePrimitiveToObject: function(type){ value = {}; delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.exp = false; this.setNodeText(); this.resetNodes(); }, changeTypeArrayToObject: function(type){ this.deleteAllChildren(); this.children = []; this.childrenItemCreated = false; var value = {}; this.value.each(function(v, idx){ value["ITEM"+idx] = v; }); if (this.parent){ delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.setNodeText(); this.resetNodes(); if (this.exp) this.createChildrenItems(); }else{ this.dictionary.data.data = value; this.dictionary.jsonParse.json = value; this.value = value; this.type = type; this.setNodeText(); this.resetNodes(); if (this.exp) this.createChildrenItems(); } }, changeTypePrimitiveToArray: function(type) { value = []; delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.exp = false; this.setNodeText(); this.resetNodes(); }, changeTypeObjectToArray: function(type){ this.deleteAllChildren(); this.children = []; this.childrenItemCreated = false; var value = []; Object.each(this.value, function(v, idx){ value.push(v); }); if (this.parent){ delete this.parent.value[this.key]; this.parent.value[this.key] = value; this.value = value; this.type = type; this.childrenItemCreated = false; this.setNodeText(); this.resetNodes(); if (this.exp) this.createChildrenItems(); }else{ this.dictionary.data.data = value; this.dictionary.jsonParse.json = value; this.value = value; this.type = type; this.childrenItemCreated = false; this.setNodeText(); this.resetNodes(); if (this.exp) this.createChildrenItems(); } }, editValue: function(){ //debugger; //this.inEdit this.valueTextNode.empty(); // this.valueTextNode.removeEvents("mousedown"); this.editValueNode = new Element("input", {"styles": this.css.itemEditValueNode}).inject(this.valueTextNode); this.editValueNode.set("value", this.value); if( this.type === "string" ){ this.selectOrgNode = new Element("span", { "styles": this.css.itemSelectOrgNode, "title" : this.dictionary.designer.lp.selectOrganizationByDblclick, "events" : { dblclick : function(ev){ var opt = { "type": "", "types" : ["person","identity","unit","group"], "title": "select", "count" : "0", "values": this.value.replace("New Item Value","").split(", "), "expand" : false, "onComplete": function( array ){ var v = []; array.each( function(d){ v.push( d.data.distinguishedName ); }.bind(this)); this.value = v.join(", "); this.parent.value[this.key] = this.value; this.setNodeText(); this.dictionary.jsonParse.loadObjectTree(); }.bind(this) }; var selector = new MWF.O2Selector(this.dictionary.designer.content, opt ); ev.stopPropagation(); }.bind(this) } }).inject(this.valueTextNode); } window.setTimeout(function(){ this.editValueNode.focus(); this.editValueNode.select(); this.editValueNode.addEvents({ "blur": function(e){ this.editValueConfirm(e); }.bind(this), "dblclick" : function (e){ if( this.type === "string" ){ var opt = { "types": ["identity","person","unit","group","role","duty","process","application","platApp","view"], "count": 1, "title": "Select", "values":[], "onComplete": function (items) { if(items.length>0){ var d = items[0].data; var v; if(d.distinguishedName){ v = d.distinguishedName; }else{ v = d.id === d.name? d.id : d.name + "|" + d.id } this.editValueNode.set("value", v); }else { this.editValueNode.set("value", ""); } this.editValueConfirm(e); }.bind(this) }; o2.xDesktop.requireApp("Selector", "package", function(){ new o2.O2Selector(this.dictionary.designer.content, opt); }.bind(this), false); } }.bind(this), "keydown": function(e){ if (e.code==13){ this.editValueConfirm(e); if (this.nextSibling){ this.nextSibling.editKey(); } } e.stopPropagation(); }.bind(this), "mousedown": function(e){ e.stopPropagation(); } }); }.bind(this), 10); }, editValueConfirm: function(e){ var value = this.editValueNode.get("Value"); if (this.type=="number"){ if (isNaN(parseFloat(value))){ this.dictionary.designer.notice(this.dictionary.designer.lp.notice.inputTypeError, "error", this.editValueNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24}); this.editValueNode.setStyles(this.css.itemEditValueNode_error); this.editValueNode.select(); e.preventDefault(); return false; } value = value.toFloat(); } this.value = value; this.parent.value[this.key] = this.value; // this.editValueNode.destroy(); // this.editValueNode = null; this.setNodeText(); this.dictionary.jsonParse.loadObjectTree(); // if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this)); }, editKey: function(){ this.itemTextNode.empty(); // this.itemTextNode.removeEvents("mousedown"); this.editKeyNode = new Element("input", {"styles": this.css.itemEditValueNode, "type": "text"}).inject(this.itemTextNode); this.editKeyNode.set("value", this.key); window.setTimeout(function(){ this.editKeyNode.focus(); this.editKeyNode.select(); //this.editKeyNode.setSelectionRange(1,this.key.length-1); this.editKeyNode.addEvents({ "blur": function(e){this.editKeyConfirm(e);}.bind(this), "keydown": function(e){ if (e.code==13){ this.editKeyConfirm(e); if (this.type!="array" && this.type!="object" && this.type!="boolean") { this.editValue(); }else{ if (this.nextSibling){ this.nextSibling.editKey(); } } } e.stopPropagation(); }.bind(this), "mousedown": function(e){e.stopPropagation();} }); }.bind(this), 10); }, editKeyConfirm: function(e){ var key = this.editKeyNode.get("Value"); if (key!=this.key){ if (this.parent.value[key]){ this.dictionary.designer.notice(this.dictionary.designer.lp.notice.sameKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24}); this.editKeyNode.setStyles(this.css.itemEditValueNode_error); this.editKeyNode.select(); e.preventDefault(); return false; } if (!isNaN(parseFloat(key))){ this.dictionary.designer.notice(this.dictionary.designer.lp.notice.numberKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24}); this.editKeyNode.setStyles(this.css.itemEditValueNode_error); this.editKeyNode.select(); e.preventDefault(); return false; } if (!key){ this.dictionary.designer.notice(this.dictionary.designer.lp.notice.emptyKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24}); this.editKeyNode.setStyles(this.css.itemEditValueNode_error); this.editKeyNode.select(); e.preventDefault(); return false; } delete this.parent.value[this.key]; this.parent.value[key] = this.value; this.key = key; } this.editKeyNode.destroy(); this.editKeyNode = null; this.setNodeText(); this.dictionary.jsonParse.loadObjectTree(); //if (this.parent){ // if (this.parent.type!="array"){ // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this)); // } //} }, selectBooleanValue: function(){ if (!this.booleanSelectNode) this.createBooleanSelectNode(); var size = this.dictionary.node.getSize(); this.booleanSelectNode.setStyle("display", "block"); var selSize = this.booleanSelectNode.getSize(); var itemNodes = this.booleanSelectNode.getChildren(); for (var i=0; isize.y){ this.booleanSelectNode.position({ relativeTo: this.valueNode, position: 'bottomLeft', edge: 'bottomLeft' }); }; this.closeBooleanSelectNodeFun = this.closeBooleanSelectNode.bind(this); $(document.body).addEvent("mousedown", this.closeBooleanSelectNodeFun); }, closeBooleanSelectNode: function(){ this.booleanSelectNode.setStyle("display", "none"); $(document.body).removeEvent("mousedown", this.closeBooleanSelectNodeFun); }, createBooleanSelectNode: function(){ var _self = this; this.booleanSelectNode = new Element("div", {"styles": this.css.booleanSelectNode}); ["true", "false"].each(function(type){ var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.booleanSelectNode); itemNode.set("text", type); if (this.value.toString()==type) itemNode.setStyles(this.css.typeSelectItemNode_over); itemNode.addEvents({ "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);}, "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);}, "mousedown": function(e){_self.selectedBoolean(this, e);} }) }.bind(this)); this.booleanSelectNode.inject(this.dictionary.node); }, selectedBoolean: function(item, e){ var text = item.get("text"); var value = (text=="false") ? false : true; this.value = value; this.parent.value[this.key] = value; this.setNodeText(); this.dictionary.jsonParse.loadObjectTree(); } }); MWF.xApplication.cms.DictionaryDesigner.DictionaryReader = new Class({ Extends: MWF.xApplication.cms.DictionaryDesigner.Dictionary, autoSave: function(){}, createRootItem: function() { this.items.push(new MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader("ROOT", this.data.data, null, 0, this, true)); } }); MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader= new Class({ Extends: MWF.xApplication.cms.DictionaryDesigner.Dictionary.item, createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){ return new MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader(key, value, parent, level, dictionary, exp, nextSibling); }, setEvent: function(){ this.itemNode.addEvent("click", function(e){this.selected();}.bind(this)); this.typeNode.addEvent("click", function(e){this.selected();}.bind(this)); this.valueNode.addEvent("click", function(e){this.selected();}.bind(this)); //this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this)); //this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this)); //this.itemNode.addEvents({ // "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this), // "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this) //}); //if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this)); //if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this)); if (this.type=="array" || this.type=="object"){ this.itemExpColActionNode.addEvents({ "click": function(){this.expOrColChildren();}.bind(this) }); }else{ //if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this)); } //if (this.parent){ // if (this.parent.type!="array"){ // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this)); // } //} //if (this.type=="boolean"){ // this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this)); // this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this)); //} } }); //MWF.xApplication.cms.ProcessDesigner.Process.Property = new Class({ // Implements: [Options, Events], // Extends: MWF.APPPD.Property, // initialize: function(process, options){ // this.setOptions(options); // this.process = process; // this.paper = this.process.paper; // this.data = process.process; // this.htmlPath = "../x_component_process_ProcessDesigner//$Process/process.html"; // } //});