Org.js 88 KB

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