Personfield.js 33 KB

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