Personfield.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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.Personfield = MWF.APPPersonfield = 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: "personfieldIcon",
  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. var v = this._getBusinessData();
  25. if (!v || !v.length){
  26. if (this.json.description){
  27. var size = this.node.getFirst().getSize();
  28. var w = size.x-3;
  29. if (COMMON.Browser.safari) w = w-20;
  30. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  31. this.descriptionNode.setStyles({
  32. "width": ""+w+"px",
  33. "height": ""+size.y+"px",
  34. "line-height": ""+size.y+"px"
  35. });
  36. this.setDescriptionEvent();
  37. }
  38. }
  39. },
  40. setDescriptionEvent: function(){
  41. if (this.descriptionNode){
  42. this.descriptionNode.addEvents({
  43. "mousedown": function(){
  44. this.descriptionNode.setStyle("display", "none");
  45. this.clickSelect();
  46. }.bind(this)
  47. });
  48. }
  49. },
  50. _loadNode: function(){
  51. if (this.readonly || this.json.isReadonly){
  52. this._loadNodeRead();
  53. }else{
  54. this._getOrgOptions();
  55. if (this.json.isInput){
  56. this._loadNodeInputEdit();
  57. }else{
  58. this._loadNodeEdit();
  59. }
  60. }
  61. },
  62. _getOrgOptions: function(){
  63. this.selectUnits = this.getSelectRange();
  64. if (this.json.selectType=="identity"){
  65. this.selectDutys = this.getSelectRangeDuty();
  66. }
  67. },
  68. getScriptSelectUnit: function(){
  69. var rangeValues = [];
  70. if (this.json.rangeUnit && this.json.rangeUnit.length){
  71. this.json.rangeUnit.each(function(unit){
  72. var unitFlag = unit.distinguishedName || unit.id || unit.unique || unit.levelName;
  73. if (unitFlag) rangeValues.push(unitFlag);
  74. }.bind(this));
  75. }
  76. if (this.json.rangeField && this.json.rangeField.length){
  77. this.json.rangeField.each(function(field){
  78. var n = (typeOf(field)=="object") ? field.name : field;
  79. var v = this.form.businessData.data[n];
  80. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  81. v.each(function(d){
  82. if (d){
  83. if (typeOf(d)==="string"){
  84. var data;
  85. this.getOrgAction().getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  86. rangeValues.push(data);
  87. }else{
  88. rangeValues.push(d);
  89. }
  90. }
  91. }.bind(this));
  92. }.bind(this));
  93. }
  94. if (this.json.rangeKey && this.json.rangeKey.code){
  95. var v = this.form.Macro.exec(this.json.rangeKey.code, this);
  96. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  97. v.each(function(d){
  98. if (d){
  99. if (typeOf(d)==="string"){
  100. var data;
  101. this.getOrgAction().getUnit(function(json){ data = json.data }.bind(this), null, d, false);
  102. rangeValues.push(data);
  103. }else{
  104. rangeValues.push(d);
  105. }
  106. }
  107. }.bind(this));
  108. }
  109. return rangeValues;
  110. },
  111. getScriptSelectDuty: function(){
  112. var rangeValues = [];
  113. if (this.json.rangeDuty && this.json.rangeDuty.length){
  114. this.json.rangeDuty.each(function(unit){
  115. var unitFlag = unit.id || unit.name;
  116. if (unitFlag) rangeValues.push(unitFlag);
  117. }.bind(this));
  118. }
  119. if (this.json.rangeDutyField && this.json.rangeDutyField.length){
  120. this.json.rangeDutyField.each(function(field){
  121. var n = (typeOf(field)=="object") ? field.name : field;
  122. var v = this.form.businessData.data[n];
  123. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  124. v.each(function(d){
  125. if (d) rangeValues.push(d);
  126. }.bind(this));
  127. }.bind(this));
  128. }
  129. if (this.json.rangeDutyKey && this.json.rangeDutyKey.code){
  130. var v = this.form.Macro.exec(this.json.rangeDutyKey.code, this);
  131. if (typeOf(v)!=="array") v = (v) ? [v.toString()] : [];
  132. v.each(function(d){
  133. if (d) rangeValues.push(d);
  134. }.bind(this));
  135. }
  136. return rangeValues;
  137. },
  138. _computeValue: function(){
  139. var values = [];
  140. if (this.json.identityValue) {
  141. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  142. }
  143. if (this.json.unitValue) {
  144. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  145. }
  146. if (this.json.dutyValue) {
  147. var dutys = JSON.decode(this.json.dutyValue);
  148. var par;
  149. if (dutys.length){
  150. dutys.each(function(duty){
  151. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  152. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  153. //var code = "return this.org.getDepartmentDuty({\"name\": \""+duty.name+"\", \"departmentName\": \""+par+"\"})";
  154. var d = this.form.Macro.exec(code, this);
  155. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  156. d.each(function(dd){if (dd) values.push(dd);});
  157. // code = "return this.org.getCompanyDuty({\"name\": \""+duty.name+"\", \"compName\": \""+par+"\"})";
  158. // d = this.form.Macro.exec(code, this);
  159. // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  160. // d.each(function(dd){values.push(dd);});
  161. }.bind(this));
  162. }
  163. }
  164. if (this.json.defaultValue && this.json.defaultValue.code){
  165. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  166. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  167. fd.each(function(fdd){
  168. if (fdd){
  169. if (typeOf(fdd)==="string"){
  170. var data;
  171. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
  172. values.push(data);
  173. }else{
  174. values.push(fdd);
  175. }
  176. }
  177. }.bind(this));
  178. }
  179. if (this.json.count>0){
  180. return values.slice(0, this.json.count);
  181. }
  182. return values;
  183. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  184. },
  185. // getDepartments: function(){
  186. // if (this.json.range==="depart"){
  187. // return this.getRange();
  188. // }
  189. // if (this.json.range==="currentdepart"){
  190. // return [this.form.app.currentTask.department];
  191. // }
  192. // return [];
  193. // },
  194. // getCompanys: function(){
  195. // if (this.json.range==="company"){
  196. // //var comp = "";
  197. // //if (this.json.rangeKey){
  198. // return this.getRange();
  199. // //}
  200. // }
  201. // if (this.json.range==="currentcompany"){
  202. // return [this.form.app.currentTask.company];
  203. // }
  204. // return [];
  205. // },
  206. getOrgAction: function(){
  207. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  208. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  209. return this.orgAction;
  210. },
  211. getNextSelectUnit: function(id){
  212. var data;
  213. if (this.json.rangeNext === "direct"){
  214. if (typeOf(id)==="array"){
  215. var units = [];
  216. id.each(function(i){
  217. this.getOrgAction().getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, i, false);
  218. if (data && data.woUnit) units.push(data.woUnit);
  219. data = null;
  220. }.bind(this));
  221. return units;
  222. }else{
  223. this.getOrgAction().getIdentity(function(json){ data = json.data }.bind(this), function(){data={"woUnit": null}}, id, false);
  224. return (data.woUnit) ? [data.woUnit] : [];
  225. }
  226. }
  227. if (this.json.rangeNext==="level"){
  228. this.getOrgAction().getUnitWithIdentityWithLevel(id, this.json.rangeNextLevel, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  229. //this.json.rangeNextLevel
  230. return (data) ? [data] : [];
  231. }
  232. if (this.json.rangeNext==="type"){
  233. if (this.json.rangeNextUnitType==="all"){
  234. this.getOrgAction().getUnitWithIdentityWithLevel(id, 1, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  235. }else{
  236. this.getOrgAction().getUnitWithIdentityWithType(id, this.json.rangeNextUnitType, function(json){ data = json.data }.bind(this), function(){data=null;}, false);
  237. }
  238. return (data) ? [data] : [];
  239. }
  240. },
  241. getSelectRange: function(){
  242. if (this.json.range==="unit"){
  243. return this.getScriptSelectUnit();
  244. }
  245. if (this.json.range==="draftUnit"){
  246. debugger;
  247. var dn = (this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn;
  248. if (!dn){
  249. if (layout.session.user.identityList.length){
  250. var ids = [];
  251. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  252. return this.getNextSelectUnit(ids);
  253. }else{
  254. return [];
  255. }
  256. }else{
  257. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  258. }
  259. }
  260. if (this.json.range==="currentUnit"){
  261. debugger;
  262. if (this.form.app.currentTask){
  263. return this.getNextSelectUnit(this.form.app.currentTask.identityDn);
  264. }else{
  265. if (this.form.app.taskList && this.form.app.taskList.length){
  266. var ids = [];
  267. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  268. return this.getNextSelectUnit(ids);
  269. }else{
  270. if (layout.session.user.identityList.length){
  271. var ids = [];
  272. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  273. return this.getNextSelectUnit(ids);
  274. }else{
  275. return [];
  276. }
  277. }
  278. }
  279. }
  280. return [];
  281. },
  282. getSelectRangeDuty: function(){
  283. if (this.json.dutyRange==="duty"){
  284. return this.getScriptSelectDuty();
  285. }
  286. return [];
  287. },
  288. getOptions: function(){
  289. var values = this.getInputData();
  290. var count = (this.json.count) ? this.json.count : 0;
  291. switch (this.json.range){
  292. case "":
  293. }
  294. var selectUnits = this.getSelectRange();
  295. if (this.json.selectType=="identity"){
  296. var selectDutys = this.getSelectRangeDuty();
  297. }
  298. if (this.json.range!=="all"){
  299. if (!selectUnits.length){
  300. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  301. return false;
  302. }
  303. }
  304. if (this.json.selectType=="identity"){
  305. if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  306. if (!selectDutys || !selectDutys.length){
  307. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  308. return false;
  309. }
  310. }
  311. }
  312. var exclude = [];
  313. if( this.json.exclude ){
  314. var v = this.form.Macro.exec(this.json.exclude.code, this);
  315. exclude = typeOf(v)==="array" ? v : [v];
  316. }
  317. return {
  318. "type": this.json.selectType,
  319. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  320. "values": (this.json.isInput) ? [] : values,
  321. "count": count,
  322. "units": selectUnits,
  323. "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  324. "exclude" : exclude,
  325. "expandSubEnable" : (this.json.expandSubEnable=="no") ? false : true,
  326. "onComplete": function(items){
  327. this.selectOnComplete(items);
  328. }.bind(this),
  329. "onCancel": this.selectOnCancel.bind(this),
  330. "onLoad": this.selectOnLoad.bind(this),
  331. "onClose": this.selectOnClose.bind(this)
  332. };
  333. },
  334. selectOnComplete: function(items){
  335. var values = [];
  336. items.each(function(item){
  337. values.push(MWF.org.parseOrgData(item.data, true));
  338. }.bind(this));
  339. if (this.json.isInput){
  340. this.addData(values);
  341. }else{
  342. this.setData(values);
  343. }
  344. //this._setBusinessData(values);
  345. this.validationMode();
  346. this.validation()
  347. },
  348. selectOnCancel: function(){
  349. this.validation();
  350. },
  351. selectOnLoad: function(){
  352. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  353. },
  354. selectOnClose: function(){
  355. v = this._getBusinessData();
  356. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  357. },
  358. clickSelect: function(){
  359. var options = this.getOptions();
  360. var selector = new MWF.O2Selector(this.form.app.content, options);
  361. },
  362. resetData: function(){
  363. var v = this.getValue();
  364. //this.setData((v) ? v.join(", ") : "");
  365. this.setData(v);
  366. },
  367. getInputData: function(){
  368. if (this.json.isInput){
  369. if (this.combox) return this.combox.getData();
  370. return this._getBusinessData();
  371. }else{
  372. return this._getBusinessData();
  373. }
  374. },
  375. _loadNodeRead: function(){
  376. this.node.empty();
  377. var node = new Element("div").inject(this.node);
  378. },
  379. _searchConfirmPerson: function(item){
  380. var inforNode = item.inforNode || new Element("div");
  381. if (item.data){
  382. var text = "";
  383. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-1, 1);
  384. switch (flag.toLowerCase()){
  385. case "i":
  386. text = item.data.name+"("+item.data.unitName+")";
  387. break;
  388. case "p":
  389. text = item.data.name+"("+item.data.employee+")";
  390. break;
  391. case "u":
  392. text = item.data.levelName;
  393. break;
  394. case "g":
  395. text = item.data.name;
  396. break;
  397. default:
  398. text = item.data.name;
  399. }
  400. inforNode.set({
  401. "styles": {"font-size": "14px", "color": ""},
  402. "text": text
  403. });
  404. }else{
  405. inforNode.set({
  406. "styles": {"font-size": "14px", "color": "#bd0000"},
  407. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  408. });
  409. }
  410. if (!item.inforNode){
  411. new mBox.Tooltip({
  412. content: inforNode,
  413. setStyles: {content: {padding: 15, lineHeight: 20}},
  414. attach: item.node,
  415. transition: 'flyin'
  416. });
  417. item.inforNode = inforNode;
  418. }
  419. },
  420. _searchOptions: function(value, callback){
  421. var options = {
  422. "type": this.json.selectType,
  423. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  424. "units": this.selectUnits,
  425. "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  426. };
  427. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  428. this.comboxFilter.filter(value, function(data){
  429. data.map(function(d){
  430. var value = Object.clone(d);
  431. d.value = value;
  432. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1);
  433. switch (flag.toLowerCase()){
  434. case "i":
  435. d.text = d.name+"("+d.unitName+")";
  436. break;
  437. case "p":
  438. d.text = d.name+"("+d.employee+")";
  439. break;
  440. case "u":
  441. d.text = d.name;
  442. break;
  443. case "g":
  444. d.text = d.name;
  445. break;
  446. default:
  447. d.text = d.name;
  448. }
  449. });
  450. if (callback) callback(data);
  451. });
  452. },
  453. _loadNodeInputEdit: function(){
  454. var input=null;
  455. MWF.require("MWF.widget.Combox", function(){
  456. this.combox = input = new MWF.widget.Combox({
  457. "count": this.json.count || 0,
  458. "splitShow": this.json.splitShow || ", ",
  459. "onCommitInput": function(item){
  460. this._searchConfirmPerson(item);
  461. //this.fireEvent("change");
  462. }.bind(this),
  463. "onChange": function(){
  464. this._setBusinessData(this.getInputData());
  465. this.fireEvent("change");
  466. }.bind(this),
  467. "optionsMethod": this._searchOptions.bind(this)
  468. });
  469. }.bind(this), false);
  470. input.setStyles({
  471. "background": "transparent",
  472. "border": "0px"
  473. });
  474. input.set(this.json.properties);
  475. var node = new Element("div", {"styles": {
  476. "overflow": "hidden",
  477. //"position": "relative",
  478. "margin-right": "20px"
  479. }}).inject(this.node, "after");
  480. input.inject(node);
  481. //this.combox = input;
  482. this.node.destroy();
  483. this.node = node;
  484. this.node.set({
  485. "id": this.json.id,
  486. "MWFType": this.json.type
  487. });
  488. if (this.json.showIcon!='no') this.iconNode = new Element("div", {
  489. "styles": this.form.css[this.iconStyle],
  490. "events": {
  491. "click": this.clickSelect.bind(this)
  492. }
  493. }).inject(this.node, "before");
  494. this.combox.addEvent("change", function(){
  495. this.validationMode();
  496. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  497. }.bind(this));
  498. },
  499. _loadNodeEdit: function(){
  500. var input = new Element("div", {
  501. "styles": {
  502. "background": "transparent",
  503. "border": "0px",
  504. "min-height": "24px"
  505. }
  506. });
  507. input.set(this.json.properties);
  508. var node = new Element("div", {"styles": {
  509. "overflow": "hidden",
  510. "position": "relative",
  511. "margin-right": "20px",
  512. "min-height": "24px"
  513. }}).inject(this.node, "after");
  514. input.inject(node);
  515. this.node.destroy();
  516. this.node = node;
  517. this.node.set({
  518. "id": this.json.id,
  519. "MWFType": this.json.type,
  520. "events": {
  521. "click": this.clickSelect.bind(this)
  522. }
  523. });
  524. if (this.json.showIcon!='no') this.iconNode = new Element("div", {
  525. "styles": this.form.css[this.iconStyle],
  526. "events": {
  527. "click": this.clickSelect.bind(this)
  528. }
  529. }).inject(this.node, "before");
  530. this.node.getFirst().setStyle("height", "auto");
  531. this.node.getFirst().addEvent("change", function(){
  532. this.validationMode();
  533. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  534. }.bind(this));
  535. },
  536. getDataText: function(data){
  537. if (typeOf(data)=="string") return data;
  538. var text = "";
  539. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  540. switch (flag.toLowerCase()){
  541. case "i":
  542. text = data.name+"("+data.unitName+")";
  543. break;
  544. case "p":
  545. text = data.name+"("+data.employee+")";
  546. break;
  547. case "u":
  548. text = data.name;
  549. break;
  550. case "g":
  551. text = data.name;
  552. break;
  553. default:
  554. text = data.name;
  555. }
  556. return text;
  557. },
  558. addData: function(value){
  559. if (!value) return false;
  560. value.each(function(v){
  561. var vtype = typeOf(v);
  562. if (vtype==="string"){
  563. var data;
  564. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  565. if (data) this.combox.addNewValue(this.getDataText(data), data);
  566. }
  567. if (vtype==="object"){
  568. this.combox.addNewValue(this.getDataText(v), v);
  569. }
  570. }.bind(this));
  571. },
  572. setData: function(value){
  573. if (!value) return false;
  574. var oldValues = this.getData();
  575. var values = [];
  576. var comboxValues = [];
  577. var type = typeOf(value);
  578. if (type==="array"){
  579. value.each(function(v){
  580. var vtype = typeOf(v);
  581. var data = null;
  582. if (vtype==="string"){
  583. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  584. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data); }.bind(this), error, v, false);
  585. }
  586. if (vtype==="object") data = v;
  587. if (data){
  588. values.push(data);
  589. comboxValues.push({"text": this.getDataText(data),"value": data});
  590. }
  591. }.bind(this));
  592. }
  593. if (type==="string"){
  594. var vData;
  595. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  596. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data); }.bind(this), error, value, false);
  597. if (vData){
  598. values.push(vData);
  599. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  600. }
  601. }
  602. if (type==="object"){
  603. values.push(value);
  604. comboxValues.push({"text": this.getDataText(value),"value": value});
  605. }
  606. var change = false;
  607. if (oldValues.length && values.length){
  608. if (oldValues.length === values.length){
  609. for (var i=0; i<oldValues.length; i++){
  610. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  611. change = true;
  612. break;
  613. }
  614. }
  615. }else{
  616. change = true;
  617. }
  618. }else if (values.length || oldValues.length) {
  619. change = true;
  620. }
  621. this._setBusinessData(values);
  622. if (change) this.fireEvent("change");
  623. if (this.json.isInput){
  624. if (this.combox){
  625. this.combox.addNewValues(comboxValues);
  626. }else{
  627. var node = this.node.getFirst();
  628. if (node){
  629. comboxValues.each(function(v, i){
  630. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  631. }.bind(this));
  632. }
  633. }
  634. //
  635. // this.combox.clear();
  636. // values.each(function(v){
  637. // var vtype = typeOf(v);
  638. // if (vtype==="string"){
  639. // var data;
  640. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  641. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  642. // }
  643. // if (vtype==="object"){
  644. // this.combox.addNewValue(this.getDataText(v), v);
  645. // }
  646. // }.bind(this));
  647. }else{
  648. if (this.node.getFirst()){
  649. var node = this.node.getFirst();
  650. node.empty();
  651. this.loadOrgWidget(values, node)
  652. }else{
  653. this.node.empty();
  654. this.loadOrgWidget(values, this.node);
  655. }
  656. }
  657. },
  658. creteShowNode: function(data, islast){
  659. var nodeText = (data.text) ? data.text : data;
  660. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  661. var node = new Element("div", {
  662. "styles": {
  663. "float": "left",
  664. "margin-right": "5px"
  665. },
  666. "text": nodeText
  667. });
  668. var text = "";
  669. if (data.value){
  670. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-1, 1);
  671. switch (flag.toLowerCase()){
  672. case "i":
  673. text = data.value.name+"("+data.value.unitName+")";
  674. break;
  675. case "p":
  676. text = data.value.name+"("+data.value.employee+")";
  677. break;
  678. case "u":
  679. text = data.value.levelName;
  680. break;
  681. case "g":
  682. text = data.value.name;
  683. break;
  684. default:
  685. text = data.value.name;
  686. }
  687. var inforNode = new Element("div").set({
  688. "styles": {"font-size": "14px", "color": ""},
  689. "text": text
  690. });
  691. new mBox.Tooltip({
  692. content: inforNode,
  693. setStyles: {content: {padding: 15, lineHeight: 20}},
  694. attach: node,
  695. transition: 'flyin'
  696. });
  697. }
  698. return node;
  699. },
  700. _setValue: function(value){
  701. if (value.length==1 && !(value[0])) value=[];
  702. var values = [];
  703. var comboxValues = [];
  704. var type = typeOf(value);
  705. if (type==="array"){
  706. value.each(function(v){
  707. var data=null;
  708. var vtype = typeOf(v);
  709. if (vtype==="string"){
  710. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  711. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  712. }
  713. if (vtype==="object") data = v;
  714. if (data){
  715. values.push(data);
  716. comboxValues.push({"text": this.getDataText(data),"value": data});
  717. }
  718. }.bind(this));
  719. }
  720. if (type==="string"){
  721. var vData;
  722. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  723. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  724. if (vData){
  725. values.push(vData);
  726. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  727. }
  728. }
  729. if (type==="object"){
  730. values.push(value);
  731. comboxValues.push({"text": this.getDataText(value),"value": value});
  732. }
  733. this._setBusinessData(values);
  734. if (this.json.isInput){
  735. if (this.combox){
  736. this.combox.addNewValues(comboxValues);
  737. // values.each(function(v){
  738. // if (typeOf(v)=="string"){
  739. // this.combox.addNewValue(v);
  740. // }else{
  741. // this.combox.addNewValue(this.getDataText(v), v);
  742. // }
  743. // }.bind(this));
  744. }else{
  745. var node = this.node.getFirst();
  746. if (node){
  747. comboxValues.each(function(v, i){
  748. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  749. }.bind(this));
  750. }
  751. }
  752. }else{
  753. if (this.node.getFirst()){
  754. var node = this.node.getFirst();
  755. this.loadOrgWidget(values, node)
  756. }else{
  757. this.loadOrgWidget(values, this.node);
  758. }
  759. }
  760. //if (this.readonly) this.loadOrgWidget(values, this.node)
  761. //this.node.set("text", value);
  762. },
  763. getValueMethod: function(value){
  764. if (value){
  765. var flag = value.substr(value.length-1, 1);
  766. switch (flag.toLowerCase()){
  767. case "i":
  768. return "getIdentity";
  769. case "p":
  770. return "getPerson";
  771. case "u":
  772. return "getUnit";
  773. case "g":
  774. return "getGroup";
  775. default:
  776. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  777. }
  778. }
  779. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  780. },
  781. loadOrgWidget: function(value, node){
  782. var height = node.getStyle("height").toInt();
  783. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  784. if (value && value.length){
  785. value.each(function(data){
  786. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  787. var copyData = Object.clone(data);
  788. switch (flag.toLowerCase()){
  789. case "i":
  790. new MWF.widget.O2Identity(copyData, node, {"style": "xform"});
  791. break;
  792. case "p":
  793. new MWF.widget.O2Person(copyData, node, {"style": "xform"});
  794. break;
  795. case "u":
  796. new MWF.widget.O2Unit(copyData, node, {"style": "xform"});
  797. break;
  798. case "g":
  799. new MWF.widget.O2Group(copyData, node, {"style": "xform"});
  800. break;
  801. default:
  802. new MWF.widget.O2Other(copyData, node, {"style": "xform"});
  803. }
  804. }.bind(this));
  805. }
  806. },
  807. _loadStyles: function(){
  808. if (this.readonly || this.json.isReadonly){
  809. if (this.json.styles) this.node.setStyles(this.json.styles);
  810. }else{
  811. if (this.json.styles) this.node.setStyles(this.json.styles);
  812. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  813. if (this.iconNode){
  814. var size = this.node.getSize();
  815. this.iconNode.setStyle("height", ""+size.y+"px");
  816. }
  817. }
  818. }
  819. });