| 1 |
- MWF.xApplication.process.ProcessDesigner.widget=MWF.xApplication.process.ProcessDesigner.widget||{};MWF.xDesktop.requireApp("process.ProcessDesigner","widget.ScriptText",null,false);MWF.xApplication.process.ProcessDesigner.widget.SerialEditor=new Class({Implements:[Options,Events],Extends:MWF.widget.Common,options:{style:"default"},initialize:function(e,t,s){this.setOptions(s);this.node=$(e);this.data=t?JSON.decode(t):[];this.name=e.get("name");this.path="/x_component_process_ProcessDesigner/widget/$SerialEditor/";this.cssPath="/x_component_process_ProcessDesigner/widget/$SerialEditor/"+this.options.style+"/css.wcss";this._loadCss();this.selectedItems=[];this.items={}},load:function(){this.titleNode=new Element("div",{styles:this.css.titleNode}).inject(this.node);this.titleNode.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialSelectTitle);this.selectNode=new Element("div",{styles:this.css.selectNode}).inject(this.node);this.downNode=new Element("div",{styles:this.css.downNode}).inject(this.node);this.previewNode=new Element("div",{styles:this.css.previewNode}).inject(this.node);this.showNode=new Element("div",{styles:this.css.showNode}).inject(this.node);this.propertyNode=new Element("div",{styles:this.css.propertyNode}).inject(this.node);this.loadSelectNode()},loadSelectNode:function(){this.getSerialRule(function(){this.loadSelectNodeItems();this.loadSelectedNodeItems()}.bind(this))},loadSelectedNodeItems:function(){debugger;this.data.each(function(e){this.selectedItems.push(new(MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem[e.key.capitalize()])(this.items[e.key],e))}.bind(this));this.fireEvent("change")},loadSelectNodeItems:function(){debugger;Object.each(this.serialRuleJson,function(e,t){this.loadSelectNodeItem(e,t)}.bind(this))},loadSelectNodeItem:function(e,t){this.items[t]=new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.Item(e,t,this)},getSerialRule:function(e){if(!this.serialRuleJson){debugger;var t="/x_component_process_ProcessDesigner/$Process/serialRule.json";MWF.getJSON(t,function(t){this.serialRuleJson=t;if(e)e()}.bind(this))}else{if(e)e()}},getData:function(){debugger;var e=[];this.selectedItems.each(function(t){e.push(t.getData())});this.data=e;return e}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.Item=new Class({initialize:function(e,t,s){this.editor=s;this.json=e;this.key=t;this.css=this.editor.css;this.load()},load:function(){this.node=new Element("div",{styles:this.css.itemNode}).inject(this.editor.selectNode);this.iconNode=new Element("div",{styles:this.css.itemIconNode}).inject(this.node);this.textNode=new Element("div",{styles:this.css.itemTextNode}).inject(this.node);this.textNode.set({text:this.json.text,title:this.json.description});this.node.addEvents({mouseover:function(){this.node.setStyles(this.css.itemNode_over);this.iconNode.setStyles(this.css.itemIconNode_over)}.bind(this),mouseout:function(){this.node.setStyles(this.css.itemNode);this.iconNode.setStyles(this.css.itemIconNode)}.bind(this),click:function(){this.selectNumberItem()}.bind(this)})},selectNumberItem:function(){this.editor.selectedItems.push(new(MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem[this.key.capitalize()])(this));this.editor.fireEvent("change")}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem=new Class({initialize:function(e,t){this.item=e;this.json=e.json;this.key=e.key;this.editor=e.editor;this.css=this.editor.css;this.data=t;this.load()},load:function(){this.node=new Element("div",{styles:this.css.selectedItemNode}).inject(this.editor.showNode);this.textNode=new Element("div",{styles:this.css.selectedItemTextNode}).inject(this.node);this.textNode.set({text:this.json.text,title:this.json.description});this.node.addEvents({mouseover:function(){if(this.editor.currentItem!=this)this.node.setStyles(this.css.selectedItemNode_over)}.bind(this),mouseout:function(){if(this.editor.currentItem!=this)this.node.setStyles(this.css.selectedItemNode)}.bind(this),click:function(){this.selectItem()}.bind(this)});this.closeNode=new Element("div",{styles:this.css.selectedItemCloseNode}).inject(this.node);this.closeNode.addEvent("click",function(){this.deleteItem()}.bind(this));this.loadProperty();this.selectItem()},loadProperty:function(){},deleteItem:function(){this.node.destroy();if(this.propertyNode)this.propertyNode.destroy();this.editor.selectedItems.erase(this);if(this.editor.currentItem===this)this.editor.currentItem=null;this.editor.fireEvent("change");MWF.release(this)},selectItem:function(){if(this.editor.currentItem)this.editor.currentItem.unSelectItem();if(this.propertyNode){this.propertyNode.setStyle("display","block");if(this.key==="number"){this.loadNumberBy()}}this.node.setStyles(this.css.selectedItemNode_check);this.editor.currentItem=this},unSelectItem:function(){this.node.setStyles(this.css.selectedItemNode);if(this.propertyNode)this.propertyNode.setStyle("display","none");this.editor.currentItem=null}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Text=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,loadProperty:function(){this.propertyNode=new Element("div",{styles:this.css.itemPropertyNode}).inject(this.editor.propertyNode);this.propertyTitleNode=new Element("div",{styles:this.css.propertyTitleNode}).inject(this.propertyNode);this.propertyTitleNode.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialTextTitle);this.propertyInputDivNode=new Element("div",{styles:this.css.propertyInputDivNode}).inject(this.propertyNode);this.propertyInputNode=new Element("input",{type:"text",value:this.data?this.data.value:"",styles:this.css.propertyInputNode}).inject(this.propertyInputDivNode);this.changeText();this.propertyInputNode.addEvents({change:function(){this.changeText()}.bind(this),blur:function(){}})},changeText:function(){var e=this.propertyInputNode.get("value");if(e){this.textNode.set("text",'"'+e+'"')}else{this.textNode.set("text",this.json.text)}this.editor.fireEvent("change")},getData:function(){var e=this.propertyInputNode.get("value");var t=this.key;var s='return serial.text("'+e+'")';return{key:t,value:e,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,loadProperty:function(){this.value="created";var e=Math.random();this.propertyNode=new Element("div",{styles:this.css.itemPropertyNode}).inject(this.editor.propertyNode);var t=new Element("div",{styles:this.css.propertyTitleNode}).inject(this.propertyNode);t.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialDateTitle);var s=new Element("div",{styles:this.css.propertyInputDivNode}).inject(this.propertyNode);var i=this.data?this.data.value:"created";html='<input name="serialDateSelect'+e+'" '+(i=="created"?"checked":"")+' type="radio" value="created"/>'+MWF.xApplication.process.ProcessDesigner.LP.serialCreatedDateTitle;html+='<input name="serialDateSelect'+e+'" '+(i=="current"?"checked":"")+' type="radio" value="current"/>'+MWF.xApplication.process.ProcessDesigner.LP.serialCurrentDateTitle;s.set("html",html);this.changeText(this.data?this.data.value:"created");s.getElements("input").addEvent("click",function(e){if(e.target.checked){var t=e.target.get("value");this.changeText(t)}}.bind(this))},changeText:function(e){var t=MWF.xApplication.process.ProcessDesigner.LP.serialCreated;if(e=="current"){t=MWF.xApplication.process.ProcessDesigner.LP.serialCurrent}this.value=e;this.textNode.set("text",this.json.text+"("+t+")");this.editor.fireEvent("change")},getData:function(){var e=this.key;var t=this.value=="current"?"year":"createYear";var s="return serial."+t+'("yyyy")';return{key:e,value:this.value,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Month=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,getData:function(){var e=this.key;var t=this.value=="current"?"month":"createMonth";var s="return serial."+t+'("MM")';return{key:e,value:this.value,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Day=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Year,getData:function(){var e=this.key;var t=this.value=="current"?"day":"createDay";var s="return serial."+t+'("dd")';return{key:e,value:this.value,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Company=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,getData:function(){var e=this.key;var t="return serial.company()";return{key:e,value:"",script:t}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Department=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,getData:function(){var e=this.key;var t="return serial.department()";return{key:e,value:"",script:t}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,loadProperty:function(){this.propertyNode=new Element("div",{styles:this.css.itemPropertyNode}).inject(this.editor.propertyNode);this.propertyTitleNode=new Element("div",{styles:this.css.propertyTitleNode}).inject(this.propertyNode);this.propertyTitleNode.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialAttributeTitle);this.propertyInputDivNode=new Element("div",{styles:this.css.propertyInputDivNode}).inject(this.propertyNode);this.propertyInputNode=new Element("input",{type:"text",value:this.data?this.data.value:"",styles:this.css.propertyInputNode}).inject(this.propertyInputDivNode);this.changeText();this.propertyInputNode.addEvents({change:function(){this.changeText()}.bind(this),blur:function(){}})},changeText:function(){var e=this.propertyInputNode.get("value");if(e){this.textNode.set("text",this.json.text+"("+e+")")}else{this.textNode.set("text",this.json.text)}this.editor.fireEvent("change")},getData:function(){var e=this.propertyInputNode.get("value");var t=this.key;var s='return serial.companyAttribute("'+e+'")';return{key:t,value:e,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.DepartmentAttribute=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute,getData:function(){var e=this.propertyInputNode.get("value");var t=this.key;var s='return serial.departmentAttribute("'+e+'")';return{key:t,value:e,script:s}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Number=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,loadProperty:function(){this.propertyNode=new Element("div",{styles:this.css.itemPropertyNode}).inject(this.editor.propertyNode);var e=new Element("div",{styles:this.css.lineNode}).inject(this.propertyNode);var t=new Element("div",{styles:this.css.propertyTitleNode}).inject(e);t.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialNumberByTitle);this.propertyNumberByDivNode=new Element("div",{styles:this.css.propertyInputDivNode}).inject(e);this.loadNumberBy();e=new Element("div",{styles:this.css.lineNode}).inject(this.propertyNode);t=new Element("div",{styles:this.css.propertyTitleNode}).inject(e);t.set("text",MWF.xApplication.process.ProcessDesigner.LP.serialNumberLongTitle);this.propertyInputDivNode=new Element("div",{styles:this.css.propertyInputDivNode}).inject(e);this.propertyInputNode=new Element("select").inject(this.propertyInputDivNode);var s=this.data?this.data.value:{};var i=s.lng||0;var r="<option "+(i==0?"selected":"")+' value="0">auto</option>';r+="<option "+(i==2?"selected":"")+' value="2">2</option>';r+="<option "+(i==3?"selected":"")+' value="3">3</option>';r+="<option "+(i==4?"selected":"")+' value="4">4</option>';r+="<option "+(i==5?"selected":"")+' value="5">5</option>';r+="<option "+(i==6?"selected":"")+' value="6">6</option>';r+="<option "+(i==7?"selected":"")+' value="7">7</option>';r+="<option "+(i==8?"selected":"")+' value="8">8</option>';r+="<option "+(i==9?"selected":"")+' value="9">9</option>';this.propertyInputNode.set("html",r);this.propertyInputNode.addEvents({change:function(){this.editor.fireEvent("change")}.bind(this)})},loadNumberBy:function(){this.propertyNumberByDivNode.empty();var e=Math.random();var t=this.data?this.data.value:{};var s=t.by||[];var i="";this.editor.selectedItems.each(function(t,r){if(t.key!="number"){var o=s.indexOf(r)==-1?"":"checked";i+="<input "+o+' name="serialNumberBySelect'+e+'" type="checkbox" value="'+r+'"/>'+t.json.text}});this.propertyNumberByDivNode.set("html",i);this.propertyNumberByDivNode.getElements("input").addEvent("click",function(e){this.editor.fireEvent("change")}.bind(this))},getData:function(){debugger;var e=this.propertyInputNode.options[this.propertyInputNode.selectedIndex].value;var t=[];var s=this.propertyNumberByDivNode.getElements("input");s.each(function(e){if(e.checked)t.push(e.get("value").toInt())}.bind(this));var i={lng:e,by:t};var r="return serial.nextSerialNumber("+JSON.encode(t)+", "+e+")";return{key:this.key,value:i,script:r}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Script=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,loadProperty:function(){this.code="";this.propertyNode=new Element("div",{styles:this.css.itemPropertyNode}).inject(this.editor.propertyNode);this.scriptNode=new Element("div",{styles:this.css.scriptNode}).inject(this.propertyNode);this.scriptNode.set("title",MWF.xApplication.process.ProcessDesigner.LP.serialScriptTitle);this.scriptArea=new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode,this.data?this.data.value:"",this.editor.process.designer,{maskNode:this.editor.process.designer.content,maxObj:this.editor.process.designer.paperNode,onChange:function(e){this.code=e;this.editor.fireEvent("change")}.bind(this)})},getData:function(){var e=this.code;var t=this.key;return{key:t,value:e,script:e}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Unit=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,getData:function(){var e=this.key;var t="return serial.unit()";return{key:e,value:"",script:t}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.Unit=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem,getData:function(){var e=this.key;var t="return serial.unit()";return{key:e,value:"",script:t}}});MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.UnitAttribute=new Class({Extends:MWF.xApplication.process.ProcessDesigner.widget.SerialEditor.SelectedItem.CompanyAttribute,getData:function(){var e=this.propertyInputNode.get("value");var t=this.key;var s='return serial.unitAttribute("'+e+'")';return{key:t,value:e,script:s}}});
|