Readerfield.min.js 5.3 KB

1
  1. MWF.xDesktop.requireApp("cms.Xform","Personfield",null,false);MWF.require("MWF.widget.Identity",null,false);MWF.xDesktop.requireApp("Organization","Selector.package",null,false);MWF.xApplication.cms.Xform.Readerfield=MWF.CMSReaderfield=new Class({Extends:MWF.CMSPersonfield,iconStyle:"readerfieldIcon",_loadUserInterface:function(){this.field=true;this._loadNode();if(this.json.compute=="show"){this._setValue(this._computeValue())}else{this._loadValue()}},_loadNodeRead:function(){this.node.empty();this.node.setStyle("overflow","hidden")},_loadNodeEdit:function(){var e=this.input=new Element("div",{styles:{background:"transparent",width:"100%",border:"0px"}});e.set(this.json.properties);var t=new Element("div",{styles:{overflow:"hidden",position:"relative","min-height":"20px","margin-right":"20px"}}).inject(this.node,"after");e.inject(t);this.node.destroy();this.node=t;this.node.set({id:this.json.id,MWFType:this.json.type,readonly:true});if(!this.readonly){this.node.setStyle("cursor","pointer");this.node.addEvents({click:this.clickSelect.bind(this)});this.iconNode=new Element("div",{styles:{background:"url("+"/x_component_cms_Xform/$Form/default/icon/selectreader.png) center center no-repeat",width:"18px",height:"18px",float:"right"}}).inject(this.node,"before");this.iconNode.setStyle("cursor","pointer");this.iconNode.addEvents({click:this.clickSelect.bind(this)})}},getData:function(e){if(this.json.compute=="save")this._setValue(this._computeValue());return this._getBusinessData()},getInputData:function(){var e=this._getBusinessData();var t=[];for(var i in e){e[i].each(function(e){t.push(e.name)})}return t.join(",")},setData:function(e){this._setValue(e)},_computeValue:function(e){var t={};if(this.json.identityValue){t.identityValue=[];this.json.identityValue.each(function(e){t.identityValue.push({name:e})}.bind(this))}if(this.json.personValue){t.personValue=[];this.json.personValue.each(function(e){t.personValue.push({name:e})}.bind(this))}if(this.json.departmentValue){t.departmentValue=[];this.json.departmentValue.each(function(e){t.departmentValue.push({name:e})}.bind(this))}if(this.json.companyValue){t.companyValue=[];this.json.companyValue.each(function(e){t.companyValue.push({name:e})}.bind(this))}if(this.json.groupValue){t.groupValue=[];this.json.groupValue.each(function(e){t.groupValue.push({name:e})}.bind(this))}return t},_setValue:function(e){this._setBusinessData(e);var t=this.node.getFirst();if(!t){t=this.node}var i={actions:this.form.documentAction,app:this.form.app,field:this};for(var n in e){v=e[n];if(n=="identityValue"){v.each(function(e){if(e.name)new MWF.widget.Identity(Object.merge(e,{type:"identity"}),t,i,!this.readonly,this.removeItem,{style:"cmsdoc"})}.bind(this))}else if(n=="personValue"){v.each(function(e){if(e.name)new MWF.widget.Department(Object.merge(e,{type:"person"}),t,i,!this.readonly,this.removeItem,{style:"cmsdoc"})}.bind(this))}else if(n=="departmentValue"){v.each(function(e){if(e.name)new MWF.widget.Department(Object.merge(e,{type:"department"}),t,i,!this.readonly,this.removeItem,{style:"cmsdoc"})}.bind(this))}else if(n=="companyValue"){v.each(function(e){if(e.name)new MWF.widget.Company(Object.merge(e,{type:"company"}),t,i,!this.readonly,this.removeItem,{style:"cmsdoc"})}.bind(this))}else if(n=="groupValue"){v.each(function(e){if(e.name)new MWF.widget.Department(Object.merge(e,{type:"group"}),t,i,!this.readonly,this.removeItem,{style:"cmsdoc"})}.bind(this))}}},removeItem:function(e){var t=this.explorer.field;var i=this.data.type;var n=this.data.name;var s=t._getBusinessData();var a=s[i+"Value"];var o;a.each(function(e,t){if(e.name==n){o=t}});a.splice(o,1);t._setBusinessData(s);this.node.destroy();e.stopPropagation()},_loadValue:function(){this._setValue(this.getValue())},clickSelect:function(){this.validationMode();var e=this.json.count?this.json.count:0;var t=this.getCompanys();var i=this.getDepartments();if(this.json.range=="depart"){if(!i.length){this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange,"error",this.node);return false}}if(this.json.range=="company"){if(!t.length){this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange,"error",this.node);return false}}var n=this._getBusinessData();var s={};var a=[];if(typeOf(this.json.selectType)=="array"&&this.json.selectType.length>1){for(var o in n){var r=[];n[o].each(function(e){r.push(e.name)}.bind(this));s[o.replace("Value","")]=r}}else{for(var o in n){n[o].each(function(e){a.push(e.name)}.bind(this))}}var h={types:typeOf(this.json.selectType)=="array"?this.json.selectType:[this.json.selectType],names:a,multipleNames:s,count:e,departments:i,companys:t,onComplete:function(e,t){var i={};if(t){for(var n in t){var s=t[n];var a=[];s.each(function(e){a.push({id:e.data.id,name:e.data.name})});i[n+"Value"]=a}}else{var n=typeOf(this.json.selectType)=="array"?this.json.selectType[0]:this.json.selectType;n=n+"Value";var i={};i[n]=[];e.each(function(e){i[n].push({id:e.data.id,name:e.data.name})})}this.setData(i);this.validation()}.bind(this),onCancel:function(){this.validation()}.bind(this),onLoad:function(){if(this.descriptionNode)this.descriptionNode.setStyle("display","none")}.bind(this),onClose:function(){var e=this.getInputData();if(!e||!e.length)if(this.descriptionNode)this.descriptionNode.setStyle("display","block")}.bind(this)};var l=new MWF.OrgSelector(this.form.app.content,h)}});