Personfield.js 34 KB

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