Org.js 88 KB

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