Org.js 88 KB

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