Org.js 77 KB

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