$Module.min.js 5.1 KB

1
  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(s,t,i,e){this.node=$(s);this.node.store("module",this);this.json=t;this.form=i},_getSource:function(){var s=this.node.getParent();while(s&&(s.get("MWFtype")!="source"&&s.get("MWFtype")!="subSource"&&s.get("MWFtype")!="subSourceItem"))s=s.getParent();return s?s.retrieve("module"):null},hide:function(){var s=this.node.getStyle("display");if(s!=="none")this.node.store("mwf_display",s);this.node.setStyle("display","none");if(this.iconNode)this.iconNode.setStyle("display","none")},show:function(){var s=this.node.retrieve("mwf_display",s);this.node.setStyle("display",s);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(t,s){if(t.code){if(this.options.moduleEvents.indexOf(s)!=-1){this.addEvent(s,function(s){return this.form.Macro.fire(t.code,this,s)}.bind(this))}else{this.node.addEvent(s,function(s){return this.form.Macro.fire(t.code,this,s)}.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 s=this.form.businessData.data[this.json.id];return s?s[layout.desktop.session.user.id]||"":""},_getBusinessSectionDataByUnit:function(){var s=this.form.businessData.data[this.json.id];if(!s)return"";var t=this.form.businessData.task?this.form.businessData.task.unit:"";return t?s[t]||"":""},_getBusinessSectionDataByActivity:function(){var s=this.form.businessData.data[this.json.id];if(!s)return"";var t=this.form.businessData.work?this.form.businessData.work.activity:"";return t?s[t]||"":""},_getBusinessSectionDataByScript:function(s){var t=this.form.businessData.data[this.json.id];if(!t)return"";var i=this.form.Macro.exec(s,this);return i?t[i]||"":""},_setBusinessData:function(s){if(this.json.section=="yes"){this._setBusinessSectionData(s)}else{if(this.json.type==="Opinion"){this._setBusinessSectionDataByPerson(s)}else{if(this.form.businessData.data[this.json.id]){this.form.businessData.data[this.json.id]=s}else{this.form.businessData.data[this.json.id]=s;this.form.Macro.environment.setData(this.form.businessData.data)}if(this.json.isTitle)this.form.businessData.work.title=s}}},_setBusinessSectionData:function(s){switch(this.json.sectionBy){case"person":this._setBusinessSectionDataByPerson(s);break;case"unit":this._setBusinessSectionDataByUnit(s);break;case"activity":this._setBusinessSectionDataByActivity(s);break;case"script":this._setBusinessSectionDataByScript(this.json.sectionByScript.code,s);break;default:if(this.form.businessData.data[this.json.id]){this.form.businessData.data[this.json.id]=s}else{this.form.businessData.data[this.json.id]=s;this.form.Macro.environment.setData(this.form.businessData.data)}}},_setBusinessSectionDataByPerson:function(s){var t=false;var i=layout.desktop.session.user.id;var e=this.form.businessData.data[this.json.id];if(!e){e={};this.form.businessData.data[this.json.id]=e;t=true}if(!e[i])t=true;e[i]=s;if(t)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByUnit:function(s){var t=false;var i=this.form.businessData.task?this.form.businessData.task.unit:"";if(i){var e=this.form.businessData.data[this.json.id];if(!e){e={};this.form.businessData.data[this.json.id]=e;t=true}if(!e[i])t=true;e[i]=s}if(t)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByActivity:function(s){var t=false;var i=this.form.businessData.work?this.form.businessData.work.activity:"";if(i){var e=this.form.businessData.data[this.json.id];if(!e){e={};this.form.businessData.data[this.json.id]=e;t=true}if(!e[i])t=true;e[i]=s}if(t)this.form.Macro.environment.setData(this.form.businessData.data)},_setBusinessSectionDataByScript:function(s,t){var i=false;var e=this.form.Macro.exec(s,this);if(e){var a=this.form.businessData.data[this.json.id];if(!a){a={};this.form.businessData.data[this.json.id]=a;i=true}if(!a[e])i=true;a[e]=t}if(i)this.form.Macro.environment.setData(this.form.businessData.data)},_queryLoaded:function(){},_afterLoaded:function(){},setValue:function(){},focus:function(){this.node.focus()}});