MWF.require("MWF.widget.UUID", null,false); MWF.require("MWF.widget.JsonTemplate", null, false); MWF.xApplication.process.ProcessDesigner.Property = new Class({ Implements: [Options, Events], load: function(){ if (!this.process.options.isView){ if (this.fireEvent("queryLoad")){ MWF.getRequestText(this.htmlPath, function(responseText, responseXML){ this.htmlString = responseText; this.fireEvent("postLoad"); }.bind(this)); } this.process.propertyListNode.addEvent("keydown", function(e){e.stopPropagation();}); } }, editProperty: function(td){ }, getHtmlString: function(callback){ if (!this.htmlString){ MWF.getRequestText(this.htmlPath, function(responseText, responseXML){ this.htmlString = responseText; if (callback) callback(); }.bind(this)); }else{ if (callback) callback(); } }, show: function(){ if (!this.process.options.isView){ if (!this.propertyContent){ this.getHtmlString(function(){ this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.process.propertyListNode); this.process.panel.propertyTabPage.showTabIm(); this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString); this.propertyContent.set("html", this.JsonTemplate.load()); this.process.panel.data = this.data; this.setEditNodeEvent(); this.setEditNodeStyles(this.propertyContent); this.loadPropertyTab(); this.loadFormFieldInput(); this.loadPersonInput(); this.loadCalendarInput(); this.loadScriptInput(); this.loadScriptText(); this.loadConditionInput(); this.loadFormSelect(); this.loadSerial(); this.loadSericalActivitySelect(); this.loadApplicationSelector(); this.loadProcessSelector(); this.loadIconSelect(); this.loadContextRoot(); this.loadProjection(); }.bind(this)); //this.loadDutySelector(); }else{ this.process.panel.data = this.data; this.propertyContent.setStyle("display", "block"); this.process.panel.propertyTabPage.showTabIm(); } // this.process.isFocus = true; } }, //hide: function(){ // if (!this.process.options.isView) { // this.JsonTemplate = null; // // this.scriptTexts.each(function(script){ // MWF.release(script); // }.bind(this)); // this.scriptTexts = null; // // this.propertyContent.set("html", ""); // } //}, hide: function(){ if (!this.process.options.isView) { if (this.propertyContent) this.propertyContent.setStyle("display", "none"); } }, loadPropertyTab: function(){ var tabNodes = this.propertyContent.getElements(".MWFTab"); if (tabNodes.length){ var tmpNode = this.propertyContent.getFirst(); var tabAreaNode = new Element("div", { "styles": this.process.css.propertyTabNode }).inject(tmpNode, "before"); MWF.require("MWF.widget.Tab", function(){ var tab = new MWF.widget.Tab(tabAreaNode, {"style": "moduleList"}); tab.load(); var tabPages = []; tabNodes.each(function(node){ var tabPage = tab.addTab(node, node.get("title"), false); tabPages.push(tabPage); }.bind(this)); tabPages[0].showTab(); }.bind(this)); } }, setEditNodeEvent: function(){ var property = this; // var inputs = this.propertyContent.getElements(".editTableInput"); var inputs = this.propertyContent.getElements("input"); inputs.each(function(input){ var jsondata = input.get("name"); var id = this.process.process.id; if (this.activity) id = this.activity.data.id; if (this.route) id = this.route.data.id; input.set("name", id+jsondata); if (jsondata){ var inputType = input.get("type").toLowerCase(); switch (inputType){ case "radio": input.addEvent("change", function(e){ property.setRadioValue(jsondata, this); }); input.addEvent("blur", function(e){ property.setRadioValue(jsondata, this); }); input.addEvent("keydown", function(e){ e.stopPropagation(); }); property.setRadioValue(jsondata, input); break; case "checkbox": input.addEvent("keydown", function(e){ e.stopPropagation(); }); break; default: input.addEvent("change", function(e){ property.setValue(jsondata, this.value); }); input.addEvent("blur", function(e){ property.setValue(jsondata, this.value); }); input.addEvent("keydown", function(e){ if (e.code===13){ property.setValue(jsondata, this.value); } e.stopPropagation(); }); property.setValue(jsondata, input.get("value")); } } }.bind(this)); var selects = this.propertyContent.getElements("select"); selects.each(function(select){ var jsondata = select.get("name"); if (jsondata){ select.addEvent("change", function(e){ property.setSelectValue(jsondata, this); }); //property.setSelectValue(jsondata, select); } }); var textareas = this.propertyContent.getElements("textarea"); textareas.each(function(input){ var jsondata = input.get("name"); if (jsondata){ input.addEvent("change", function(e){ property.setValue(jsondata, this.value); }); input.addEvent("blur", function(e){ property.setValue(jsondata, this.value); }); input.addEvent("keydown", function(e){ e.stopPropagation(); }); } }.bind(this)); }, setSelectValue: function(name, select){ var idx = select.selectedIndex; var options = select.getElements("option"); var value = ""; if (options[idx]){ value = options[idx].get("value"); } this.data[name] = value; }, setRadioValue: function(name, input){ if (input.checked){ var oldValue = this.data[name]; var value = input.value; if (value=="false") value = false; if (value=="true") value = true; this.data[name] = value; if (this.route) this.route._setEditProperty(name, input, oldValue); } }, setValue: function(name, value){ var oldValue = this.data[name]; this.data[name] = value; if (name=="name"){ if (!value) this.data[name] = MWF.APPPD.LP.unnamed; // this.activity.redraw(); } if (this.route) this.route._setEditProperty(name, input, oldValue); }, setEditNodeStyles: function(node){ var nodes = node.getChildren(); if (nodes.length){ nodes.each(function(el){ var cName = el.get("class"); if (cName){ if (this.process.css[cName]) el.setStyles(this.process.css[cName]); } this.setEditNodeStyles(el); }.bind(this)); } }, loadScriptText: function(){ this.scriptTexts = []; var scriptNodes = this.propertyContent.getElements(".MWFScriptText"); MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){ var _self = this; scriptNodes.each(function(node){ var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(node, this.data[node.get("name")], this.process.designer, { "maskNode": this.process.designer.content, "maxObj": this.process.designer.paperNode, "onChange": function(code){ _self.data[node.get("name")] = code; } }); this.scriptTexts.push(script); //this.setScriptItems(script, node); }.bind(this)); }.bind(this)); }, loadScriptInput: function(){ var scriptNodes = this.propertyContent.getElements(".MWFScript"); MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptSelector", function(){ var _self = this; scriptNodes.each(function(node){ var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector(node, this.data[node.get("name")], this.process.designer, { "maskNode": this.process.designer.content, "onSelected": function(scriptData){ _self.data[node.get("name")] = scriptData.name; }, "onDelete": function(){ _self.data[node.get("name")] = ""; node.empty(); } //"onPostSave": function(script){ // this.saveScriptItem(node, script); //}.bind(this), //"onQueryDelete": function(script){ // this.deleteScriptItem(node, script); //}.bind(this) }); //this.setScriptItems(script, node); }.bind(this)); }.bind(this)); }, loadScriptArea: function(){ var scriptAreas = this.propertyContent.getElements(".MWFScriptArea"); var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea"); this.loadScriptEditor(scriptAreas); this.loadScriptEditor(formulaAreas, "formula"); }, loadScriptEditor: function(scriptAreas, style){ scriptAreas.each(function(node){ var title = node.get("title"); var name = node.get("name"); if (!this.data[name]) this.data[name] = {"code": "", "html": ""}; var scriptContent = this.data[name]; MWF.require("MWF.widget.ScriptArea", function(){ var scriptArea = new MWF.widget.ScriptArea(node, { "title": title, //"maxObj": this.propertyNode.parentElement.parentElement.parentElement, "maxObj": this.process.designer.content, "onChange": function(){ if (!this.data[name]){ this.data[name] = {"code": "", "html": ""}; //if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name); } var json = scriptArea.toJson(); this.data[name].code = json.code; }.bind(this), //"onSave": function(){ // this.designer.saveForm(); //}.bind(this), "style": style || "default" }); scriptArea.load(scriptContent); }.bind(this)); }.bind(this)); }, loadUnitTypeSelector: function(){ var nodes = this.propertyContent.getElements(".MWFFormUnitTypeSelector"); if (nodes.length){ this.getUnitTypeList(function(){ nodes.each(function(node){ var select = new Element("select").inject(node); select.addEvent("change", function(e){ this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value); }.bind(this)); this.setUnitTypeSelectOptions(node, select); this.setValue(select.getParent("div").get("name"), select.options[select.selectedIndex].value); // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node); // refreshNode.addEvent("click", function(e){ // this.getUnitTypeList(function(){ // this.setUnitTypeSelectOptions(node, select); // }.bind(this), true); // }.bind(this)); }.bind(this)); }.bind(this)); } }, setUnitTypeSelectOptions: function(node, select){ var name = node.get("name"); select.empty(); var option = new Element("option", {"value":"all", "text": MWF.xApplication.process.ProcessDesigner.LP.all, "selected": (!this.data[name] || this.data[name]==="all")}).inject(select); this.unitTypeList.each(function(unitType){ var option = new Element("option", { "text": unitType, "value": unitType, "selected": (this.data[name]===unitType) }).inject(select); }.bind(this)); }, getUnitTypeList: function(callback, refresh){ if (!this.unitTypeList || refresh){ //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){ // var action = new MWF.xApplication.Org.Actions.RestActions(); var action = MWF.Actions.get("x_organization_assemble_control"); action.listUnitType(function(json){ this.unitTypeList = json.data.valueList; if (callback) callback(); }.bind(this)); //}.bind(this)); }else{ if (callback) callback(); } }, loadFormFieldInput: function(){ var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson"); MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){ fieldNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "formField", "application": this.process.process.application, "fieldType": "person", "names": this.data[node.get("name")] || [], "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); }.bind(this)); }, createCalendar: function(node){ if (!node.retrieve("calendar")){ var calendar = new MWF.widget.Calendar(node, { "isTime": true, "target": node.getParent(), "style": "xform", "onChange": function(dv, date, t){ this.setValue(node.get("name"), dv) }.bind(this) }); node.store("calendar", calendar); } }, loadCalendarInput: function(){ var nodes = this.propertyContent.getElements(".MWFDateTime"); MWF.require("MWF.widget.Calendar", function(){ nodes.each(function(node){ var input = node.getFirst(); input.addEvents({ "click": function(){ this.createCalendar(input) }.bind(this), "focus": function(){ this.createCalendar(input) }.bind(this) }); }.bind(this)); }.bind(this)); }, loadPersonInput: function(){ debugger; var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity"); var personNodes = this.propertyContent.getElements(".MWFPersonPerson"); var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit"); var personGroupNodes = this.propertyContent.getElements(".MWFPersonGroup"); var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty"); // var personDepartmentNodes = this.propertyContent.getElements(".MWFPersonDepartment"); // var personCompanyNodes = this.propertyContent.getElements(".MWFPersonCompany"); var dutyNodes = this.propertyContent.getElements(".MWFDutySelector"); MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){ personIdentityNodes.each(function(node){ count = node.get("count") || 0; new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "identity", "names": this.data[node.get("name")], "count": count, "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); personNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "person", "names": this.data[node.get("name")], "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); personUnitNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "unit", "names": this.data[node.get("name")], "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); personGroupNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "group", "names": this.data[node.get("name")], "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); dutyNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "duty", "names": this.data[node.get("name")], "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this), "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this) }); }.bind(this)); dutyNameNodes.each(function(node){ new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { "type": "dutyName", "names": this.data[node.get("name")], "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) }); }.bind(this)); // personDepartmentNodes.each(function(node){ // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { // "type": "department", // "names": this.data[node.get("name")], // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) // }); // }.bind(this)); // personCompanyNodes.each(function(node){ // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { // "type": "company", // "names": this.data[node.get("name")], // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this) // }); // }.bind(this)); // dutyNodes.each(function(node){ // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, { // "type": "duty", // "names": this.data[node.get("name")], // "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this), // "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this) // }); // }.bind(this)); }.bind(this)); }, removeDutyItem: function(node, item){ if (item.data.id){ var values = JSON.decode(this.data[node.get("name")]) || []; var value = values.filter(function(v){ return v.id == item.data.id; }); value.each(function(v) { values = values.erase(v); }); this.data[node.get("name")] = JSON.encode(values); } item.node.destroy(); MWF.release(item); delete item; }, addDutyItem: function(node, ids){ var value = this.data[node.get("name")] || ""; if (!value) value = "[]"; var values = JSON.decode(value); ids.each(function(id){ if (id.data.dutyId){ for (var i=0; i