Org.js 82 KB

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