Personfield.js 32 KB

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