Org.js 81 KB

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