Readerfield.min.js 4.3 KB

1
  1. MWF.xDesktop.requireApp("cms.Xform","Personfield",null,false);MWF.require("MWF.widget.O2Identity",null,false);MWF.xDesktop.requireApp("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()}},_loadNode:function(){if(this.readonly||this.json.isReadonly){this._loadNodeRead()}else{this._loadNodeEdit()}},_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,title:MWF.xApplication.cms.Xform.LP.readerFieldNotice});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(){return this._getBusinessData()},setData:function(e){this._setValue(e)},_computeValue:function(){var t=[];if(this.json.identityValue){this.json.identityValue.each(function(e){if(e)t.push(e)})}if(this.json.unitValue){this.json.unitValue.each(function(e){if(e)t.push(e)})}if(this.json.defaultValue&&this.json.defaultValue.code){var e=this.form.Macro.exec(this.json.defaultValue.code,this);if(typeOf(e)!=="array")e=e?[e.toString()]:[];e.each(function(e){t.push(e)})}if(this.json.count>0){return t.slice(0,this.json.count)}return t},_getBusinessData:function(){if(this.json.section=="yes"){var e=this._getBusinessSectionData()}else{var e=this.form.businessData.data[this.json.id]||[]}return typeOf(e)!="array"?[e]:e},_setValue:function(e){this._setBusinessData(e);var t=this.node.getFirst();if(!t){t=this.node}t.empty();this.loadOrgWidget(e,t)},loadOrgWidget:function(e,s){var n={style:"xform",canRemove:!this.readonly,onRemove:this.removeItem};e.each(function(e){if(e.distinguishedName){var t=e.distinguishedName.substr(e.distinguishedName.length-1,1);switch(t.toLowerCase()){case"i":var i=new MWF.widget.O2Identity(e,s,n);break;case"p":var i=new MWF.widget.O2Person(e,s,n);break;case"u":var i=new MWF.widget.O2Unit(e,s,n);break;case"g":var i=new MWF.widget.O2Group(e,s,n);break;default:var i=new MWF.widget.O2Other(e,s,n)}i.field=this}}.bind(this))},removeItem:function(e,t){var i=this.field;var s=this.data.distinguishedName;var n=i._getBusinessData();var o;n.each(function(e,t){if(e.distinguishedName==s){o=t}});n.splice(o,1);i._setBusinessData(n);this.node.destroy();t.stopPropagation()},_loadValue:function(){this._setValue(this.getValue())},clickSelect:function(){this.validationMode();var e=this.json.count?this.json.count:0;var t=typeOf(this.json.selectType)=="array"?this.json.selectType:[this.json.selectType];if(t.contains("unit")||t.contains("identity")){var i=this.getSelectRange();if(this.json.range!=="all"){if(!i.length){this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange,"error",this.node);return false}}}else{var i=[]}if(!t[0]){this.form.notice(MWF.xApplication.process.Xform.LP.noSelectType,"error",this.node);return false}var s={type:"",types:t,values:this._getBusinessData(),count:e,units:i,expand:false,onComplete:function(e,t){var i=[];e.each(function(e){i.push(MWF.org.parseOrgData(e.data))});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 n=new MWF.O2Selector(this.form.app.content,s)}});