123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448 |
- MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
- MWF.xDesktop.requireApp("Selector", "package", null, false);
- MWF.require("MWF.widget.O2Identity", null, false);
- /** @class Org 人员组织组件。
- * @o2cn 人员组织组件
- * @example
- * //可以在脚本中获取该组件
- * //方法1:
- * var field = this.form.get("fieldId"); //获取组件对象
- * //方法2
- * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
- *
- * var data = field.getData(); //获取值
- * field.setData(value); //设置值
- * field.hide(); //隐藏字段
- * var id = field.json.id; //获取字段标识
- * var flag = field.isEmpty(); //字段是否为空
- * @extends MWF.xApplication.process.Xform.$Input
- * @o2category FormComponents
- * @o2range {Process|CMS|Portal}
- * @hideconstructor
- */
- MWF.xApplication.process.Xform.Org = MWF.APPOrg = new Class(
- /** @lends MWF.xApplication.process.Xform.Org# */
- {
- Implements: [Events],
- Extends: MWF.APP$Input,
- options: {
- /**
- * 组件加载前触发。当前组件的queryLoad事件还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取当前组件。
- * @event MWF.xApplication.process.Xform.Org#queryLoad
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 组件加载时触发.
- * @event MWF.xApplication.process.Xform.Org#load
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 组件加载后触发.
- * @event MWF.xApplication.process.Xform.Org#postLoad
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 当组件值改变时触发。
- * @event MWF.xApplication.process.Xform.Org#change
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 当组件不允许输入(使用人员选择框)时,完成选择人员,并且给组件赋值后执行。
- * @event MWF.xApplication.process.Xform.Org#select
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- "moduleEvents": ["load", "queryLoad", "postLoad", "change", "select", "removeItem"],
- /**
- * 人员选择框事件:加载前执行。this.target指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#queryLoadSelector
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载后执行,由于选择项为异步加载,此时选择项并未加载完成。this.target指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#postLoadSelector
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载选择框容器节点前执行。this.target指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载选择框容器节点后执行。this.target指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#postLoadContent
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载分类前执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载分类后执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#postLoadCategory
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#selectCategory
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:取消选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#unselectCategory
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:展开分类后执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#expand
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:折叠分类后执行。this.target指向分类,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#collapse
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载选择项前执行。this.target指向选择项,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#queryLoadItem
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:加载选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#postLoadItem
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#selectItem
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:取消选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#unselectItem
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 人员选择框事件:在人员选择框点取消时执行。this.target指向人员选择框。
- * @event MWF.xApplication.process.Xform.Org#close
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- "selectorEvents" : ["queryLoadSelector","postLoadSelector","queryLoadContent","postLoadContent","queryLoadCategory","postLoadCategory",
- "selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change","expand","collapse","cancel"],
- "readonly": true
- },
- iconStyle: "orgIcon",
- isReadonly : function(){
- var readonly = !!(this.readonly || this.form.json.isReadonly);
- if( readonly )return readonly;
- if( this.json.isReadonly === "script" ){
- if( this.json.readonlyScript && this.json.readonlyScript.code ){
- readonly = this.form.Macro.exec(this.json.readonlyScript.code, this);
- }
- }else{
- readonly = !!this.json.isReadonly
- }
- return readonly || !!this.isSectionMergeRead();
- },
- getTextData: function(){
- //var value = this.node.get("value");
- //var text = this.node.get("text");
- var value = this.getValue();
- //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
- var text = [];
- if( typeOf( value ) === "object" )value = [value];
- if( typeOf( value ) === "array" ){
- value.each(function(v){
- if( typeOf(v) === "string" ){
- text.push(v);
- }else{
- text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
- }
- }.bind(this));
- return {"value": value || "", "text": [text.join(",")]};
- }else{
- return {"value": [""], "text": [""]};
- }
- },
- loadDescription: function(){
- if (this.isReadonly())return;
- if(this.descriptionNode)return;
- var v = this._getBusinessData();
- if (!v || !v.length){
- if (this.json.description){
- var size, w;
- if( this.node.offsetParent === null ){ //隐藏
- size = { y: 26 }
- }else{
- size = this.node.getFirst().getSize();
- w = size.x-3;
- if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
- if (COMMON.Browser.safari) w = w - 20;
- }
- }
- this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
- this.descriptionNode.setStyles({
- "height": ""+size.y+"px",
- "line-height": ""+size.y+"px"
- });
- if( w )this.descriptionNode.setStyles({
- "width": ""+w+"px"
- });
- this.setDescriptionEvent();
- }
- }
- },
- setDescriptionEvent: function(){
- if (this.descriptionNode){
- this.descriptionNode.addEvents({
- "mousedown": function( ev ){
- this.descriptionNode.setStyle("display", "none");
- if( this.json.isInput ){
- if( this.combox ){
- if (!this.combox.editItem) this.combox.intoEdit(ev);
- window.setTimeout( function () {
- this.combox.input.node.focus();
- }.bind(this), 300)
- }
- }else{
- this.clickSelect( ev );
- }
- }.bind(this)
- });
- }
- },
- _loadNode: function(){
- this.field = true;
- if (this.isReadonly()){
- this._loadNodeRead();
- }else{
- this._getOrgOptions();
- if (this.json.isInput){
- this._loadNodeInputEdit();
- }else{
- this._loadNodeEdit();
- }
- }
- },
- _loadMergeReadContentNode: function(contentNode, data){
- this.loadOrgWidget(data.data, contentNode);
- },
- _loadMergeEditNodeByDefault: function(){
- var data = this.getSortedSectionData();
- var businessData = [];
- data.each(function(d){
- businessData = businessData.concat( d.data || [] );
- });
- this._setBusinessData( businessData );
- this._loadNode();
- },
- _getOrgOptions: function(){
- this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
- if( this.selectTypeList.contains( "identity" ) ) {
- this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
- }
- if( this.selectTypeList.contains( "unit" ) ) {
- this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
- }
- if( this.selectTypeList.contains( "group" ) ){
- this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
- }
- //this.selectUnits = this.getSelectRange();
- //if (this.json.selectType=="identity"){
- // this.selectDutys = this.getSelectRangeDuty();
- //}
- },
- _valueMerge: function(values, v){
- if (o2.typeOf(v)=="function"){
- return v.then(function(re){
- this._valueMerge(values, re)
- }.bind(this), function(){});
- }else{
- return values.concat(v);
- }
- },
- _computeValue: function(){
- var simple = this.json.storeRange === "simple";
- var values = [];
- if (this.json.identityValue) {
- this.json.identityValue.each(function(v){
- if (v) values.push(MWF.org.parseOrgData(v, true, simple))
- });
- }
- if (this.json.unitValue) {
- this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
- }
- if (this.json.dutyValue) {
- var dutys = JSON.decode(this.json.dutyValue);
- var par;
- if (dutys.length){
- dutys.each(function(duty){
- if (duty.code) par = this.form.Macro.exec(duty.code, this);
- if (par){
- var pars = (o2.typeOf(par)=="array") ? par : [par];
- var promise = Promise.all(pars).then(function(p){
- var uName = p.distinguishedName || p;
- if (o2.typeOf(p)=="array") uName = p[0].distinguishedName || p[0];
- var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
- var r = (!!uName) ? this.form.Macro.exec(code, this) : "";
- var m = (o2.typeOf(r)=="array") ? "all" : "resolve";
- return Promise[m](r).then(function(d){
- if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
- var arr = [];
- d.each(function(dd){
- if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
- });
- return arr;
- }.bind(this)).catch(function(){
- console.log("catch error : can not get duty : " + duty.name, + "-" + uName);
- });
- }.bind(this), function(){});
- values.push(promise);
- }
- }.bind(this));
- }
- }
- if (this.json.defaultValue && this.json.defaultValue.code){
- var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
- if (o2.typeOf(fd)=="array"){
- fd.each(function(v){values.push(v);});
- }else{
- values.push(fd);
- }
- // if (fd && fd.isAG){
- // values.push(fd);
- // }else{
- // if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
- // fd.each(function(fdd){
- // if (fdd){
- // if (typeOf(fdd)==="string"){
- // var data;
- // this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
- // values.push(data);
- // }else{
- // values.push(fdd);
- // }
- // }
- // }.bind(this));
- // }
- }
- // if (this.json.count>0){
- // return values.slice(0, this.json.count);
- // }
- return values;
- //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
- },
- __computeValue: function(){
- var simple = this.json.storeRange === "simple";
- var values = [];
- if (this.json.identityValue) {
- this.json.identityValue.each(function(v){
- if (v) values.push(MWF.org.parseOrgData(v, true, simple))
- });
- }
- if (this.json.unitValue) {
- this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
- }
- if (this.json.dutyValue) {
- var dutys = JSON.decode(this.json.dutyValue);
- var par;
- if (dutys.length){
- dutys.each(function(duty){
- if (duty.code) par = this.form.Macro.exec(duty.code, this);
- if (par && par.isAG){
- var ag = o2.AG.all(par).then(function(p){
- var uName = "";
- if (p && p.length) uName = p[0].distinguishedName || p[0];
- var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
- var r = this.form.Macro.exec(code, this);
- o2.AG.all(r).then(function(d) {
- //var d = rd[0];
- if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
- var arr = [];
- d.each(function(dd){
- if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
- });
- return arr;
- }.bind(this));
- }.bind(this));
- values.push(ag);
- }else{
- var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\", true)";
- var r = this.form.Macro.exec(code, this);
- var ag = o2.AG.all(r).then(function(d) {
- //var d = rd[0];
- if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
- var arr = [];
- d.each(function(dd){
- if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
- });
- return arr;
- }.bind(this));
- values.push(ag);
- // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
- // d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
- }
- }.bind(this));
- }
- }
- if (this.json.defaultValue && this.json.defaultValue.code){
- var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
- if (fd && fd.isAG){
- // value.addResolve(function(v){
- // this._setBusinessData(v);
- // if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
- // if (this.readonly || this.json.isReadonly) this.node.set("text", v);
- // }.bind(this));
- values.push(fd);
- // fd.then(function(v){
- // return this._valueMerge(values, v);
- // }.bind(this));
- // return fd;
- }else{
- if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
- fd.each(function(fdd){
- if (fdd){
- if (typeOf(fdd)==="string"){
- var data;
- this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
- values.push(data);
- }else{
- values.push(fdd);
- }
- }
- }.bind(this));
- }
- }
- if (this.json.count>0){
- return values.slice(0, this.json.count);
- }
- return values;
- //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
- },
- getOrgAction: function(){
- if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
- return this.orgAction;
- },
- getOptions: function(){
- var _self = this;
- if( this.selectTypeList.length === 0 )return false;
- var values = this.getInputData() || [];
- var exclude = [];
- if( this.json.exclude ){
- var v = this.form.Macro.exec(this.json.exclude.code, this);
- exclude = typeOf(v)==="array" ? v : [v];
- }
- //var count = (this.json.count) ? this.json.count : 0;
- var identityOpt;
- if( this.identityOptions ){
- identityOpt = this.identityOptions.getOptions();
- if (this.json.identityRange!=="all"){
- if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
- this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
- identityOpt.disabled = true;
- // return false;
- }
- }
- if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
- if (!identityOpt.dutys || !identityOpt.dutys.length){
- this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
- identityOpt.disabled = true;
- // return false;
- }
- }
- identityOpt.values = (this.json.isInput) ? [] : values;
- identityOpt.exclude = exclude;
- if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
- }
- var unitOpt;
- if( this.unitOptions ){
- unitOpt = this.unitOptions.getOptions();
- if (this.json.unitRange!=="all"){
- if ( !unitOpt.units || !unitOpt.units.length){
- this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
- unitOpt.disabled = true;
- // return false;
- }
- }
- unitOpt.values = (this.json.isInput) ? [] : values;
- unitOpt.exclude = exclude;
- if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
- }
- var groupOpt;
- if( this.groupOptions ){
- groupOpt = this.groupOptions.getOptions();
- groupOpt.values = (this.json.isInput) ? [] : values;
- groupOpt.exclude = exclude;
- if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
- }
- //var selectUnits = this.getSelectRange();
- //if (this.json.selectType=="identity"){
- // var selectDutys = this.getSelectRangeDuty();
- //}
- //if (this.json.range!=="all"){
- // if (!selectUnits.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
- // return false;
- // }
- //}
- //if (this.json.selectType=="identity"){
- // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
- // if (!selectDutys || !selectDutys.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
- // return false;
- // }
- // }
- //}
- var defaultOpt = {};
- if( this.json.events && typeOf(this.json.events) === "object" ){
- Object.each(this.json.events, function(e, key){
- if (e.code){
- if (this.options.selectorEvents.indexOf(key)!==-1){
- if( key === "postLoadSelector" ) {
- this.addEvent("loadSelector", function (selector) {
- return this.form.Macro.fire(e.code, selector);
- }.bind(this))
- }else if( key === "queryLoadSelector"){
- defaultOpt["onQueryLoad"] = function(target){
- return this.form.Macro.fire(e.code, target);
- }.bind(this)
- }else{
- defaultOpt["on"+key.capitalize()] = function(target){
- return this.form.Macro.fire(e.code, target);
- }.bind(this)
- }
- }
- }
- }.bind(this));
- }
- if( this.selectTypeList.length === 1 ){
- return Object.merge( {
- "type": this.selectTypeList[0],
- "onComplete": function(items){
- this.selectOnComplete(items);
- }.bind(this),
- "onCancel": this.selectOnCancel.bind(this),
- // "onLoad": this.selectOnLoad.bind(this),
- "onLoad": function(){
- //this 为 selector
- _self.selectOnLoad(this, this.selector );
- },
- "onClose": this.selectOnClose.bind(this)
- }, defaultOpt, identityOpt || unitOpt || groupOpt )
- }else if( this.selectTypeList.length > 1 ){
- var options = {
- "type" : "",
- "types" : this.selectTypeList,
- "onComplete": function(items){
- this.selectOnComplete(items);
- }.bind(this),
- "onCancel": this.selectOnCancel.bind(this),
- // "onLoad": this.selectOnLoad.bind(this),
- "onLoad": function(){
- //this 为 selector
- _self.selectOnLoad(this)
- },
- "onClose": this.selectOnClose.bind(this)
- };
- if( this.form.json.selectorStyle ){
- options = Object.merge( options, this.form.json.selectorStyle );
- }
- if( identityOpt )options.identityOptions = Object.merge( {}, defaultOpt, identityOpt );
- if( unitOpt )options.unitOptions = Object.merge( {}, defaultOpt, unitOpt );
- if( groupOpt )options.groupOptions = Object.merge( {}, defaultOpt, groupOpt );
- return options;
- }
- //return {
- // "type": this.json.selectType,
- // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- // "values": (this.json.isInput) ? [] : values,
- // "count": count,
- // "units": selectUnits,
- // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
- // "exclude" : exclude,
- // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
- // "categoryType": this.json.categoryType || "unit",
- // "onComplete": function(items){
- // this.selectOnComplete(items);
- // }.bind(this),
- // "onCancel": this.selectOnCancel.bind(this),
- // "onLoad": this.selectOnLoad.bind(this),
- // "onClose": this.selectOnClose.bind(this)
- //};
- },
- selectOnComplete: function(items){
- var array = [];
- items.each(function(item){
- array.push(item.data);
- }.bind(this));
- var simple = this.json.storeRange === "simple";
- this.checkEmpower( array, function( data ){
- var values = [];
- data.each(function(d){
- values.push(MWF.org.parseOrgData(d, true, simple));
- }.bind(this));
- if (this.json.isInput){
- this.addData(values);
- }else{
- this.setData(values, true);
- }
- //this._setBusinessData(values);
- this.validationMode();
- this.validation();
- var p = this.getValue();
- if (p.then){
- p.then(function(){
- this.fireEvent("select");
- }.bind(this), function(){});
- }else{
- this.fireEvent("select");
- }
- }.bind(this))
- },
- selectOnCancel: function(){
- this.validation();
- },
- selectOnLoad: function( selector ){
- if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
- this.fireEvent("loadSelector", [selector])
- },
- selectOnClose: function(){
- var v = this._getBusinessData();
- if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
- },
- checkDescription: function(){
- if (!this.json.description)return;
- var v = this._getBusinessData();
- if (!v || !v.length){
- if( this.descriptionNode ){
- if( this.node.getFirst() ){
- var size = this.node.getFirst().getSize();
- var w = size.x-3;
- if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
- if (COMMON.Browser.safari) w = w - 20;
- }
- this.descriptionNode.setStyles({
- "display": "block",
- "width": ""+w+"px",
- "height": ""+( size.y || 26)+"px",
- "line-height": ""+( size.y || 26)+"px"
- });
- }else{
- this.descriptionNode.setStyle("display", "block");
- }
- }else{
- this.loadDescription();
- }
- }else{
- if(this.descriptionNode)this.descriptionNode.setStyle("display", "none");
- }
- },
- /**
- * @summary 弹出选择界面.
- * @example
- * this.form.get('org').clickSelect();
- */
- clickSelect: function( ev ){
- if (this.isReadonly())return;
- if( layout.mobile ){
- setTimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
- var options = this.getOptions();
- if(options){
- if( this.selector && this.selector.loading ) {
- }else if( this.selector && this.selector.selector && this.selector.selector.active ){
- }else{
- /**
- * @summary 人员选择框package的对象
- * @member {o2.O2Selector}
- * @example
- * //可以在脚本中获取该组件
- * var selector = this.form.get("fieldId").selector.selector; //获取人员选择框对象
- * var options = selector.options; //获取人员选择框的选项
- */
- this.selector = new MWF.O2Selector(this.form.app.content, options);
- }
- }
- }.bind(this), 100 )
- }else{
- var options = this.getOptions();
- if(options){
- if( this.selector && this.selector.loading ) {
- }else if( this.selector && this.selector.selector && this.selector.selector.active ){
- }else {
- this.selector = new MWF.O2Selector(this.form.app.content, options);
- }
- }
- }
- },
- resetData: function(){
- var v = this.getValue();
- //this.setData((v) ? v.join(", ") : "");
- this.setData(v);
- },
- isEmpty: function(){
- var data = this.getData();
- if( typeOf(data) !== "array" )return true;
- if( data.length === 0 )return true;
- return false;
- },
- getInputData: function(){
- if (this.json.isInput){
- if (this.combox)return this.combox.getData();
- //return this._getBusinessData();
- return this.node.retrieve("data");
- }else{
- //return this._getBusinessData();
- return this.node.retrieve("data");
- }
- },
- _loadNodeRead: function(){
- this.node.empty();
- var node = new Element("div").inject(this.node);
- this.node.set({
- "nodeId": this.json.id,
- "MWFType": this.json.type
- });
- },
- _searchConfirmPerson: function(item){
- var inforNode = item.inforNode || new Element("div");
- var simple = this.json.storeRange === "simple";
- if (item.data){
- var data = item.data;
- if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
- var dn = data.distinguishedName || data;
- if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
- MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
- identityList : [dn]
- }, function(json){
- if( json.data.length > 0 ){
- if( data["person"] )json.data[0].id = data["person"];
- item.data = MWF.org.parseOrgData( json.data[0], true, simple );
- item.value = this.getDataText( item.data );
- if(item.node)item.node.set("text", item.value);
- }
- }.bind(this), null, false)
- }
- }
- if( item.data && ( item.data.createTime || item.data.updateTime ) ){
- item.data = MWF.org.parseOrgData( item.data, true, simple );
- }
- var text = "";
- var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- text = item.data.name+"("+item.data.unitName+")";
- break;
- case "@p":
- text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
- break;
- case "@u":
- text = item.data.levelName;
- break;
- case "@g":
- text = item.data.name;
- break;
- default:
- text = item.data.name;
- }
- inforNode.set({
- "styles": {"font-size": "14px", "color": ""},
- "text": text
- });
- }else{
- inforNode.set({
- "styles": {"font-size": "14px", "color": "#bd0000"},
- "text": MWF.xApplication.process.Xform.LP.noOrgObject
- });
- }
- if (!item.inforNode){
- new mBox.Tooltip({
- content: inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: item.node,
- transition: 'flyin'
- });
- item.inforNode = inforNode;
- }
- },
- getSearchOptions: function(){
- if( this.selectTypeList.length === 0 )return false;
- var identityOpt;
- if( this.identityOptions ){
- identityOpt = this.identityOptions.getSearchOptions();
- //if (this.json.identityRange!=="all"){
- // if ( !identityOpt.units || !identityOpt.units.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
- // return false;
- // }
- //}
- //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
- // if (!identityOpt.dutys || !identityOpt.dutys.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
- // return false;
- // }
- //}
- }
- var unitOpt;
- if( this.unitOptions ){
- unitOpt = this.unitOptions.getSearchOptions();
- //if (this.json.unitRange!=="all"){
- // if ( !unitOpt.units || !unitOpt.units.length){
- // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
- // return false;
- // }
- //}
- }
- var groupOpt;
- if( this.groupOptions ){
- groupOpt = this.groupOptions.getOptions();
- }
- if( this.selectTypeList.length === 1 ){
- return Object.merge( {
- "type": this.selectTypeList[0]
- }, identityOpt || unitOpt || groupOpt )
- }else if( this.selectTypeList.length > 1 ){
- var options = {
- "type" : "",
- "types" : this.selectTypeList
- };
- if( identityOpt )options.identityOptions = identityOpt;
- if( unitOpt )options.unitOptions = unitOpt;
- if( groupOpt )options.groupOptions = groupOpt;
- return options;
- }
- //return {
- // "type": this.json.selectType,
- // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- // "values": (this.json.isInput) ? [] : values,
- // "count": count,
- // "units": selectUnits,
- // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
- // "exclude" : exclude,
- // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
- // "categoryType": this.json.categoryType || "unit",
- // "onComplete": function(items){
- // this.selectOnComplete(items);
- // }.bind(this),
- // "onCancel": this.selectOnCancel.bind(this),
- // "onLoad": this.selectOnLoad.bind(this),
- // "onClose": this.selectOnClose.bind(this)
- //};
- },
- _searchOptions: function(value, callback){
- //var options = {
- // "type": this.json.selectType,
- // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- // "units": this.selectUnits,
- // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
- //};
- var options = this.getSearchOptions();
- if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
- this.comboxFilter.filter(value, function(data){
- data.map(function(d){
- var value = Object.clone(d);
- d.value = value;
- var flag = d.distinguishedName.substr(d.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- d.text = d.name+"("+d.unitName+")";
- break;
- case "@p":
- d.text = d.name+(d.employee ? "("+d.employee+")" : "");
- break;
- case "@u":
- d.text = d.name;
- break;
- case "@g":
- d.text = d.name;
- break;
- default:
- d.text = d.name;
- }
- });
- if (callback) callback(data);
- });
- },
- _resetNodeInputEdit: function(){
- var node = new Element("div", {
- "styles": {
- "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
- //"position": "relative",
- "margin-right": this.hasIcon() ? "20px" : "0px"
- }
- }).inject(this.node, "after");
- this.node.destroy();
- this.node = node;
- },
- _loadNodeInputEdit: function(){
- this.node.setStyle("overflow","visible");
- var input=null;
- MWF.require("MWF.widget.Combox", function(){
- this.combox = input = new MWF.widget.Combox({
- "count": this.json.count || 0,
- "splitShow": this.json.splitShow || ", ",
- "onCommitInput": function(item){
- this._searchConfirmPerson(item);
- //this.fireEvent("change");
- }.bind(this),
- "onChange": function(){
- this.node.store("data", this.getInputData());
- this._setBusinessData(this.getInputData());
- this.fireEvent("change");
- }.bind(this),
- "optionsMethod": this._searchOptions.bind(this)
- });
- }.bind(this), false);
- input.setStyles({
- "background": "transparent",
- "border": "0px"
- });
- input.set(this.json.properties);
- if (!this.json.preprocessing) this._resetNodeInputEdit();
- this.node.empty();
- input.inject(this.node);
- this.node.set({
- "id": this.json.id,
- "MWFType": this.json.type
- });
- if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
- this.iconNode = new Element("div", {
- "styles": this.form.css[this.iconStyle],
- "events": {
- "click": function (ev) {
- this.clickSelect(ev);
- }.bind(this)
- //this.clickSelect.bind(this)
- }
- }).inject(this.node, "before");
- }else if( this.form.json.nodeStyleWithhideModuleIcon ){
- this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
- }
- this.combox.addEvent("change", function(){
- this.validationMode();
- if (this.validation()){
- this.node.store("data", this.getInputData());
- this._setBusinessData(this.getInputData("change"));
- }
- }.bind(this));
- },
- _resetNodeEdit: function(){
- var input = new Element("div", {
- "styles": {
- "background": "transparent",
- "border": "0px",
- "min-height": "24px"
- }
- });
- var node = new Element("div", {"styles": {
- "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
- "position": "relative",
- "margin-right": this.hasIcon() ? "20px" : "0px",
- "min-height": "24px"
- }}).inject(this.node, "after");
- input.inject(node);
- this.node.destroy();
- this.node = node;
- },
- _loadNodeEdit: function(){
- if (!this.json.preprocessing) this._resetNodeEdit();
- var input = this.node.getFirst();
- if( !input && this.nodeHtml ){
- this.node.set("html", this.nodeHtml);
- input = this.node.getFirst();
- }
- input.set(this.json.properties);
- this.node.set({
- "id": this.json.id,
- "MWFType": this.json.type,
- "events": {
- "click": function (ev) {
- this.clickSelect(ev);
- }.bind(this)
- //this.clickSelect.bind(this)
- }
- });
- if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
- this.iconNode = new Element("div", {
- "styles": this.form.css[this.iconStyle],
- "events": {
- "click": function (ev) {
- this.clickSelect(ev);
- }.bind(this)
- //this.clickSelect.bind(this)
- }
- }).inject(this.node, "before");
- }else if( this.form.json.nodeStyleWithhideModuleIcon ){
- this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
- }
- this.node.getFirst().setStyle("height", "auto");
- this.node.getFirst().addEvent("change", function(){
- this.validationMode();
- if (this.validation()){
- this.node.store("data", this.getInputData());
- this._setBusinessData(this.getInputData("change"));
- }
- }.bind(this));
- },
- getDataText: function(data){
- if (typeOf(data)=="string") return data;
- if( !data || !data.distinguishedName )return "";
- var text = "";
- var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- text = data.name+"("+data.unitName+")";
- break;
- case "@p":
- text = data.name+ (data.employee ? ("("+data.employee+")") : "");
- break;
- case "@u":
- text = data.name;
- break;
- case "@g":
- text = data.name;
- break;
- default:
- text = data.name;
- }
- return text;
- },
- addData: function(value){
- if (!value) return false;
- var simple = this.json.storeRange === "simple";
- value.each(function(v){
- var vtype = typeOf(v);
- if (vtype==="string"){
- var data;
- this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, v, false);
- if (data) this.combox.addNewValue(this.getDataText(data), data);
- }
- if (vtype==="object"){
- var d = MWF.org.parseOrgData(v, true, simple);
- this.combox.addNewValue(this.getDataText(d), d);
- }
- }.bind(this));
- },
- checkChange: function(oldValues, values){
- var change = false;
- if (!values) values = [];
- if (oldValues.length && (values && values.length)){
- if (oldValues.length === values.length){
- for (var i=0; i<oldValues.length; i++){
- if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
- change = true;
- break;
- }
- }
- }else{
- change = true;
- }
- }else if (values.length || oldValues.length) {
- change = true;
- }
- if (change) this.fireEvent("change");
- },
- setData: function(value, fireChange){
- if (!value) return false;
- var oldValues = this.getData();
- if (value.length==1 && !(value[0])) value=[];
- var promise = this._setValue(value);
- if (fireChange) Promise.resolve(promise).then(function(values){
- o2.promiseAll(values).then(function(v){
- this.checkChange(oldValues, v)
- }.bind(this), function(){});
- }.bind(this), function(){});
- },
- // __setData: function(value){
- // if (!value) return false;
- // var oldValues = this.getData();
- // var values = [];
- // var comboxValues = [];
- //
- // var simple = this.json.storeRange === "simple";
- //
- // var type = typeOf(value);
- // if (type==="array"){
- // value.each(function(v){
- // var vtype = typeOf(v);
- // var data = null;
- // if (vtype==="string"){
- // var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
- // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
- // }
- // if (vtype==="object") {
- // data = MWF.org.parseOrgData(v, true, simple);
- // if(data.woPerson)delete data.woPerson;
- // }
- // if (data){
- // values.push(data);
- // comboxValues.push({"text": this.getDataText(data),"value": data});
- // }
- // }.bind(this));
- // }
- // if (type==="string"){
- // var vData;
- // var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
- // this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
- // if (vData){
- // values.push(vData);
- // comboxValues.push({"text": this.getDataText(vData),"value": vData});
- // }
- // }
- // if (type==="object"){
- // var vData = MWF.org.parseOrgData(value, true, simple);
- // if(vData.woPerson)delete vData.woPerson;
- // values.push( vData );
- // comboxValues.push({"text": this.getDataText(value),"value": vData});
- // }
- //
- // var change = false;
- // if (oldValues.length && values.length){
- // if (oldValues.length === values.length){
- // for (var i=0; i<oldValues.length; i++){
- // if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
- // change = true;
- // break;
- // }
- // }
- // }else{
- // change = true;
- // }
- // }else if (values.length || oldValues.length) {
- // change = true;
- // }
- // this._setBusinessData(values);
- // if (change) this.fireEvent("change");
- //
- // if (this.json.isInput){
- // if (this.combox){
- // this.combox.clear();
- // this.combox.addNewValues(comboxValues);
- // }else{
- // var node = this.node.getFirst();
- // if (node){
- // node.empty();
- // comboxValues.each(function(v, i){
- // this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
- // }.bind(this));
- // }
- // }
- // }else{
- // if (this.node.getFirst()){
- // var node = this.node.getFirst();
- // node.empty();
- // this.loadOrgWidget(values, node)
- // }else{
- // this.node.empty();
- // this.loadOrgWidget(values, this.node);
- // }
- // }
- // },
- creteShowNode: function(data, islast){
- var nodeText = (data.text) ? data.text : data;
- if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
- var node = new Element("div", {
- "styles": {
- "float": "left",
- "margin-right": "5px"
- },
- "text": nodeText
- });
- var text = "";
- if (data.value && data.value.distinguishedName){
- var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- text = data.value.name+"("+data.value.unitName+")";
- break;
- case "@p":
- text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
- break;
- case "@u":
- text = data.value.levelName;
- break;
- case "@g":
- text = data.value.name;
- break;
- default:
- text = data.value.name;
- }
- var inforNode = new Element("div").set({
- "styles": {"font-size": "14px", "color": ""},
- "text": text
- });
- new mBox.Tooltip({
- content: inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: node,
- transition: 'flyin'
- });
- }
- return node;
- },
- _setValue: function(value){
- var values = [];
- var ags = [];
- var simple = this.json.storeRange === "simple";
- var flag = false;
- if (typeOf(value)!=="array") value = (!!value) ? [value] : [];
- //value = (value.flat) ? value.flat() : value.flatten();
- if (value.some(function(e){ return (e && o2.typeOf(e.then)=="function") }) || this.json.asyncMode==="yes"){
- var p = Promise.all(value).then(function(d){
- if (typeOf(d)!=="array") d = (!!d) ? [d] : [];
- d.each(function(da){
- if (typeOf(da)!=="array") da = (!!da) ? [da] : [];
- da.each(function(dd){
- if (dd){
- if (typeOf(dd)==="string"){
- var pp = this.getOrgAction()[this.getValueMethod(dd)](function(json){
- return MWF.org.parseOrgData(json.data, true, simple);
- }.bind(this), null, dd, true).catch(function(e){
- console.log("error:" + e);
- console.log(e);
- });
- ags.push(pp);
- }else{
- values.push(dd);
- }
- }
- }.bind(this));
- }.bind(this));
- if (ags.length){
- return Promise.all(ags).then(function(data){
- values = values.concat(data);
- flag = true;
- this.__setValue(values);
- return values;
- }.bind(this), function(){});
- }else{
- flag = true;
- this.__setValue(values);
- return values
- }
- }.bind(this), function(){});
- this.moduleValueAG = p;
- if (p && p.then) p.then(function(){
- this.moduleValueAG = null;
- }.bind(this), function(){
- this.moduleValueAG = null;
- }.bind(this));
- return p;
- }else{
- value.each(function(dd){
- if (dd){
- if (typeOf(dd)==="string"){
- this.getOrgAction()[this.getValueMethod(dd)](function(json){
- values.push(MWF.org.parseOrgData(json.data, true, simple));
- }.bind(this), null, dd, false);
- }else{
- values.push(dd);
- }
- }
- }.bind(this));
- this.__setValue(values);
- return values
- }
- // var ag = o2.AG.all(value).then(function(d) {
- // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
- //
- // d.each(function(dd){
- // //if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
- // if (dd){
- // if (typeOf(dd)==="string"){
- // ags.push(this.getOrgAction()[this.getValueMethod(dd)](function(json){
- // return MWF.org.parseOrgData(json.data, true, simple);
- // }.bind(this).ag(), null, dd, true));
- // }else{
- // values.push(dd);
- // }
- // }
- // }.bind(this));
- // if (ags.length){
- // return o2.AG.all(ags).then(function(data){
- // values = values.concat(data);
- // flag = true;
- // this.__setValue(values);
- // return values;
- // }.bind(this));
- // }else{
- // flag = true;
- // this.__setValue(values);
- // return values
- // }
- // }.bind(this));
- //
- // this.moduleValueAG = ag;
- // if (ag) ag.then(function(){
- // this.moduleValueAG = null;
- // }.bind(this));
- // return ag;
- },
- __setValue: function(value){
- this.moduleValueAG = null;
- if (value.length==1 && !(value[0])) value=[];
- if (this.json.count>0){
- value = value.slice(0, this.json.count);
- }
- var values = [];
- var comboxValues = [];
- var type = typeOf(value);
- var simple = this.json.storeRange === "simple";
- if (type==="array"){
- value.each(function(v){
- var data=null;
- var vtype = typeOf(v);
- if (vtype==="string"){
- var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
- this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
- }
- if (vtype==="object") data = v;
- if (data){
- var d = MWF.org.parseOrgData(data, true, simple)
- values.push(d);
- comboxValues.push({"text": this.getDataText(d),"value": d});
- }
- }.bind(this));
- }
- if (type==="string"){
- var vData;
- var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
- this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true,simple); }.bind(this), error, value, false);
- if (vData){
- values.push(vData);
- comboxValues.push({"text": this.getDataText(vData),"value": vData});
- }
- }
- if (type==="object"){
- var v = MWF.org.parseOrgData(value, true, simple)
- values.push(v);
- comboxValues.push({"text": this.getDataText(v),"value": v});
- }
- this.node.store("data", values);
- this._setBusinessData(values);
- if (this.json.isInput){
- if (this.combox){
- this.combox.clear();
- this.combox.addNewValues(comboxValues);
- // values.each(function(v){
- // if (typeOf(v)=="string"){
- // this.combox.addNewValue(v);
- // }else{
- // this.combox.addNewValue(this.getDataText(v), v);
- // }
- // }.bind(this));
- }else{
- var node = this.node.getFirst();
- if (node){
- node.empty();
- comboxValues.each(function(v, i){
- this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
- }.bind(this));
- }
- }
- }else{
- if (this.node.getFirst()){
- var node = this.node.getFirst();
- node.empty();
- this.loadOrgWidget(values, node)
- }else{
- this.node.empty();
- this.loadOrgWidget(values, this.node);
- }
- }
- this.checkDescription();
- this.fieldModuleLoaded = true;
- //if (this.readonly) this.loadOrgWidget(values, this.node)
- //this.node.set("text", value);
- },
- getValueMethod: function(value){
- if (value){
- var flag = value.substr(value.length-2, 2);
- switch (flag.toLowerCase()){
- case "@i":
- return "getIdentity";
- case "@p":
- return "getPerson";
- case "@u":
- return "getUnit";
- case "@g":
- return "getGroup";
- default:
- return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
- }
- }
- return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
- },
- loadOrgWidget: function(value, node){
- var _self = this;
- var disableInfor = layout.mobile ? true : false;
- if( this.json.showCard === "no" )disableInfor = true;
- var canRemove = this.json.canRemove ? true : false;
- var height = node.getStyle("height").toInt();
- if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
- if (value && value.length){
- value.each(function(data){
- if( !data || !data.distinguishedName )return;
- var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
- var copyData = Object.clone(data);
- if( this.json.displayTextScript && this.json.displayTextScript.code ){
- this.currentData = copyData;
- var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
- if( displayName ){
- copyData.displayName = displayName;
- }
- this.currentData = null;
- }
- var opt = {"style": "xform","lazy":true,"disableInfor" : disableInfor, "canRemove":canRemove, "onRemove": function () {
- _self.fireEvent("removeItem", [{
- data: data,
- item: this
- }])
- }, "styles": this.json.itemStyles || "" };
- var widget;
- switch (flag.toLowerCase()){
- case "@i":
- widget = new MWF.widget.O2Identity(copyData, node, opt);
- break;
- case "@p":
- widget = new MWF.widget.O2Person(copyData, node, opt);
- break;
- case "@u":
- widget = new MWF.widget.O2Unit(copyData, node, opt);
- break;
- case "@g":
- widget = new MWF.widget.O2Group(copyData, node, opt);
- break;
- default:
- widget = new MWF.widget.O2Other(copyData, node, opt);
- }
- widget.field = this;
- if( layout.mobile ){
- widget.node.setStyles({
- "float" : "none"
- })
- }
- }.bind(this));
- }
- },
- _loadStyles: function(){
- if (this.isReadonly()){
- if (this.json.styles) this.node.setStyles(this.json.styles);
- }else{
- if (this.json.styles) this.node.setStyles(this.json.styles);
- if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
- if (this.iconNode && this.iconNode.offsetParent !== null ){
- var size = this.node.getSize();
- this.iconNode.setStyle("height", ""+size.y+"px");
- }
- }
- },
- checkEmpower : function( data, callback ){
- if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
- var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
- empowerChecker.load(data, callback);
- }else{
- if( callback )callback( data );
- }
- },
- _beforeReloaded: function(){
- this.selector = null;
- if (this.combox) {
- this.combox.clear();
- this.combox = null;
- }
- },
- getExcelData: function(){
- var text, value = this.getData();
- if (o2.typeOf(value) === "array") {
- var textArray = [];
- value.each(function (item) {
- if (o2.typeOf(item) === "object") {
- textArray.push(item.distinguishedName);
- } else {
- textArray.push(item);
- }
- }.bind(this));
- text = textArray.join(", \n");
- } else if (o2.typeOf(value) === "object") {
- text = value.distinguishedName;
- } else {
- text = value;
- }
- return text;
- },
- setExcelData: function(data){
- this.excelData = data;
- this.setData(data, true);
- }
- });
- MWF.APPOrg.EmpowerChecker = new Class({
- Implements: [Events],
- initialize: function (form, json) {
- this.form = form;
- this.json = json;
- this.css = this.form.css;
- this.checkedAllItems = true;
- },
- load : function( data, callback, container ){
- if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
- var array = [];
- data.each( function( d ){
- if( d.distinguishedName ){
- var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
- if( flag === "i" ){
- array.push( d.distinguishedName )
- }
- }
- }.bind(this));
- if( array.length > 0 ){
- o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
- "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
- "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
- "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
- "identityList" : array
- }, function( json ){
- var arr = [];
- json.data.each( function(d){
- if(d.fromIdentity !== d.toIdentity )arr.push(d);
- });
- if( arr.length > 0 ){
- this.openSelectEmpowerDlg( arr, data, callback, container );
- }else{
- if( callback )callback( data );
- }
- }.bind(this), function(){
- if( callback )callback( data );
- }.bind(this))
- }else{
- if( callback )callback( data );
- }
- }else{
- if( callback )callback( data );
- }
- },
- getIgnoreEmpowerArray : function( callback ){
- var array = [];
- if( this.empowerSelectNodes && this.empowerSelectNodes.length ){
- this.empowerSelectNodes.each(function(node){
- if( !node.retrieve("isSelected") ){
- var d = node.retrieve("data");
- array.push( d.fromIdentity );
- }
- }.bind(this));
- }
- if( callback )callback( array );
- return array;
- },
- setIgnoreEmpowerFlag : function(data, callback){
- var ignoreList = this.getIgnoreEmpowerArray();
- for( var i=0; i<data.length; i++ ){
- var d = data[i];
- if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
- d.ignoreEmpower = true;
- }else if( d.ignoreEmpower ){
- delete d.ignoreEmpower;
- }
- }
- if( callback )callback( data );
- },
- replaceEmpowerIdentity : function(data, callback){
- var empowerData = {};
- this.empowerSelectNodes.each(function(node){
- if( node.retrieve("isSelected") ){
- var d = node.retrieve("data");
- empowerData[ d.fromIdentity ] = d;
- }
- }.bind(this));
- if( Object.keys(empowerData).length === 0 ){
- callback( data );
- }else{
- var identityList = [];
- for( var key in empowerData ){
- identityList.push( empowerData[key].toIdentity );
- }
- o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
- var newData = data.clone();
- var d = {};
- json.data.each( function(j){
- d[j.distinguishedName] = j;
- });
- for( var i=0; i<newData.length; i++ ){
- var nd = newData[i];
- if( nd.distinguishedName && empowerData[nd.distinguishedName]){
- if( d[empowerData[nd.distinguishedName].toIdentity] ){
- newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
- }
- }
- }
- callback( newData );
- },function(){
- callback( data );
- });
- }
- },
- openSelectEmpowerDlg : function( data, orginData, callback, container ){
- if( layout.mobile ){
- this.openSelectEmpowerDlg_mobile(data, orginData, callback, container);
- }else{
- this.openSelectEmpowerDlg_pc(data, orginData, callback, container);
- }
- },
- openSelectEmpowerDlg_mobile : function( data, orginData, callback, container ){
- var that = this;
- //处理json
- var subItemList = [];
- // var empowerMap = {};
- // var selectableItems = [];
- var valueList = [];
- data.each( function( d ){
- subItemList.push({
- "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
- "id" : d.fromIdentity + "#" + d.toIdentity
- })
- valueList.push({
- "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
- "id" : d.fromIdentity + "#" + d.toIdentity
- })
- // empowerMap[ d.fromIdentity ] = d.toIdentity;
- }.bind(this));
- if( subItemList.length === 0 ){
- callback();
- return;
- }
- var empowerList = Array.clone(subItemList);
- // selectableItems.push({
- // "empowerMap" : empowerMap,
- // "subItemList" : subItemList
- // });
- // if( selectableItems.length === 0 ){
- // callback();
- // return;
- // }
- // var empowerList = Array.clone(selectableItems);
- o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
- var options = {
- "count": 0,
- "title": MWF.xApplication.process.Xform.LP.selectEmpower,
- "selectAllEnable" : true,
- "selectableItems": subItemList,
- "expand": false,
- "category": false,
- "values": valueList,
- "zIndex" : 3001,
- "closeOnclickOk" : true,
- "onComplete": function (items) {
- var arr = [];
- items.each(function (item) {
- arr.push( item.data.id )
- }.bind(this));
- var ignoreList = [];
- empowerList.each( function (obj) {
- if( arr.indexOf( obj.id ) === -1 )ignoreList.push( obj.id.split("#")[0] )
- });
- for( var i=0; i<orginData.length; i++ ){
- var d = orginData[i];
- if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
- d.ignoreEmpower = true;
- }else if( d.ignoreEmpower ){
- delete d.ignoreEmpower;
- }
- }
- if( callback )callback( orginData );
- // empowerList.each( function(obj){
- // var list = obj.subItemList.filter(function(item, index){
- // return !arr.contains( item.id );
- // }.bind(this));
- // ignoreList = ignoreList.map(function(item,index){
- // return item.id.split("#")[1];
- // })
- // });
- // empowerList.each( function(obj){
- // var org = that.orgItemsObject[obj.orgId];
- // // if( obj.ignoreList.length > 0 ){
- // var data = org.getData();
- // for( var i=0; i<data.length; i++ ){
- // var d = data[i];
- // if( obj.ignoreList.indexOf( d.distinguishedName ) > -1 ){
- // d.ignoreEmpower = true;
- // }else if( d.ignoreEmpower ){
- // delete d.ignoreEmpower;
- // }
- // }
- // org.setData( data );
- // }
- // if( obj.empowerMap ){
- // var data = org.getValue();
- // for( var i=0; i<data.length; i++ ){
- // var d = data[i];
- // if( obj.empowerMap[ d.distinguishedName ] ){
- // d.empowerToIdentity = obj.empowerMap[ d.distinguishedName ];
- // }
- // }
- // org.empowerData = Array.clone(data);
- // }
- // if(callback)callback();
- // })
- }.bind(this)
- };
- if( this.form.json.selectorStyle ){
- Object.merge(options, this.form.json.selectorStyle );
- }
- options.flatCategory = false;
- var selector = new o2.xApplication.Template.Selector.Custom($(document.body), options);
- selector.load();
- }.bind(this))
- },
- openSelectEmpowerDlg_pc : function( data, orginData, callback, container ){
- var node = new Element("div", {"styles": this.css.empowerAreaNode});
- var html = "<div style=\"line-height: 20px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
- html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
- node.set("html", html);
- var itemNode = node.getLast();
- this.getEmpowerItems(itemNode, data);
- node.inject( container || this.form.app.content);
- var dlg = o2.DL.open({
- "title": MWF.xApplication.process.Xform.LP.selectEmpower,
- "style": this.form.json.dialogStyle || "user",
- "isResize": true,
- "content": node,
- "width": 630,
- //"height" : 500,
- "buttonList": [
- {
- "type" : "ok",
- "text": MWF.LP.process.button.ok,
- "action": function(d, e){
- //this.replaceEmpowerIdentity( orginData, callback ); //直接替换已授权的人,已废弃
- this.setIgnoreEmpowerFlag( orginData, callback ); //然后设置忽略的人的标志
- dlg.close();
- }.bind(this)
- },
- {
- "type" : "cancel",
- "text": MWF.LP.process.button.cancel,
- "action": function(){dlg.close();}
- }
- ],
- "onPostShow": function(){
- var selectNode = this.createSelectAllEmpowerNode();
- selectNode.inject( dlg.button );
- if( layout.mobile ){
- dlg.node.inject( $(document.body) );
- dlg.node.setStyles({
- "width":"100%",
- "height": "100%",
- "top" : "0px",
- "left" : "0px"
- });
- var y = dlg.node.getSize().y - 190;
- itemNode.setStyle("height",y+"px");
- dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
- dlg.setContentSize();
- }else{
- dlg.content.setStyle("overflow","hidden");
- var y = Math.min(300, itemNode.getSize().y);
- var marginTop = itemNode.getStyle("margin-top");
- var marginBottom = itemNode.getStyle("margin-bottom");
- itemNode.setStyle("height",y+"px");
- dlg.options.contentHeight = y + 30 + 20 ; //+100;
- dlg.setContentSize();
- dlg.node.setStyles({
- "height": ""+(dlg.options.height) +"px"
- });
- dlg.reCenter();
- }
- }.bind(this)
- });
- },
- getEmpowerItems: function(itemNode, data){
- var _self = this;
- this.empowerSelectNodes = [];
- var count = 1;
- var node;
- data.each(function( d ){
- if(d.fromIdentity == d.toIdentity )return;
- if( count % 2 === 1 ){
- node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
- node.store("nodeType","Odd");
- //node.setStyle("margin-right","10px");
- }else{
- node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
- node.store("nodeType","Even");
- }
- count++;
- this.empowerSelectNodes.push( node );
- node.store("data", d);
- var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
- node.store("iconNode",iconNode);
- var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
- var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
- var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
- var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
- node.addEvents({
- "mouseover": function(){
- var isSelected = this.retrieve("isSelected");
- if (!isSelected){
- this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
- if( _self.css.empowerItemIconNode_over ){
- var iconNode = this.retrieve("iconNode");
- if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
- }
- }
- },
- "mouseout": function(){
- var isSelected = this.retrieve("isSelected");
- if (!isSelected){
- this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
- if( _self.css.empowerItemIconNode_over ){
- var iconNode = this.retrieve("iconNode");
- if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
- }
- }
- },
- "click": function(){
- var isSelected = this.retrieve("isSelected");
- if (isSelected){
- _self.unselectEmpowerItem( this)
- }else{
- _self.selectEmpowerItem(this)
- }
- }
- });
- if( this.checkedAllItems )node.click();
- }.bind(this));
- },
- unselectEmpowerItem : function( itemNode ){
- itemNode.store("isSelected", false);
- itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
- itemNode.getElements("div").each( function( div ){
- var className = div.get("class");
- if( className && this.css[className] )div.setStyles( this.css[className] )
- }.bind(this))
- },
- selectEmpowerItem : function( itemNode ){
- itemNode.store("isSelected", true);
- itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
- itemNode.getElements("div").each( function( div ){
- var className = div.get("class");
- if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
- }.bind(this))
- },
- createSelectAllEmpowerNode : function(){
- var _self = this;
- var node = new Element("div", {
- styles : this.css.empowerSelectAllItemNode,
- text : MWF.xApplication.process.Xform.LP.selectAll
- });
- node.addEvents({
- "mouseover": function(){
- var isSelected = this.retrieve("isSelected");
- if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
- },
- "mouseout": function(){
- var isSelected = this.retrieve("isSelected");
- if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
- },
- "click": function(){
- var isSelected = this.retrieve("isSelected");
- if (isSelected){
- this.store("isSelected", false);
- this.setStyles( _self.css.empowerSelectAllItemNode );
- _self.empowerSelectNodes.each( function(itemNode){
- _self.unselectEmpowerItem(itemNode)
- }.bind(this))
- }else{
- this.store("isSelected", true);
- this.setStyles( _self.css.empowerSelectAllItemNode_selected );
- _self.empowerSelectNodes.each( function(itemNode){
- _self.selectEmpowerItem(itemNode)
- }.bind(this))
- }
- }
- });
- if( this.checkedAllItems ){
- node.store("isSelected", true);
- node.setStyles( _self.css.empowerSelectAllItemNode_selected );
- }
- return node;
- }
- });
- MWF.APPOrg.GroupOptions = new Class({
- Implements: [Events],
- initialize: function (form, json) {
- this.form = form;
- this.json = json;
- this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- },
- getOptions: function(){
- var count = (this.json.groupCount) ? this.json.groupCount : 0;
- if( this.json.groupRange==="group" ){
- return {
- "count": count,
- "storeRange" : this.json.storeRange,
- "include": this.getSelectRange( true )
- }
- }else{
- return {
- "count": count,
- "storeRange" : this.json.storeRange
- }
- }
- },
- getSearchOptions : function(){
- return {};
- },
- getSelectRange : function( refresh ){
- if( !this.selectRange || refresh){
- this.selectRange = this._getSelectRange();
- }
- return this.selectRange;
- },
- _getSelectRange : function(){
- var rangeValues = [];
- if (this.json.groupRangeKey && this.json.groupRangeKey.code){
- var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- rangeValues = v;
- //v.each(function(d){
- // if (d){
- // if (typeOf(d)==="string"){
- // var data;
- // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
- // rangeValues.push(data);
- // }else{
- // rangeValues.push(d);
- // }
- // }
- //}.bind(this));
- }
- return rangeValues;
- }
- });
- MWF.APPOrg.UnitOptions = new Class({
- Implements: [Events],
- initialize : function( form, json ){
- this.form = form;
- this.json = json;
- this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- },
- getOptions: function(){
- var count = (this.json.unitCount) ? this.json.unitCount : 0;
- var selectUnits = this.getSelectRange( true );
- return {
- "count": count,
- "units": selectUnits,
- "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
- "storeRange" : this.json.storeRange,
- "expandSubEnable" : (this.json.unitExpandSubEnable==="no") ? false : true,
- "firstLevelSelectable":this.json.firstLevelSelectable==="yes"
- };
- },
- getSearchOptions : function(){
- var selectUnits = this.getSelectRange( true );
- return {
- "units": selectUnits,
- "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
- };
- },
- getSelectRange : function( refresh ){
- if( !this.selectRange || refresh){
- this.selectRange = this._getSelectRange();
- }
- return this.selectRange;
- },
- _getSelectRange : function(){
- if (this.json.unitRange==="unit"){
- return this.getScriptSelectUnit();
- }
- if (this.json.unitRange==="draftUnit"){
- var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
- if (!dn){
- if ( layout.session.user.identityList && layout.session.user.identityList.length){
- var ids = [];
- layout.session.user.identityList.each(function(id){ ids.push(id.id); });
- return this.getNextSelectUnit(ids);
- }else{
- return [];
- }
- }else{
- return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
- }
- }
- if (this.json.unitRange==="currentUnit"){
- if (this.form.app.currentTask){
- return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
- }else{
- if (this.form.app.taskList && this.form.app.taskList.length){
- var ids = [];
- this.form.app.taskList.each(function(task){ ids.push(task.identity); });
- return this.getNextSelectUnit(ids);
- }else{
- if ( layout.session.user.identityList && layout.session.user.identityList.length){
- var ids = [];
- layout.session.user.identityList.each(function(id){ ids.push(id.id); });
- return this.getNextSelectUnit(ids);
- }else{
- return [];
- }
- }
- }
- }
- return [];
- },
- getScriptSelectUnit: function(){
- var rangeValues = [];
- if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
- this.json.unitRangeUnit.each(function(unit){
- //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
- //if (unitFlag) rangeValues.push(unitFlag);
- rangeValues.push(unit);
- }.bind(this));
- }
- if (this.json.unitRangeField && this.json.unitRangeField.length){
- this.json.unitRangeField.each(function(field){
- var n = (typeOf(field)=="object") ? field.name : field;
- var v = this.form.businessData.data[n];
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d){
- // if (typeOf(d)==="string"){
- // var data;
- // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
- // rangeValues.push(data);
- // }else{
- rangeValues.push(d);
- // }
- }
- }.bind(this));
- }.bind(this));
- }
- if (this.json.unitRangeKey && this.json.unitRangeKey.code){
- var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d){
- // if (typeOf(d)==="string"){
- // var data;
- // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
- // rangeValues.push(data);
- // }else{
- rangeValues.push(d);
- // }
- }
- }.bind(this));
- }
- return rangeValues;
- },
- getNextSelectUnit: function(id){
- var ids = typeOf(id)==="array" ? id : [id];
- var data;
- var units = [];
- ids.each( function(i){
- if (this.json.unitRangeNext === "direct"){
- this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
- if (data && data.woUnit) units.push(data.woUnit);
- }else if(this.json.unitRangeNext==="level"){
- this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- if (data) units.push(data);
- }else if (this.json.unitRangeNext==="type"){
- if (this.json.unitRangeNextUnitType==="all"){
- this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- }else{
- this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- }
- if (data) units.push(data);
- }
- data = null;
- }.bind(this));
- return units;
- //if (this.json.unitRangeNext === "direct"){
- // if (typeOf(id)==="array"){
- // var units = [];
- // id.each(function(i){
- // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
- // if (data && data.woUnit) units.push(data.woUnit);
- // data = null;
- // }.bind(this));
- // return units;
- // }else{
- // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
- // return (data.woUnit) ? [data.woUnit] : [];
- // }
- //}
- //if (this.json.unitRangeNext==="level"){
- // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // //this.json.rangeNextLevel
- // return (data) ? [data] : [];
- //}
- //if (this.json.unitRangeNext==="type"){
- // if (this.json.unitRangeNextUnitType==="all"){
- // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // }else{
- // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // }
- //
- // return (data) ? [data] : [];
- //}
- }
- });
- MWF.APPOrg.IdentityOptions = new Class({
- Implements: [Events],
- initialize : function( form, json ){
- this.form = form;
- this.json = json;
- this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- },
- getOptions: function(){
- var count = (this.json.identityCount) ? this.json.identityCount : 0;
- if( this.json.identityOnlyUseInclude ){
- return {
- "noUnit" : true,
- "count": count,
- "resultType" : this.json.identityResultType,
- "storeRange" : this.json.storeRange,
- "include" : this._getInclude()
- };
- }else{
- var selectUnits = this.getSelectRange( true );
- var selectDutys = this.getSelectRangeDuty( true );
- return {
- "count": count,
- "units": selectUnits,
- "unitType": this.json.unitType || "",
- "dutys": selectDutys,
- "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
- "resultType" : this.json.identityResultType,
- "categoryType": this.json.categoryType || "unit",
- "dutyUnitLevelBy" : this.json.dutyUnitLevelBy || "duty",
- "storeRange" : this.json.storeRange,
- "include" : this._getInclude()
- };
- }
- },
- getSearchOptions : function(){
- var selectUnits = this.getSelectRange( true );
- var selectDutys = this.getSelectRangeDuty( true );
- return {
- "units": selectUnits,
- "dutys": selectDutys,
- "resultType" : this.json.identityResultType
- };
- },
- getSelectRange : function( refresh ){
- if( !this.selectRange || refresh ){
- this.selectRange = this._getSelectRange();
- }
- return this.selectRange;
- },
- _getInclude : function(){
- var include = [];
- if( this.json.identityIncludeKey ){
- var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
- if( v )include = typeOf(v)==="array" ? v : [v];
- }
- return include;
- },
- _getSelectRange : function(){
- if (this.json.identityRange==="unit"){
- return this.getScriptSelectUnit();
- }
- if (this.json.identityRange==="draftUnit"){
- var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
- if (!dn){
- if ( layout.session.user.identityList && layout.session.user.identityList.length){
- var ids = [];
- layout.session.user.identityList.each(function(id){ ids.push(id.id); });
- return this.getNextSelectUnit(ids);
- }else{
- return [];
- }
- }else{
- return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
- }
- }
- if (this.json.identityRange==="currentUnit"){
- if (this.form.app.currentTask){
- return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
- }else{
- if (this.form.app.taskList && this.form.app.taskList.length){
- var ids = [];
- this.form.app.taskList.each(function(task){ ids.push(task.identity); });
- return this.getNextSelectUnit(ids);
- }else{
- if ( layout.session.user.identityList && layout.session.user.identityList.length){
- var ids = [];
- layout.session.user.identityList.each(function(id){ ids.push(id.id); });
- return this.getNextSelectUnit(ids);
- }else{
- return [];
- }
- }
- }
- }
- return [];
- },
- getScriptSelectUnit: function(){
- var rangeValues = [];
- if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
- this.json.identityRangeUnit.each(function(unit){
- //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
- //if (unitFlag) rangeValues.push(unitFlag);
- rangeValues.push(unit);
- }.bind(this));
- }
- if (this.json.identityRangeField && this.json.identityRangeField.length){
- this.json.identityRangeField.each(function(field){
- var n = (typeOf(field)=="object") ? field.name : field;
- var v = this.form.businessData.data[n];
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d){
- // if (typeOf(d)==="string"){
- // var data;
- // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
- // rangeValues.push(data);
- // }else{
- rangeValues.push(d);
- // }
- }
- }.bind(this));
- }.bind(this));
- }
- if (this.json.identityRangeKey && this.json.identityRangeKey.code){
- var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d){
- // if (typeOf(d)==="string"){
- // var data;
- // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
- // rangeValues.push(data);
- // }else{
- rangeValues.push(d);
- // }
- }
- }.bind(this));
- }
- return rangeValues;
- },
- getNextSelectUnit: function(id){
- var ids = typeOf(id)==="array" ? id : [id];
- var data;
- var units = [];
- ids.each(function(i){
- if (this.json.identityRangeNext === "direct"){
- this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
- if (data && data.woUnit) units.push(data.woUnit);
- }else if (this.json.identityRangeNext==="level"){
- this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- if (data) units.push(data);
- }else if (this.json.identityRangeNext==="type"){
- if (this.json.identityRangeNextUnitType==="all"){
- this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- }else{
- this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- }
- if (data) units.push(data);
- }
- data = null;
- }.bind(this));
- return units;
- //if (this.json.identityRangeNext === "direct"){
- //if (typeOf(id)==="array"){
- // var units = [];
- // id.each(function(i){
- // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
- // if (data && data.woUnit) units.push(data.woUnit);
- // data = null;
- // }.bind(this));
- // return units;
- //}else{
- // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
- // return (data.woUnit) ? [data.woUnit] : [];
- //}
- //}
- //if (this.json.identityRangeNext==="level"){
- // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // return (data) ? [data] : [];
- // //this.json.rangeNextLevel
- //}
- //if (this.json.identityRangeNext==="type"){
- // if (this.json.identityRangeNextUnitType==="all"){
- // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // }else{
- // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
- // }
- // return (data) ? [data] : [];
- //}
- },
- getSelectRangeDuty: function( refresh ){
- if( !this.selectRangeDuty || refresh ){
- this.selectRangeDuty = this._getSelectRangeDuty();
- }
- return this.selectRangeDuty;
- },
- _getSelectRangeDuty: function(){
- if (this.json.dutyRange==="duty"){
- return this.getScriptSelectDuty();
- }
- return [];
- },
- getScriptSelectDuty: function(){
- var rangeValues = [];
- if( this.json.rangeDuty && this.json.rangeDuty.length ){
- var rangeDuty = this.json.rangeDuty;
- if( typeOf(rangeDuty) === "string" ){
- rangeDuty = JSON.parse( rangeDuty );
- }
- if( typeOf(rangeDuty) === "array" ){
- rangeDuty.each(function(unit){
- var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
- if (unitFlag) rangeValues.push(unitFlag);
- }.bind(this));
- }
- }
- //if (this.json.rangeDuty && this.json.rangeDuty.length){
- // this.json.rangeDuty.each(function(unit){
- // var unitFlag = unit.id || unit.name;
- // if (unitFlag) rangeValues.push(unitFlag);
- // }.bind(this));
- //}
- if (this.json.rangeDutyField && this.json.rangeDutyField.length){
- this.json.rangeDutyField.each(function(field){
- var n = (typeOf(field)=="object") ? field.name : field;
- var v = this.form.businessData.data[n];
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d) rangeValues.push(d);
- }.bind(this));
- }.bind(this));
- }
- if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
- var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
- if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
- v.each(function(d){
- if (d) rangeValues.push(d);
- }.bind(this));
- }
- return rangeValues;
- }
- });
|