Personfield.js 32 KB

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