Personfield.js 32 KB

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