Org.js 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xDesktop.requireApp("Selector", "package", null, false);
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. /** @class Org 人员组织组件。
  5. * @o2cn 人员组织组件
  6. * @example
  7. * //可以在脚本中获取该组件
  8. * //方法1:
  9. * var field = this.form.get("fieldId"); //获取组件对象
  10. * //方法2
  11. * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
  12. *
  13. * var data = field.getData(); //获取值
  14. * field.setData(value); //设置值
  15. * field.hide(); //隐藏字段
  16. * var id = field.json.id; //获取字段标识
  17. * var flag = field.isEmpty(); //字段是否为空
  18. * @extends MWF.xApplication.process.Xform.$Input
  19. * @o2category FormComponents
  20. * @o2range {Process|CMS|Portal}
  21. * @hideconstructor
  22. */
  23. MWF.xApplication.process.Xform.Org = MWF.APPOrg = new Class(
  24. /** @lends MWF.xApplication.process.Xform.Org# */
  25. {
  26. Implements: [Events],
  27. Extends: MWF.APP$Input,
  28. options: {
  29. /**
  30. * 组件加载前触发。当前组件的queryLoad事件还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取当前组件。
  31. * @event MWF.xApplication.process.Xform.Org#queryLoad
  32. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  33. */
  34. /**
  35. * 组件加载时触发.
  36. * @event MWF.xApplication.process.Xform.Org#load
  37. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  38. */
  39. /**
  40. * 组件加载后触发.
  41. * @event MWF.xApplication.process.Xform.Org#postLoad
  42. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  43. */
  44. /**
  45. * 当组件值改变时触发。
  46. * @event MWF.xApplication.process.Xform.Org#change
  47. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  48. */
  49. /**
  50. * 当组件不允许输入(使用人员选择框)时,完成选择人员,并且给组件赋值后执行。
  51. * @event MWF.xApplication.process.Xform.Org#select
  52. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  53. */
  54. "moduleEvents": ["load", "queryLoad", "postLoad", "change", "select", "removeItem"],
  55. /**
  56. * 人员选择框事件:加载前执行。this.target指向人员选择框。
  57. * @event MWF.xApplication.process.Xform.Org#queryLoadSelector
  58. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  59. */
  60. /**
  61. * 人员选择框事件:加载后执行,由于选择项为异步加载,此时选择项并未加载完成。this.target指向人员选择框。
  62. * @event MWF.xApplication.process.Xform.Org#postLoadSelector
  63. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  64. */
  65. /**
  66. * 人员选择框事件:加载选择框容器节点前执行。this.target指向人员选择框。
  67. * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
  68. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  69. */
  70. /**
  71. * 人员选择框事件:加载选择框容器节点后执行。this.target指向人员选择框。
  72. * @event MWF.xApplication.process.Xform.Org#postLoadContent
  73. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  74. */
  75. /**
  76. * 人员选择框事件:加载分类前执行。this.target指向分类,this.target.selector指向人员选择框。
  77. * @event MWF.xApplication.process.Xform.Org#queryLoadCategory
  78. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  79. */
  80. /**
  81. * 人员选择框事件:加载分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  82. * @event MWF.xApplication.process.Xform.Org#postLoadCategory
  83. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  84. */
  85. /**
  86. * 人员选择框事件:选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  87. * @event MWF.xApplication.process.Xform.Org#selectCategory
  88. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  89. */
  90. /**
  91. * 人员选择框事件:取消选择分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  92. * @event MWF.xApplication.process.Xform.Org#unselectCategory
  93. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  94. */
  95. /**
  96. * 人员选择框事件:展开分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  97. * @event MWF.xApplication.process.Xform.Org#expand
  98. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  99. */
  100. /**
  101. * 人员选择框事件:折叠分类后执行。this.target指向分类,this.target.selector指向人员选择框。
  102. * @event MWF.xApplication.process.Xform.Org#collapse
  103. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  104. */
  105. /**
  106. * 人员选择框事件:加载选择项前执行。this.target指向选择项,this.target.selector指向人员选择框。
  107. * @event MWF.xApplication.process.Xform.Org#queryLoadItem
  108. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  109. */
  110. /**
  111. * 人员选择框事件:加载选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  112. * @event MWF.xApplication.process.Xform.Org#postLoadItem
  113. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  114. */
  115. /**
  116. * 人员选择框事件:选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  117. * @event MWF.xApplication.process.Xform.Org#selectItem
  118. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  119. */
  120. /**
  121. * 人员选择框事件:取消选择选择项后执行。this.target指向选择项,this.target.selector指向人员选择框。
  122. * @event MWF.xApplication.process.Xform.Org#unselectItem
  123. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  124. */
  125. /**
  126. * 人员选择框事件:在人员选择框点取消时执行。this.target指向人员选择框。
  127. * @event MWF.xApplication.process.Xform.Org#close
  128. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  129. */
  130. "selectorEvents" : ["queryLoadSelector","postLoadSelector","queryLoadContent","postLoadContent","queryLoadCategory","postLoadCategory",
  131. "selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change","expand","collapse","cancel"],
  132. "readonly": true
  133. },
  134. iconStyle: "orgIcon",
  135. isReadonly : function(){
  136. var readonly = !!(this.readonly || this.form.json.isReadonly);
  137. if( readonly )return readonly;
  138. if( this.json.isReadonly === "script" ){
  139. if( this.json.readonlyScript && this.json.readonlyScript.code ){
  140. readonly = this.form.Macro.exec(this.json.readonlyScript.code, this);
  141. }
  142. }else{
  143. readonly = !!this.json.isReadonly
  144. }
  145. return readonly || !!this.isSectionMergeRead();
  146. },
  147. getTextData: function(){
  148. //var value = this.node.get("value");
  149. //var text = this.node.get("text");
  150. var value = this.getValue();
  151. //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  152. var text = [];
  153. if( typeOf( value ) === "object" )value = [value];
  154. if( typeOf( value ) === "array" ){
  155. value.each(function(v){
  156. if( typeOf(v) === "string" ){
  157. text.push(v);
  158. }else{
  159. text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
  160. }
  161. }.bind(this));
  162. return {"value": value || "", "text": [text.join(",")]};
  163. }else{
  164. return {"value": [""], "text": [""]};
  165. }
  166. },
  167. loadDescription: function(){
  168. if (this.isReadonly())return;
  169. if(this.descriptionNode)return;
  170. var v = this._getBusinessData();
  171. if (!v || !v.length){
  172. if (this.json.description){
  173. var size, w;
  174. if( this.node.offsetParent === null ){ //隐藏
  175. size = { y: 26 }
  176. }else{
  177. size = this.node.getFirst().getSize();
  178. // w = size.x-3;
  179. // if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
  180. // if (COMMON.Browser.safari) w = w - 20;
  181. // }
  182. }
  183. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  184. this.descriptionNode.setStyles({
  185. "height": ""+size.y+"px",
  186. "line-height": ""+size.y+"px"
  187. });
  188. this.descriptionNode.setStyles({
  189. "width": "auto",
  190. "overflow": "auto"
  191. });
  192. // if( w )this.descriptionNode.setStyles({
  193. // "width": ""+w+"px"
  194. // });
  195. this.setDescriptionEvent();
  196. }
  197. }
  198. },
  199. setDescriptionEvent: function(){
  200. if (this.descriptionNode){
  201. this.descriptionNode.addEvents({
  202. "mousedown": function( ev ){
  203. this.descriptionNode.setStyle("display", "none");
  204. if( this.json.isInput ){
  205. if( this.combox ){
  206. if (!this.combox.editItem) this.combox.intoEdit(ev);
  207. window.setTimeout( function () {
  208. this.combox.input.node.focus();
  209. }.bind(this), 300)
  210. }
  211. }else{
  212. this.clickSelect( ev );
  213. }
  214. }.bind(this)
  215. });
  216. }
  217. },
  218. _loadNode: function(){
  219. this.field = true;
  220. if (this.isReadonly()){
  221. this._loadNodeRead();
  222. }else{
  223. this._getOrgOptions();
  224. if (this.json.isInput){
  225. this._loadNodeInputEdit();
  226. }else{
  227. this._loadNodeEdit();
  228. }
  229. }
  230. },
  231. _loadMergeReadContentNode: function(contentNode, data){
  232. this.loadOrgWidget(data.data, contentNode);
  233. },
  234. _loadMergeEditNodeByDefault: function(){
  235. var data = this.getSortedSectionData();
  236. var businessData = [];
  237. data.each(function(d){
  238. businessData = businessData.concat( d.data || [] );
  239. });
  240. this._setBusinessData( businessData );
  241. this._loadNode();
  242. },
  243. _getOrgOptions: function(){
  244. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  245. if( this.selectTypeList.contains( "identity" ) ) {
  246. this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
  247. }
  248. if( this.selectTypeList.contains( "unit" ) ) {
  249. this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
  250. }
  251. if( this.selectTypeList.contains( "group" ) ){
  252. this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  253. }
  254. //this.selectUnits = this.getSelectRange();
  255. //if (this.json.selectType=="identity"){
  256. // this.selectDutys = this.getSelectRangeDuty();
  257. //}
  258. },
  259. _valueMerge: function(values, v){
  260. if (o2.typeOf(v)=="function"){
  261. return v.then(function(re){
  262. this._valueMerge(values, re)
  263. }.bind(this), function(){});
  264. }else{
  265. return values.concat(v);
  266. }
  267. },
  268. _computeValue: function(){
  269. var simple = this.json.storeRange === "simple";
  270. var values = [];
  271. if (this.json.identityValue) {
  272. this.json.identityValue.each(function(v){
  273. if (v) values.push(MWF.org.parseOrgData(v, true, simple))
  274. });
  275. }
  276. if (this.json.unitValue) {
  277. this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
  278. }
  279. if (this.json.dutyValue) {
  280. var dutys = JSON.decode(this.json.dutyValue);
  281. var par;
  282. if (dutys.length){
  283. dutys.each(function(duty){
  284. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  285. if (par){
  286. var pars = (o2.typeOf(par)=="array") ? par : [par];
  287. var promise = Promise.all(pars).then(function(p){
  288. var uName = p.distinguishedName || p;
  289. if (o2.typeOf(p)=="array") uName = p[0].distinguishedName || p[0];
  290. var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
  291. var r = (!!uName) ? this.form.Macro.exec(code, this) : "";
  292. var m = (o2.typeOf(r)=="array") ? "all" : "resolve";
  293. return Promise[m](r).then(function(d){
  294. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  295. var arr = [];
  296. d.each(function(dd){
  297. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  298. });
  299. return arr;
  300. }.bind(this)).catch(function(){
  301. console.log("catch error : can not get duty : " + duty.name, + "-" + uName);
  302. });
  303. }.bind(this), function(){});
  304. values.push(promise);
  305. }
  306. }.bind(this));
  307. }
  308. }
  309. if (this.json.defaultValue && this.json.defaultValue.code){
  310. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  311. if (o2.typeOf(fd)=="array"){
  312. fd.each(function(v){values.push(v);});
  313. }else{
  314. values.push(fd);
  315. }
  316. // if (fd && fd.isAG){
  317. // values.push(fd);
  318. // }else{
  319. // if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  320. // fd.each(function(fdd){
  321. // if (fdd){
  322. // if (typeOf(fdd)==="string"){
  323. // var data;
  324. // this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
  325. // values.push(data);
  326. // }else{
  327. // values.push(fdd);
  328. // }
  329. // }
  330. // }.bind(this));
  331. // }
  332. }
  333. // if (this.json.count>0){
  334. // return values.slice(0, this.json.count);
  335. // }
  336. return values;
  337. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  338. },
  339. __computeValue: function(){
  340. var simple = this.json.storeRange === "simple";
  341. var values = [];
  342. if (this.json.identityValue) {
  343. this.json.identityValue.each(function(v){
  344. if (v) values.push(MWF.org.parseOrgData(v, true, simple))
  345. });
  346. }
  347. if (this.json.unitValue) {
  348. this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
  349. }
  350. if (this.json.dutyValue) {
  351. var dutys = JSON.decode(this.json.dutyValue);
  352. var par;
  353. if (dutys.length){
  354. dutys.each(function(duty){
  355. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  356. if (par && par.isAG){
  357. var ag = o2.AG.all(par).then(function(p){
  358. var uName = "";
  359. if (p && p.length) uName = p[0].distinguishedName || p[0];
  360. var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
  361. var r = this.form.Macro.exec(code, this);
  362. o2.AG.all(r).then(function(d) {
  363. //var d = rd[0];
  364. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  365. var arr = [];
  366. d.each(function(dd){
  367. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  368. });
  369. return arr;
  370. }.bind(this));
  371. }.bind(this));
  372. values.push(ag);
  373. }else{
  374. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\", true)";
  375. var r = this.form.Macro.exec(code, this);
  376. var ag = o2.AG.all(r).then(function(d) {
  377. //var d = rd[0];
  378. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  379. var arr = [];
  380. d.each(function(dd){
  381. if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  382. });
  383. return arr;
  384. }.bind(this));
  385. values.push(ag);
  386. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  387. // d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
  388. }
  389. }.bind(this));
  390. }
  391. }
  392. if (this.json.defaultValue && this.json.defaultValue.code){
  393. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  394. if (fd && fd.isAG){
  395. // value.addResolve(function(v){
  396. // this._setBusinessData(v);
  397. // if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
  398. // if (this.readonly || this.json.isReadonly) this.node.set("text", v);
  399. // }.bind(this));
  400. values.push(fd);
  401. // fd.then(function(v){
  402. // return this._valueMerge(values, v);
  403. // }.bind(this));
  404. // return fd;
  405. }else{
  406. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  407. fd.each(function(fdd){
  408. if (fdd){
  409. if (typeOf(fdd)==="string"){
  410. var data;
  411. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
  412. values.push(data);
  413. }else{
  414. values.push(fdd);
  415. }
  416. }
  417. }.bind(this));
  418. }
  419. }
  420. if (this.json.count>0){
  421. return values.slice(0, this.json.count);
  422. }
  423. return values;
  424. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  425. },
  426. getOrgAction: function(){
  427. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  428. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  429. return this.orgAction;
  430. },
  431. getOptions: function(){
  432. var _self = this;
  433. if( this.selectTypeList.length === 0 )return false;
  434. var values = this.getInputData() || [];
  435. var exclude = [];
  436. if( this.json.exclude ){
  437. var v = this.form.Macro.exec(this.json.exclude.code, this);
  438. exclude = typeOf(v)==="array" ? v : [v];
  439. }
  440. //var count = (this.json.count) ? this.json.count : 0;
  441. var identityOpt;
  442. if( this.identityOptions ){
  443. identityOpt = this.identityOptions.getOptions();
  444. if (this.json.identityRange!=="all"){
  445. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  446. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  447. identityOpt.disabled = true;
  448. // return false;
  449. }
  450. }
  451. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  452. if (!identityOpt.dutys || !identityOpt.dutys.length){
  453. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  454. identityOpt.disabled = true;
  455. // return false;
  456. }
  457. }
  458. identityOpt.values = (this.json.isInput) ? [] : values;
  459. identityOpt.exclude = exclude;
  460. if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
  461. }
  462. var unitOpt;
  463. if( this.unitOptions ){
  464. unitOpt = this.unitOptions.getOptions();
  465. if (this.json.unitRange!=="all"){
  466. if ( !unitOpt.units || !unitOpt.units.length){
  467. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  468. unitOpt.disabled = true;
  469. // return false;
  470. }
  471. }
  472. unitOpt.values = (this.json.isInput) ? [] : values;
  473. unitOpt.exclude = exclude;
  474. if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
  475. }
  476. var groupOpt;
  477. if( this.groupOptions ){
  478. groupOpt = this.groupOptions.getOptions();
  479. groupOpt.values = (this.json.isInput) ? [] : values;
  480. groupOpt.exclude = exclude;
  481. if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
  482. }
  483. //var selectUnits = this.getSelectRange();
  484. //if (this.json.selectType=="identity"){
  485. // var selectDutys = this.getSelectRangeDuty();
  486. //}
  487. //if (this.json.range!=="all"){
  488. // if (!selectUnits.length){
  489. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  490. // return false;
  491. // }
  492. //}
  493. //if (this.json.selectType=="identity"){
  494. // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  495. // if (!selectDutys || !selectDutys.length){
  496. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  497. // return false;
  498. // }
  499. // }
  500. //}
  501. var defaultOpt = {};
  502. if( this.json.events && typeOf(this.json.events) === "object" ){
  503. Object.each(this.json.events, function(e, key){
  504. if (e.code){
  505. if (this.options.selectorEvents.indexOf(key)!==-1){
  506. if( key === "postLoadSelector" ) {
  507. this.addEvent("loadSelector", function (selector) {
  508. return this.form.Macro.fire(e.code, selector);
  509. }.bind(this))
  510. }else if( key === "queryLoadSelector"){
  511. defaultOpt["onQueryLoad"] = function(target){
  512. return this.form.Macro.fire(e.code, target);
  513. }.bind(this)
  514. }else{
  515. defaultOpt["on"+key.capitalize()] = function(target){
  516. return this.form.Macro.fire(e.code, target);
  517. }.bind(this)
  518. }
  519. }
  520. }
  521. }.bind(this));
  522. }
  523. if( this.selectTypeList.length === 1 ){
  524. return Object.merge( {
  525. "type": this.selectTypeList[0],
  526. "onComplete": function(items){
  527. this.selectOnComplete(items);
  528. }.bind(this),
  529. "onCancel": this.selectOnCancel.bind(this),
  530. // "onLoad": this.selectOnLoad.bind(this),
  531. "onLoad": function(){
  532. //this 为 selector
  533. _self.selectOnLoad(this, this.selector );
  534. },
  535. "onClose": this.selectOnClose.bind(this)
  536. }, defaultOpt, identityOpt || unitOpt || groupOpt )
  537. }else if( this.selectTypeList.length > 1 ){
  538. var options = {
  539. "type" : "",
  540. "types" : this.selectTypeList,
  541. "onComplete": function(items){
  542. this.selectOnComplete(items);
  543. }.bind(this),
  544. "onCancel": this.selectOnCancel.bind(this),
  545. // "onLoad": this.selectOnLoad.bind(this),
  546. "onLoad": function(){
  547. //this 为 selector
  548. _self.selectOnLoad(this)
  549. },
  550. "onClose": this.selectOnClose.bind(this)
  551. };
  552. if( this.form.json.selectorStyle ){
  553. options = Object.merge( options, this.form.json.selectorStyle );
  554. }
  555. if( identityOpt )options.identityOptions = Object.merge( {}, defaultOpt, identityOpt );
  556. if( unitOpt )options.unitOptions = Object.merge( {}, defaultOpt, unitOpt );
  557. if( groupOpt )options.groupOptions = Object.merge( {}, defaultOpt, groupOpt );
  558. return options;
  559. }
  560. //return {
  561. // "type": this.json.selectType,
  562. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  563. // "values": (this.json.isInput) ? [] : values,
  564. // "count": count,
  565. // "units": selectUnits,
  566. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  567. // "exclude" : exclude,
  568. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  569. // "categoryType": this.json.categoryType || "unit",
  570. // "onComplete": function(items){
  571. // this.selectOnComplete(items);
  572. // }.bind(this),
  573. // "onCancel": this.selectOnCancel.bind(this),
  574. // "onLoad": this.selectOnLoad.bind(this),
  575. // "onClose": this.selectOnClose.bind(this)
  576. //};
  577. },
  578. selectOnComplete: function(items){
  579. var array = [];
  580. items.each(function(item){
  581. array.push(item.data);
  582. }.bind(this));
  583. var simple = this.json.storeRange === "simple";
  584. this.checkEmpower( array, function( data ){
  585. var values = [];
  586. data.each(function(d){
  587. values.push(MWF.org.parseOrgData(d, true, simple));
  588. }.bind(this));
  589. if (this.json.isInput){
  590. this.addData(values);
  591. }else{
  592. this.setData(values, true);
  593. }
  594. //this._setBusinessData(values);
  595. this.validationMode();
  596. this.validation();
  597. var p = this.getValue();
  598. if (p.then){
  599. p.then(function(){
  600. this.fireEvent("select");
  601. }.bind(this), function(){});
  602. }else{
  603. this.fireEvent("select");
  604. }
  605. }.bind(this))
  606. },
  607. selectOnCancel: function(){
  608. this.validation();
  609. },
  610. selectOnLoad: function( selector ){
  611. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  612. this.fireEvent("loadSelector", [selector])
  613. },
  614. selectOnClose: function(){
  615. var v = this._getBusinessData();
  616. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  617. },
  618. checkDescription: function(){
  619. if (!this.json.description)return;
  620. var v = this._getBusinessData();
  621. if (!v || !v.length){
  622. if( this.descriptionNode ){
  623. if( this.node.getFirst() ){
  624. var size = this.node.getFirst().getSize();
  625. var w = size.x-3;
  626. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ) {
  627. if (COMMON.Browser.safari) w = w - 20;
  628. }
  629. this.descriptionNode.setStyles({
  630. "display": "block",
  631. "width": ""+w+"px",
  632. "height": ""+( size.y || 26)+"px",
  633. "line-height": ""+( size.y || 26)+"px"
  634. });
  635. }else{
  636. this.descriptionNode.setStyle("display", "block");
  637. }
  638. }else{
  639. this.loadDescription();
  640. }
  641. }else{
  642. if(this.descriptionNode)this.descriptionNode.setStyle("display", "none");
  643. }
  644. },
  645. /**
  646. * @summary 弹出选择界面.
  647. * @example
  648. * this.form.get('org').clickSelect();
  649. */
  650. clickSelect: function( ev ){
  651. if (this.isReadonly())return;
  652. if( layout.mobile ){
  653. setTimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
  654. var options = this.getOptions();
  655. if(options){
  656. if( this.selector && this.selector.loading ) {
  657. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  658. }else{
  659. /**
  660. * @summary 人员选择框package的对象
  661. * @member {o2.O2Selector}
  662. * @example
  663. * //可以在脚本中获取该组件
  664. * var selector = this.form.get("fieldId").selector.selector; //获取人员选择框对象
  665. * var options = selector.options; //获取人员选择框的选项
  666. */
  667. this.selector = new MWF.O2Selector(this.form.app.content, options);
  668. }
  669. }
  670. }.bind(this), 100 )
  671. }else{
  672. var options = this.getOptions();
  673. if(options){
  674. if( this.selector && this.selector.loading ) {
  675. }else if( this.selector && this.selector.selector && this.selector.selector.active ){
  676. }else {
  677. this.selector = new MWF.O2Selector(this.form.app.content, options);
  678. }
  679. }
  680. }
  681. },
  682. resetData: function(){
  683. var v = this.getValue();
  684. //this.setData((v) ? v.join(", ") : "");
  685. this.setData(v);
  686. },
  687. isEmpty: function(){
  688. var data = this.getData();
  689. if( typeOf(data) !== "array" )return true;
  690. if( data.length === 0 )return true;
  691. return false;
  692. },
  693. getInputData: function(){
  694. if (this.json.isInput){
  695. if (this.combox)return this.combox.getData();
  696. //return this._getBusinessData();
  697. return this.node.retrieve("data");
  698. }else{
  699. //return this._getBusinessData();
  700. return this.node.retrieve("data");
  701. }
  702. },
  703. _loadNodeRead: function(){
  704. this.node.empty();
  705. var node = new Element("div").inject(this.node);
  706. this.node.set({
  707. "nodeId": this.json.id,
  708. "MWFType": this.json.type
  709. });
  710. this.clearDefaultMargin();
  711. },
  712. _searchConfirmPerson: function(item){
  713. var inforNode = item.inforNode || new Element("div");
  714. var simple = this.json.storeRange === "simple";
  715. if (item.data){
  716. var data = item.data;
  717. if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
  718. var dn = data.distinguishedName || data;
  719. if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
  720. MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
  721. identityList : [dn]
  722. }, function(json){
  723. if( json.data.length > 0 ){
  724. if( data["person"] )json.data[0].id = data["person"];
  725. item.data = MWF.org.parseOrgData( json.data[0], true, simple );
  726. item.value = this.getDataText( item.data );
  727. if(item.node)item.node.set("text", item.value);
  728. }
  729. }.bind(this), null, false)
  730. }
  731. }
  732. if( item.data && ( item.data.createTime || item.data.updateTime ) ){
  733. item.data = MWF.org.parseOrgData( item.data, true, simple );
  734. }
  735. var text = "";
  736. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-2, 2);
  737. switch (flag.toLowerCase()){
  738. case "@i":
  739. text = item.data.name+"("+item.data.unitName+")";
  740. break;
  741. case "@p":
  742. text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
  743. break;
  744. case "@u":
  745. text = item.data.levelName;
  746. break;
  747. case "@g":
  748. text = item.data.name;
  749. break;
  750. default:
  751. text = item.data.name;
  752. }
  753. inforNode.set({
  754. "styles": {"font-size": "14px", "color": ""},
  755. "text": text
  756. });
  757. }else{
  758. inforNode.set({
  759. "styles": {"font-size": "14px", "color": "#bd0000"},
  760. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  761. });
  762. }
  763. if (!item.inforNode){
  764. new mBox.Tooltip({
  765. content: inforNode,
  766. setStyles: {content: {padding: 15, lineHeight: 20}},
  767. attach: item.node,
  768. transition: 'flyin'
  769. });
  770. item.inforNode = inforNode;
  771. }
  772. },
  773. getSearchOptions: function(){
  774. if( this.selectTypeList.length === 0 )return false;
  775. var identityOpt;
  776. if( this.identityOptions ){
  777. identityOpt = this.identityOptions.getSearchOptions();
  778. //if (this.json.identityRange!=="all"){
  779. // if ( !identityOpt.units || !identityOpt.units.length){
  780. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  781. // return false;
  782. // }
  783. //}
  784. //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  785. // if (!identityOpt.dutys || !identityOpt.dutys.length){
  786. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  787. // return false;
  788. // }
  789. //}
  790. }
  791. var unitOpt;
  792. if( this.unitOptions ){
  793. unitOpt = this.unitOptions.getSearchOptions();
  794. //if (this.json.unitRange!=="all"){
  795. // if ( !unitOpt.units || !unitOpt.units.length){
  796. // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  797. // return false;
  798. // }
  799. //}
  800. }
  801. var groupOpt;
  802. if( this.groupOptions ){
  803. groupOpt = this.groupOptions.getOptions();
  804. }
  805. if( this.selectTypeList.length === 1 ){
  806. return Object.merge( {
  807. "type": this.selectTypeList[0]
  808. }, identityOpt || unitOpt || groupOpt )
  809. }else if( this.selectTypeList.length > 1 ){
  810. var options = {
  811. "type" : "",
  812. "types" : this.selectTypeList
  813. };
  814. if( identityOpt )options.identityOptions = identityOpt;
  815. if( unitOpt )options.unitOptions = unitOpt;
  816. if( groupOpt )options.groupOptions = groupOpt;
  817. return options;
  818. }
  819. //return {
  820. // "type": this.json.selectType,
  821. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  822. // "values": (this.json.isInput) ? [] : values,
  823. // "count": count,
  824. // "units": selectUnits,
  825. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  826. // "exclude" : exclude,
  827. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  828. // "categoryType": this.json.categoryType || "unit",
  829. // "onComplete": function(items){
  830. // this.selectOnComplete(items);
  831. // }.bind(this),
  832. // "onCancel": this.selectOnCancel.bind(this),
  833. // "onLoad": this.selectOnLoad.bind(this),
  834. // "onClose": this.selectOnClose.bind(this)
  835. //};
  836. },
  837. _searchOptions: function(value, callback){
  838. //var options = {
  839. // "type": this.json.selectType,
  840. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  841. // "units": this.selectUnits,
  842. // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  843. //};
  844. var options = this.getSearchOptions();
  845. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  846. this.comboxFilter.filter(value, function(data){
  847. data.map(function(d){
  848. var value = Object.clone(d);
  849. d.value = value;
  850. var flag = d.distinguishedName.substr(d.distinguishedName.length-2, 2);
  851. switch (flag.toLowerCase()){
  852. case "@i":
  853. d.text = d.name+"("+d.unitName+")";
  854. break;
  855. case "@p":
  856. d.text = d.name+(d.employee ? "("+d.employee+")" : "");
  857. break;
  858. case "@u":
  859. d.text = d.name;
  860. break;
  861. case "@g":
  862. d.text = d.name;
  863. break;
  864. default:
  865. d.text = d.name;
  866. }
  867. });
  868. if (callback) callback(data);
  869. });
  870. },
  871. _resetNodeInputEdit: function(){
  872. var node = new Element("div", {
  873. "styles": {
  874. "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
  875. //"position": "relative",
  876. "margin-right": this.hasIcon() ? "20px" : "0px"
  877. }
  878. }).inject(this.node, "after");
  879. this.node.destroy();
  880. this.node = node;
  881. },
  882. _loadNodeInputEdit: function(){
  883. this.node.setStyle("overflow","visible");
  884. var input=null;
  885. MWF.require("MWF.widget.Combox", function(){
  886. this.combox = input = new MWF.widget.Combox({
  887. "count": this.json.count || 0,
  888. "splitShow": this.json.splitShow || ", ",
  889. "onCommitInput": function(item){
  890. this._searchConfirmPerson(item);
  891. //this.fireEvent("change");
  892. }.bind(this),
  893. "onChange": function(){
  894. this.node.store("data", this.getInputData());
  895. this._setBusinessData(this.getInputData());
  896. this.fireEvent("change");
  897. }.bind(this),
  898. "optionsMethod": this._searchOptions.bind(this)
  899. });
  900. }.bind(this), false);
  901. input.setStyles({
  902. "background": "transparent",
  903. "border": "0px"
  904. });
  905. input.set(this.json.properties);
  906. if (!this.json.preprocessing) this._resetNodeInputEdit();
  907. this.node.empty();
  908. input.inject(this.node);
  909. this.node.set({
  910. "id": this.json.id,
  911. "MWFType": this.json.type
  912. });
  913. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  914. this.iconNode = new Element("div", {
  915. "styles": this.form.css[this.iconStyle],
  916. "events": {
  917. "click": function (ev) {
  918. this.clickSelect(ev);
  919. }.bind(this)
  920. //this.clickSelect.bind(this)
  921. }
  922. }).inject(this.node, "before");
  923. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  924. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  925. }
  926. this.combox.addEvent("change", function(){
  927. this.validationMode();
  928. if (this.validation()){
  929. this.node.store("data", this.getInputData());
  930. this._setBusinessData(this.getInputData("change"));
  931. }
  932. }.bind(this));
  933. },
  934. _resetNodeEdit: function(){
  935. var input = new Element("div", {
  936. "styles": {
  937. "background": "transparent",
  938. "border": "0px",
  939. "min-height": "24px"
  940. }
  941. });
  942. var node = new Element("div", {"styles": {
  943. "overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
  944. "position": "relative",
  945. "margin-right": this.hasIcon() ? "20px" : "0px",
  946. "min-height": "24px"
  947. }}).inject(this.node, "after");
  948. input.inject(node);
  949. this.node.destroy();
  950. this.node = node;
  951. },
  952. _loadNodeEdit: function(){
  953. if (!this.json.preprocessing) this._resetNodeEdit();
  954. var input = this.node.getFirst();
  955. if( !input && this.nodeHtml ){
  956. this.node.set("html", this.nodeHtml);
  957. input = this.node.getFirst();
  958. }
  959. input.set(this.json.properties);
  960. this.node.set({
  961. "id": this.json.id,
  962. "MWFType": this.json.type,
  963. "events": {
  964. "click": function (ev) {
  965. this.clickSelect(ev);
  966. }.bind(this)
  967. //this.clickSelect.bind(this)
  968. }
  969. });
  970. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  971. this.iconNode = new Element("div", {
  972. "styles": this.form.css[this.iconStyle],
  973. "events": {
  974. "click": function (ev) {
  975. this.clickSelect(ev);
  976. }.bind(this)
  977. //this.clickSelect.bind(this)
  978. }
  979. }).inject(this.node, "before");
  980. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  981. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  982. }
  983. this.node.getFirst().setStyle("height", "auto");
  984. this.node.getFirst().addEvent("change", function(){
  985. this.validationMode();
  986. if (this.validation()){
  987. this.node.store("data", this.getInputData());
  988. this._setBusinessData(this.getInputData("change"));
  989. }
  990. }.bind(this));
  991. },
  992. getDataText: function(data){
  993. if (typeOf(data)=="string") return data;
  994. if( !data || !data.distinguishedName )return "";
  995. var text = "";
  996. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  997. switch (flag.toLowerCase()){
  998. case "@i":
  999. text = data.name+"("+data.unitName+")";
  1000. break;
  1001. case "@p":
  1002. text = data.name+ (data.employee ? ("("+data.employee+")") : "");
  1003. break;
  1004. case "@u":
  1005. text = data.name;
  1006. break;
  1007. case "@g":
  1008. text = data.name;
  1009. break;
  1010. default:
  1011. text = data.name;
  1012. }
  1013. return text;
  1014. },
  1015. addData: function(value){
  1016. if (!value) return false;
  1017. var simple = this.json.storeRange === "simple";
  1018. value.each(function(v){
  1019. var vtype = typeOf(v);
  1020. if (vtype==="string"){
  1021. var data;
  1022. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, v, false);
  1023. if (data) this.combox.addNewValue(this.getDataText(data), data);
  1024. }
  1025. if (vtype==="object"){
  1026. var d = MWF.org.parseOrgData(v, true, simple);
  1027. this.combox.addNewValue(this.getDataText(d), d);
  1028. }
  1029. }.bind(this));
  1030. },
  1031. checkChange: function(oldValues, values){
  1032. var change = false;
  1033. if (!values) values = [];
  1034. if (oldValues.length && (values && values.length)){
  1035. if (oldValues.length === values.length){
  1036. for (var i=0; i<oldValues.length; i++){
  1037. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1038. change = true;
  1039. break;
  1040. }
  1041. }
  1042. }else{
  1043. change = true;
  1044. }
  1045. }else if (values.length || oldValues.length) {
  1046. change = true;
  1047. }
  1048. if (change) this.fireEvent("change");
  1049. },
  1050. setData: function(value, fireChange){
  1051. // if (!value) return false;
  1052. var oldValues = this.getData();
  1053. if (value.length==1 && !(value[0])) value=[];
  1054. var promise = this._setValue(value);
  1055. if (fireChange) Promise.resolve(promise).then(function(values){
  1056. o2.promiseAll(values).then(function(v){
  1057. this.checkChange(oldValues, v)
  1058. }.bind(this), function(){});
  1059. }.bind(this), function(){});
  1060. },
  1061. // __setData: function(value){
  1062. // if (!value) return false;
  1063. // var oldValues = this.getData();
  1064. // var values = [];
  1065. // var comboxValues = [];
  1066. //
  1067. // var simple = this.json.storeRange === "simple";
  1068. //
  1069. // var type = typeOf(value);
  1070. // if (type==="array"){
  1071. // value.each(function(v){
  1072. // var vtype = typeOf(v);
  1073. // var data = null;
  1074. // if (vtype==="string"){
  1075. // var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  1076. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  1077. // }
  1078. // if (vtype==="object") {
  1079. // data = MWF.org.parseOrgData(v, true, simple);
  1080. // if(data.woPerson)delete data.woPerson;
  1081. // }
  1082. // if (data){
  1083. // values.push(data);
  1084. // comboxValues.push({"text": this.getDataText(data),"value": data});
  1085. // }
  1086. // }.bind(this));
  1087. // }
  1088. // if (type==="string"){
  1089. // var vData;
  1090. // var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  1091. // this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
  1092. // if (vData){
  1093. // values.push(vData);
  1094. // comboxValues.push({"text": this.getDataText(vData),"value": vData});
  1095. // }
  1096. // }
  1097. // if (type==="object"){
  1098. // var vData = MWF.org.parseOrgData(value, true, simple);
  1099. // if(vData.woPerson)delete vData.woPerson;
  1100. // values.push( vData );
  1101. // comboxValues.push({"text": this.getDataText(value),"value": vData});
  1102. // }
  1103. //
  1104. // var change = false;
  1105. // if (oldValues.length && values.length){
  1106. // if (oldValues.length === values.length){
  1107. // for (var i=0; i<oldValues.length; i++){
  1108. // if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1109. // change = true;
  1110. // break;
  1111. // }
  1112. // }
  1113. // }else{
  1114. // change = true;
  1115. // }
  1116. // }else if (values.length || oldValues.length) {
  1117. // change = true;
  1118. // }
  1119. // this._setBusinessData(values);
  1120. // if (change) this.fireEvent("change");
  1121. //
  1122. // if (this.json.isInput){
  1123. // if (this.combox){
  1124. // this.combox.clear();
  1125. // this.combox.addNewValues(comboxValues);
  1126. // }else{
  1127. // var node = this.node.getFirst();
  1128. // if (node){
  1129. // node.empty();
  1130. // comboxValues.each(function(v, i){
  1131. // this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  1132. // }.bind(this));
  1133. // }
  1134. // }
  1135. // }else{
  1136. // if (this.node.getFirst()){
  1137. // var node = this.node.getFirst();
  1138. // node.empty();
  1139. // this.loadOrgWidget(values, node)
  1140. // }else{
  1141. // this.node.empty();
  1142. // this.loadOrgWidget(values, this.node);
  1143. // }
  1144. // }
  1145. // },
  1146. creteShowNode: function(data, islast){
  1147. var nodeText = (data.text) ? data.text : data;
  1148. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  1149. var node = new Element("div", {
  1150. "styles": {
  1151. "float": "left",
  1152. "margin-right": "5px"
  1153. },
  1154. "text": nodeText
  1155. });
  1156. var text = "";
  1157. if (data.value && data.value.distinguishedName){
  1158. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
  1159. switch (flag.toLowerCase()){
  1160. case "@i":
  1161. text = data.value.name+"("+data.value.unitName+")";
  1162. break;
  1163. case "@p":
  1164. text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
  1165. break;
  1166. case "@u":
  1167. text = data.value.levelName;
  1168. break;
  1169. case "@g":
  1170. text = data.value.name;
  1171. break;
  1172. default:
  1173. text = data.value.name;
  1174. }
  1175. var inforNode = new Element("div").set({
  1176. "styles": {"font-size": "14px", "color": ""},
  1177. "text": text
  1178. });
  1179. new mBox.Tooltip({
  1180. content: inforNode,
  1181. setStyles: {content: {padding: 15, lineHeight: 20}},
  1182. attach: node,
  1183. transition: 'flyin'
  1184. });
  1185. }
  1186. return node;
  1187. },
  1188. _setValue: function(value){
  1189. var values = [];
  1190. var ags = [];
  1191. var simple = this.json.storeRange === "simple";
  1192. var flag = false;
  1193. if (typeOf(value)!=="array") value = (!!value) ? [value] : [];
  1194. //value = (value.flat) ? value.flat() : value.flatten();
  1195. if (value.some(function(e){ return (e && o2.typeOf(e.then)=="function") }) || this.json.asyncMode==="yes"){
  1196. var p = Promise.all(value).then(function(d){
  1197. if (typeOf(d)!=="array") d = (!!d) ? [d] : [];
  1198. d.each(function(da){
  1199. if (typeOf(da)!=="array") da = (!!da) ? [da] : [];
  1200. da.each(function(dd){
  1201. if (dd){
  1202. if (typeOf(dd)==="string"){
  1203. var pp = this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1204. return MWF.org.parseOrgData(json.data, true, simple);
  1205. }.bind(this), null, dd, true).catch(function(e){
  1206. console.log("error:" + e);
  1207. console.log(e);
  1208. });
  1209. ags.push(pp);
  1210. }else{
  1211. values.push(dd);
  1212. }
  1213. }
  1214. }.bind(this));
  1215. }.bind(this));
  1216. if (ags.length){
  1217. return Promise.all(ags).then(function(data){
  1218. values = values.concat(data);
  1219. flag = true;
  1220. this.__setValue(values);
  1221. return values;
  1222. }.bind(this), function(){});
  1223. }else{
  1224. flag = true;
  1225. this.__setValue(values);
  1226. return values
  1227. }
  1228. }.bind(this), function(){});
  1229. this.moduleValueAG = p;
  1230. if (p && p.then) p.then(function(){
  1231. this.moduleValueAG = null;
  1232. }.bind(this), function(){
  1233. this.moduleValueAG = null;
  1234. }.bind(this));
  1235. return p;
  1236. }else{
  1237. value.each(function(dd){
  1238. if (dd){
  1239. if (typeOf(dd)==="string"){
  1240. this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1241. values.push(MWF.org.parseOrgData(json.data, true, simple));
  1242. }.bind(this), null, dd, false);
  1243. }else{
  1244. values.push(dd);
  1245. }
  1246. }
  1247. }.bind(this));
  1248. this.__setValue(values);
  1249. return values
  1250. }
  1251. // var ag = o2.AG.all(value).then(function(d) {
  1252. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  1253. //
  1254. // d.each(function(dd){
  1255. // //if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
  1256. // if (dd){
  1257. // if (typeOf(dd)==="string"){
  1258. // ags.push(this.getOrgAction()[this.getValueMethod(dd)](function(json){
  1259. // return MWF.org.parseOrgData(json.data, true, simple);
  1260. // }.bind(this).ag(), null, dd, true));
  1261. // }else{
  1262. // values.push(dd);
  1263. // }
  1264. // }
  1265. // }.bind(this));
  1266. // if (ags.length){
  1267. // return o2.AG.all(ags).then(function(data){
  1268. // values = values.concat(data);
  1269. // flag = true;
  1270. // this.__setValue(values);
  1271. // return values;
  1272. // }.bind(this));
  1273. // }else{
  1274. // flag = true;
  1275. // this.__setValue(values);
  1276. // return values
  1277. // }
  1278. // }.bind(this));
  1279. //
  1280. // this.moduleValueAG = ag;
  1281. // if (ag) ag.then(function(){
  1282. // this.moduleValueAG = null;
  1283. // }.bind(this));
  1284. // return ag;
  1285. },
  1286. __setValue: function(value){
  1287. this.moduleValueAG = null;
  1288. if (value.length==1 && !(value[0])) value=[];
  1289. if (this.json.count>0){
  1290. value = value.slice(0, this.json.count);
  1291. }
  1292. var values = [];
  1293. var comboxValues = [];
  1294. var type = typeOf(value);
  1295. var simple = this.json.storeRange === "simple";
  1296. if (type==="array"){
  1297. value.each(function(v){
  1298. var data=null;
  1299. var vtype = typeOf(v);
  1300. if (vtype==="string"){
  1301. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  1302. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
  1303. }
  1304. if (vtype==="object") data = v;
  1305. if (data){
  1306. var d = MWF.org.parseOrgData(data, true, simple)
  1307. values.push(d);
  1308. comboxValues.push({"text": this.getDataText(d),"value": d});
  1309. }
  1310. }.bind(this));
  1311. }
  1312. if (type==="string"){
  1313. var vData;
  1314. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  1315. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true,simple); }.bind(this), error, value, false);
  1316. if (vData){
  1317. values.push(vData);
  1318. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  1319. }
  1320. }
  1321. if (type==="object"){
  1322. var v = MWF.org.parseOrgData(value, true, simple)
  1323. values.push(v);
  1324. comboxValues.push({"text": this.getDataText(v),"value": v});
  1325. }
  1326. this.node.store("data", values);
  1327. this._setBusinessData(values);
  1328. if (this.json.isInput){
  1329. if (this.combox){
  1330. this.combox.clear();
  1331. this.combox.addNewValues(comboxValues);
  1332. // values.each(function(v){
  1333. // if (typeOf(v)=="string"){
  1334. // this.combox.addNewValue(v);
  1335. // }else{
  1336. // this.combox.addNewValue(this.getDataText(v), v);
  1337. // }
  1338. // }.bind(this));
  1339. }else{
  1340. var node = this.node.getFirst();
  1341. if (node){
  1342. node.empty();
  1343. comboxValues.each(function(v, i){
  1344. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  1345. }.bind(this));
  1346. }
  1347. }
  1348. }else{
  1349. if (this.node.getFirst()){
  1350. var node = this.node.getFirst();
  1351. node.empty();
  1352. this.loadOrgWidget(values, node)
  1353. }else{
  1354. this.node.empty();
  1355. this.loadOrgWidget(values, this.node);
  1356. }
  1357. }
  1358. this.checkDescription();
  1359. this.fieldModuleLoaded = true;
  1360. //if (this.readonly) this.loadOrgWidget(values, this.node)
  1361. //this.node.set("text", value);
  1362. },
  1363. getValueMethod: function(value){
  1364. if (value){
  1365. var flag = value.substr(value.length-2, 2);
  1366. switch (flag.toLowerCase()){
  1367. case "@i":
  1368. return "getIdentity";
  1369. case "@p":
  1370. return "getPerson";
  1371. case "@u":
  1372. return "getUnit";
  1373. case "@g":
  1374. return "getGroup";
  1375. default:
  1376. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1377. }
  1378. }
  1379. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1380. },
  1381. loadOrgWidget: function(value, node){
  1382. var _self = this;
  1383. var disableInfor = layout.mobile ? true : false;
  1384. if( this.json.showCard === "no" )disableInfor = true;
  1385. var canRemove = this.json.canRemove ? true : false;
  1386. var height = node.getStyle("height").toInt();
  1387. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  1388. if (value && value.length){
  1389. value.each(function(data){
  1390. if( !data || !data.distinguishedName )return;
  1391. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  1392. var copyData = Object.clone(data);
  1393. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  1394. this.currentData = copyData;
  1395. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  1396. if( displayName ){
  1397. copyData.displayName = displayName;
  1398. }
  1399. this.currentData = null;
  1400. }
  1401. var opt = {"style": "xform","lazy":true,"disableInfor" : disableInfor, "canRemove":canRemove, "onRemove": function () {
  1402. _self.fireEvent("removeItem", [{
  1403. data: data,
  1404. item: this
  1405. }])
  1406. }, "styles": this.json.itemStyles || "" };
  1407. var widget;
  1408. switch (flag.toLowerCase()){
  1409. case "@i":
  1410. widget = new MWF.widget.O2Identity(copyData, node, opt);
  1411. break;
  1412. case "@p":
  1413. widget = new MWF.widget.O2Person(copyData, node, opt);
  1414. break;
  1415. case "@u":
  1416. widget = new MWF.widget.O2Unit(copyData, node, opt);
  1417. break;
  1418. case "@g":
  1419. widget = new MWF.widget.O2Group(copyData, node, opt);
  1420. break;
  1421. default:
  1422. widget = new MWF.widget.O2Other(copyData, node, opt);
  1423. }
  1424. widget.field = this;
  1425. if( layout.mobile ){
  1426. widget.node.setStyles({
  1427. "float" : "none"
  1428. })
  1429. }
  1430. }.bind(this));
  1431. }
  1432. },
  1433. _loadStyles: function(){
  1434. if (this.isReadonly()){
  1435. if (this.json.styles) this.node.setStyles(this.json.styles);
  1436. }else{
  1437. if (this.json.styles) this.node.setStyles(this.json.styles);
  1438. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  1439. if (this.iconNode && this.iconNode.offsetParent !== null ){
  1440. var size = this.node.getSize();
  1441. this.iconNode.setStyle("height", ""+size.y+"px");
  1442. }
  1443. }
  1444. },
  1445. checkEmpower : function( data, callback ){
  1446. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  1447. var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
  1448. empowerChecker.load(data, callback);
  1449. }else{
  1450. if( callback )callback( data );
  1451. }
  1452. },
  1453. _beforeReloaded: function(){
  1454. this.selector = null;
  1455. if (this.combox) {
  1456. this.combox.clear();
  1457. this.combox = null;
  1458. }
  1459. },
  1460. getExcelData: function(){
  1461. var text, value = this.getData();
  1462. if (o2.typeOf(value) === "array") {
  1463. var textArray = [];
  1464. value.each(function (item) {
  1465. if (o2.typeOf(item) === "object") {
  1466. textArray.push(item.distinguishedName);
  1467. } else {
  1468. textArray.push(item);
  1469. }
  1470. }.bind(this));
  1471. text = textArray.join(", \n");
  1472. } else if (o2.typeOf(value) === "object") {
  1473. text = value.distinguishedName;
  1474. } else {
  1475. text = value;
  1476. }
  1477. return text;
  1478. },
  1479. setExcelData: function(data){
  1480. this.excelData = data;
  1481. this.setData(data, true);
  1482. }
  1483. });
  1484. MWF.APPOrg.EmpowerChecker = new Class({
  1485. Implements: [Events],
  1486. initialize: function (form, json) {
  1487. this.form = form;
  1488. this.json = json;
  1489. this.css = this.form.css;
  1490. this.checkedAllItems = true;
  1491. },
  1492. load : function( data, callback, container ){
  1493. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
  1494. var array = [];
  1495. data.each( function( d ){
  1496. if( d.distinguishedName ){
  1497. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
  1498. if( flag === "i" ){
  1499. array.push( d.distinguishedName )
  1500. }
  1501. }
  1502. }.bind(this));
  1503. if( array.length > 0 ){
  1504. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  1505. "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
  1506. "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
  1507. "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
  1508. "identityList" : array
  1509. }, function( json ){
  1510. var arr = [];
  1511. json.data.each( function(d){
  1512. if(d.fromIdentity !== d.toIdentity )arr.push(d);
  1513. });
  1514. if( arr.length > 0 ){
  1515. this.openSelectEmpowerDlg( arr, data, callback, container );
  1516. }else{
  1517. if( callback )callback( data );
  1518. }
  1519. }.bind(this), function(){
  1520. if( callback )callback( data );
  1521. }.bind(this))
  1522. }else{
  1523. if( callback )callback( data );
  1524. }
  1525. }else{
  1526. if( callback )callback( data );
  1527. }
  1528. },
  1529. getIgnoreEmpowerArray : function( callback ){
  1530. var array = [];
  1531. if( this.empowerSelectNodes && this.empowerSelectNodes.length ){
  1532. this.empowerSelectNodes.each(function(node){
  1533. if( !node.retrieve("isSelected") ){
  1534. var d = node.retrieve("data");
  1535. array.push( d.fromIdentity );
  1536. }
  1537. }.bind(this));
  1538. }
  1539. if( callback )callback( array );
  1540. return array;
  1541. },
  1542. setIgnoreEmpowerFlag : function(data, callback){
  1543. var ignoreList = this.getIgnoreEmpowerArray();
  1544. for( var i=0; i<data.length; i++ ){
  1545. var d = data[i];
  1546. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1547. d.ignoreEmpower = true;
  1548. }else if( d.ignoreEmpower ){
  1549. delete d.ignoreEmpower;
  1550. }
  1551. }
  1552. if( callback )callback( data );
  1553. },
  1554. replaceEmpowerIdentity : function(data, callback){
  1555. var empowerData = {};
  1556. this.empowerSelectNodes.each(function(node){
  1557. if( node.retrieve("isSelected") ){
  1558. var d = node.retrieve("data");
  1559. empowerData[ d.fromIdentity ] = d;
  1560. }
  1561. }.bind(this));
  1562. if( Object.keys(empowerData).length === 0 ){
  1563. callback( data );
  1564. }else{
  1565. var identityList = [];
  1566. for( var key in empowerData ){
  1567. identityList.push( empowerData[key].toIdentity );
  1568. }
  1569. o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
  1570. var newData = data.clone();
  1571. var d = {};
  1572. json.data.each( function(j){
  1573. d[j.distinguishedName] = j;
  1574. });
  1575. for( var i=0; i<newData.length; i++ ){
  1576. var nd = newData[i];
  1577. if( nd.distinguishedName && empowerData[nd.distinguishedName]){
  1578. if( d[empowerData[nd.distinguishedName].toIdentity] ){
  1579. newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
  1580. }
  1581. }
  1582. }
  1583. callback( newData );
  1584. },function(){
  1585. callback( data );
  1586. });
  1587. }
  1588. },
  1589. openSelectEmpowerDlg : function( data, orginData, callback, container ){
  1590. if( layout.mobile ){
  1591. this.openSelectEmpowerDlg_mobile(data, orginData, callback, container);
  1592. }else{
  1593. this.openSelectEmpowerDlg_pc(data, orginData, callback, container);
  1594. }
  1595. },
  1596. openSelectEmpowerDlg_mobile : function( data, orginData, callback, container ){
  1597. var that = this;
  1598. //处理json
  1599. var subItemList = [];
  1600. // var empowerMap = {};
  1601. // var selectableItems = [];
  1602. var valueList = [];
  1603. data.each( function( d ){
  1604. subItemList.push({
  1605. "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
  1606. "id" : d.fromIdentity + "#" + d.toIdentity
  1607. })
  1608. valueList.push({
  1609. "name" : d.fromIdentity.split("@")[0] + " "+MWF.xApplication.process.Xform.LP.empowerTo+" " + d.toIdentity.split("@")[0],
  1610. "id" : d.fromIdentity + "#" + d.toIdentity
  1611. })
  1612. // empowerMap[ d.fromIdentity ] = d.toIdentity;
  1613. }.bind(this));
  1614. if( subItemList.length === 0 ){
  1615. callback();
  1616. return;
  1617. }
  1618. var empowerList = Array.clone(subItemList);
  1619. // selectableItems.push({
  1620. // "empowerMap" : empowerMap,
  1621. // "subItemList" : subItemList
  1622. // });
  1623. // if( selectableItems.length === 0 ){
  1624. // callback();
  1625. // return;
  1626. // }
  1627. // var empowerList = Array.clone(selectableItems);
  1628. o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
  1629. var options = {
  1630. "count": 0,
  1631. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1632. "selectAllEnable" : true,
  1633. "selectableItems": subItemList,
  1634. "expand": false,
  1635. "category": false,
  1636. "values": valueList,
  1637. "zIndex" : 3001,
  1638. "closeOnclickOk" : true,
  1639. "onComplete": function (items) {
  1640. var arr = [];
  1641. items.each(function (item) {
  1642. arr.push( item.data.id )
  1643. }.bind(this));
  1644. var ignoreList = [];
  1645. empowerList.each( function (obj) {
  1646. if( arr.indexOf( obj.id ) === -1 )ignoreList.push( obj.id.split("#")[0] )
  1647. });
  1648. for( var i=0; i<orginData.length; i++ ){
  1649. var d = orginData[i];
  1650. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1651. d.ignoreEmpower = true;
  1652. }else if( d.ignoreEmpower ){
  1653. delete d.ignoreEmpower;
  1654. }
  1655. }
  1656. if( callback )callback( orginData );
  1657. // empowerList.each( function(obj){
  1658. // var list = obj.subItemList.filter(function(item, index){
  1659. // return !arr.contains( item.id );
  1660. // }.bind(this));
  1661. // ignoreList = ignoreList.map(function(item,index){
  1662. // return item.id.split("#")[1];
  1663. // })
  1664. // });
  1665. // empowerList.each( function(obj){
  1666. // var org = that.orgItemsObject[obj.orgId];
  1667. // // if( obj.ignoreList.length > 0 ){
  1668. // var data = org.getData();
  1669. // for( var i=0; i<data.length; i++ ){
  1670. // var d = data[i];
  1671. // if( obj.ignoreList.indexOf( d.distinguishedName ) > -1 ){
  1672. // d.ignoreEmpower = true;
  1673. // }else if( d.ignoreEmpower ){
  1674. // delete d.ignoreEmpower;
  1675. // }
  1676. // }
  1677. // org.setData( data );
  1678. // }
  1679. // if( obj.empowerMap ){
  1680. // var data = org.getValue();
  1681. // for( var i=0; i<data.length; i++ ){
  1682. // var d = data[i];
  1683. // if( obj.empowerMap[ d.distinguishedName ] ){
  1684. // d.empowerToIdentity = obj.empowerMap[ d.distinguishedName ];
  1685. // }
  1686. // }
  1687. // org.empowerData = Array.clone(data);
  1688. // }
  1689. // if(callback)callback();
  1690. // })
  1691. }.bind(this)
  1692. };
  1693. if( this.form.json.selectorStyle ){
  1694. Object.merge(options, this.form.json.selectorStyle );
  1695. }
  1696. options.flatCategory = false;
  1697. var selector = new o2.xApplication.Template.Selector.Custom($(document.body), options);
  1698. selector.load();
  1699. }.bind(this))
  1700. },
  1701. openSelectEmpowerDlg_pc : function( data, orginData, callback, container ){
  1702. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  1703. var html = "<div style=\"line-height: 20px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  1704. html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1705. node.set("html", html);
  1706. var itemNode = node.getLast();
  1707. this.getEmpowerItems(itemNode, data);
  1708. node.inject( container || this.form.app.content);
  1709. var dlg = o2.DL.open({
  1710. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1711. "style": this.form.json.dialogStyle || "user",
  1712. "isResize": true,
  1713. "content": node,
  1714. "width": 630,
  1715. //"height" : 500,
  1716. "buttonList": [
  1717. {
  1718. "type" : "ok",
  1719. "text": MWF.LP.process.button.ok,
  1720. "action": function(d, e){
  1721. //this.replaceEmpowerIdentity( orginData, callback ); //直接替换已授权的人,已废弃
  1722. this.setIgnoreEmpowerFlag( orginData, callback ); //然后设置忽略的人的标志
  1723. dlg.close();
  1724. }.bind(this)
  1725. },
  1726. {
  1727. "type" : "cancel",
  1728. "text": MWF.LP.process.button.cancel,
  1729. "action": function(){dlg.close();}
  1730. }
  1731. ],
  1732. "onPostShow": function(){
  1733. var selectNode = this.createSelectAllEmpowerNode();
  1734. selectNode.inject( dlg.button );
  1735. if( layout.mobile ){
  1736. dlg.node.inject( $(document.body) );
  1737. dlg.node.setStyles({
  1738. "width":"100%",
  1739. "height": "100%",
  1740. "top" : "0px",
  1741. "left" : "0px"
  1742. });
  1743. var y = dlg.node.getSize().y - 190;
  1744. itemNode.setStyle("height",y+"px");
  1745. dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
  1746. dlg.setContentSize();
  1747. }else{
  1748. dlg.content.setStyle("overflow","hidden");
  1749. var y = Math.min(300, itemNode.getSize().y);
  1750. var marginTop = itemNode.getStyle("margin-top");
  1751. var marginBottom = itemNode.getStyle("margin-bottom");
  1752. itemNode.setStyle("height",y+"px");
  1753. dlg.options.contentHeight = y + 30 + 20 ; //+100;
  1754. dlg.setContentSize();
  1755. dlg.node.setStyles({
  1756. "height": ""+(dlg.options.height) +"px"
  1757. });
  1758. dlg.reCenter();
  1759. }
  1760. }.bind(this)
  1761. });
  1762. },
  1763. getEmpowerItems: function(itemNode, data){
  1764. var _self = this;
  1765. this.empowerSelectNodes = [];
  1766. var count = 1;
  1767. var node;
  1768. data.each(function( d ){
  1769. if(d.fromIdentity == d.toIdentity )return;
  1770. if( count % 2 === 1 ){
  1771. node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
  1772. node.store("nodeType","Odd");
  1773. //node.setStyle("margin-right","10px");
  1774. }else{
  1775. node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
  1776. node.store("nodeType","Even");
  1777. }
  1778. count++;
  1779. this.empowerSelectNodes.push( node );
  1780. node.store("data", d);
  1781. var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
  1782. node.store("iconNode",iconNode);
  1783. var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
  1784. var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
  1785. var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
  1786. var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
  1787. node.addEvents({
  1788. "mouseover": function(){
  1789. var isSelected = this.retrieve("isSelected");
  1790. if (!isSelected){
  1791. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
  1792. if( _self.css.empowerItemIconNode_over ){
  1793. var iconNode = this.retrieve("iconNode");
  1794. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
  1795. }
  1796. }
  1797. },
  1798. "mouseout": function(){
  1799. var isSelected = this.retrieve("isSelected");
  1800. if (!isSelected){
  1801. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
  1802. if( _self.css.empowerItemIconNode_over ){
  1803. var iconNode = this.retrieve("iconNode");
  1804. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
  1805. }
  1806. }
  1807. },
  1808. "click": function(){
  1809. var isSelected = this.retrieve("isSelected");
  1810. if (isSelected){
  1811. _self.unselectEmpowerItem( this)
  1812. }else{
  1813. _self.selectEmpowerItem(this)
  1814. }
  1815. }
  1816. });
  1817. if( this.checkedAllItems )node.click();
  1818. }.bind(this));
  1819. },
  1820. unselectEmpowerItem : function( itemNode ){
  1821. itemNode.store("isSelected", false);
  1822. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
  1823. itemNode.getElements("div").each( function( div ){
  1824. var className = div.get("class");
  1825. if( className && this.css[className] )div.setStyles( this.css[className] )
  1826. }.bind(this))
  1827. },
  1828. selectEmpowerItem : function( itemNode ){
  1829. itemNode.store("isSelected", true);
  1830. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
  1831. itemNode.getElements("div").each( function( div ){
  1832. var className = div.get("class");
  1833. if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
  1834. }.bind(this))
  1835. },
  1836. createSelectAllEmpowerNode : function(){
  1837. var _self = this;
  1838. var node = new Element("div", {
  1839. styles : this.css.empowerSelectAllItemNode,
  1840. text : MWF.xApplication.process.Xform.LP.selectAll
  1841. });
  1842. node.addEvents({
  1843. "mouseover": function(){
  1844. var isSelected = this.retrieve("isSelected");
  1845. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
  1846. },
  1847. "mouseout": function(){
  1848. var isSelected = this.retrieve("isSelected");
  1849. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
  1850. },
  1851. "click": function(){
  1852. var isSelected = this.retrieve("isSelected");
  1853. if (isSelected){
  1854. this.store("isSelected", false);
  1855. this.setStyles( _self.css.empowerSelectAllItemNode );
  1856. _self.empowerSelectNodes.each( function(itemNode){
  1857. _self.unselectEmpowerItem(itemNode)
  1858. }.bind(this))
  1859. }else{
  1860. this.store("isSelected", true);
  1861. this.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1862. _self.empowerSelectNodes.each( function(itemNode){
  1863. _self.selectEmpowerItem(itemNode)
  1864. }.bind(this))
  1865. }
  1866. }
  1867. });
  1868. if( this.checkedAllItems ){
  1869. node.store("isSelected", true);
  1870. node.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1871. }
  1872. return node;
  1873. }
  1874. });
  1875. MWF.APPOrg.GroupOptions = new Class({
  1876. Implements: [Events],
  1877. initialize: function (form, json) {
  1878. this.form = form;
  1879. this.json = json;
  1880. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1881. },
  1882. getOptions: function(){
  1883. var count = (this.json.groupCount) ? this.json.groupCount : 0;
  1884. if( this.json.groupRange==="group" ){
  1885. return {
  1886. "count": count,
  1887. "storeRange" : this.json.storeRange,
  1888. "include": this.getSelectRange( true )
  1889. }
  1890. }else{
  1891. return {
  1892. "count": count,
  1893. "storeRange" : this.json.storeRange
  1894. }
  1895. }
  1896. },
  1897. getSearchOptions : function(){
  1898. return {};
  1899. },
  1900. getSelectRange : function( refresh ){
  1901. if( !this.selectRange || refresh){
  1902. this.selectRange = this._getSelectRange();
  1903. }
  1904. return this.selectRange;
  1905. },
  1906. _getSelectRange : function(){
  1907. var rangeValues = [];
  1908. if (this.json.groupRangeKey && this.json.groupRangeKey.code){
  1909. var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
  1910. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1911. rangeValues = v;
  1912. //v.each(function(d){
  1913. // if (d){
  1914. // if (typeOf(d)==="string"){
  1915. // var data;
  1916. // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
  1917. // rangeValues.push(data);
  1918. // }else{
  1919. // rangeValues.push(d);
  1920. // }
  1921. // }
  1922. //}.bind(this));
  1923. }
  1924. return rangeValues;
  1925. }
  1926. });
  1927. MWF.APPOrg.UnitOptions = new Class({
  1928. Implements: [Events],
  1929. initialize : function( form, json ){
  1930. this.form = form;
  1931. this.json = json;
  1932. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1933. },
  1934. getOptions: function(){
  1935. var count = (this.json.unitCount) ? this.json.unitCount : 0;
  1936. var selectUnits = this.getSelectRange( true );
  1937. return {
  1938. "count": count,
  1939. "units": selectUnits,
  1940. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  1941. "storeRange" : this.json.storeRange,
  1942. "expandSubEnable" : (this.json.unitExpandSubEnable==="no") ? false : true,
  1943. "firstLevelSelectable":this.json.firstLevelSelectable==="yes"
  1944. };
  1945. },
  1946. getSearchOptions : function(){
  1947. var selectUnits = this.getSelectRange( true );
  1948. return {
  1949. "units": selectUnits,
  1950. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
  1951. };
  1952. },
  1953. getSelectRange : function( refresh ){
  1954. if( !this.selectRange || refresh){
  1955. this.selectRange = this._getSelectRange();
  1956. }
  1957. return this.selectRange;
  1958. },
  1959. _getSelectRange : function(){
  1960. if (this.json.unitRange==="unit"){
  1961. return this.getScriptSelectUnit();
  1962. }
  1963. if (this.json.unitRange==="draftUnit"){
  1964. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1965. if (!dn){
  1966. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1967. var ids = [];
  1968. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1969. return this.getNextSelectUnit(ids);
  1970. }else{
  1971. return [];
  1972. }
  1973. }else{
  1974. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1975. }
  1976. }
  1977. if (this.json.unitRange==="currentUnit"){
  1978. if (this.form.app.currentTask){
  1979. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1980. }else{
  1981. if (this.form.app.taskList && this.form.app.taskList.length){
  1982. var ids = [];
  1983. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1984. return this.getNextSelectUnit(ids);
  1985. }else{
  1986. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1987. var ids = [];
  1988. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1989. return this.getNextSelectUnit(ids);
  1990. }else{
  1991. return [];
  1992. }
  1993. }
  1994. }
  1995. }
  1996. return [];
  1997. },
  1998. getScriptSelectUnit: function(){
  1999. var rangeValues = [];
  2000. if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
  2001. this.json.unitRangeUnit.each(function(unit){
  2002. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  2003. //if (unitFlag) rangeValues.push(unitFlag);
  2004. rangeValues.push(unit);
  2005. }.bind(this));
  2006. }
  2007. if (this.json.unitRangeField && this.json.unitRangeField.length){
  2008. this.json.unitRangeField.each(function(field){
  2009. var n = (typeOf(field)=="object") ? field.name : field;
  2010. var v = this.form.businessData.data[n];
  2011. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2012. v.each(function(d){
  2013. if (d){
  2014. // if (typeOf(d)==="string"){
  2015. // var data;
  2016. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2017. // rangeValues.push(data);
  2018. // }else{
  2019. rangeValues.push(d);
  2020. // }
  2021. }
  2022. }.bind(this));
  2023. }.bind(this));
  2024. }
  2025. if (this.json.unitRangeKey && this.json.unitRangeKey.code){
  2026. var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
  2027. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2028. v.each(function(d){
  2029. if (d){
  2030. // if (typeOf(d)==="string"){
  2031. // var data;
  2032. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2033. // rangeValues.push(data);
  2034. // }else{
  2035. rangeValues.push(d);
  2036. // }
  2037. }
  2038. }.bind(this));
  2039. }
  2040. return rangeValues;
  2041. },
  2042. getNextSelectUnit: function(id){
  2043. var ids = typeOf(id)==="array" ? id : [id];
  2044. var data;
  2045. var units = [];
  2046. ids.each( function(i){
  2047. if (this.json.unitRangeNext === "direct"){
  2048. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2049. if (data && data.woUnit) units.push(data.woUnit);
  2050. }else if(this.json.unitRangeNext==="level"){
  2051. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2052. if (data) units.push(data);
  2053. }else if (this.json.unitRangeNext==="type"){
  2054. if (this.json.unitRangeNextUnitType==="all"){
  2055. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2056. }else{
  2057. this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2058. }
  2059. if (data) units.push(data);
  2060. }
  2061. data = null;
  2062. }.bind(this));
  2063. return units;
  2064. //if (this.json.unitRangeNext === "direct"){
  2065. // if (typeOf(id)==="array"){
  2066. // var units = [];
  2067. // id.each(function(i){
  2068. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2069. // if (data && data.woUnit) units.push(data.woUnit);
  2070. // data = null;
  2071. // }.bind(this));
  2072. // return units;
  2073. // }else{
  2074. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  2075. // return (data.woUnit) ? [data.woUnit] : [];
  2076. // }
  2077. //}
  2078. //if (this.json.unitRangeNext==="level"){
  2079. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2080. // //this.json.rangeNextLevel
  2081. // return (data) ? [data] : [];
  2082. //}
  2083. //if (this.json.unitRangeNext==="type"){
  2084. // if (this.json.unitRangeNextUnitType==="all"){
  2085. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2086. // }else{
  2087. // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2088. // }
  2089. //
  2090. // return (data) ? [data] : [];
  2091. //}
  2092. }
  2093. });
  2094. MWF.APPOrg.IdentityOptions = new Class({
  2095. Implements: [Events],
  2096. initialize : function( form, json ){
  2097. this.form = form;
  2098. this.json = json;
  2099. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  2100. },
  2101. getOptions: function(){
  2102. var count = (this.json.identityCount) ? this.json.identityCount : 0;
  2103. if( this.json.identityOnlyUseInclude ){
  2104. return {
  2105. "noUnit" : true,
  2106. "count": count,
  2107. "resultType" : this.json.identityResultType,
  2108. "storeRange" : this.json.storeRange,
  2109. "include" : this._getInclude()
  2110. };
  2111. }else{
  2112. var selectUnits = this.getSelectRange( true );
  2113. var selectDutys = this.getSelectRangeDuty( true );
  2114. return {
  2115. "count": count,
  2116. "units": selectUnits,
  2117. "unitType": this.json.unitType || "",
  2118. "dutys": selectDutys,
  2119. "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
  2120. "resultType" : this.json.identityResultType,
  2121. "categoryType": this.json.categoryType || "unit",
  2122. "dutyUnitLevelBy" : this.json.dutyUnitLevelBy || "duty",
  2123. "storeRange" : this.json.storeRange,
  2124. "include" : this._getInclude()
  2125. };
  2126. }
  2127. },
  2128. getSearchOptions : function(){
  2129. var selectUnits = this.getSelectRange( true );
  2130. var selectDutys = this.getSelectRangeDuty( true );
  2131. return {
  2132. "units": selectUnits,
  2133. "dutys": selectDutys,
  2134. "resultType" : this.json.identityResultType
  2135. };
  2136. },
  2137. getSelectRange : function( refresh ){
  2138. if( !this.selectRange || refresh ){
  2139. this.selectRange = this._getSelectRange();
  2140. }
  2141. return this.selectRange;
  2142. },
  2143. _getInclude : function(){
  2144. var include = [];
  2145. if( this.json.identityIncludeKey ){
  2146. var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
  2147. if( v )include = typeOf(v)==="array" ? v : [v];
  2148. }
  2149. return include;
  2150. },
  2151. _getSelectRange : function(){
  2152. if (this.json.identityRange==="unit"){
  2153. return this.getScriptSelectUnit();
  2154. }
  2155. if (this.json.identityRange==="draftUnit"){
  2156. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  2157. if (!dn){
  2158. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  2159. var ids = [];
  2160. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  2161. return this.getNextSelectUnit(ids);
  2162. }else{
  2163. return [];
  2164. }
  2165. }else{
  2166. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  2167. }
  2168. }
  2169. if (this.json.identityRange==="currentUnit"){
  2170. if (this.form.app.currentTask){
  2171. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  2172. }else{
  2173. if (this.form.app.taskList && this.form.app.taskList.length){
  2174. var ids = [];
  2175. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  2176. return this.getNextSelectUnit(ids);
  2177. }else{
  2178. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  2179. var ids = [];
  2180. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  2181. return this.getNextSelectUnit(ids);
  2182. }else{
  2183. return [];
  2184. }
  2185. }
  2186. }
  2187. }
  2188. return [];
  2189. },
  2190. getScriptSelectUnit: function(){
  2191. var rangeValues = [];
  2192. if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
  2193. this.json.identityRangeUnit.each(function(unit){
  2194. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
  2195. //if (unitFlag) rangeValues.push(unitFlag);
  2196. rangeValues.push(unit);
  2197. }.bind(this));
  2198. }
  2199. if (this.json.identityRangeField && this.json.identityRangeField.length){
  2200. this.json.identityRangeField.each(function(field){
  2201. var n = (typeOf(field)=="object") ? field.name : field;
  2202. var v = this.form.businessData.data[n];
  2203. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2204. v.each(function(d){
  2205. if (d){
  2206. // if (typeOf(d)==="string"){
  2207. // var data;
  2208. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2209. // rangeValues.push(data);
  2210. // }else{
  2211. rangeValues.push(d);
  2212. // }
  2213. }
  2214. }.bind(this));
  2215. }.bind(this));
  2216. }
  2217. if (this.json.identityRangeKey && this.json.identityRangeKey.code){
  2218. var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
  2219. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2220. v.each(function(d){
  2221. if (d){
  2222. // if (typeOf(d)==="string"){
  2223. // var data;
  2224. // this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  2225. // rangeValues.push(data);
  2226. // }else{
  2227. rangeValues.push(d);
  2228. // }
  2229. }
  2230. }.bind(this));
  2231. }
  2232. return rangeValues;
  2233. },
  2234. getNextSelectUnit: function(id){
  2235. var ids = typeOf(id)==="array" ? id : [id];
  2236. var data;
  2237. var units = [];
  2238. ids.each(function(i){
  2239. if (this.json.identityRangeNext === "direct"){
  2240. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2241. if (data && data.woUnit) units.push(data.woUnit);
  2242. }else if (this.json.identityRangeNext==="level"){
  2243. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2244. if (data) units.push(data);
  2245. }else if (this.json.identityRangeNext==="type"){
  2246. if (this.json.identityRangeNextUnitType==="all"){
  2247. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2248. }else{
  2249. this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2250. }
  2251. if (data) units.push(data);
  2252. }
  2253. data = null;
  2254. }.bind(this));
  2255. return units;
  2256. //if (this.json.identityRangeNext === "direct"){
  2257. //if (typeOf(id)==="array"){
  2258. // var units = [];
  2259. // id.each(function(i){
  2260. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  2261. // if (data && data.woUnit) units.push(data.woUnit);
  2262. // data = null;
  2263. // }.bind(this));
  2264. // return units;
  2265. //}else{
  2266. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  2267. // return (data.woUnit) ? [data.woUnit] : [];
  2268. //}
  2269. //}
  2270. //if (this.json.identityRangeNext==="level"){
  2271. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2272. // return (data) ? [data] : [];
  2273. // //this.json.rangeNextLevel
  2274. //}
  2275. //if (this.json.identityRangeNext==="type"){
  2276. // if (this.json.identityRangeNextUnitType==="all"){
  2277. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2278. // }else{
  2279. // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  2280. // }
  2281. // return (data) ? [data] : [];
  2282. //}
  2283. },
  2284. getSelectRangeDuty: function( refresh ){
  2285. if( !this.selectRangeDuty || refresh ){
  2286. this.selectRangeDuty = this._getSelectRangeDuty();
  2287. }
  2288. return this.selectRangeDuty;
  2289. },
  2290. _getSelectRangeDuty: function(){
  2291. if (this.json.dutyRange==="duty"){
  2292. return this.getScriptSelectDuty();
  2293. }
  2294. return [];
  2295. },
  2296. getScriptSelectDuty: function(){
  2297. var rangeValues = [];
  2298. if( this.json.rangeDuty && this.json.rangeDuty.length ){
  2299. var rangeDuty = this.json.rangeDuty;
  2300. if( typeOf(rangeDuty) === "string" ){
  2301. rangeDuty = JSON.parse( rangeDuty );
  2302. }
  2303. if( typeOf(rangeDuty) === "array" ){
  2304. rangeDuty.each(function(unit){
  2305. var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
  2306. if (unitFlag) rangeValues.push(unitFlag);
  2307. }.bind(this));
  2308. }
  2309. }
  2310. //if (this.json.rangeDuty && this.json.rangeDuty.length){
  2311. // this.json.rangeDuty.each(function(unit){
  2312. // var unitFlag = unit.id || unit.name;
  2313. // if (unitFlag) rangeValues.push(unitFlag);
  2314. // }.bind(this));
  2315. //}
  2316. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  2317. this.json.rangeDutyField.each(function(field){
  2318. var n = (typeOf(field)=="object") ? field.name : field;
  2319. var v = this.form.businessData.data[n];
  2320. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2321. v.each(function(d){
  2322. if (d) rangeValues.push(d);
  2323. }.bind(this));
  2324. }.bind(this));
  2325. }
  2326. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  2327. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  2328. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  2329. v.each(function(d){
  2330. if (d) rangeValues.push(d);
  2331. }.bind(this));
  2332. }
  2333. return rangeValues;
  2334. }
  2335. });