Org.js 95 KB

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