Org.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  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. "readonly": true
  10. },
  11. iconStyle: "orgIcon",
  12. getTextData: function(){
  13. //var value = this.node.get("value");
  14. //var text = this.node.get("text");
  15. var value = this.getValue();
  16. //var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  17. var text = [];
  18. value.each(function(v){
  19. text.push(v.name+((v.unitName) ? "("+v.unitName+")" : ""));
  20. }.bind(this));
  21. return {"value": value || "", "text": [text.join(",")]};
  22. },
  23. loadDescription: function(){
  24. if (this.readonly || this.json.isReadonly)return;
  25. var v = this._getBusinessData();
  26. if (!v || !v.length){
  27. if (this.json.description){
  28. var size = this.node.getFirst().getSize();
  29. var w = size.x-3;
  30. if (COMMON.Browser.safari) w = w-20;
  31. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  32. this.descriptionNode.setStyles({
  33. "width": ""+w+"px",
  34. "height": ""+size.y+"px",
  35. "line-height": ""+size.y+"px"
  36. });
  37. this.setDescriptionEvent();
  38. }
  39. }
  40. },
  41. setDescriptionEvent: function(){
  42. if (this.descriptionNode){
  43. this.descriptionNode.addEvents({
  44. "mousedown": function(){
  45. this.descriptionNode.setStyle("display", "none");
  46. this.clickSelect();
  47. }.bind(this)
  48. });
  49. }
  50. },
  51. _loadNode: function(){
  52. this.field = true;
  53. if (this.readonly || this.json.isReadonly){
  54. this._loadNodeRead();
  55. }else{
  56. this._getOrgOptions();
  57. if (this.json.isInput){
  58. this._loadNodeInputEdit();
  59. }else{
  60. this._loadNodeEdit();
  61. }
  62. }
  63. },
  64. _getOrgOptions: function(){
  65. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  66. if( this.selectTypeList.contains( "identity" ) ) {
  67. this.identityOptions = new MWF.APPOrg.IdentityOptions(this.form, this.json);
  68. }
  69. if( this.selectTypeList.contains( "unit" ) ) {
  70. this.unitOptions = new MWF.APPOrg.UnitOptions(this.form, this.json);
  71. }
  72. if( this.selectTypeList.contains( "group" ) ){
  73. this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  74. }
  75. //this.selectUnits = this.getSelectRange();
  76. //if (this.json.selectType=="identity"){
  77. // this.selectDutys = this.getSelectRangeDuty();
  78. //}
  79. },
  80. _computeValue: function(){
  81. var values = [];
  82. if (this.json.identityValue) {
  83. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  84. }
  85. if (this.json.unitValue) {
  86. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  87. }
  88. if (this.json.dutyValue) {
  89. var dutys = JSON.decode(this.json.dutyValue);
  90. var par;
  91. if (dutys.length){
  92. dutys.each(function(duty){
  93. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  94. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  95. //var code = "return this.org.getDepartmentDuty({\"name\": \""+duty.name+"\", \"departmentName\": \""+par+"\"})";
  96. var d = this.form.Macro.exec(code, this);
  97. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  98. d.each(function(dd){if (dd) values.push(dd);});
  99. // code = "return this.org.getCompanyDuty({\"name\": \""+duty.name+"\", \"compName\": \""+par+"\"})";
  100. // d = this.form.Macro.exec(code, this);
  101. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  102. // d.each(function(dd){values.push(dd);});
  103. }.bind(this));
  104. }
  105. }
  106. if (this.json.defaultValue && this.json.defaultValue.code){
  107. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  108. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  109. fd.each(function(fdd){
  110. if (fdd){
  111. if (typeOf(fdd)==="string"){
  112. var data;
  113. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
  114. values.push(data);
  115. }else{
  116. values.push(fdd);
  117. }
  118. }
  119. }.bind(this));
  120. }
  121. if (this.json.count>0){
  122. return values.slice(0, this.json.count);
  123. }
  124. return values;
  125. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  126. },
  127. getOrgAction: function(){
  128. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  129. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  130. return this.orgAction;
  131. },
  132. getOptions: function(){
  133. if( this.selectTypeList.length === 0 )return false;
  134. var values = this.getInputData();
  135. var exclude = [];
  136. if( this.json.exclude ){
  137. var v = this.form.Macro.exec(this.json.exclude.code, this);
  138. exclude = typeOf(v)==="array" ? v : [v];
  139. }
  140. //var count = (this.json.count) ? this.json.count : 0;
  141. var identityOpt;
  142. if( this.identityOptions ){
  143. identityOpt = this.identityOptions.getOptions();
  144. if (this.json.identityRange!=="all"){
  145. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  146. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  147. return false;
  148. }
  149. }
  150. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  151. if (!identityOpt.dutys || !identityOpt.dutys.length){
  152. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  153. return false;
  154. }
  155. }
  156. identityOpt.values = (this.json.isInput) ? [] : values;
  157. identityOpt.exclude = exclude;
  158. if( this.form.json.selectorStyle )identityOpt = Object.merge( identityOpt, this.form.json.selectorStyle );
  159. }
  160. var unitOpt;
  161. if( this.unitOptions ){
  162. unitOpt = this.unitOptions.getOptions();
  163. if (this.json.unitRange!=="all"){
  164. if ( !unitOpt.units || !unitOpt.units.length){
  165. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  166. return false;
  167. }
  168. }
  169. unitOpt.values = (this.json.isInput) ? [] : values;
  170. unitOpt.exclude = exclude;
  171. if( this.form.json.selectorStyle )unitOpt = Object.merge( unitOpt, this.form.json.selectorStyle );
  172. }
  173. var groupOpt;
  174. if( this.groupOptions ){
  175. groupOpt = this.groupOptions.getOptions();
  176. groupOpt.values = (this.json.isInput) ? [] : values;
  177. groupOpt.exclude = exclude;
  178. if( this.form.json.selectorStyle )groupOpt = Object.merge( groupOpt, this.form.json.selectorStyle );
  179. }
  180. //var selectUnits = this.getSelectRange();
  181. //if (this.json.selectType=="identity"){
  182. // var selectDutys = this.getSelectRangeDuty();
  183. //}
  184. //if (this.json.range!=="all"){
  185. // if (!selectUnits.length){
  186. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  187. // return false;
  188. // }
  189. //}
  190. //if (this.json.selectType=="identity"){
  191. // if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  192. // if (!selectDutys || !selectDutys.length){
  193. // this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  194. // return false;
  195. // }
  196. // }
  197. //}
  198. if( this.selectTypeList.length === 1 ){
  199. return Object.merge( {
  200. "type": this.selectTypeList[0],
  201. "onComplete": function(items){
  202. this.selectOnComplete(items);
  203. }.bind(this),
  204. "onCancel": this.selectOnCancel.bind(this),
  205. "onLoad": this.selectOnLoad.bind(this),
  206. "onClose": this.selectOnClose.bind(this)
  207. }, identityOpt || unitOpt || groupOpt )
  208. }else if( this.selectTypeList.length > 1 ){
  209. var options = {
  210. "type" : "",
  211. "types" : this.selectTypeList,
  212. "onComplete": function(items){
  213. this.selectOnComplete(items);
  214. }.bind(this),
  215. "onCancel": this.selectOnCancel.bind(this),
  216. "onLoad": this.selectOnLoad.bind(this),
  217. "onClose": this.selectOnClose.bind(this)
  218. };
  219. if( this.form.json.selectorStyle ){
  220. options = Object.merge( options, this.form.json.selectorStyle );
  221. }
  222. if( identityOpt )options.identityOptions = identityOpt;
  223. if( unitOpt )options.unitOptions = unitOpt;
  224. if( groupOpt )options.groupOptions = groupOpt;
  225. return options;
  226. }
  227. //return {
  228. // "type": this.json.selectType,
  229. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  230. // "values": (this.json.isInput) ? [] : values,
  231. // "count": count,
  232. // "units": selectUnits,
  233. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  234. // "exclude" : exclude,
  235. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  236. // "categoryType": this.json.categoryType || "unit",
  237. // "onComplete": function(items){
  238. // this.selectOnComplete(items);
  239. // }.bind(this),
  240. // "onCancel": this.selectOnCancel.bind(this),
  241. // "onLoad": this.selectOnLoad.bind(this),
  242. // "onClose": this.selectOnClose.bind(this)
  243. //};
  244. },
  245. selectOnComplete: function(items){
  246. var array = [];
  247. items.each(function(item){
  248. array.push(item.data);
  249. }.bind(this));
  250. this.checkEmpower( array, function( data ){
  251. var values = [];
  252. data.each(function(d){
  253. values.push(MWF.org.parseOrgData(d, true));
  254. }.bind(this));
  255. if (this.json.isInput){
  256. this.addData(values);
  257. }else{
  258. this.setData(values);
  259. }
  260. //this._setBusinessData(values);
  261. this.validationMode();
  262. this.validation();
  263. this.fireEvent("select");
  264. }.bind(this))
  265. },
  266. selectOnCancel: function(){
  267. this.validation();
  268. },
  269. selectOnLoad: function(){
  270. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  271. },
  272. selectOnClose: function(){
  273. v = this._getBusinessData();
  274. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  275. },
  276. clickSelect: function(){
  277. var options = this.getOptions();
  278. if(options){
  279. var selector = new MWF.O2Selector(this.form.app.content, options);
  280. }
  281. },
  282. resetData: function(){
  283. var v = this.getValue();
  284. //this.setData((v) ? v.join(", ") : "");
  285. this.setData(v);
  286. },
  287. getInputData: function(){
  288. if (this.json.isInput){
  289. if (this.combox)return this.combox.getData();
  290. return this._getBusinessData();
  291. }else{
  292. return this._getBusinessData();
  293. }
  294. },
  295. _loadNodeRead: function(){
  296. this.node.empty();
  297. var node = new Element("div").inject(this.node);
  298. },
  299. _searchConfirmPerson: function(item){
  300. var inforNode = item.inforNode || new Element("div");
  301. if (item.data){
  302. var data = item.data;
  303. if( this.selectTypeList.contains("identity") && this.json.identityResultType === "person"){
  304. var dn = data.distinguishedName || data;
  305. if( dn.substr( dn.length-1, 1).toLowerCase() === "i" ){
  306. MWF.Actions.get("x_organization_assemble_express").listPersonWithIdentity({
  307. identityList : [dn]
  308. }, function(json){
  309. if( json.data.length > 0 ){
  310. if( data["person"] )json.data[0].id = data["person"];
  311. item.data = MWF.org.parseOrgData( json.data[0], true );
  312. item.value = this.getDataText( item.data );
  313. if(item.node)item.node.set("text", item.value);
  314. }
  315. }.bind(this), null, false)
  316. }
  317. }
  318. if( item.data && ( item.data.createTime || item.data.updateTime ) ){
  319. item.data = MWF.org.parseOrgData( item.data, true );
  320. }
  321. var text = "";
  322. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-1, 1);
  323. switch (flag.toLowerCase()){
  324. case "i":
  325. text = item.data.name+"("+item.data.unitName+")";
  326. break;
  327. case "p":
  328. text = item.data.name+(item.data.employee ? "("+item.data.employee+")" : "");
  329. break;
  330. case "u":
  331. text = item.data.levelName;
  332. break;
  333. case "g":
  334. text = item.data.name;
  335. break;
  336. default:
  337. text = item.data.name;
  338. }
  339. inforNode.set({
  340. "styles": {"font-size": "14px", "color": ""},
  341. "text": text
  342. });
  343. }else{
  344. inforNode.set({
  345. "styles": {"font-size": "14px", "color": "#bd0000"},
  346. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  347. });
  348. }
  349. if (!item.inforNode){
  350. new mBox.Tooltip({
  351. content: inforNode,
  352. setStyles: {content: {padding: 15, lineHeight: 20}},
  353. attach: item.node,
  354. transition: 'flyin'
  355. });
  356. item.inforNode = inforNode;
  357. }
  358. },
  359. getSearchOptions: function(){
  360. if( this.selectTypeList.length === 0 )return false;
  361. var identityOpt;
  362. if( this.identityOptions ){
  363. identityOpt = this.identityOptions.getSearchOptions();
  364. //if (this.json.identityRange!=="all"){
  365. // if ( !identityOpt.units || !identityOpt.units.length){
  366. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  367. // return false;
  368. // }
  369. //}
  370. //if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  371. // if (!identityOpt.dutys || !identityOpt.dutys.length){
  372. // this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  373. // return false;
  374. // }
  375. //}
  376. }
  377. var unitOpt;
  378. if( this.unitOptions ){
  379. unitOpt = this.unitOptions.getSearchOptions();
  380. //if (this.json.unitRange!=="all"){
  381. // if ( !unitOpt.units || !unitOpt.units.length){
  382. // this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  383. // return false;
  384. // }
  385. //}
  386. }
  387. var groupOpt;
  388. if( this.groupOptions ){
  389. groupOpt = this.groupOptions.getOptions();
  390. }
  391. if( this.selectTypeList.length === 1 ){
  392. return Object.merge( {
  393. "type": this.selectTypeList[0]
  394. }, identityOpt || unitOpt || groupOpt )
  395. }else if( this.selectTypeList.length > 1 ){
  396. var options = {
  397. "type" : "",
  398. "types" : this.selectTypeList
  399. };
  400. if( identityOpt )options.identityOptions = identityOpt;
  401. if( unitOpt )options.unitOptions = unitOpt;
  402. if( groupOpt )options.groupOptions = groupOpt;
  403. return options;
  404. }
  405. //return {
  406. // "type": this.json.selectType,
  407. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  408. // "values": (this.json.isInput) ? [] : values,
  409. // "count": count,
  410. // "units": selectUnits,
  411. // "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  412. // "exclude" : exclude,
  413. // "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  414. // "categoryType": this.json.categoryType || "unit",
  415. // "onComplete": function(items){
  416. // this.selectOnComplete(items);
  417. // }.bind(this),
  418. // "onCancel": this.selectOnCancel.bind(this),
  419. // "onLoad": this.selectOnLoad.bind(this),
  420. // "onClose": this.selectOnClose.bind(this)
  421. //};
  422. },
  423. _searchOptions: function(value, callback){
  424. //var options = {
  425. // "type": this.json.selectType,
  426. // "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  427. // "units": this.selectUnits,
  428. // "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  429. //};
  430. var options = this.getSearchOptions();
  431. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  432. this.comboxFilter.filter(value, function(data){
  433. data.map(function(d){
  434. var value = Object.clone(d);
  435. d.value = value;
  436. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1);
  437. switch (flag.toLowerCase()){
  438. case "i":
  439. d.text = d.name+"("+d.unitName+")";
  440. break;
  441. case "p":
  442. d.text = d.name+(d.employee ? "("+d.employee+")" : "");
  443. break;
  444. case "u":
  445. d.text = d.name;
  446. break;
  447. case "g":
  448. d.text = d.name;
  449. break;
  450. default:
  451. d.text = d.name;
  452. }
  453. });
  454. if (callback) callback(data);
  455. });
  456. },
  457. _loadNodeInputEdit: function(){
  458. var input=null;
  459. MWF.require("MWF.widget.Combox", function(){
  460. this.combox = input = new MWF.widget.Combox({
  461. "count": this.json.count || 0,
  462. "splitShow": this.json.splitShow || ", ",
  463. "onCommitInput": function(item){
  464. this._searchConfirmPerson(item);
  465. //this.fireEvent("change");
  466. }.bind(this),
  467. "onChange": function(){
  468. this._setBusinessData(this.getInputData());
  469. this.fireEvent("change");
  470. }.bind(this),
  471. "optionsMethod": this._searchOptions.bind(this)
  472. });
  473. }.bind(this), false);
  474. input.setStyles({
  475. "background": "transparent",
  476. "border": "0px"
  477. });
  478. input.set(this.json.properties);
  479. var node = new Element("div", {"styles": {
  480. "overflow": "hidden",
  481. //"position": "relative",
  482. "margin-right": "20px"
  483. }}).inject(this.node, "after");
  484. input.inject(node);
  485. //this.combox = input;
  486. this.node.destroy();
  487. this.node = node;
  488. this.node.set({
  489. "id": this.json.id,
  490. "MWFType": this.json.type
  491. });
  492. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  493. this.iconNode = new Element("div", {
  494. "styles": this.form.css[this.iconStyle],
  495. "events": {
  496. "click": this.clickSelect.bind(this)
  497. }
  498. }).inject(this.node, "before");
  499. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  500. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  501. }
  502. this.combox.addEvent("change", function(){
  503. this.validationMode();
  504. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  505. }.bind(this));
  506. },
  507. _loadNodeEdit: function(){
  508. var input = new Element("div", {
  509. "styles": {
  510. "background": "transparent",
  511. "border": "0px",
  512. "min-height": "24px"
  513. }
  514. });
  515. input.set(this.json.properties);
  516. var node = new Element("div", {"styles": {
  517. "overflow": "hidden",
  518. "position": "relative",
  519. "margin-right": "20px",
  520. "min-height": "24px"
  521. }}).inject(this.node, "after");
  522. input.inject(node);
  523. this.node.destroy();
  524. this.node = node;
  525. this.node.set({
  526. "id": this.json.id,
  527. "MWFType": this.json.type,
  528. "events": {
  529. "click": this.clickSelect.bind(this)
  530. }
  531. });
  532. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  533. this.iconNode = new Element("div", {
  534. "styles": this.form.css[this.iconStyle],
  535. "events": {
  536. "click": this.clickSelect.bind(this)
  537. }
  538. }).inject(this.node, "before");
  539. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  540. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  541. }
  542. this.node.getFirst().setStyle("height", "auto");
  543. this.node.getFirst().addEvent("change", function(){
  544. this.validationMode();
  545. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  546. }.bind(this));
  547. },
  548. getDataText: function(data){
  549. if (typeOf(data)=="string") return data;
  550. var text = "";
  551. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  552. switch (flag.toLowerCase()){
  553. case "i":
  554. text = data.name+"("+data.unitName+")";
  555. break;
  556. case "p":
  557. text = data.name+ (data.employee ? ("("+data.employee+")") : "");
  558. break;
  559. case "u":
  560. text = data.name;
  561. break;
  562. case "g":
  563. text = data.name;
  564. break;
  565. default:
  566. text = data.name;
  567. }
  568. return text;
  569. },
  570. addData: function(value){
  571. if (!value) return false;
  572. value.each(function(v){
  573. var vtype = typeOf(v);
  574. if (vtype==="string"){
  575. var data;
  576. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  577. if (data) this.combox.addNewValue(this.getDataText(data), data);
  578. }
  579. if (vtype==="object"){
  580. this.combox.addNewValue(this.getDataText(v), v);
  581. }
  582. }.bind(this));
  583. },
  584. setData: function(value){
  585. if (!value) return false;
  586. var oldValues = this.getData();
  587. var values = [];
  588. var comboxValues = [];
  589. var type = typeOf(value);
  590. if (type==="array"){
  591. value.each(function(v){
  592. var vtype = typeOf(v);
  593. var data = null;
  594. if (vtype==="string"){
  595. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  596. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data); }.bind(this), error, v, false);
  597. }
  598. if (vtype==="object") data = v;
  599. if (data){
  600. values.push(data);
  601. comboxValues.push({"text": this.getDataText(data),"value": data});
  602. }
  603. }.bind(this));
  604. }
  605. if (type==="string"){
  606. var vData;
  607. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  608. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data); }.bind(this), error, value, false);
  609. if (vData){
  610. values.push(vData);
  611. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  612. }
  613. }
  614. if (type==="object"){
  615. values.push(value);
  616. comboxValues.push({"text": this.getDataText(value),"value": value});
  617. }
  618. var change = false;
  619. if (oldValues.length && values.length){
  620. if (oldValues.length === values.length){
  621. for (var i=0; i<oldValues.length; i++){
  622. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  623. change = true;
  624. break;
  625. }
  626. }
  627. }else{
  628. change = true;
  629. }
  630. }else if (values.length || oldValues.length) {
  631. change = true;
  632. }
  633. this._setBusinessData(values);
  634. if (change) this.fireEvent("change");
  635. if (this.json.isInput){
  636. if (this.combox){
  637. this.combox.addNewValues(comboxValues);
  638. }else{
  639. var node = this.node.getFirst();
  640. if (node){
  641. comboxValues.each(function(v, i){
  642. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  643. }.bind(this));
  644. }
  645. }
  646. //
  647. // this.combox.clear();
  648. // values.each(function(v){
  649. // var vtype = typeOf(v);
  650. // if (vtype==="string"){
  651. // var data;
  652. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  653. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  654. // }
  655. // if (vtype==="object"){
  656. // this.combox.addNewValue(this.getDataText(v), v);
  657. // }
  658. // }.bind(this));
  659. }else{
  660. if (this.node.getFirst()){
  661. var node = this.node.getFirst();
  662. node.empty();
  663. this.loadOrgWidget(values, node)
  664. }else{
  665. this.node.empty();
  666. this.loadOrgWidget(values, this.node);
  667. }
  668. }
  669. },
  670. creteShowNode: function(data, islast){
  671. var nodeText = (data.text) ? data.text : data;
  672. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  673. var node = new Element("div", {
  674. "styles": {
  675. "float": "left",
  676. "margin-right": "5px"
  677. },
  678. "text": nodeText
  679. });
  680. var text = "";
  681. if (data.value){
  682. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-1, 1);
  683. switch (flag.toLowerCase()){
  684. case "i":
  685. text = data.value.name+"("+data.value.unitName+")";
  686. break;
  687. case "p":
  688. text = data.value.name+ (data.value.employee ? "("+data.value.employee+")" : "");
  689. break;
  690. case "u":
  691. text = data.value.levelName;
  692. break;
  693. case "g":
  694. text = data.value.name;
  695. break;
  696. default:
  697. text = data.value.name;
  698. }
  699. var inforNode = new Element("div").set({
  700. "styles": {"font-size": "14px", "color": ""},
  701. "text": text
  702. });
  703. new mBox.Tooltip({
  704. content: inforNode,
  705. setStyles: {content: {padding: 15, lineHeight: 20}},
  706. attach: node,
  707. transition: 'flyin'
  708. });
  709. }
  710. return node;
  711. },
  712. _setValue: function(value){
  713. if (value.length==1 && !(value[0])) value=[];
  714. var values = [];
  715. var comboxValues = [];
  716. var type = typeOf(value);
  717. if (type==="array"){
  718. value.each(function(v){
  719. var data=null;
  720. var vtype = typeOf(v);
  721. if (vtype==="string"){
  722. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  723. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  724. }
  725. if (vtype==="object") data = v;
  726. if (data){
  727. values.push(data);
  728. comboxValues.push({"text": this.getDataText(data),"value": data});
  729. }
  730. }.bind(this));
  731. }
  732. if (type==="string"){
  733. var vData;
  734. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  735. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  736. if (vData){
  737. values.push(vData);
  738. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  739. }
  740. }
  741. if (type==="object"){
  742. values.push(value);
  743. comboxValues.push({"text": this.getDataText(value),"value": value});
  744. }
  745. this._setBusinessData(values);
  746. if (this.json.isInput){
  747. if (this.combox){
  748. this.combox.addNewValues(comboxValues);
  749. // values.each(function(v){
  750. // if (typeOf(v)=="string"){
  751. // this.combox.addNewValue(v);
  752. // }else{
  753. // this.combox.addNewValue(this.getDataText(v), v);
  754. // }
  755. // }.bind(this));
  756. }else{
  757. var node = this.node.getFirst();
  758. if (node){
  759. comboxValues.each(function(v, i){
  760. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  761. }.bind(this));
  762. }
  763. }
  764. }else{
  765. if (this.node.getFirst()){
  766. var node = this.node.getFirst();
  767. this.loadOrgWidget(values, node)
  768. }else{
  769. this.loadOrgWidget(values, this.node);
  770. }
  771. }
  772. //if (this.readonly) this.loadOrgWidget(values, this.node)
  773. //this.node.set("text", value);
  774. },
  775. getValueMethod: function(value){
  776. if (value){
  777. var flag = value.substr(value.length-1, 1);
  778. switch (flag.toLowerCase()){
  779. case "i":
  780. return "getIdentity";
  781. case "p":
  782. return "getPerson";
  783. case "u":
  784. return "getUnit";
  785. case "g":
  786. return "getGroup";
  787. default:
  788. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  789. }
  790. }
  791. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  792. },
  793. loadOrgWidget: function(value, node){
  794. var height = node.getStyle("height").toInt();
  795. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  796. if (value && value.length){
  797. value.each(function(data){
  798. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  799. var copyData = Object.clone(data);
  800. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  801. this.currentData = copyData;
  802. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  803. if( displayName ){
  804. copyData.displayName = displayName;
  805. }
  806. this.currentData = null;
  807. }
  808. var widget;
  809. switch (flag.toLowerCase()){
  810. case "i":
  811. widget = new MWF.widget.O2Identity(copyData, node, {"style": "xform","lazy":true});
  812. break;
  813. case "p":
  814. widget = new MWF.widget.O2Person(copyData, node, {"style": "xform","lazy":true});
  815. break;
  816. case "u":
  817. widget = new MWF.widget.O2Unit(copyData, node, {"style": "xform","lazy":true});
  818. break;
  819. case "g":
  820. widget = new MWF.widget.O2Group(copyData, node, {"style": "xform","lazy":true});
  821. break;
  822. default:
  823. widget = new MWF.widget.O2Other(copyData, node, {"style": "xform","lazy":true});
  824. }
  825. widget.field = this;
  826. if( layout.mobile ){
  827. widget.node.setStyles({
  828. "float" : "none"
  829. })
  830. }
  831. }.bind(this));
  832. }
  833. },
  834. _loadStyles: function(){
  835. if (this.readonly || this.json.isReadonly){
  836. if (this.json.styles) this.node.setStyles(this.json.styles);
  837. }else{
  838. if (this.json.styles) this.node.setStyles(this.json.styles);
  839. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  840. if (this.iconNode){
  841. var size = this.node.getSize();
  842. this.iconNode.setStyle("height", ""+size.y+"px");
  843. }
  844. }
  845. },
  846. checkEmpower : function( data, callback ){
  847. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  848. var empowerChecker = new MWF.APPOrg.EmpowerChecker(this.form, this.json);
  849. empowerChecker.load(data, callback);
  850. }else{
  851. if( callback )callback( data );
  852. }
  853. }
  854. });
  855. MWF.APPOrg.EmpowerChecker = new Class({
  856. Implements: [Events],
  857. initialize: function (form, json) {
  858. this.form = form;
  859. this.json = json;
  860. this.css = this.form.css;
  861. this.checkedAllItems = true;
  862. },
  863. load : function( data, callback, container ){
  864. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ){
  865. var array = [];
  866. data.each( function( d ){
  867. if( d.distinguishedName ){
  868. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1).toLowerCase();
  869. if( flag === "i" ){
  870. array.push( d.distinguishedName )
  871. }
  872. }
  873. }.bind(this));
  874. if( array.length > 0 ){
  875. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  876. "application" : (this.form.businessData.work || this.form.businessData.workCompleted).application,
  877. "process" : (this.form.businessData.work || this.form.businessData.workCompleted).process,
  878. "identityList" : array
  879. }, function( json ){
  880. var arr = [];
  881. json.data.each( function(d){
  882. if(d.fromIdentity !== d.toIdentity )arr.push(d);
  883. });
  884. if( arr.length > 0 ){
  885. this.openSelectEmpowerDlg( arr, data, callback, container );
  886. }else{
  887. if( callback )callback( data );
  888. }
  889. }.bind(this), function(){
  890. if( callback )callback( data );
  891. }.bind(this))
  892. }else{
  893. if( callback )callback( data );
  894. }
  895. }else{
  896. if( callback )callback( data );
  897. }
  898. },
  899. replaceEmpowerIdentity : function(data, callback){
  900. var empowerData = {};
  901. this.empowerSelectNodes.each(function(node){
  902. if( node.retrieve("isSelected") ){
  903. var d = node.retrieve("data");
  904. empowerData[ d.fromIdentity ] = d;
  905. }
  906. }.bind(this));
  907. var identityList = [];
  908. for( var key in empowerData ){
  909. identityList.push( empowerData[key].toIdentity );
  910. }
  911. o2.Actions.get("x_organization_assemble_express").listIdentity({ "identityList" : identityList }, function(json){
  912. var newData = data.clone();
  913. var d = {};
  914. json.data.each( function(j){
  915. d[j.distinguishedName] = j;
  916. });
  917. for( var i=0; i<newData.length; i++ ){
  918. var nd = newData[i];
  919. if( nd.distinguishedName && empowerData[nd.distinguishedName]){
  920. if( d[empowerData[nd.distinguishedName].toIdentity] ){
  921. newData[i] = d[empowerData[nd.distinguishedName].toIdentity]
  922. }
  923. }
  924. }
  925. callback( newData );
  926. },function(){
  927. callback( data );
  928. });
  929. },
  930. openSelectEmpowerDlg : function( data, orginData, callback, container ){
  931. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  932. var html = "<div style=\"line-height: 30px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  933. html += "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  934. node.set("html", html);
  935. var itemNode = node.getLast();
  936. this.getEmpowerItems(itemNode, data);
  937. node.inject( container || this.form.app.content);
  938. var dlg = o2.DL.open({
  939. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  940. "style": this.form.json.dialogStyle || "user",
  941. "isResize": true,
  942. "content": node,
  943. "width": 630,
  944. //"height" : 500,
  945. "buttonList": [
  946. {
  947. "type" : "ok",
  948. "text": MWF.LP.process.button.ok,
  949. "action": function(d, e){
  950. this.replaceEmpowerIdentity( orginData, callback );
  951. dlg.close();
  952. }.bind(this)
  953. },
  954. {
  955. "type" : "cancel",
  956. "text": MWF.LP.process.button.cancel,
  957. "action": function(){dlg.close();}
  958. }
  959. ],
  960. "onPostShow": function(){
  961. var selectNode = this.createSelectAllEmpowerNode();
  962. selectNode.inject( dlg.button );
  963. if( layout.mobile ){
  964. dlg.node.inject( $(document.body) );
  965. dlg.node.setStyles({
  966. "width":"100%",
  967. "height": "100%",
  968. "top" : "0px",
  969. "left" : "0px"
  970. });
  971. var y = dlg.node.getSize().y - 190;
  972. itemNode.setStyle("height",y+"px");
  973. dlg.options.contentHeight = dlg.node.getSize().y - 100 ; //+100;
  974. dlg.setContentSize();
  975. }else{
  976. dlg.content.setStyle("overflow","hidden");
  977. var y = Math.min(300, itemNode.getSize().y);
  978. var marginTop = itemNode.getStyle("margin-top");
  979. var marginBottom = itemNode.getStyle("margin-bottom");
  980. itemNode.setStyle("height",y+"px");
  981. dlg.options.contentHeight = y + 30 + 20 ; //+100;
  982. dlg.setContentSize();
  983. dlg.node.setStyles({
  984. "height": ""+(dlg.options.height) +"px"
  985. });
  986. dlg.reCenter();
  987. }
  988. }.bind(this)
  989. });
  990. },
  991. getEmpowerItems: function(itemNode, data){
  992. var _self = this;
  993. this.empowerSelectNodes = [];
  994. var count = 1;
  995. var node;
  996. data.each(function( d ){
  997. if(d.fromIdentity == d.toIdentity )return;
  998. if( count % 2 === 1 ){
  999. node = new Element("div", {"styles": this.css.empowerItemOddNode}).inject(itemNode);
  1000. node.store("nodeType","Odd");
  1001. //node.setStyle("margin-right","10px");
  1002. }else{
  1003. node = new Element("div", {"styles": this.css.empowerItemEvenNode}).inject(itemNode);
  1004. node.store("nodeType","Even");
  1005. }
  1006. count++;
  1007. this.empowerSelectNodes.push( node );
  1008. node.store("data", d);
  1009. var iconNode = new Element("div.empowerItemIconNode", {"styles": this.css.empowerItemIconNode}).inject(node);
  1010. node.store("iconNode",iconNode);
  1011. var contentNode = new Element("div.empowerItemContentNode", {"styles": this.css.empowerItemContentNode}).inject(node);
  1012. var formIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.fromIdentity.split("@")[0] }).inject(contentNode);
  1013. var titleNode = new Element("div.empowerItemTitleNode", {"styles": this.css.empowerItemTitleNode, text : MWF.xApplication.process.Xform.LP.empowerTo }).inject(contentNode);
  1014. var toIdentityNode = new Element("div.empowerItemPersonNode", {"styles": this.css.empowerItemPersonNode, text : d.toIdentity.split("@")[0] }).inject(contentNode);
  1015. node.addEvents({
  1016. "mouseover": function(){
  1017. var isSelected = this.retrieve("isSelected");
  1018. if (!isSelected){
  1019. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node_over" ]);
  1020. if( _self.css.empowerItemIconNode_over ){
  1021. var iconNode = this.retrieve("iconNode");
  1022. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode_over);
  1023. }
  1024. }
  1025. },
  1026. "mouseout": function(){
  1027. var isSelected = this.retrieve("isSelected");
  1028. if (!isSelected){
  1029. this.setStyles(_self.css[ "empowerItem"+this.retrieve("nodeType")+"Node" ])
  1030. if( _self.css.empowerItemIconNode_over ){
  1031. var iconNode = this.retrieve("iconNode");
  1032. if(iconNode)iconNode.setStyles(_self.css.empowerItemIconNode);
  1033. }
  1034. }
  1035. },
  1036. "click": function(){
  1037. var isSelected = this.retrieve("isSelected");
  1038. if (isSelected){
  1039. _self.unselectEmpowerItem( this)
  1040. }else{
  1041. _self.selectEmpowerItem(this)
  1042. }
  1043. }
  1044. });
  1045. if( this.checkedAllItems )node.click();
  1046. }.bind(this));
  1047. },
  1048. unselectEmpowerItem : function( itemNode ){
  1049. itemNode.store("isSelected", false);
  1050. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node" ] );
  1051. itemNode.getElements("div").each( function( div ){
  1052. var className = div.get("class");
  1053. if( className && this.css[className] )div.setStyles( this.css[className] )
  1054. }.bind(this))
  1055. },
  1056. selectEmpowerItem : function( itemNode ){
  1057. itemNode.store("isSelected", true);
  1058. itemNode.setStyles( this.css[ "empowerItem"+itemNode.retrieve("nodeType")+"Node_selected" ] );
  1059. itemNode.getElements("div").each( function( div ){
  1060. var className = div.get("class");
  1061. if( className && this.css[className+"_selected"] )div.setStyles( this.css[className+"_selected"] )
  1062. }.bind(this))
  1063. },
  1064. createSelectAllEmpowerNode : function(){
  1065. var _self = this;
  1066. var node = new Element("div", {
  1067. styles : this.css.empowerSelectAllItemNode,
  1068. text : MWF.xApplication.process.Xform.LP.selectAll
  1069. });
  1070. node.addEvents({
  1071. "mouseover": function(){
  1072. var isSelected = this.retrieve("isSelected");
  1073. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode_over);
  1074. },
  1075. "mouseout": function(){
  1076. var isSelected = this.retrieve("isSelected");
  1077. if (!isSelected) this.setStyles(_self.css.empowerSelectAllItemNode)
  1078. },
  1079. "click": function(){
  1080. var isSelected = this.retrieve("isSelected");
  1081. if (isSelected){
  1082. this.store("isSelected", false);
  1083. this.setStyles( _self.css.empowerSelectAllItemNode );
  1084. _self.empowerSelectNodes.each( function(itemNode){
  1085. _self.unselectEmpowerItem(itemNode)
  1086. }.bind(this))
  1087. }else{
  1088. this.store("isSelected", true);
  1089. this.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1090. _self.empowerSelectNodes.each( function(itemNode){
  1091. _self.selectEmpowerItem(itemNode)
  1092. }.bind(this))
  1093. }
  1094. }
  1095. });
  1096. if( this.checkedAllItems ){
  1097. node.store("isSelected", true);
  1098. node.setStyles( _self.css.empowerSelectAllItemNode_selected );
  1099. }
  1100. return node;
  1101. }
  1102. });
  1103. MWF.APPOrg.GroupOptions = new Class({
  1104. Implements: [Events],
  1105. initialize: function (form, json) {
  1106. this.form = form;
  1107. this.json = json;
  1108. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1109. },
  1110. getOptions: function(){
  1111. var count = (this.json.groupCount) ? this.json.groupCount : 0;
  1112. if( this.json.groupRange==="group" ){
  1113. return {
  1114. "count": count,
  1115. "include": this.getSelectRange( true )
  1116. }
  1117. }else{
  1118. return {
  1119. "count": count
  1120. }
  1121. }
  1122. },
  1123. getSearchOptions : function(){
  1124. return {};
  1125. },
  1126. getSelectRange : function( refresh ){
  1127. if( !this.selectRange || refresh){
  1128. this.selectRange = this._getSelectRange();
  1129. }
  1130. return this.selectRange;
  1131. },
  1132. _getSelectRange : function(){
  1133. var rangeValues = [];
  1134. if (this.json.groupRangeKey && this.json.groupRangeKey.code){
  1135. var v = this.form.Macro.exec(this.json.groupRangeKey.code, this);
  1136. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1137. rangeValues = v;
  1138. //v.each(function(d){
  1139. // if (d){
  1140. // if (typeOf(d)==="string"){
  1141. // var data;
  1142. // this.orgAction.getGroup(function(json){ data = json.data }.bind(this), null, d, false);
  1143. // rangeValues.push(data);
  1144. // }else{
  1145. // rangeValues.push(d);
  1146. // }
  1147. // }
  1148. //}.bind(this));
  1149. }
  1150. return rangeValues;
  1151. }
  1152. });
  1153. MWF.APPOrg.UnitOptions = new Class({
  1154. Implements: [Events],
  1155. initialize : function( form, json ){
  1156. this.form = form;
  1157. this.json = json;
  1158. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1159. },
  1160. getOptions: function(){
  1161. var count = (this.json.unitCount) ? this.json.unitCount : 0;
  1162. var selectUnits = this.getSelectRange( true );
  1163. return {
  1164. "count": count,
  1165. "units": selectUnits,
  1166. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  1167. "expandSubEnable" : (this.json.unitExpandSubEnable=="no") ? false : true
  1168. };
  1169. },
  1170. getSearchOptions : function(){
  1171. var selectUnits = this.getSelectRange( true );
  1172. return {
  1173. "units": selectUnits,
  1174. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType
  1175. };
  1176. },
  1177. getSelectRange : function( refresh ){
  1178. if( !this.selectRange || refresh){
  1179. this.selectRange = this._getSelectRange();
  1180. }
  1181. return this.selectRange;
  1182. },
  1183. _getSelectRange : function(){
  1184. if (this.json.unitRange==="unit"){
  1185. return this.getScriptSelectUnit();
  1186. }
  1187. if (this.json.unitRange==="draftUnit"){
  1188. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1189. if (!dn){
  1190. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1191. var ids = [];
  1192. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1193. return this.getNextSelectUnit(ids);
  1194. }else{
  1195. return [];
  1196. }
  1197. }else{
  1198. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1199. }
  1200. }
  1201. if (this.json.unitRange==="currentUnit"){
  1202. if (this.form.app.currentTask){
  1203. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1204. }else{
  1205. if (this.form.app.taskList && this.form.app.taskList.length){
  1206. var ids = [];
  1207. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1208. return this.getNextSelectUnit(ids);
  1209. }else{
  1210. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1211. var ids = [];
  1212. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1213. return this.getNextSelectUnit(ids);
  1214. }else{
  1215. return [];
  1216. }
  1217. }
  1218. }
  1219. }
  1220. return [];
  1221. },
  1222. getScriptSelectUnit: function(){
  1223. var rangeValues = [];
  1224. if (this.json.unitRangeUnit && this.json.unitRangeUnit.length){
  1225. this.json.unitRangeUnit.each(function(unit){
  1226. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  1227. //if (unitFlag) rangeValues.push(unitFlag);
  1228. rangeValues.push(unit);
  1229. }.bind(this));
  1230. }
  1231. if (this.json.unitRangeField && this.json.unitRangeField.length){
  1232. this.json.unitRangeField.each(function(field){
  1233. var n = (typeOf(field)=="object") ? field.name : field;
  1234. var v = this.form.businessData.data[n];
  1235. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1236. v.each(function(d){
  1237. if (d){
  1238. if (typeOf(d)==="string"){
  1239. var data;
  1240. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1241. rangeValues.push(data);
  1242. }else{
  1243. rangeValues.push(d);
  1244. }
  1245. }
  1246. }.bind(this));
  1247. }.bind(this));
  1248. }
  1249. if (this.json.unitRangeKey && this.json.unitRangeKey.code){
  1250. var v = this.form.Macro.exec(this.json.unitRangeKey.code, this);
  1251. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1252. v.each(function(d){
  1253. if (d){
  1254. if (typeOf(d)==="string"){
  1255. var data;
  1256. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1257. rangeValues.push(data);
  1258. }else{
  1259. rangeValues.push(d);
  1260. }
  1261. }
  1262. }.bind(this));
  1263. }
  1264. return rangeValues;
  1265. },
  1266. getNextSelectUnit: function(id){
  1267. var ids = typeOf(id)==="array" ? id : [id];
  1268. var data;
  1269. var units = [];
  1270. ids.each( function(i){
  1271. if (this.json.unitRangeNext === "direct"){
  1272. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1273. if (data && data.woUnit) units.push(data.woUnit);
  1274. }else if(this.json.unitRangeNext==="level"){
  1275. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1276. if (data) units.push(data);
  1277. }else if (this.json.unitRangeNext==="type"){
  1278. if (this.json.unitRangeNextUnitType==="all"){
  1279. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1280. }else{
  1281. this.orgAction.getUnitWithIdentityWithType(i, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1282. }
  1283. if (data) units.push(data);
  1284. }
  1285. data = null;
  1286. }.bind(this));
  1287. return units;
  1288. //if (this.json.unitRangeNext === "direct"){
  1289. // if (typeOf(id)==="array"){
  1290. // var units = [];
  1291. // id.each(function(i){
  1292. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1293. // if (data && data.woUnit) units.push(data.woUnit);
  1294. // data = null;
  1295. // }.bind(this));
  1296. // return units;
  1297. // }else{
  1298. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1299. // return (data.woUnit) ? [data.woUnit] : [];
  1300. // }
  1301. //}
  1302. //if (this.json.unitRangeNext==="level"){
  1303. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.unitRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1304. // //this.json.rangeNextLevel
  1305. // return (data) ? [data] : [];
  1306. //}
  1307. //if (this.json.unitRangeNext==="type"){
  1308. // if (this.json.unitRangeNextUnitType==="all"){
  1309. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1310. // }else{
  1311. // this.orgAction.getUnitWithIdentityWithType(id, this.json.unitRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1312. // }
  1313. //
  1314. // return (data) ? [data] : [];
  1315. //}
  1316. }
  1317. });
  1318. MWF.APPOrg.IdentityOptions = new Class({
  1319. Implements: [Events],
  1320. initialize : function( form, json ){
  1321. this.form = form;
  1322. this.json = json;
  1323. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1324. },
  1325. getOptions: function(){
  1326. var count = (this.json.identityCount) ? this.json.identityCount : 0;
  1327. if( this.json.identityOnlyUseInclude ){
  1328. return {
  1329. "noUnit" : true,
  1330. "count": count,
  1331. "resultType" : this.json.identityResultType,
  1332. "include" : this._getInclude()
  1333. };
  1334. }else{
  1335. var selectUnits = this.getSelectRange( true );
  1336. var selectDutys = this.getSelectRangeDuty( true );
  1337. return {
  1338. "count": count,
  1339. "units": selectUnits,
  1340. "dutys": selectDutys,
  1341. "expandSubEnable" : (this.json.identityExpandSubEnable=="no") ? false : true,
  1342. "resultType" : this.json.identityResultType,
  1343. "categoryType": this.json.categoryType || "unit",
  1344. "include" : this._getInclude()
  1345. };
  1346. }
  1347. },
  1348. getSearchOptions : function(){
  1349. var selectUnits = this.getSelectRange( true );
  1350. var selectDutys = this.getSelectRangeDuty( true );
  1351. return {
  1352. "units": selectUnits,
  1353. "dutys": selectDutys,
  1354. "resultType" : this.json.identityResultType
  1355. };
  1356. },
  1357. getSelectRange : function( refresh ){
  1358. if( !this.selectRange || refresh ){
  1359. this.selectRange = this._getSelectRange();
  1360. }
  1361. return this.selectRange;
  1362. },
  1363. _getInclude : function(){
  1364. var include = [];
  1365. if( this.json.identityIncludeKey ){
  1366. var v = this.form.Macro.exec(this.json.identityIncludeKey.code, this);
  1367. if( v )include = typeOf(v)==="array" ? v : [v];
  1368. }
  1369. return include;
  1370. },
  1371. _getSelectRange : function(){
  1372. if (this.json.identityRange==="unit"){
  1373. return this.getScriptSelectUnit();
  1374. }
  1375. if (this.json.identityRange==="draftUnit"){
  1376. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  1377. if (!dn){
  1378. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1379. var ids = [];
  1380. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1381. return this.getNextSelectUnit(ids);
  1382. }else{
  1383. return [];
  1384. }
  1385. }else{
  1386. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  1387. }
  1388. }
  1389. if (this.json.identityRange==="currentUnit"){
  1390. if (this.form.app.currentTask){
  1391. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  1392. }else{
  1393. if (this.form.app.taskList && this.form.app.taskList.length){
  1394. var ids = [];
  1395. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  1396. return this.getNextSelectUnit(ids);
  1397. }else{
  1398. if ( layout.session.user.identityList && layout.session.user.identityList.length){
  1399. var ids = [];
  1400. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  1401. return this.getNextSelectUnit(ids);
  1402. }else{
  1403. return [];
  1404. }
  1405. }
  1406. }
  1407. }
  1408. return [];
  1409. },
  1410. getScriptSelectUnit: function(){
  1411. var rangeValues = [];
  1412. if (this.json.identityRangeUnit && this.json.identityRangeUnit.length){
  1413. this.json.identityRangeUnit.each(function(unit){
  1414. //var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName ;
  1415. //if (unitFlag) rangeValues.push(unitFlag);
  1416. rangeValues.push(unit);
  1417. }.bind(this));
  1418. }
  1419. if (this.json.identityRangeField && this.json.identityRangeField.length){
  1420. this.json.identityRangeField.each(function(field){
  1421. var n = (typeOf(field)=="object") ? field.name : field;
  1422. var v = this.form.businessData.data[n];
  1423. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1424. v.each(function(d){
  1425. if (d){
  1426. if (typeOf(d)==="string"){
  1427. var data;
  1428. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1429. rangeValues.push(data);
  1430. }else{
  1431. rangeValues.push(d);
  1432. }
  1433. }
  1434. }.bind(this));
  1435. }.bind(this));
  1436. }
  1437. if (this.json.identityRangeKey && this.json.identityRangeKey.code){
  1438. var v = this.form.Macro.exec(this.json.identityRangeKey.code, this);
  1439. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1440. v.each(function(d){
  1441. if (d){
  1442. if (typeOf(d)==="string"){
  1443. var data;
  1444. this.orgAction.getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  1445. rangeValues.push(data);
  1446. }else{
  1447. rangeValues.push(d);
  1448. }
  1449. }
  1450. }.bind(this));
  1451. }
  1452. return rangeValues;
  1453. },
  1454. getNextSelectUnit: function(id){
  1455. var ids = typeOf(id)==="array" ? id : [id];
  1456. var data;
  1457. var units = [];
  1458. ids.each(function(i){
  1459. if (this.json.identityRangeNext === "direct"){
  1460. this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1461. if (data && data.woUnit) units.push(data.woUnit);
  1462. }else if (this.json.identityRangeNext==="level"){
  1463. this.orgAction.getUnitWithIdentityWithLevel(i, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1464. if (data) units.push(data);
  1465. }else if (this.json.identityRangeNext==="type"){
  1466. if (this.json.identityRangeNextUnitType==="all"){
  1467. this.orgAction.getUnitWithIdentityWithLevel(i, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1468. }else{
  1469. this.orgAction.getUnitWithIdentityWithType(i, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1470. }
  1471. if (data) units.push(data);
  1472. }
  1473. data = null;
  1474. }.bind(this));
  1475. return units;
  1476. //if (this.json.identityRangeNext === "direct"){
  1477. //if (typeOf(id)==="array"){
  1478. // var units = [];
  1479. // id.each(function(i){
  1480. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  1481. // if (data && data.woUnit) units.push(data.woUnit);
  1482. // data = null;
  1483. // }.bind(this));
  1484. // return units;
  1485. //}else{
  1486. // this.orgAction.getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  1487. // return (data.woUnit) ? [data.woUnit] : [];
  1488. //}
  1489. //}
  1490. //if (this.json.identityRangeNext==="level"){
  1491. // this.orgAction.getUnitWithIdentityWithLevel(id, this.json.identityRangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1492. // return (data) ? [data] : [];
  1493. // //this.json.rangeNextLevel
  1494. //}
  1495. //if (this.json.identityRangeNext==="type"){
  1496. // if (this.json.identityRangeNextUnitType==="all"){
  1497. // this.orgAction.getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1498. // }else{
  1499. // this.orgAction.getUnitWithIdentityWithType(id, this.json.identityRangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  1500. // }
  1501. // return (data) ? [data] : [];
  1502. //}
  1503. },
  1504. getSelectRangeDuty: function( refresh ){
  1505. if( !this.selectRangeDuty || refresh ){
  1506. this.selectRangeDuty = this._getSelectRangeDuty();
  1507. }
  1508. return this.selectRangeDuty;
  1509. },
  1510. _getSelectRangeDuty: function(){
  1511. if (this.json.dutyRange==="duty"){
  1512. return this.getScriptSelectDuty();
  1513. }
  1514. return [];
  1515. },
  1516. getScriptSelectDuty: function(){
  1517. var rangeValues = [];
  1518. if( this.json.rangeDuty && this.json.rangeDuty.length ){
  1519. var rangeDuty = this.json.rangeDuty;
  1520. if( typeOf(rangeDuty) === "string" ){
  1521. rangeDuty = JSON.parse( rangeDuty );
  1522. }
  1523. if( typeOf(rangeDuty) === "array" ){
  1524. rangeDuty.each(function(unit){
  1525. var unitFlag = typeOf(unit) === "string" ? unit : (unit.id || unit.name);
  1526. if (unitFlag) rangeValues.push(unitFlag);
  1527. }.bind(this));
  1528. }
  1529. }
  1530. //if (this.json.rangeDuty && this.json.rangeDuty.length){
  1531. // this.json.rangeDuty.each(function(unit){
  1532. // var unitFlag = unit.id || unit.name;
  1533. // if (unitFlag) rangeValues.push(unitFlag);
  1534. // }.bind(this));
  1535. //}
  1536. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  1537. this.json.rangeDutyField.each(function(field){
  1538. var n = (typeOf(field)=="object") ? field.name : field;
  1539. var v = this.form.businessData.data[n];
  1540. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1541. v.each(function(d){
  1542. if (d) rangeValues.push(d);
  1543. }.bind(this));
  1544. }.bind(this));
  1545. }
  1546. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  1547. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  1548. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  1549. v.each(function(d){
  1550. if (d) rangeValues.push(d);
  1551. }.bind(this));
  1552. }
  1553. return rangeValues;
  1554. }
  1555. });