| 1 |
- MWF.require("MWF.widget.Common",null,false);MWF.xApplication.process.Xform.$Module=MWF.APP$Module=new Class({Implements:[Events],options:{moduleEvents:["load","queryLoad","postLoad"]},initialize:function(node,json,form,options){this.node=$(node);this.node.store("module",this);this.json=json;this.form=form},_getSource:function(){var parent=this.node.getParent();while(parent&&(parent.get("MWFtype")!="source"&&parent.get("MWFtype")!="subSource"&&parent.get("MWFtype")!="subSourceItem"))parent=parent.getParent();return parent?parent.retrieve("module"):null},hide:function(){var dsp=this.node.getStyle("display");if(dsp!=="none")this.node.store("mwf_display",dsp);this.node.setStyle("display","none");if(this.iconNode)this.iconNode.setStyle("display","none")},show:function(){var dsp=this.node.retrieve("mwf_display",dsp);this.node.setStyle("display",dsp);if(this.iconNode)this.iconNode.setStyle("display","block")},load:function(){if(this.fireEvent("queryLoad")){this._queryLoaded();this._loadUserInterface();this._loadStyles();this._loadEvents();this._afterLoaded();this.fireEvent("postLoad");this.fireEvent("load")}},_loadUserInterface:function(){},_loadStyles:function(){if(this.json.styles)this.node.setStyles(this.json.styles)},_loadEvents:function(){Object.each(this.json.events,function(e,key){if(e.code){if(this.options.moduleEvents.indexOf(key)!=-1){this.addEvent(key,function(event){return this.form.Macro.fire(e.code,this,event)}.bind(this))}else{this.node.addEvent(key,function(event){return this.form.Macro.fire(e.code,this,event)}.bind(this))}}}.bind(this))},_getBusinessData:function(){if(this.json.section=="yes"){return this._getBusinessSectionData()}else{if(this.json.type==="Opinion"){return this._getBusinessSectionDataByPerson()}else{return this.form.businessData.data[this.json.id]||""}}},_getBusinessSectionData:function(){switch(this.json.sectionBy){case"person":return this._getBusinessSectionDataByPerson();break;case"unit":return this._getBusinessSectionDataByUnit();break;case"activity":return this._getBusinessSectionDataByActivity();break;case"script":return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);break;default:return this.form.businessData.data[this.json.id]||""}},_getBusinessSectionDataByPerson:function(){var dataObj=this.form.businessData.data[this.json.id];return dataObj?dataObj[layout.desktop.session.user.id]||"":""},_getBusinessSectionDataByUnit:function(){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj)return"";var key=this.form.businessData.task?this.form.businessData.task.unit:"";return key?dataObj[key]||"":""},_getBusinessSectionDataByActivity:function(){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj)return"";var key=this.form.businessData.work?this.form.businessData.work.activity:"";return key?dataObj[key]||"":""},_getBusinessSectionDataByScript:function(code){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj)return"";var key=this.form.Macro.exec(code,this);return key?dataObj[key]||"":""},_setBusinessData:function(v){if(this.json.section=="yes"){this._setBusinessSectionData(v)}else{if(this.json.type==="Opinion"){this._setBusinessSectionDataByPerson(v)}else{if(this.form.businessData.data[this.json.id]){this.form.businessData.data[this.json.id]=v}else{this.form.businessData.data[this.json.id]=v;this.form.Macro.environment.setData(this.form.businessData.data)}if(this.json.isTitle)this.form.businessData.work.title=v}}},_setBusinessSectionData:function(v){switch(this.json.sectionBy){case"person":this._setBusinessSectionDataByPerson(v);break;case"unit":this._setBusinessSectionDataByUnit(v);break;case"activity":this._setBusinessSectionDataByActivity(v);break;case"script":this._setBusinessSectionDataByScript(this.json.sectionByScript.code,v);break;default:if(this.form.businessData.data[this.json.id]){this.form.businessData.data[this.json.id]=v}else{this.form.businessData.data[this.json.id]=v;this.form.Macro.environment.setData(this.form.businessData.data)}}},_setBusinessSectionDataByPerson:function(v){var resetData=false;var key=layout.desktop.session.user.id;var dataObj=this.form.businessData.data[this.json.id];if(!dataObj){dataObj={};this.form.businessData.data[this.json.id]=dataObj;resetData=true}if(!dataObj[key])resetData=true;dataObj[key]=v;if(resetData)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByUnit:function(v){var resetData=false;var key=this.form.businessData.task?this.form.businessData.task.unit:"";if(key){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj){dataObj={};this.form.businessData.data[this.json.id]=dataObj;resetData=true}if(!dataObj[key])resetData=true;dataObj[key]=v}if(resetData)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByActivity:function(v){var resetData=false;var key=this.form.businessData.work?this.form.businessData.work.activity:"";if(key){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj){dataObj={};this.form.businessData.data[this.json.id]=dataObj;resetData=true}if(!dataObj[key])resetData=true;dataObj[key]=v}if(resetData)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByScript:function(code,v){var resetData=false;var key=this.form.Macro.exec(code,this);if(key){var dataObj=this.form.businessData.data[this.json.id];if(!dataObj){dataObj={};this.form.businessData.data[this.json.id]=dataObj;resetData=true}if(!dataObj[key])resetData=true;dataObj[key]=v}if(resetData)this.form.Macro.environment.setData(this.form.businessData.data)},_queryLoaded:function(){},_afterLoaded:function(){},setValue:function(){},focus:function(){this.node.focus()}});
|