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