MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {}; MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false); MWF.xApplication.process.FormDesigner.Module.Subform = MWF.FCSubform = new Class({ Extends: MWF.FC$Element, Implements: [Options, Events], options: { "style": "default", "propertyPath": "../x_component_process_FormDesigner/Module/Subform/subform.html", "actions": [ { "name": "move", "icon": "move1.png", "event": "mousedown", "action": "move", "title": MWF.APPFD.LP.formAction.move }, { "name": "delete", "icon": "delete1.png", "event": "click", "action": "delete", "title": MWF.APPFD.LP.formAction["delete"] }, { "name": "selectParent", "icon": "selectParent.png", "event": "click", "action": "selectParent", "title": MWF.APPFD.LP.formAction["selectParent"] } // { // "name": "styleBrush", // "icon": "styleBrush.png", // "event": "click", // "action": "styleBrush", // "title": MWF.APPFD.LP.formAction["styleBrush"] // } ] }, initialize: function(form, options){ this.setOptions(options); this.path = "../x_component_process_FormDesigner/Module/Subform/"; this.cssPath = "../x_component_process_FormDesigner/Module/Subform/"+this.options.style+"/css.wcss"; this._loadCss(); this.moduleType = "element"; this.moduleName = "subform"; this.form = form; this.container = null; this.containerNode = null; }, load : function(json, node, parent){ this.json = json; this.node= node; this.node.store("module", this); //this.node.empty(); this.node.setStyles(this.css.moduleNode); //this._loadNodeStyles(); this._initModule(); if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){ this.redoSelectedSubform(this.json.subformSelected, null, ""); }else{ this.node.empty(); this.loadIcon(); } this._loadTreeNode(parent); this.setCustomStyles(); this.parentContainer = this.treeNode.parentNode.module; this._setEditStyle_custom("id"); this.parseModules(); this.json.moduleName = this.moduleName; this.node.addEvent("click", function(){ this.refreshSubform(); }.bind(this)); this.node.addEvent("dblclick", function(e){ this.openSubform(e); }.bind(this)); }, _initModule: function(){ if (!this.json.isSaved) this.setStyleTemplate(); this.setPropertiesOrStyles("styles"); this.setPropertiesOrStyles("inputStyles"); this.setPropertiesOrStyles("properties"); this._setNodeProperty(); if (!this.form.isSubform) this._createIconAction(); this._setNodeEvent(); this.json.isSaved = true; if( !this.form.subformModuleList )this.form.subformModuleList = []; this.form.subformModuleList.push( this ); this.queryGetFormDataFun = this.queryGetFormData.bind(this); this.postGetFormDataFun = this.postGetFormData.bind(this); this.form.addEvent("queryGetFormData", this.queryGetFormDataFun); this.form.addEvent("postGetFormData", this.postGetFormDataFun); }, openSubform: function(e){ if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){ layout.desktop.openApplication(e, "process.FormDesigner", {"id": this.json.subformSelected, "appId": "FormDesigner"+this.json.subformSelected}); } }, _createMoveNode: function(){ this.moveNode = new Element("div", { "MWFType": "subform", "id": this.json.id, "styles": this.css.moduleNodeMove, "events": { "selectstart": function(){ return false; } } }).inject(this.form.container); }, _getDroppableNodes: function(){ var nodes = [this.form.node].concat(this.form.moduleElementNodeList, this.form.moduleContainerNodeList, this.form.moduleComponentNodeList); this.form.moduleList.each( function(module){ //子表单不能往数据模板里拖 if( module.moduleName === "datatemplate" ){ var subDoms = this.form.getModuleNodes(module.node); nodes.erase( module.node ); subDoms.each(function (dom) { nodes.erase( dom ); }) } }.bind(this)); return nodes; }, _createNode: function(){ this.node = this.moveNode.clone(true, true); this.node.setStyles(this.css.moduleNode); this.node.set("id", this.json.id); this.node.addEvent("selectstart", function(){ return false; }); // debugger; // if (this.json.subformSelected && this.json.subformSelected!="none" && this.json.subformType!=="script"){ // this.redoSelectedSubform(this.json.subformSelected, $(this.property.data.pid+"selectSubform").getElement("select"), ""); // }else{ this.loadIcon(); // } this.node.addEvent("click", function(){ this.refreshSubform(); }.bind(this)); this.node.addEvent("dblclick", function(e){ this.openSubform(e); }.bind(this)); }, postGetFormData: function(node){ if (!node || node.contains(this.node)) this.show(); }, queryGetFormData: function(node){ if (!node || node.contains(this.node)) this.hide(); }, hide: function(){ this.node.empty(); }, show: function(){ if (this.subformData){ this.subformModule = new MWF.FCSubform.Form(this.form, this.node, { mode : this.form.options.mode, parentformIdList : this.getParentformIdList(), level : this.getLevel() }); this.subformModule.subformSelector = this.getSubformSelector(); this.subformModule.subformSelectedValue = this.getSubformSelectedValue(); this.subformModule.level1Subform = this.getLevel1Subform(); this.subformModule.load(this.subformData); }else{ this.node.empty(); this.loadIcon(); } }, "delete": function(e){ var module = this; this.form.designer.shortcut = false; this.form.designer.confirm("warn", module.node, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){ if (this.queryGetFormDataFun) module.form.removeEvent("queryGetFormData", this.queryGetFormDataFun); if (this.postGetFormDataFun) module.form.removeEvent("postGetFormData", this.postGetFormDataFun); module.addHistoryLog( "delete", null, null, null, null, module.getHtml() ); module.destroy(); module.form.selected(); module.form.designer.shortcut = true; this.close(); }, function(){ module.form.designer.shortcut = true; this.close(); }, null); }, getLevel : function(){ return ( this.form.options.level1 || 0 ) + 1; }, getLevel1Subform : function(){ return this.form.level1Subform || this; }, getSubformSelector : function(){ return this.subformSelector || this.form.subformSelector; }, getSubformSelectedValue : function(){ return this.subformSelectedValue || this.form.subformSelectedValue; }, checkSubformNested : function( id ){ if( this.form.options.parentformIdList ){ return !this.form.options.parentformIdList.contains( id ); } return true; }, isSubformUnique : function( id , oldId ){ if( !this.form.topform )return true; if( !this.getLevel1Subform() || !this.getLevel1Subform().json )return true; return this.form.topform.isSubformUnique( id, this.getLevel1Subform().json.id, oldId ); }, getParentformIdList : function(){ var parentformIdList; if( this.form.options.parentformIdList ){ parentformIdList = Array.clone( this.form.options.parentformIdList ); parentformIdList.push( this.form.json.id ) }else{ parentformIdList = [ this.form.json.id ]; } return parentformIdList; }, refreshSubform: function(){ if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){ MWF.Actions.get("x_processplatform_assemble_designer").getForm(this.json.subformSelected, function(json){ if (this.subformData.updateTime!==json.data.updateTime){ var select = null; if (this.property){ select = $(this.property.data.pid+"selectSubform").getElement("select"); } this.clearSubformList(this.json.subformSelected); this.reloadSubform(json.data, select, ""); } }.bind(this)); } }, loadIcon: function(){ this.iconNode = new Element("div", { "styles": this.css.iconNode }).inject(this.node); new Element("div", { "styles": this.css.iconNodeIcon }).inject(this.iconNode); new Element("div", { "styles": this.css.iconNodeText, "text": "Subform" }).inject(this.iconNode); }, _loadNodeStyles: function(){ this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode); this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon); this.iconNode.getLast("div").setStyles(this.css.iconNodeText); }, _setEditStyle_custom : function(name, input, oldValue){ if (name==="subformSelected"){ if (this.json.subformSelected!==oldValue){ this.redoSelectedSubform(name, input, oldValue); } } if (name==="subformType"){ if (this.json.subformType!==oldValue){ if (this.json.subformType !== "script"){ this.redoSelectedSubform(name, $(this.property.data.pid+"selectSubform").getElement("select"), ""); } if (this.json.subformType === "script"){ this.subformData = null; this.clearSubformList(this.json.subformSelected); this.node.empty(); this.loadIcon(); } } } }, redoSelectedSubform: function(name, input, oldValue){ if (this.json.subformSelected==="none") this.json.subformSelected=""; if (this.json.subformSelected && this.json.subformSelected!=="none"){ if(input)this.subformSelector = input; if( !input )input = this.getSubformSelector(); if( oldValue )this.subformSelectedValue = oldValue; if( !oldValue )oldValue = this.getSubformSelectedValue() || ""; var level1Subform = this.getLevel1Subform(); if( !this.checkSubformNested(this.json.subformSelected) ){ //var p = level1Subform.node.getPosition(document.body); //this.form.designer.alert("error", { // "event": { // "x": p.x + 150, // "y": p.y + 80 // } //}, this.form.designer.lp.subformNestedTitle, this.form.designer.lp.subformNestedInfor, 400, 120); this.form.designer.notice( this.form.designer.lp.subformNestedInfor, "error", level1Subform.node ); level1Subform.json.subformSelected = oldValue; if (input) { for (var i = 0; i < input.options.length; i++) { if (input.options[i].value === oldValue || (input.options[i].value==="none" && !oldValue ) ) { input.options[i].set("selected", true); break; } } } if( !oldValue ){ level1Subform.node.empty(); level1Subform.loadIcon(); }else{ level1Subform.refreshSubform(); } }else if( !this.isSubformUnique( this.json.subformSelected , oldValue ) ){ //if (this.form.subformList && this.form.subformList[this.json.subformSelected] ){ //var p = (input) ? input.getPosition() : this.node.getPosition(); //var p = level1Subform.node.getPosition(document.body); //this.form.designer.alert("error", { // "event": { // "x": p.x+150, // "y": p.y+80 // } //}, this.form.designer.lp.subformConflictTitle, this.form.designer.lp.subformConflictInfor, 400, 120); this.form.designer.notice( this.form.designer.lp.subformConflictInfor, "error", level1Subform.node ); level1Subform.json.subformSelected = oldValue; if (input){ for (var i=0; i