Personfield.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. return this.getNextSelectUnit((this.form.businessData.work || this.form.businessData.workCompleted).creatorIdentityDn);
  247. }
  248. if (this.json.range==="currentUnit"){
  249. if (this.form.app.currentTask){
  250. return this.getNextSelectUnit(this.form.app.currentTask.identity);
  251. }else{
  252. if (this.form.app.taskList.length){
  253. var ids = [];
  254. this.form.app.taskList.each(function(task){ ids.push(task.identity); });
  255. return this.getNextSelectUnit(ids);
  256. }else{
  257. if (layout.session.user.identityList.length){
  258. var ids = [];
  259. layout.session.user.identityList.each(function(id){ ids.push(id.id); });
  260. return this.getNextSelectUnit(ids);
  261. }else{
  262. return [];
  263. }
  264. }
  265. }
  266. }
  267. return [];
  268. },
  269. getSelectRangeDuty: function(){
  270. if (this.json.dutyRange==="duty"){
  271. return this.getScriptSelectDuty();
  272. }
  273. return [];
  274. },
  275. clickSelect: function(){
  276. //var names = (nameValue) ? this.getInputData().split(MWF.splitStr) : [];
  277. var values = this.getInputData();
  278. var count = (this.json.count) ? this.json.count : 0;
  279. switch (this.json.range){
  280. case "":
  281. }
  282. debugger;
  283. var selectUnits = this.getSelectRange();
  284. if (this.json.selectType=="identity"){
  285. var selectDutys = this.getSelectRangeDuty();
  286. }
  287. // var selectUnits = this.selectUnits;
  288. // if (this.json.selectType=="identity"){
  289. // var selectDutys = this.selectDutys;
  290. // }
  291. if (this.json.range!=="all"){
  292. if (!selectUnits.length){
  293. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  294. return false;
  295. }
  296. }
  297. if (this.json.selectType=="identity"){
  298. if ((this.json.dutyRange) && this.json.dutyRange!=="all"){
  299. if (!selectDutys || !selectDutys.length){
  300. this.form.notice(MWF.xApplication.process.Xform.LP.noSelectRange, "error", this.node);
  301. return false;
  302. }
  303. }
  304. }
  305. var options = {
  306. "type": this.json.selectType,
  307. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  308. "values": (this.json.isInput) ? [] : values,
  309. "count": count,
  310. "units": selectUnits,
  311. "dutys": (this.json.selectType=="identity") ? selectDutys : [],
  312. "onComplete": function(items){
  313. var values = [];
  314. items.each(function(item){
  315. values.push(MWF.org.parseOrgData(item.data));
  316. }.bind(this));
  317. if (this.json.isInput){
  318. this.addData(values);
  319. }else{
  320. this.setData(values);
  321. }
  322. //this._setBusinessData(values);
  323. this.validationMode();
  324. this.validation()
  325. }.bind(this),
  326. "onCancel": function(){
  327. this.validation();
  328. }.bind(this),
  329. "onLoad": function(){
  330. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  331. }.bind(this),
  332. "onClose": function(){
  333. v = this._getBusinessData();
  334. if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  335. }.bind(this)
  336. };
  337. var selector = new MWF.O2Selector(this.form.app.content, options);
  338. },
  339. resetData: function(){
  340. var v = this.getValue();
  341. //this.setData((v) ? v.join(", ") : "");
  342. this.setData(v);
  343. },
  344. getInputData: function(){
  345. if (this.json.isInput){
  346. if (this.combox) return this.combox.getData();
  347. return this._getBusinessData();
  348. }else{
  349. return this._getBusinessData();
  350. }
  351. },
  352. _loadNodeRead: function(){
  353. this.node.empty();
  354. var node = new Element("div").inject(this.node);
  355. },
  356. _searchConfirmPerson: function(item){
  357. var inforNode = item.inforNode || new Element("div");
  358. if (item.data){
  359. var text = "";
  360. var flag = item.data.distinguishedName.substr(item.data.distinguishedName.length-1, 1);
  361. switch (flag.toLowerCase()){
  362. case "i":
  363. text = item.data.name+"("+item.data.unitName+")";
  364. break;
  365. case "p":
  366. text = item.data.name+"("+item.data.employee+")";
  367. break;
  368. case "u":
  369. text = item.data.levelName;
  370. break;
  371. case "g":
  372. text = item.data.name;
  373. break;
  374. default:
  375. text = item.data.name;
  376. }
  377. inforNode.set({
  378. "styles": {"font-size": "14px", "color": ""},
  379. "text": text
  380. });
  381. }else{
  382. inforNode.set({
  383. "styles": {"font-size": "14px", "color": "#bd0000"},
  384. "text": MWF.xApplication.process.Xform.LP.noOrgObject
  385. });
  386. }
  387. if (!item.inforNode){
  388. new mBox.Tooltip({
  389. content: inforNode,
  390. setStyles: {content: {padding: 15, lineHeight: 20}},
  391. attach: item.node,
  392. transition: 'flyin'
  393. });
  394. item.inforNode = inforNode;
  395. }
  396. },
  397. _searchOptions: function(value, callback){
  398. var options = {
  399. "type": this.json.selectType,
  400. "unitType": (this.json.selectUnitType==="all") ? "" : this.json.selectUnitType,
  401. "units": this.selectUnits,
  402. "dutys": (this.json.selectType=="identity") ? this.selectDutys : []
  403. };
  404. if (!this.comboxFilter) this.comboxFilter = new MWF.O2SelectorFilter(value, options);
  405. this.comboxFilter.filter(value, function(data){
  406. data.map(function(d){
  407. var value = Object.clone(d);
  408. d.value = value;
  409. var flag = d.distinguishedName.substr(d.distinguishedName.length-1, 1);
  410. switch (flag.toLowerCase()){
  411. case "i":
  412. d.text = d.name+"("+d.unitName+")";
  413. break;
  414. case "p":
  415. d.text = d.name+"("+d.employee+")";
  416. break;
  417. case "u":
  418. d.text = d.name;
  419. break;
  420. case "g":
  421. d.text = d.name;
  422. break;
  423. default:
  424. d.text = d.name;
  425. }
  426. });
  427. if (callback) callback(data);
  428. });
  429. },
  430. _loadNodeInputEdit: function(){
  431. var input=null;
  432. MWF.require("MWF.widget.Combox", function(){
  433. this.combox = input = new MWF.widget.Combox({
  434. "count": this.json.count || 0,
  435. "splitShow": this.json.splitShow || ", ",
  436. "onCommitInput": function(item){
  437. this._searchConfirmPerson(item);
  438. //this.fireEvent("change");
  439. }.bind(this),
  440. "onChange": function(){
  441. this._setBusinessData(this.getInputData());
  442. this.fireEvent("change");
  443. }.bind(this),
  444. "optionsMethod": this._searchOptions.bind(this)
  445. });
  446. }.bind(this), false);
  447. input.setStyles({
  448. "background": "transparent",
  449. "border": "0px"
  450. });
  451. input.set(this.json.properties);
  452. var node = new Element("div", {"styles": {
  453. "overflow": "hidden",
  454. //"position": "relative",
  455. "margin-right": "20px"
  456. }}).inject(this.node, "after");
  457. input.inject(node);
  458. //this.combox = input;
  459. this.node.destroy();
  460. this.node = node;
  461. this.node.set({
  462. "id": this.json.id,
  463. "MWFType": this.json.type
  464. });
  465. if (this.json.showIcon!='no') this.iconNode = new Element("div", {
  466. "styles": this.form.css[this.iconStyle],
  467. "events": {
  468. "click": this.clickSelect.bind(this)
  469. }
  470. }).inject(this.node, "before");
  471. this.combox.addEvent("change", function(){
  472. this.validationMode();
  473. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  474. }.bind(this));
  475. },
  476. _loadNodeEdit: function(){
  477. debugger;
  478. var input = new Element("div", {
  479. "styles": {
  480. "background": "transparent",
  481. "border": "0px",
  482. "min-height": "24px"
  483. }
  484. });
  485. input.set(this.json.properties);
  486. var node = new Element("div", {"styles": {
  487. "overflow": "hidden",
  488. "position": "relative",
  489. "margin-right": "20px",
  490. "min-height": "24px"
  491. }}).inject(this.node, "after");
  492. input.inject(node);
  493. this.node.destroy();
  494. this.node = node;
  495. this.node.set({
  496. "id": this.json.id,
  497. "MWFType": this.json.type,
  498. "events": {
  499. "click": this.clickSelect.bind(this)
  500. }
  501. });
  502. if (this.json.showIcon!='no') this.iconNode = new Element("div", {
  503. "styles": this.form.css[this.iconStyle],
  504. "events": {
  505. "click": this.clickSelect.bind(this)
  506. }
  507. }).inject(this.node, "before");
  508. this.node.getFirst().setStyle("height", "auto");
  509. this.node.getFirst().addEvent("change", function(){
  510. this.validationMode();
  511. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  512. }.bind(this));
  513. },
  514. getDataText: function(data){
  515. if (typeOf(data)=="string") return data;
  516. var text = "";
  517. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  518. switch (flag.toLowerCase()){
  519. case "i":
  520. text = data.name+"("+data.unitName+")";
  521. break;
  522. case "p":
  523. text = data.name+"("+data.employee+")";
  524. break;
  525. case "u":
  526. text = data.name;
  527. break;
  528. case "g":
  529. text = data.name;
  530. break;
  531. default:
  532. text = data.name;
  533. }
  534. return text;
  535. },
  536. addData: function(value){
  537. if (!value) return false;
  538. value.each(function(v){
  539. var vtype = typeOf(v);
  540. if (vtype==="string"){
  541. var data;
  542. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  543. if (data) this.combox.addNewValue(this.getDataText(data), data);
  544. }
  545. if (vtype==="object"){
  546. this.combox.addNewValue(this.getDataText(v), v);
  547. }
  548. }.bind(this));
  549. },
  550. setData: function(value){
  551. if (!value) return false;
  552. var oldValues = this.getData();
  553. var values = [];
  554. var comboxValues = [];
  555. var type = typeOf(value);
  556. if (type==="array"){
  557. value.each(function(v){
  558. var vtype = typeOf(v);
  559. var data = null;
  560. if (vtype==="string"){
  561. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  562. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  563. }
  564. if (vtype==="object") data = v;
  565. if (data){
  566. values.push(data);
  567. comboxValues.push({"text": this.getDataText(data),"value": data});
  568. }
  569. }.bind(this));
  570. }
  571. if (type==="string"){
  572. var vData;
  573. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  574. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  575. if (vData){
  576. values.push(vData);
  577. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  578. }
  579. }
  580. if (type==="object"){
  581. values.push(value);
  582. comboxValues.push({"text": this.getDataText(value),"value": value});
  583. }
  584. var change = false;
  585. if (oldValues.length && values.length){
  586. if (oldValues.length == values.length){
  587. for (var i=0; i<oldValues.length; i++){
  588. if ((oldValues[i].distinguishedName!=values[i].distinguishedName) || (oldValues[i].name!=values[i].name) || (oldValues[i].unique!=values[i].unique)){
  589. change = true;
  590. break;
  591. }
  592. }
  593. }else{
  594. change = true;
  595. }
  596. }else if (values.length || oldValues.length) {
  597. change = true;
  598. }
  599. this._setBusinessData(values);
  600. if (change) this.fireEvent("change");
  601. if (this.json.isInput){
  602. if (this.combox){
  603. this.combox.addNewValues(comboxValues);
  604. }else{
  605. var node = this.node.getFirst();
  606. if (node){
  607. comboxValues.each(function(v, i){
  608. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  609. }.bind(this));
  610. }
  611. }
  612. //
  613. // this.combox.clear();
  614. // values.each(function(v){
  615. // var vtype = typeOf(v);
  616. // if (vtype==="string"){
  617. // var data;
  618. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  619. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  620. // }
  621. // if (vtype==="object"){
  622. // this.combox.addNewValue(this.getDataText(v), v);
  623. // }
  624. // }.bind(this));
  625. }else{
  626. if (this.node.getFirst()){
  627. var node = this.node.getFirst();
  628. node.empty();
  629. this.loadOrgWidget(values, node)
  630. }else{
  631. this.node.empty();
  632. this.loadOrgWidget(values, this.node);
  633. }
  634. }
  635. },
  636. creteShowNode: function(data, islast){
  637. var nodeText = (data.text) ? data.text : data;
  638. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  639. var node = new Element("div", {
  640. "styles": {
  641. "float": "left",
  642. "margin-right": "5px"
  643. },
  644. "text": nodeText
  645. });
  646. var text = "";
  647. if (data.value){
  648. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-1, 1);
  649. switch (flag.toLowerCase()){
  650. case "i":
  651. text = data.value.name+"("+data.value.unitName+")";
  652. break;
  653. case "p":
  654. text = data.value.name+"("+data.value.employee+")";
  655. break;
  656. case "u":
  657. text = data.value.levelName;
  658. break;
  659. case "g":
  660. text = data.value.name;
  661. break;
  662. default:
  663. text = data.value.name;
  664. }
  665. var inforNode = new Element("div").set({
  666. "styles": {"font-size": "14px", "color": ""},
  667. "text": text
  668. });
  669. new mBox.Tooltip({
  670. content: inforNode,
  671. setStyles: {content: {padding: 15, lineHeight: 20}},
  672. attach: node,
  673. transition: 'flyin'
  674. });
  675. }
  676. return node;
  677. },
  678. _setValue: function(value){
  679. debugger;
  680. if (value.length==1 && !(value[0])) value=[];
  681. var values = [];
  682. var comboxValues = [];
  683. var type = typeOf(value);
  684. if (type==="array"){
  685. value.each(function(v){
  686. var data=null;
  687. var vtype = typeOf(v);
  688. if (vtype==="string"){
  689. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  690. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  691. }
  692. if (vtype==="object") data = v;
  693. if (data){
  694. values.push(data);
  695. comboxValues.push({"text": this.getDataText(data),"value": data});
  696. }
  697. }.bind(this));
  698. }
  699. if (type==="string"){
  700. var vData;
  701. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  702. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  703. if (vData){
  704. values.push(vData);
  705. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  706. }
  707. }
  708. if (type==="object"){
  709. values.push(value);
  710. comboxValues.push({"text": this.getDataText(value),"value": value});
  711. }
  712. this._setBusinessData(values);
  713. if (this.json.isInput){
  714. if (this.combox){
  715. this.combox.addNewValues(comboxValues);
  716. // values.each(function(v){
  717. // if (typeOf(v)=="string"){
  718. // this.combox.addNewValue(v);
  719. // }else{
  720. // this.combox.addNewValue(this.getDataText(v), v);
  721. // }
  722. // }.bind(this));
  723. }else{
  724. var node = this.node.getFirst();
  725. if (node){
  726. comboxValues.each(function(v, i){
  727. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  728. }.bind(this));
  729. }
  730. }
  731. }else{
  732. if (this.node.getFirst()){
  733. var node = this.node.getFirst();
  734. this.loadOrgWidget(values, node)
  735. }else{
  736. this.loadOrgWidget(values, this.node);
  737. }
  738. }
  739. //if (this.readonly) this.loadOrgWidget(values, this.node)
  740. //this.node.set("text", value);
  741. },
  742. getValueMethod: function(value){
  743. if (value){
  744. var flag = value.substr(value.length-1, 1);
  745. switch (flag.toLowerCase()){
  746. case "i":
  747. return "getIdentity";
  748. case "p":
  749. return "getPerson";
  750. case "u":
  751. return "getUnit";
  752. case "g":
  753. return "getGroup";
  754. default:
  755. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  756. }
  757. }
  758. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  759. },
  760. loadOrgWidget: function(value, node){
  761. var height = node.getStyle("height").toInt();
  762. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  763. if (value && value.length){
  764. value.each(function(data){
  765. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  766. switch (flag.toLowerCase()){
  767. case "i":
  768. new MWF.widget.O2Identity(data, node, {"style": "xform"});
  769. break;
  770. case "p":
  771. new MWF.widget.O2Person(data, node, {"style": "xform"});
  772. break;
  773. case "u":
  774. new MWF.widget.O2Unit(data, node, {"style": "xform"});
  775. break;
  776. case "g":
  777. new MWF.widget.O2Group(data, node, {"style": "xform"});
  778. break;
  779. default:
  780. new MWF.widget.O2Other(data, node, {"style": "xform"});
  781. }
  782. }.bind(this));
  783. }
  784. },
  785. _loadStyles: function(){
  786. if (this.readonly || this.json.isReadonly){
  787. if (this.json.styles) this.node.setStyles(this.json.styles);
  788. }else{
  789. if (this.json.styles) this.node.setStyles(this.json.styles);
  790. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  791. if (this.iconNode){
  792. var size = this.node.getSize();
  793. this.iconNode.setStyle("height", ""+size.y+"px");
  794. }
  795. }
  796. }
  797. });