Org.js 74 KB

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