Org.js 88 KB

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