Org.js 79 KB

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