| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- MWF.require("MWF.widget.Common", null, false);
- /** @class $Module 组件类,此类为所有组件的父类。 */
- MWF.xApplication.process.Xform.$Module = MWF.APP$Module = new Class(
- /** @lends MWF.xApplication.process.Xform.$Module# */
- {
- Implements: [Events],
- options: {
- "moduleEvents": ["load", "queryLoad", "postLoad"]
- },
- initialize: function(node, json, form, options){
- /**
- * 组件的节点
- * {@link https://mootools.net/core/docs/1.6.0/Element/Element MootoolsElement }
- * @member {Element}
- */
- this.node = $(node);
- this.node.store("module", this);
- this.json = json;
- /**
- * 组件的所在表单对象.
- * @member {MWF.xApplication.process.Xform.Form}
- */
- 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(){
- this._loadModuleEvents();
- if (this.fireEvent("queryLoad")){
- this._queryLoaded();
- this._loadUserInterface();
- this._loadStyles();
- this._loadDomEvents();
- //this._loadEvents();
- this._afterLoaded();
- this.fireEvent("postLoad");
- this.fireEvent("load");
- }
- },
- _loadUserInterface: function(){
- // this.node = this.node;
- },
- _loadStyles: function(){
- if (this.json.styles) Object.each(this.json.styles, function(value, key){
- if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
- var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
- var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
- var host3 = MWF.Actions.getHost("x_cms_assemble_control");
- if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
- value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
- value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
- }
- if (value.indexOf("/x_portal_assemble_surface")!==-1){
- value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }else if (value.indexOf("x_portal_assemble_surface")!==-1){
- value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
- }
- if (value.indexOf("/x_cms_assemble_control")!==-1){
- value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
- }else if (value.indexOf("x_cms_assemble_control")!==-1){
- value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
- }
- value = o2.filterUrl(value);
- }
- this.node.setStyle(key, value);
- }.bind(this));
- // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
- // var host = MWF.Actions.getHost(root);
- // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
- // }
- //if (this.json.styles) this.node.setStyles(this.json.styles);
- },
- _loadModuleEvents : 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));
- }
- }
- }.bind(this));
- },
- _loadDomEvents: function(){
- Object.each(this.json.events, function(e, key){
- if (e.code){
- if (this.options.moduleEvents.indexOf(key)===-1){
- this.node.addEvent(key, function(event){
- return this.form.Macro.fire(e.code, this, event);
- }.bind(this));
- }
- }
- }.bind(this));
- },
- _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));
- },
- addModuleEvent: function(key, fun){
- if (this.options.moduleEvents.indexOf(key)!==-1){
- this.addEvent(key, function(event){
- return (fun) ? fun(this, event) : null;
- }.bind(this));
- }else{
- this.node.addEvent(key, function(event){
- return (fun) ? fun(this, event) : null;
- }.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();
- case "unit":
- return this._getBusinessSectionDataByUnit();
- case "activity":
- return this._getBusinessSectionDataByActivity();
- case "splitValue":
- return this._getBusinessSectionDataBySplitValue();
- case "script":
- return this._getBusinessSectionDataByScript(((this.json.sectionByScript) ? this.json.sectionByScript.code : ""));
- default:
- return this.form.businessData.data[this.json.id] || "";
- }
- },
- _getBusinessSectionDataByPerson: function(){
- this.form.sectionListObj[this.json.id] = layout.desktop.session.user.id;
- var dataObj = this.form.businessData.data[this.json.id];
- return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
- },
- _getBusinessSectionDataByUnit: function(){
- this.form.sectionListObj[this.json.id] = "";
- var dataObj = this.form.businessData.data[this.json.id];
- if (!dataObj) return "";
- var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
- if (key) this.form.sectionListObj[this.json.id] = key;
- return (key) ? (dataObj[key] || "") : "";
- },
- _getBusinessSectionDataByActivity: function(){
- this.form.sectionListObj[this.json.id] = "";
- var dataObj = this.form.businessData.data[this.json.id];
- if (!dataObj) return "";
- var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
- if (key) this.form.sectionListObj[this.json.id] = key;
- return (key) ? (dataObj[key] || "") : "";
- },
- _getBusinessSectionDataBySplitValue: function(){
- this.form.sectionListObj[this.json.id] = "";
- var dataObj = this.form.businessData.data[this.json.id];
- if (!dataObj) return "";
- var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
- if (key) this.form.sectionListObj[this.json.id] = key;
- return (key) ? (dataObj[key] || "") : "";
- },
- _getBusinessSectionDataByScript: function(code){
- this.form.sectionListObj[this.json.id] = "";
- var dataObj = this.form.businessData.data[this.json.id];
- if (!dataObj) return "";
- var key = this.form.Macro.exec(code, this);
- if (key) this.form.sectionListObj[this.json.id] = key;
- 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 "splitValue":
- this._setBusinessSectionDataBySplitValue(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);
- },
- _setBusinessSectionDataBySplitValue: function(v){
- var resetData = false;
- var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
- 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();
- }
- });
|