Org.js 96 KB

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