Org.js 82 KB

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