Org.js 95 KB

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