Org.js 96 KB

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