Org.js 88 KB

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