Org.js 69 KB

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