Org.js 82 KB

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