Org.js 76 KB

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