Org.js 96 KB

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