Org.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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. "readonly": true
  10. },
  11. iconStyle: "orgIcon",
  12. getTextData: function(){
  13. //var value = this.node.get("value");
  14. //var text = this.node.get("text");
  15. var value = this.getValue();
  16. //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  17. var text = [];
  18. value.each(function(v){
  19. if( typeOf(v) === "string" ){ //������������
  20. text.push(v);
  21. }else{
  22. text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
  23. }
  24. }.bind(this));
  25. return {"value": value || "", "text": [text.join(",")]};
  26. },
  27. loadDescription: function(){
  28. if (this.readonly || this.json.isReadonly)return;
  29. var v = this._getBusinessData();
  30. if (!v || !v.length){
  31. if (this.json.description){
  32. var size = this.node.getFirst().getSize();
  33. var w = size.x-3;
  34. if (COMMON.Browser.safari) w = w-20;
  35. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  36. this.descriptionNode.setStyles({
  37. "width": ""+w+"px",
  38. "height": ""+size.y+"px",
  39. "line-height": ""+size.y+"px"
  40. });
  41. this.setDescriptionEvent();
  42. }
  43. }
  44. },
  45. setDescriptionEvent: function(){
  46. if (this.descriptionNode){
  47. this.descriptionNode.addEvents({
  48. "mousedown": function(){
  49. this.descriptionNode.setStyle("display", "none");
  50. this.clickSelect();
  51. }.bind(this)
  52. });
  53. }
  54. },
  55. _loadNode: function(){
  56. this.field = true;
  57. if (this.readonly || this.json.isReadonly){
  58. this._loadNodeRead();
  59. }else{
  60. this._getOrgOptions();
  61. if (this.json.isInput){
  62. this._loadNodeInputEdit();
  63. }else{
  64. this._loadNodeEdit();
  65. }
  66. }
  67. },
  68. _getOrgOptions: function(){
  69. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  70. if( this.selectTypeList.contains( "identity" ) ) {
  71. this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
  72. }
  73. if( this.selectTypeList.contains( "unit" ) ) {
  74. this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
  75. }
  76. if( this.selectTypeList.contains( "group" ) ){
  77. this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  78. }
  79. //this.selectUnits = this.getSelectRange();
  80. //if (this.json.selectType=="identity"){
  81. // this.selectDutys = this.getSelectRangeDuty();
  82. //}
  83. },
  84. _computeValue: function(){
  85. var values = [];
  86. if (this.json.identityValue) {
  87. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  88. }
  89. if (this.json.unitValue) {
  90. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  91. }
  92. if (this.json.dutyValue) {
  93. var dutys = JSON.decode(this.json.dutyValue);
  94. var par;
  95. if (dutys.length){
  96. dutys.each(function(duty){
  97. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  98. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  99. //var code = "return this.org.getDepartmentDuty({\"name\": \""+duty.name+"\", \"departmentName\": \""+par+"\"})";
  100. var d = this.form.Macro.exec(code, this);
  101. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  102. d.each(function(dd){if (dd) values.push(dd);});
  103. // code = "return this.org.getCompanyDuty({\"name\": \""+duty.name+"\", \"compName\": \""+par+"\"})";
  104. // d = this.form.Macro.exec(code, this);
  105. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  106. // d.each(function(dd){values.push(dd);});
  107. }.bind(this));
  108. }
  109. }
  110. if (this.json.defaultValue && this.json.defaultValue.code){
  111. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  112. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  113. fd.each(function(fdd){
  114. if (fdd){
  115. if (typeOf(fdd)==="string"){
  116. var data;
  117. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
  118. values.push(data);
  119. }else{
  120. values.push(fdd);
  121. }
  122. }
  123. }.bind(this));
  124. }
  125. if (this.json.count>0){
  126. return values.slice(0, this.json.count);
  127. }
  128. return values;
  129. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  130. },
  131. getOrgAction: function(){
  132. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  133. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  134. return this.orgAction;
  135. },
  136. getOptions: function(){
  137. if( this.selectTypeList.length === 0 )return false;
  138. var values = this.getInputData();
  139. var exclude = [];
  140. if( this.json.exclude ){
  141. var v = this.form.Macro.exec(this.json.exclude.code, this);
  142. exclude = typeOf(v)==="array" ? v : [v];
  143. }
  144. //var count = (this.json.count) ? this.json.count : 0;
  145. var identityOpt;
  146. if( this.identityOptions ){
  147. identityOpt = this.identityOptions.getOptions();
  148. if (this.json.identityRange!=="all"){
  149. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  150. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  151. return false;
  152. }
  153. }
  154. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  155. if (!identityOpt.dutys || !identityOpt.dutys.length){
  156. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  157. return false;
  158. }
  159. }
  160. identityOpt.values = (this.json.isInput) ? [] : values;
  161. identityOpt.exclude = exclude;
  162. if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
  163. }
  164. var unitOpt;
  165. if( this.unitOptions ){
  166. unitOpt = this.unitOptions.getOptions();
  167. if (this.json.unitRange!=="all"){
  168. if ( !unitOpt.units || !unitOpt.units.length){
  169. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  170. return false;
  171. }
  172. }
  173. unitOpt.values = (this.json.isInput) ? [] : values;
  174. unitOpt.exclude = exclude;
  175. if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
  176. }
  177. var groupOpt;
  178. if( this.groupOptions ){
  179. groupOpt = this.groupOptions.getOptions();
  180. groupOpt.values = (this.json.isInput) ? [] : values;
  181. groupOpt.exclude = exclude;
  182. if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
  183. }
  184. //var selectUnits = this.getSelectRange();
  185. //if (this.json.selectType=="identity"){
  186. // var selectDutys = this.getSelectRangeDuty();
  187. //}
  188. //if (this.json.range!=="all"){
  189. // if (!selectUnits.length){
  190. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  191. // return false;
  192. // }
  193. //}
  194. //if (this.json.selectType=="identity"){
  195. // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  196. // if (!selectDutys || !selectDutys.length){
  197. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  198. // return false;
  199. // }
  200. // }
  201. //}
  202. if( this.selectTypeList.length === 1 ){
  203. return Object.merge( {
  204. "type": this.selectTypeList[0],
  205. "onComplete": function(items){
  206. this.selectOnComplete(items);
  207. }.bind(this),
  208. "onCancel": this.selectOnCancel.bind(this),
  209. "onLoad": this.selectOnLoad.bind(this),
  210. "onClose": this.selectOnClose.bind(this)
  211. }, identityOpt || unitOpt || groupOpt )
  212. }else if( this.selectTypeList.length > 1 ){
  213. var options = {
  214. "type" : "",
  215. "types" : this.selectTypeList,
  216. "onComplete": function(items){
  217. this.selectOnComplete(items);
  218. }.bind(this),
  219. "onCancel": this.selectOnCancel.bind(this),
  220. "onLoad": this.selectOnLoad.bind(this),
  221. "onClose": this.selectOnClose.bind(this)
  222. };
  223. if( this.form.json.selectorStyle ){
  224. options = Object.merge( options, this.form.json.selectorStyle );
  225. }
  226. if( identityOpt )options.identityOptions = identityOpt;
  227. if( unitOpt )options.unitOptions = unitOpt;
  228. if( groupOpt )options.groupOptions = groupOpt;
  229. return options;
  230. }
  231. //return {
  232. // "type": this.json.selectType,
  233. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  234. // "values": (this.json.isInput) ? [] : values,
  235. // "count": count,
  236. // "units": selectUnits,
  237. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  238. // "exclude" : exclude,
  239. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  240. // "categoryType": this.json.categoryType || "unit",
  241. // "onComplete": function(items){
  242. // this.selectOnComplete(items);
  243. // }.bind(this),
  244. // "onCancel": this.selectOnCancel.bind(this),
  245. // "onLoad": this.selectOnLoad.bind(this),
  246. // "onClose": this.selectOnClose.bind(this)
  247. //};
  248. },
  249. selectOnComplete: function(items){
  250. var array = [];
  251. items.each(function(item){
  252. array.push(item.data);
  253. }.bind(this));
  254. this.checkEmpower( array, function( data ){
  255. var values = [];
  256. data.each(function(d){
  257. values.push(MWF.org.parseOrgData(d, true));
  258. }.bind(this));
  259. if (this.json.isInput){
  260. this.addData(values);
  261. }else{
  262. this.setData(values);
  263. }
  264. //this._setBusinessData(values);
  265. this.validationMode();
  266. this.validation();
  267. this.fireEvent("select");
  268. }.bind(this))
  269. },
  270. selectOnCancel: function(){
  271. this.validation();
  272. },
  273. selectOnLoad: function(){
  274. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  275. },
  276. selectOnClose: function(){
  277. v = this._getBusinessData();
  278. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  279. },
  280. clickSelect: function(){
  281. var options = this.getOptions();
  282. if(options){
  283. var selector = new MWF.O2Selector(this.form.app.content, options);
  284. }
  285. },
  286. resetData: function(){
  287. var v = this.getValue();
  288. //this.setData((v) ? v.join(", ") : "");
  289. this.setData(v);
  290. },
  291. getInputData: function(){
  292. if (this.json.isInput){
  293. if (this.combox)return this.combox.getData();
  294. return this._getBusinessData();
  295. }else{
  296. return this._getBusinessData();
  297. }
  298. },
  299. _loadNodeRead: function(){
  300. this.node.empty();
  301. var node = new Element("div").inject(this.node);
  302. },
  303. _searchConfirmPerson: function(item){
  304. var inforNode = item.inforNode || new Element("div");
  305. if (item.data){
  306. var data = item.data;
  307. if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
  308. var dn = data.distinguishedName || data;
  309. if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
  310. MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
  311. identityList : [dn]
  312. }, function(json){
  313. if( json.data.length > 0 ){
  314. if( data["person"] )json.data[0].id = data["person"];
  315. item.data = MWF.org.parseOrgData( json.data[0], true );
  316. item.value = this.getDataText( item.data );
  317. if(item.node)item.node.set("text", item.value);
  318. }
  319. }.bind(this), null, false)
  320. }
  321. }
  322. if( item.data && ( item.data.createTime || item.data.updateTime ) ){
  323. item.data = MWF.org.parseOrgData( item.data, true );
  324. }
  325. var text = "";
  326. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-1, 1);
  327. switch (flag.toLowerCase()){
  328. case "i":
  329. text = item.data.name+"("+item.data.unitName+")";
  330. break;
  331. case "p":
  332. text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
  333. break;
  334. case "u":
  335. text = item.data.levelName;
  336. break;
  337. case "g":
  338. text = item.data.name;
  339. break;
  340. default:
  341. text = item.data.name;
  342. }
  343. inforNode.set({
  344. "styles": {"font-size": "14px", "color": ""},
  345. "text": text
  346. });
  347. }else{
  348. inforNode.set({
  349. "styles": {"font-size": "14px", "color": "#bd0000"},
  350. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  351. });
  352. }
  353. if (!item.inforNode){
  354. new mBox.Tooltip({
  355. content: inforNode,
  356. setStyles: {content: {padding: 15, lineHeight: 20}},
  357. attach: item.node,
  358. transition: 'flyin'
  359. });
  360. item.inforNode = inforNode;
  361. }
  362. },
  363. getSearchOptions: function(){
  364. if( this.selectTypeList.length === 0 )return false;
  365. var identityOpt;
  366. if( this.identityOptions ){
  367. identityOpt = this.identityOptions.getSearchOptions();
  368. //if (this.json.identityRange!=="all"){
  369. // if ( !identityOpt.units || !identityOpt.units.length){
  370. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  371. // return false;
  372. // }
  373. //}
  374. //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  375. // if (!identityOpt.dutys || !identityOpt.dutys.length){
  376. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  377. // return false;
  378. // }
  379. //}
  380. }
  381. var unitOpt;
  382. if( this.unitOptions ){
  383. unitOpt = this.unitOptions.getSearchOptions();
  384. //if (this.json.unitRange!=="all"){
  385. // if ( !unitOpt.units || !unitOpt.units.length){
  386. // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  387. // return false;
  388. // }
  389. //}
  390. }
  391. var groupOpt;
  392. if( this.groupOptions ){
  393. groupOpt = this.groupOptions.getOptions();
  394. }
  395. if( this.selectTypeList.length === 1 ){
  396. return Object.merge( {
  397. "type": this.selectTypeList[0]
  398. }, identityOpt || unitOpt || groupOpt )
  399. }else if( this.selectTypeList.length > 1 ){
  400. var options = {
  401. "type" : "",
  402. "types" : this.selectTypeList
  403. };
  404. if( identityOpt )options.identityOptions = identityOpt;
  405. if( unitOpt )options.unitOptions = unitOpt;
  406. if( groupOpt )options.groupOptions = groupOpt;
  407. return options;
  408. }
  409. //return {
  410. // "type": this.json.selectType,
  411. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  412. // "values": (this.json.isInput) ? [] : values,
  413. // "count": count,
  414. // "units": selectUnits,
  415. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  416. // "exclude" : exclude,
  417. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  418. // "categoryType": this.json.categoryType || "unit",
  419. // "onComplete": function(items){
  420. // this.selectOnComplete(items);
  421. // }.bind(this),
  422. // "onCancel": this.selectOnCancel.bind(this),
  423. // "onLoad": this.selectOnLoad.bind(this),
  424. // "onClose": this.selectOnClose.bind(this)
  425. //};
  426. },
  427. _searchOptions: function(value, callback){
  428. //var options = {
  429. // "type": this.json.selectType,
  430. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  431. // "units": this.selectUnits,
  432. // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  433. //};
  434. var options = this.getSearchOptions();
  435. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  436. this.comboxFilter.filter(value, function(data){
  437. data.map(function(d){
  438. var value = Object.clone(d);
  439. d.value = value;
  440. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1);
  441. switch (flag.toLowerCase()){
  442. case "i":
  443. d.text = d.name+"("+d.unitName+")";
  444. break;
  445. case "p":
  446. d.text = d.name+(d.employee ? "("+d.employee+")" : "");
  447. break;
  448. case "u":
  449. d.text = d.name;
  450. break;
  451. case "g":
  452. d.text = d.name;
  453. break;
  454. default:
  455. d.text = d.name;
  456. }
  457. });
  458. if (callback) callback(data);
  459. });
  460. },
  461. _loadNodeInputEdit: function(){
  462. var input=null;
  463. MWF.require("MWF.widget.Combox", function(){
  464. this.combox = input = new MWF.widget.Combox({
  465. "count": this.json.count || 0,
  466. "splitShow": this.json.splitShow || ", ",
  467. "onCommitInput": function(item){
  468. this._searchConfirmPerson(item);
  469. //this.fireEvent("change");
  470. }.bind(this),
  471. "onChange": function(){
  472. this._setBusinessData(this.getInputData());
  473. this.fireEvent("change");
  474. }.bind(this),
  475. "optionsMethod": this._searchOptions.bind(this)
  476. });
  477. }.bind(this), false);
  478. input.setStyles({
  479. "background": "transparent",
  480. "border": "0px"
  481. });
  482. input.set(this.json.properties);
  483. var node = new Element("div", {"styles": {
  484. "overflow": "hidden",
  485. //"position": "relative",
  486. "margin-right": "20px"
  487. }}).inject(this.node, "after");
  488. input.inject(node);
  489. //this.combox = input;
  490. this.node.destroy();
  491. this.node = node;
  492. this.node.set({
  493. "id": this.json.id,
  494. "MWFType": this.json.type
  495. });
  496. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  497. this.iconNode = new Element("div", {
  498. "styles": this.form.css[this.iconStyle],
  499. "events": {
  500. "click": this.clickSelect.bind(this)
  501. }
  502. }).inject(this.node, "before");
  503. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  504. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  505. }
  506. this.combox.addEvent("change", function(){
  507. this.validationMode();
  508. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  509. }.bind(this));
  510. },
  511. _loadNodeEdit: function(){
  512. var input = new Element("div", {
  513. "styles": {
  514. "background": "transparent",
  515. "border": "0px",
  516. "min-height": "24px"
  517. }
  518. });
  519. input.set(this.json.properties);
  520. var node = new Element("div", {"styles": {
  521. "overflow": "hidden",
  522. "position": "relative",
  523. "margin-right": "20px",
  524. "min-height": "24px"
  525. }}).inject(this.node, "after");
  526. input.inject(node);
  527. this.node.destroy();
  528. this.node = node;
  529. this.node.set({
  530. "id": this.json.id,
  531. "MWFType": this.json.type,
  532. "events": {
  533. "click": this.clickSelect.bind(this)
  534. }
  535. });
  536. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  537. this.iconNode = new Element("div", {
  538. "styles": this.form.css[this.iconStyle],
  539. "events": {
  540. "click": this.clickSelect.bind(this)
  541. }
  542. }).inject(this.node, "before");
  543. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  544. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  545. }
  546. this.node.getFirst().setStyle("height", "auto");
  547. this.node.getFirst().addEvent("change", function(){
  548. this.validationMode();
  549. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  550. }.bind(this));
  551. },
  552. getDataText: function(data){
  553. if (typeOf(data)=="string") return data;
  554. var text = "";
  555. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  556. switch (flag.toLowerCase()){
  557. case "i":
  558. text = data.name+"("+data.unitName+")";
  559. break;
  560. case "p":
  561. text = data.name+ (data.employee ? ("("+data.employee+")") : "");
  562. break;
  563. case "u":
  564. text = data.name;
  565. break;
  566. case "g":
  567. text = data.name;
  568. break;
  569. default:
  570. text = data.name;
  571. }
  572. return text;
  573. },
  574. addData: function(value){
  575. if (!value) return false;
  576. value.each(function(v){
  577. var vtype = typeOf(v);
  578. if (vtype==="string"){
  579. var data;
  580. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  581. if (data) this.combox.addNewValue(this.getDataText(data), data);
  582. }
  583. if (vtype==="object"){
  584. this.combox.addNewValue(this.getDataText(v), v);
  585. }
  586. }.bind(this));
  587. },
  588. setData: function(value){
  589. if (!value) return false;
  590. var oldValues = this.getData();
  591. var values = [];
  592. var comboxValues = [];
  593. var type = typeOf(value);
  594. if (type==="array"){
  595. value.each(function(v){
  596. var vtype = typeOf(v);
  597. var data = null;
  598. if (vtype==="string"){
  599. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  600. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), error, v, false);
  601. }
  602. if (vtype==="object") data = v;
  603. if (data){
  604. values.push(data);
  605. comboxValues.push({"text": this.getDataText(data),"value": data});
  606. }
  607. }.bind(this));
  608. }
  609. if (type==="string"){
  610. var vData;
  611. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  612. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true); }.bind(this), error, value, false);
  613. if (vData){
  614. values.push(vData);
  615. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  616. }
  617. }
  618. if (type==="object"){
  619. values.push(value);
  620. comboxValues.push({"text": this.getDataText(value),"value": value});
  621. }
  622. var change = false;
  623. if (oldValues.length && values.length){
  624. if (oldValues.length === values.length){
  625. for (var i=0; i<oldValues.length; i++){
  626. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  627. change = true;
  628. break;
  629. }
  630. }
  631. }else{
  632. change = true;
  633. }
  634. }else if (values.length || oldValues.length) {
  635. change = true;
  636. }
  637. this._setBusinessData(values);
  638. if (change) this.fireEvent("change");
  639. if (this.json.isInput){
  640. if (this.combox){
  641. this.combox.clear();
  642. this.combox.addNewValues(comboxValues);
  643. }else{
  644. var node = this.node.getFirst();
  645. if (node){
  646. comboxValues.each(function(v, i){
  647. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  648. }.bind(this));
  649. }
  650. }
  651. //
  652. // this.combox.clear();
  653. // values.each(function(v){
  654. // var vtype = typeOf(v);
  655. // if (vtype==="string"){
  656. // var data;
  657. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  658. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  659. // }
  660. // if (vtype==="object"){
  661. // this.combox.addNewValue(this.getDataText(v), v);
  662. // }
  663. // }.bind(this));
  664. }else{
  665. if (this.node.getFirst()){
  666. var node = this.node.getFirst();
  667. node.empty();
  668. this.loadOrgWidget(values, node)
  669. }else{
  670. this.node.empty();
  671. this.loadOrgWidget(values, this.node);
  672. }
  673. }
  674. },
  675. creteShowNode: function(data, islast){
  676. var nodeText = (data.text) ? data.text : data;
  677. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  678. var node = new Element("div", {
  679. "styles": {
  680. "float": "left",
  681. "margin-right": "5px"
  682. },
  683. "text": nodeText
  684. });
  685. var text = "";
  686. if (data.value){
  687. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-1, 1);
  688. switch (flag.toLowerCase()){
  689. case "i":
  690. text = data.value.name+"("+data.value.unitName+")";
  691. break;
  692. case "p":
  693. text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
  694. break;
  695. case "u":
  696. text = data.value.levelName;
  697. break;
  698. case "g":
  699. text = data.value.name;
  700. break;
  701. default:
  702. text = data.value.name;
  703. }
  704. var inforNode = new Element("div").set({
  705. "styles": {"font-size": "14px", "color": ""},
  706. "text": text
  707. });
  708. new mBox.Tooltip({
  709. content: inforNode,
  710. setStyles: {content: {padding: 15, lineHeight: 20}},
  711. attach: node,
  712. transition: 'flyin'
  713. });
  714. }
  715. return node;
  716. },
  717. _setValue: function(value){
  718. if (value.length==1 && !(value[0])) value=[];
  719. var values = [];
  720. var comboxValues = [];
  721. var type = typeOf(value);
  722. if (type==="array"){
  723. value.each(function(v){
  724. var data=null;
  725. var vtype = typeOf(v);
  726. if (vtype==="string"){
  727. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  728. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  729. }
  730. if (vtype==="object") data = v;
  731. if (data){
  732. values.push(data);
  733. comboxValues.push({"text": this.getDataText(data),"value": data});
  734. }
  735. }.bind(this));
  736. }
  737. if (type==="string"){
  738. var vData;
  739. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  740. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  741. if (vData){
  742. values.push(vData);
  743. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  744. }
  745. }
  746. if (type==="object"){
  747. values.push(value);
  748. comboxValues.push({"text": this.getDataText(value),"value": value});
  749. }
  750. this._setBusinessData(values);
  751. if (this.json.isInput){
  752. if (this.combox){
  753. this.combox.clear();
  754. this.combox.addNewValues(comboxValues);
  755. // values.each(function(v){
  756. // if (typeOf(v)=="string"){
  757. // this.combox.addNewValue(v);
  758. // }else{
  759. // this.combox.addNewValue(this.getDataText(v), v);
  760. // }
  761. // }.bind(this));
  762. }else{
  763. var node = this.node.getFirst();
  764. if (node){
  765. comboxValues.each(function(v, i){
  766. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  767. }.bind(this));
  768. }
  769. }
  770. }else{
  771. if (this.node.getFirst()){
  772. var node = this.node.getFirst();
  773. this.loadOrgWidget(values, node)
  774. }else{
  775. this.loadOrgWidget(values, this.node);
  776. }
  777. }
  778. //if (this.readonly) this.loadOrgWidget(values, this.node)
  779. //this.node.set("text", value);
  780. },
  781. getValueMethod: function(value){
  782. if (value){
  783. var flag = value.substr(value.length-1, 1);
  784. switch (flag.toLowerCase()){
  785. case "i":
  786. return "getIdentity";
  787. case "p":
  788. return "getPerson";
  789. case "u":
  790. return "getUnit";
  791. case "g":
  792. return "getGroup";
  793. default:
  794. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  795. }
  796. }
  797. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  798. },
  799. loadOrgWidget: function(value, node){
  800. var height = node.getStyle("height").toInt();
  801. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  802. if (value && value.length){
  803. value.each(function(data){
  804. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  805. var copyData = Object.clone(data);
  806. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  807. this.currentData = copyData;
  808. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  809. if( displayName ){
  810. copyData.displayName = displayName;
  811. }
  812. this.currentData = null;
  813. }
  814. var widget;
  815. switch (flag.toLowerCase()){
  816. case "i":
  817. widget = new MWF.widget.O2Identity(copyData, node, {"style": "xform","lazy":true});
  818. break;
  819. case "p":
  820. widget = new MWF.widget.O2Person(copyData, node, {"style": "xform","lazy":true});
  821. break;
  822. case "u":
  823. widget = new MWF.widget.O2Unit(copyData, node, {"style": "xform","lazy":true});
  824. break;
  825. case "g":
  826. widget = new MWF.widget.O2Group(copyData, node, {"style": "xform","lazy":true});
  827. break;
  828. default:
  829. widget = new MWF.widget.O2Other(copyData, node, {"style": "xform","lazy":true});
  830. }
  831. widget.field = this;
  832. if( layout.mobile ){
  833. widget.node.setStyles({
  834. "float" : "none"
  835. })
  836. }
  837. }.bind(this));
  838. }
  839. },
  840. _loadStyles: function(){
  841. if (this.readonly || this.json.isReadonly){
  842. if (this.json.styles) this.node.setStyles(this.json.styles);
  843. }else{
  844. if (this.json.styles) this.node.setStyles(this.json.styles);
  845. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  846. if (this.iconNode){
  847. var size = this.node.getSize();
  848. this.iconNode.setStyle("height", ""+size.y+"px");
  849. }
  850. }
  851. },
  852. checkEmpower : function( data, callback ){
  853. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  854. var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
  855. empowerChecker.load(data, callback);
  856. }else{
  857. if( callback )callback( data );
  858. }
  859. }
  860. });
  861. MWF.APPOrg.EmpowerChecker = new Class({
  862. Implements: [Events],
  863. initialize: function (form, json) {
  864. this.form = form;
  865. this.json = json;
  866. this.css = this.form.css;
  867. this.checkedAllItems = true;
  868. },
  869. load : function( data, callback, container ){
  870. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
  871. var array = [];
  872. data.each( function( d ){
  873. if( d.distinguishedName ){
  874. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
  875. if( flag === "i" ){
  876. array.push( d.distinguishedName )
  877. }
  878. }
  879. }.bind(this));
  880. if( array.length > 0 ){
  881. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  882. "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
  883. "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
  884. "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
  885. "identityList" : array
  886. }, function( json ){
  887. var arr = [];
  888. json.data.each( function(d){
  889. if(d.fromIdentity !== d.toIdentity )arr.push(d);
  890. });
  891. if( arr.length > 0 ){
  892. this.openSelectEmpowerDlg( arr, data, callback, container );
  893. }else{
  894. if( callback )callback( data );
  895. }
  896. }.bind(this), function(){
  897. if( callback )callback( data );
  898. }.bind(this))
  899. }else{
  900. if( callback )callback( data );
  901. }
  902. }else{
  903. if( callback )callback( data );
  904. }
  905. },
  906. getIgnoreEmpowerArray : function( callback ){
  907. var array = [];
  908. this.empowerSelectNodes.each(function(node){
  909. if( !node.retrieve("isSelected") ){
  910. var d = node.retrieve("data");
  911. array.push( d.fromIdentity );
  912. }
  913. }.bind(this));
  914. if( callback )callback( array );
  915. return array;
  916. },
  917. setIgnoreEmpowerFlag : function(data, callback){
  918. var ignoreList = this.getIgnoreEmpowerArray();
  919. for( var i=0; i<data.length; i++ ){
  920. var d = data[i];
  921. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  922. d.ignoreEmpower = true;
  923. }else if( d.ignoreEmpower ){
  924. delete d.ignoreEmpower;
  925. }
  926. }
  927. if( callback )callback( data );
  928. },
  929. replaceEmpowerIdentity : function(data, callback){
  930. debugger;
  931. var empowerData = {};
  932. this.empowerSelectNodes.each(function(node){
  933. if( node.retrieve("isSelected") ){
  934. var d = node.retrieve("data");
  935. empowerData[ d.fromIdentity ] = d;
  936. }
  937. }.bind(this));
  938. if( Object.keys(empowerData).length === 0 ){
  939. callback( data );
  940. }else{
  941. var identityList = [];
  942. for( var key in empowerData ){
  943. identityList.push( empowerData[key].toIdentity );
  944. }
  945. o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
  946. var newData = data.clone();
  947. var d = {};
  948. json.data.each( function(j){
  949. d[j.distinguishedName] = j;
  950. });
  951. for( var i=0; i<newData.length; i++ ){
  952. var nd = newData[i];
  953. if( nd.distinguishedName && empowerData[nd.distinguishedName]){
  954. if( d[empowerData[nd.distinguishedName].toIdentity] ){
  955. newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
  956. }
  957. }
  958. }
  959. callback( newData );
  960. },function(){
  961. callback( data );
  962. });
  963. }
  964. },
  965. openSelectEmpowerDlg : function( data, orginData, callback, container ){
  966. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  967. var html = "<div style=\"line-height: 30px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  968. html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  969. node.set("html", html);
  970. var itemNode = node.getLast();
  971. this.getEmpowerItems(itemNode, data);
  972. node.inject( container || this.form.app.content);
  973. var dlg = o2.DL.open({
  974. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  975. "style": this.form.json.dialogStyle || "user",
  976. "isResize": true,
  977. "content": node,
  978. "width": 630,
  979. //"height" : 500,
  980. "buttonList": [
  981. {
  982. "type" : "ok",
  983. "text": MWF.LP.process.button.ok,
  984. "action": function(d, e){
  985. //this.replaceEmpowerIdentity( orginData, callback );
  986. this.setIgnoreEmpowerFlag( orginData, callback );
  987. dlg.close();
  988. }.bind(this)
  989. },
  990. {
  991. "type" : "cancel",
  992. "text": MWF.LP.process.button.cancel,
  993. "action": function(){dlg.close();}
  994. }
  995. ],
  996. "onPostShow": function(){
  997. var selectNode = this.createSelectAllEmpowerNode();
  998. selectNode.inject( dlg.button );
  999. if( layout.mobile ){
  1000. dlg.node.inject( $(document.body) );
  1001. dlg.node.setStyles({
  1002. "width":"100%",
  1003. "height": "100%",
  1004. "top" : "0px",
  1005. "left" : "0px"
  1006. });
  1007. var y = dlg.node.getSize().y - 190;
  1008. itemNode.setStyle("height",y+"px");
  1009. dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
  1010. dlg.setContentSize();
  1011. }else{
  1012. dlg.content.setStyle("overflow","hidden");
  1013. var y = Math.min(300, itemNode.getSize().y);
  1014. var marginTop = itemNode.getStyle("margin-top");
  1015. var marginBottom = itemNode.getStyle("margin-bottom");
  1016. itemNode.setStyle("height",y+"px");
  1017. dlg.options.contentHeight = y + 30 + 20 ; //+100;
  1018. dlg.setContentSize();
  1019. dlg.node.setStyles({
  1020. "height": ""+(dlg.options.height) +"px"
  1021. });
  1022. dlg.reCenter();
  1023. }
  1024. }.bind(this)
  1025. });
  1026. },
  1027. getEmpowerItems: function(itemNode, data){
  1028. var _self = this;
  1029. this.empowerSelectNodes = [];
  1030. var count = 1;
  1031. var node;
  1032. data.each(function( d ){
  1033. if(d.fromIdentity == d.toIdentity )return;
  1034. if( count % 2 === 1 ){
  1035. node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
  1036. node.store("nodeType","Odd");
  1037. //node.setStyle("margin-right","10px");
  1038. }else{
  1039. node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
  1040. node.store("nodeType","Even");
  1041. }
  1042. count++;
  1043. this.empowerSelectNodes.push( node );
  1044. node.store("data", d);
  1045. var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
  1046. node.store("iconNode",iconNode);
  1047. var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
  1048. var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
  1049. var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
  1050. var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
  1051. node.addEvents({
  1052. "mouseover": function(){
  1053. var isSelected = this.retrieve("isSelected");
  1054. if (!isSelected){
  1055. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
  1056. if( _self.css.empowerItemIconNode_over ){
  1057. var iconNode = this.retrieve("iconNode");
  1058. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
  1059. }
  1060. }
  1061. },
  1062. "mouseout": function(){
  1063. var isSelected = this.retrieve("isSelected");
  1064. if (!isSelected){
  1065. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
  1066. if( _self.css.empowerItemIconNode_over ){
  1067. var iconNode = this.retrieve("iconNode");
  1068. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
  1069. }
  1070. }
  1071. },
  1072. "click": function(){
  1073. var isSelected = this.retrieve("isSelected");
  1074. if (isSelected){
  1075. _self.unselectEmpowerItem( this)
  1076. }else{
  1077. _self.selectEmpowerItem(this)
  1078. }
  1079. }
  1080. });
  1081. if( this.checkedAllItems )node.click();
  1082. }.bind(this));
  1083. },
  1084. unselectEmpowerItem : function( itemNode ){
  1085. itemNode.store("isSelected", false);
  1086. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
  1087. itemNode.getElements("div").each( function( div ){
  1088. var className = div.get("class");
  1089. if( className && this.css[className] )div.setStyles( this.css[className] )
  1090. }.bind(this))
  1091. },
  1092. selectEmpowerItem : function( itemNode ){
  1093. itemNode.store("isSelected", true);
  1094. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
  1095. itemNode.getElements("div").each( function( div ){
  1096. var className = div.get("class");
  1097. if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
  1098. }.bind(this))
  1099. },
  1100. createSelectAllEmpowerNode : function(){
  1101. var _self = this;
  1102. var node = new Element("div", {
  1103. styles : this.css.empowerSelectAllItemNode,
  1104. text : MWF.xApplication.process.Xform.LP.selectAll
  1105. });
  1106. node.addEvents({
  1107. "mouseover": function(){
  1108. var isSelected = this.retrieve("isSelected");
  1109. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
  1110. },
  1111. "mouseout": function(){
  1112. var isSelected = this.retrieve("isSelected");
  1113. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
  1114. },
  1115. "click": function(){
  1116. var isSelected = this.retrieve("isSelected");
  1117. if (isSelected){
  1118. this.store("isSelected", false);
  1119. this.setStyles( _self.css.empowerSelectAllItemNode );
  1120. _self.empowerSelectNodes.each( function(itemNode){
  1121. _self.unselectEmpowerItem(itemNode)
  1122. }.bind(this))
  1123. }else{
  1124. this.store("isSelected", true);
  1125. this.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1126. _self.empowerSelectNodes.each( function(itemNode){
  1127. _self.selectEmpowerItem(itemNode)
  1128. }.bind(this))
  1129. }
  1130. }
  1131. });
  1132. if( this.checkedAllItems ){
  1133. node.store("isSelected", true);
  1134. node.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1135. }
  1136. return node;
  1137. }
  1138. });
  1139. MWF.APPOrg.GroupOptions = new Class({
  1140. Implements: [Events],
  1141. initialize: function (form, json) {
  1142. this.form = form;
  1143. this.json = json;
  1144. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1145. },
  1146. getOptions: function(){
  1147. var count = (this.json.groupCount) ? this.json.groupCount : 0;
  1148. if( this.json.groupRange==="group" ){
  1149. return {
  1150. "count": count,
  1151. "include": this.getSelectRange( true )
  1152. }
  1153. }else{
  1154. return {
  1155. "count": count
  1156. }
  1157. }
  1158. },
  1159. getSearchOptions : function(){
  1160. return {};
  1161. },
  1162. getSelectRange : function( refresh ){
  1163. if( !this.selectRange || refresh){
  1164. this.selectRange = this._getSelectRange();
  1165. }
  1166. return this.selectRange;
  1167. },
  1168. _getSelectRange : function(){
  1169. var rangeValues = [];
  1170. if (this.json.groupRangeKey && this.json.groupRangeKey.code){
  1171. var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
  1172. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1173. rangeValues = v;
  1174. //v.each(function(d){
  1175. // if (d){
  1176. // if (typeOf(d)==="string"){
  1177. // var data;
  1178. // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
  1179. // rangeValues.push(data);
  1180. // }else{
  1181. // rangeValues.push(d);
  1182. // }
  1183. // }
  1184. //}.bind(this));
  1185. }
  1186. return rangeValues;
  1187. }
  1188. });
  1189. MWF.APPOrg.UnitOptions = new Class({
  1190. Implements: [Events],
  1191. initialize : function( form, json ){
  1192. this.form = form;
  1193. this.json = json;
  1194. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1195. },
  1196. getOptions: function(){
  1197. var count = (this.json.unitCount) ? this.json.unitCount : 0;
  1198. var selectUnits = this.getSelectRange( true );
  1199. return {
  1200. "count": count,
  1201. "units": selectUnits,
  1202. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  1203. "expandSubEnable" : (this.json.unitExpandSubEnable=="no") ? false : true
  1204. };
  1205. },
  1206. getSearchOptions : function(){
  1207. var selectUnits = this.getSelectRange( true );
  1208. return {
  1209. "units": selectUnits,
  1210. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
  1211. };
  1212. },
  1213. getSelectRange : function( refresh ){
  1214. if( !this.selectRange || refresh){
  1215. this.selectRange = this._getSelectRange();
  1216. }
  1217. return this.selectRange;
  1218. },
  1219. _getSelectRange : function(){
  1220. if (this.json.unitRange==="unit"){
  1221. return this.getScriptSelectUnit();
  1222. }
  1223. if (this.json.unitRange==="draftUnit"){
  1224. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1225. if (!dn){
  1226. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1227. var ids = [];
  1228. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1229. return this.getNextSelectUnit(ids);
  1230. }else{
  1231. return [];
  1232. }
  1233. }else{
  1234. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1235. }
  1236. }
  1237. if (this.json.unitRange==="currentUnit"){
  1238. if (this.form.app.currentTask){
  1239. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1240. }else{
  1241. if (this.form.app.taskList && this.form.app.taskList.length){
  1242. var ids = [];
  1243. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1244. return this.getNextSelectUnit(ids);
  1245. }else{
  1246. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1247. var ids = [];
  1248. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1249. return this.getNextSelectUnit(ids);
  1250. }else{
  1251. return [];
  1252. }
  1253. }
  1254. }
  1255. }
  1256. return [];
  1257. },
  1258. getScriptSelectUnit: function(){
  1259. var rangeValues = [];
  1260. if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
  1261. this.json.unitRangeUnit.each(function(unit){
  1262. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  1263. //if (unitFlag) rangeValues.push(unitFlag);
  1264. rangeValues.push(unit);
  1265. }.bind(this));
  1266. }
  1267. if (this.json.unitRangeField && this.json.unitRangeField.length){
  1268. this.json.unitRangeField.each(function(field){
  1269. var n = (typeOf(field)=="object") ? field.name : field;
  1270. var v = this.form.businessData.data[n];
  1271. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1272. v.each(function(d){
  1273. if (d){
  1274. if (typeOf(d)==="string"){
  1275. var data;
  1276. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1277. rangeValues.push(data);
  1278. }else{
  1279. rangeValues.push(d);
  1280. }
  1281. }
  1282. }.bind(this));
  1283. }.bind(this));
  1284. }
  1285. if (this.json.unitRangeKey && this.json.unitRangeKey.code){
  1286. var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
  1287. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1288. v.each(function(d){
  1289. if (d){
  1290. if (typeOf(d)==="string"){
  1291. var data;
  1292. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1293. rangeValues.push(data);
  1294. }else{
  1295. rangeValues.push(d);
  1296. }
  1297. }
  1298. }.bind(this));
  1299. }
  1300. return rangeValues;
  1301. },
  1302. getNextSelectUnit: function(id){
  1303. var ids = typeOf(id)==="array" ? id : [id];
  1304. var data;
  1305. var units = [];
  1306. ids.each( function(i){
  1307. if (this.json.unitRangeNext === "direct"){
  1308. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1309. if (data && data.woUnit) units.push(data.woUnit);
  1310. }else if(this.json.unitRangeNext==="level"){
  1311. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1312. if (data) units.push(data);
  1313. }else if (this.json.unitRangeNext==="type"){
  1314. if (this.json.unitRangeNextUnitType==="all"){
  1315. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1316. }else{
  1317. this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1318. }
  1319. if (data) units.push(data);
  1320. }
  1321. data = null;
  1322. }.bind(this));
  1323. return units;
  1324. //if (this.json.unitRangeNext === "direct"){
  1325. // if (typeOf(id)==="array"){
  1326. // var units = [];
  1327. // id.each(function(i){
  1328. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1329. // if (data && data.woUnit) units.push(data.woUnit);
  1330. // data = null;
  1331. // }.bind(this));
  1332. // return units;
  1333. // }else{
  1334. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1335. // return (data.woUnit) ? [data.woUnit] : [];
  1336. // }
  1337. //}
  1338. //if (this.json.unitRangeNext==="level"){
  1339. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1340. // //this.json.rangeNextLevel
  1341. // return (data) ? [data] : [];
  1342. //}
  1343. //if (this.json.unitRangeNext==="type"){
  1344. // if (this.json.unitRangeNextUnitType==="all"){
  1345. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1346. // }else{
  1347. // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1348. // }
  1349. //
  1350. // return (data) ? [data] : [];
  1351. //}
  1352. }
  1353. });
  1354. MWF.APPOrg.IdentityOptions = new Class({
  1355. Implements: [Events],
  1356. initialize : function( form, json ){
  1357. this.form = form;
  1358. this.json = json;
  1359. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1360. },
  1361. getOptions: function(){
  1362. var count = (this.json.identityCount) ? this.json.identityCount : 0;
  1363. if( this.json.identityOnlyUseInclude ){
  1364. return {
  1365. "noUnit" : true,
  1366. "count": count,
  1367. "resultType" : this.json.identityResultType,
  1368. "include" : this._getInclude()
  1369. };
  1370. }else{
  1371. var selectUnits = this.getSelectRange( true );
  1372. var selectDutys = this.getSelectRangeDuty( true );
  1373. return {
  1374. "count": count,
  1375. "units": selectUnits,
  1376. "dutys": selectDutys,
  1377. "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
  1378. "resultType" : this.json.identityResultType,
  1379. "categoryType": this.json.categoryType || "unit",
  1380. "dutyUnitLevelBy" : this.json.dutyUnitLevelBy || "duty",
  1381. "include" : this._getInclude()
  1382. };
  1383. }
  1384. },
  1385. getSearchOptions : function(){
  1386. var selectUnits = this.getSelectRange( true );
  1387. var selectDutys = this.getSelectRangeDuty( true );
  1388. return {
  1389. "units": selectUnits,
  1390. "dutys": selectDutys,
  1391. "resultType" : this.json.identityResultType
  1392. };
  1393. },
  1394. getSelectRange : function( refresh ){
  1395. if( !this.selectRange || refresh ){
  1396. this.selectRange = this._getSelectRange();
  1397. }
  1398. return this.selectRange;
  1399. },
  1400. _getInclude : function(){
  1401. var include = [];
  1402. if( this.json.identityIncludeKey ){
  1403. var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
  1404. if( v )include = typeOf(v)==="array" ? v : [v];
  1405. }
  1406. return include;
  1407. },
  1408. _getSelectRange : function(){
  1409. if (this.json.identityRange==="unit"){
  1410. return this.getScriptSelectUnit();
  1411. }
  1412. if (this.json.identityRange==="draftUnit"){
  1413. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1414. if (!dn){
  1415. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1416. var ids = [];
  1417. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1418. return this.getNextSelectUnit(ids);
  1419. }else{
  1420. return [];
  1421. }
  1422. }else{
  1423. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1424. }
  1425. }
  1426. if (this.json.identityRange==="currentUnit"){
  1427. if (this.form.app.currentTask){
  1428. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1429. }else{
  1430. if (this.form.app.taskList && this.form.app.taskList.length){
  1431. var ids = [];
  1432. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1433. return this.getNextSelectUnit(ids);
  1434. }else{
  1435. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1436. var ids = [];
  1437. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1438. return this.getNextSelectUnit(ids);
  1439. }else{
  1440. return [];
  1441. }
  1442. }
  1443. }
  1444. }
  1445. return [];
  1446. },
  1447. getScriptSelectUnit: function(){
  1448. var rangeValues = [];
  1449. if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
  1450. this.json.identityRangeUnit.each(function(unit){
  1451. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
  1452. //if (unitFlag) rangeValues.push(unitFlag);
  1453. rangeValues.push(unit);
  1454. }.bind(this));
  1455. }
  1456. if (this.json.identityRangeField && this.json.identityRangeField.length){
  1457. this.json.identityRangeField.each(function(field){
  1458. var n = (typeOf(field)=="object") ? field.name : field;
  1459. var v = this.form.businessData.data[n];
  1460. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1461. v.each(function(d){
  1462. if (d){
  1463. if (typeOf(d)==="string"){
  1464. var data;
  1465. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1466. rangeValues.push(data);
  1467. }else{
  1468. rangeValues.push(d);
  1469. }
  1470. }
  1471. }.bind(this));
  1472. }.bind(this));
  1473. }
  1474. if (this.json.identityRangeKey && this.json.identityRangeKey.code){
  1475. var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
  1476. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1477. v.each(function(d){
  1478. if (d){
  1479. if (typeOf(d)==="string"){
  1480. var data;
  1481. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1482. rangeValues.push(data);
  1483. }else{
  1484. rangeValues.push(d);
  1485. }
  1486. }
  1487. }.bind(this));
  1488. }
  1489. return rangeValues;
  1490. },
  1491. getNextSelectUnit: function(id){
  1492. var ids = typeOf(id)==="array" ? id : [id];
  1493. var data;
  1494. var units = [];
  1495. ids.each(function(i){
  1496. if (this.json.identityRangeNext === "direct"){
  1497. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1498. if (data && data.woUnit) units.push(data.woUnit);
  1499. }else if (this.json.identityRangeNext==="level"){
  1500. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1501. if (data) units.push(data);
  1502. }else if (this.json.identityRangeNext==="type"){
  1503. if (this.json.identityRangeNextUnitType==="all"){
  1504. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1505. }else{
  1506. this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1507. }
  1508. if (data) units.push(data);
  1509. }
  1510. data = null;
  1511. }.bind(this));
  1512. return units;
  1513. //if (this.json.identityRangeNext === "direct"){
  1514. //if (typeOf(id)==="array"){
  1515. // var units = [];
  1516. // id.each(function(i){
  1517. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1518. // if (data && data.woUnit) units.push(data.woUnit);
  1519. // data = null;
  1520. // }.bind(this));
  1521. // return units;
  1522. //}else{
  1523. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1524. // return (data.woUnit) ? [data.woUnit] : [];
  1525. //}
  1526. //}
  1527. //if (this.json.identityRangeNext==="level"){
  1528. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1529. // return (data) ? [data] : [];
  1530. // //this.json.rangeNextLevel
  1531. //}
  1532. //if (this.json.identityRangeNext==="type"){
  1533. // if (this.json.identityRangeNextUnitType==="all"){
  1534. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1535. // }else{
  1536. // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1537. // }
  1538. // return (data) ? [data] : [];
  1539. //}
  1540. },
  1541. getSelectRangeDuty: function( refresh ){
  1542. if( !this.selectRangeDuty || refresh ){
  1543. this.selectRangeDuty = this._getSelectRangeDuty();
  1544. }
  1545. return this.selectRangeDuty;
  1546. },
  1547. _getSelectRangeDuty: function(){
  1548. if (this.json.dutyRange==="duty"){
  1549. return this.getScriptSelectDuty();
  1550. }
  1551. return [];
  1552. },
  1553. getScriptSelectDuty: function(){
  1554. var rangeValues = [];
  1555. if( this.json.rangeDuty && this.json.rangeDuty.length ){
  1556. var rangeDuty = this.json.rangeDuty;
  1557. if( typeOf(rangeDuty) === "string" ){
  1558. rangeDuty = JSON.parse( rangeDuty );
  1559. }
  1560. if( typeOf(rangeDuty) === "array" ){
  1561. rangeDuty.each(function(unit){
  1562. var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
  1563. if (unitFlag) rangeValues.push(unitFlag);
  1564. }.bind(this));
  1565. }
  1566. }
  1567. //if (this.json.rangeDuty && this.json.rangeDuty.length){
  1568. // this.json.rangeDuty.each(function(unit){
  1569. // var unitFlag = unit.id || unit.name;
  1570. // if (unitFlag) rangeValues.push(unitFlag);
  1571. // }.bind(this));
  1572. //}
  1573. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  1574. this.json.rangeDutyField.each(function(field){
  1575. var n = (typeOf(field)=="object") ? field.name : field;
  1576. var v = this.form.businessData.data[n];
  1577. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1578. v.each(function(d){
  1579. if (d) rangeValues.push(d);
  1580. }.bind(this));
  1581. }.bind(this));
  1582. }
  1583. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  1584. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  1585. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1586. v.each(function(d){
  1587. if (d) rangeValues.push(d);
  1588. }.bind(this));
  1589. }
  1590. return rangeValues;
  1591. }
  1592. });