MWF.APPDD = MWF.xApplication.process.DictionaryDesigner; MWF.APPDD.options = { "multitask": true, "executable": false }; //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false); MWF.xDesktop.requireApp("process.DictionaryDesigner", "Dictionary", null, false); MWF.xApplication.process.DictionaryDesigner.Main = new Class({ Extends: MWF.xApplication.Common.Main, Implements: [Options, Events], options: { "style": "default", "name": "process.DictionaryDesigner", "icon": "icon.png", "title": MWF.APPDD.LP.title, "appTitle": MWF.APPDD.LP.title, "id": "", "width": "1200", "height": "600", "actions": null, "category": null, "processData": null }, onQueryLoad: function(){ this.shortcut = true; if (this.status){ this.options.application = this.status.applicationId; this.application = this.status.application || this.status.applicationId; this.options.id = this.status.id; this.setOptions(this.status.options); } if( !this.application && this.options.application ){ this.application = this.options.application; } if (!this.options.id){ this.options.desktopReload = false; this.options.title = this.options.title + "-"+MWF.APPDD.LP.newDictionary; } if (!this.actions){ // if (this.options.action){ // MWF.xDesktop.requireApp("process."+this.options.action, "Actions.RestActions", function(){ // this.actions = new MWF.xApplication.process[this.options.action].Actions.RestActions(); // }.bind(this), false); // }else{ this.actions = MWF.Actions.get("x_processplatform_assemble_designer"); //this.actions = new MWF.xApplication.process.ProcessManager.Actions.RestActions(); // } this.actions.application = this.application; } this.lp = MWF.xApplication.process.DictionaryDesigner.LP; this.addEvent("queryClose", function(e){ if (this.explorer && this.explorer.reload){ this.explorer.reload(); } }.bind(this)); // this.processData = this.options.processData; }, loadApplication: function(callback){ this.createNode(); if (!this.options.isRefresh){ this.maxSize(function(){ this.openForm(); }.bind(this)); }else{ this.openForm(); } if (!this.options.readMode) this.addKeyboardEvents(); if (callback) callback(); }, addKeyboardEvents: function(){ this.addEvent("copy", function(){ this.copyModule(); }.bind(this)); this.addEvent("paste", function(){ this.pasteModule(); }.bind(this)); this.addEvent("cut", function(){ this.cutModule(); }.bind(this)); this.addEvent("keySave", function(e){ this.keySave(e); }.bind(this)); this.addEvent("keyDelete", function(e){ this.keyDelete(e); }.bind(this)); }, keySave: function(e){ if (this.shortcut) { if (this.tab.showPage) { var dictionary = this.tab.showPage.dictionary; if (dictionary) { dictionary.save(); e.preventDefault(); } } } }, keyDelete: function(){ if (this.shortcut) { if (this.tab.showPage) { var dictionary = this.tab.showPage.dictionary; if (dictionary) { if (dictionary.currentSelectedItem) { var item = dictionary.currentSelectedItem; item.delItem(item.itemTextNode); } } } } }, copyModule: function(){ if (this.shortcut) { if (this.tab.showPage) { var dictionary = this.tab.showPage.dictionary; if (dictionary) { if (dictionary.currentSelectedItem) { var item = dictionary.currentSelectedItem; MWF.clipboard.data = { "type": "dictionary", "data": { "key": item.key, "value": (typeOf(item.value)=="object") ? Object.clone(item.value) : item.value } }; } } } } }, cutModule: function(){ if (this.shortcut) { if (this.tab.showPage) { var dictionary = this.tab.showPage.dictionary; if (dictionary) { if (dictionary.currentSelectedItem) { this.copyModule(); var item = dictionary.currentSelectedItem; item.destroy(); } } } } }, pasteModule: function(){ if (this.shortcut) { if (MWF.clipboard.data) { if (MWF.clipboard.data.type == "dictionary") { if (this.tab.showPage) { var dictionary = this.tab.showPage.dictionary; if (dictionary) { if (dictionary.currentSelectedItem) { var item = dictionary.currentSelectedItem; var key = MWF.clipboard.data.data.key; var value = (typeOf(MWF.clipboard.data.data.value)=="object") ? Object.clone(MWF.clipboard.data.data.value) : MWF.clipboard.data.data.value; var level = item.level; var parent = item; var nextSibling = null; if (!item.parent){//top level level = 1; }else{ if (item.type!="array" && item.type!="object"){ parent = item.parent; nextSibling = item; }else{ if (item.exp){ level = item.level+1; }else{ parent = item.parent; nextSibling = item; } } } var idx = parent.children.length; if (item.type=="array"){ if (nextSibling){ key = nextSibling.key; parent.value.splice(nextSibling.key, 0, value); for (var i=nextSibling.key; i bodySize.x/2) width = bodySize.x/2; if (width<40) width = 40; this.contentNode.setStyle("margin-left", width+1); this.dictionaryListNode.setStyle("width", width); }.bind(this) }); }, loadDictionaryList: function(){ this.actions.listDictionary(this.application.id || this.application, function (json) { json.data.each(function(dictionary){ this.createListDictionaryItem(dictionary); }.bind(this)); }.bind(this), null, false); }, createListDictionaryItem: function(dictionary, isNew){ var _self = this; var listDictionaryItem = new Element("div", {"styles": this.css.listDictionaryItem}).inject(this.dictionaryListAreaNode, (isNew) ? "top": "bottom"); var listDictionaryItemIcon = new Element("div", {"styles": this.css.listDictionaryItemIcon}).inject(listDictionaryItem); var listDictionaryItemText = new Element("div", {"styles": this.css.listDictionaryItemText, "text": (dictionary.name) ? dictionary.name+" ("+dictionary.alias+")" : this.lp.newDictionary}).inject(listDictionaryItem); listDictionaryItem.store("dictionary", dictionary); listDictionaryItem.addEvents({ "click": function(e){_self.loadDictionaryByData(this, e);}, "mouseover": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem_over);}, "mouseout": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem);} }); }, loadDictionaryByData: function(node, e){ var dictionary = node.retrieve("dictionary"); var openNew = true; for (var i = 0; i bodySize.x/2) width = bodySize.x/2; if (width<40) width = 40; this.contentNode.setStyle("margin-right", width+1); this.propertyNode.setStyle("width", width); }.bind(this) }); }, loadPropertyContentResize: function(){ this.propertyContentResize = new Drag(this.propertyContentResizeNode, { "snap": 1, "onStart": function(el, e){ var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x; var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y; el.store("position", {"x": x, "y": y}); var size = this.propertyDomArea.getSize(); el.store("initialHeight", size.y); }.bind(this), "onDrag": function(el, e){ var size = this.propertyContentNode.getSize(); // var x = e.event.x; var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y; var position = el.retrieve("position"); var dy = y.toFloat()-position.y.toFloat(); var initialHeight = el.retrieve("initialHeight").toFloat(); var height = initialHeight+dy; if (height<40) height = 40; if (height> size.y-40) height = size.y-40; this.propertyDomPercent = height/size.y; this.setPropertyContentResize(); }.bind(this) }); }, setPropertyContentResize: function(){ var size = this.propertyContentNode.getSize(); var resizeNodeSize = this.propertyContentResizeNode.getSize(); var height = size.y-resizeNodeSize.y; var domHeight = this.propertyDomPercent*height; var contentHeight = height-domHeight; this.propertyDomArea.setStyle("height", ""+domHeight+"px"); this.propertyContentArea.setStyle("height", ""+contentHeight+"px"); if (this.form){ if (this.form.currentSelectedModule){ if (this.form.currentSelectedModule.property){ var tab = this.form.currentSelectedModule.property.propertyTab; if (tab){ var tabTitleSize = tab.tabNodeContainer.getSize(); tab.pages.each(function(page){ var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat(); var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat(); var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15; page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight); }.bind(this)); } } } } }, //resizeNode------------------------------------------------ resizeNode: function(){ var nodeSize = this.node.getSize(); this.contentNode.setStyle("height", ""+nodeSize.y+"px"); this.propertyNode.setStyle("height", ""+nodeSize.y+"px"); var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat(); var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat(); var allContentToolberSize = this.contentToolbarNode.getComputedSize(); var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom; this.editContentNode.setStyle("height", ""+y+"px"); if (this.designNode){ var designMarginTop = this.designNode.getStyle("margin-top").toFloat(); var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat(); y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom; this.designNode.setStyle("height", ""+y+"px"); } titleSize = this.propertyTitleNode.getSize(); titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat(); titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat(); titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat(); titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat(); y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom; y = nodeSize.y-y; this.propertyContentNode.setStyle("height", ""+y+"px"); this.propertyResizeBar.setStyle("height", ""+y+"px"); this.setPropertyContentResize(); titleSize = this.dictionaryListTitleNode.getSize(); titleMarginTop = this.dictionaryListTitleNode.getStyle("margin-top").toFloat(); titleMarginBottom = this.dictionaryListTitleNode.getStyle("margin-bottom").toFloat(); titlePaddingTop = this.dictionaryListTitleNode.getStyle("padding-top").toFloat(); titlePaddingBottom = this.dictionaryListTitleNode.getStyle("padding-bottom").toFloat(); nodeMarginTop = this.dictionaryListAreaSccrollNode.getStyle("margin-top").toFloat(); nodeMarginBottom = this.dictionaryListAreaSccrollNode.getStyle("margin-bottom").toFloat(); y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom; y = nodeSize.y-y; this.dictionaryListAreaSccrollNode.setStyle("height", ""+y+"px"); this.dictionaryListResizeNode.setStyle("height", ""+y+"px"); }, //loadForm------------------------------------------ loadDictionary: function(){ this.getDictionaryData(this.options.id, function(ddata){ this.setTitle(this.options.appTitle + "-"+ddata.name); if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name); this.options.appTitle = this.options.appTitle + "-"+ddata.name; if (this.options.readMode){ this.dictionary = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, ddata); }else{ this.dictionary = new MWF.xApplication.process.DictionaryDesigner.Dictionary(this, ddata); } this.dictionary.load(); if (this.status){ if (this.status.openDictionarys){ this.status.openDictionarys.each(function(id){ this.loadDictionaryData(id, function(data){ var showTab = true; if (this.status.currentId){ if (this.status.currentId!=data.id) showTab = false; } if (this.options.readMode){ var dictionary = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab}); }else{ var dictionary = new MWF.xApplication.process.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab}); } dictionary.load(); }.bind(this), true); }.bind(this)); } } }.bind(this)); }, getDictionaryData: function(id, callback){ if (!this.options.id){ this.loadNewDictionaryData(callback); }else{ this.loadDictionaryData(id, callback); } }, loadNewDictionaryData: function(callback){ var data = { "name": "", "id": "", "application": this.application.id, "alias": "", "description": "", "data": {} }; this.createListDictionaryItem(data, true); if (callback) callback(data); }, loadDictionaryData: function(id, callback){ this.actions.getDictionary(id, function(json){ if (json){ var data = json.data; if (!this.application){ this.actions.getApplication(data.application, function(json){ this.application = {"name": json.data.name, "id": json.data.id}; if (callback) callback(data); }.bind(this)); }else{ if (callback) callback(data); } } }.bind(this)); }, saveDictionary: function(){ if (this.tab.showPage){ var dictionary = this.tab.showPage.dictionary; dictionary.save(function(){ if (dictionary==this.dictionary){ var name = dictionary.data.name; this.setTitle(MWF.APPDD.LP.title + "-"+name); this.options.desktopReload = true; this.options.id = dictionary.data.id; } }.bind(this)); } }, saveDictionaryAs: function(){ this.dictionary.saveAs(); }, dictionaryExplode: function(){ this.dictionary.explode(); }, dictionaryImplode: function(){ this.dictionary.implode(); }, //recordStatus: function(){ // return {"id": this.options.id}; //}, dictionarySearch: function(){ this.dictionary.loadSearch(); }, recordStatus: function(){ if (this.tab){ var openDictionarys = []; this.tab.pages.each(function(page){ if (page.dictionary.data.id!=this.options.id) openDictionarys.push(page.dictionary.data.id); }.bind(this)); var currentId = this.tab.showPage.dictionary.data.id; var application = o2.typeOf(this.application) === "object" ? { name: this.application.name, id: this.application.id } : this.application; var status = { "id": this.options.id, "application": application, "applicationId": application.id || application, "openDictionarys": openDictionarys, "currentId": currentId, "options": { "action": this.options.action, "noCreate": this.options.noCreate, "noDelete": this.options.noDelete, "noModifyName": this.options.noModifyName, "readMode": this.options.readMode } }; return status; } return {"id": this.options.id, "application": application}; } });