Org.js 74 KB

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