Personfield.js 33 KB

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