Personfield.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. _loadNodeInputEdit: function() {
  472. var input = null;
  473. MWF.require("MWF.widget.Combox", function () {
  474. this.combox = input = new MWF.widget.Combox({
  475. "count": this.json.count || 0,
  476. "splitShow": this.json.splitShow || ", ",
  477. "onCommitInput": function (item) {
  478. this._searchConfirmPerson(item);
  479. //this.fireEvent("change");
  480. }.bind(this),
  481. "onChange": function () {
  482. this._setBusinessData(this.getInputData());
  483. this.fireEvent("change");
  484. }.bind(this),
  485. "optionsMethod": this._searchOptions.bind(this)
  486. });
  487. }.bind(this), false);
  488. input.setStyles({
  489. "background": "transparent",
  490. "border": "0px"
  491. });
  492. input.set(this.json.properties);
  493. var node = new Element("div", {
  494. "styles": {
  495. "overflow": "hidden",
  496. //"position": "relative",
  497. "margin-right": "20px"
  498. }
  499. }).inject(this.node, "after");
  500. input.inject(node);
  501. //this.combox = input;
  502. this.node.destroy();
  503. this.node = node;
  504. this.node.set({
  505. "id": this.json.id,
  506. "MWFType": this.json.type
  507. });
  508. if (this.json.showIcon != 'no' && !this.form.json.hideModuleIcon){
  509. this.iconNode = new Element("div", {
  510. "styles": this.form.css[this.iconStyle],
  511. "events": {
  512. "click": function (ev) {
  513. this.clickSelect( ev );
  514. }.bind(this)
  515. //this.clickSelect.bind(this)
  516. }
  517. }).inject(this.node, "before");
  518. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  519. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  520. }
  521. this.combox.addEvent("change", function(){
  522. this.validationMode();
  523. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  524. }.bind(this));
  525. },
  526. _loadNodeEdit: function(){
  527. var input = new Element("div", {
  528. "styles": {
  529. "background": "transparent",
  530. "border": "0px",
  531. "min-height": "24px"
  532. }
  533. });
  534. input.set(this.json.properties);
  535. var node = new Element("div", {"styles": {
  536. "overflow": "hidden",
  537. "position": "relative",
  538. "margin-right": "20px",
  539. "min-height": "24px"
  540. }}).inject(this.node, "after");
  541. input.inject(node);
  542. this.node.destroy();
  543. this.node = node;
  544. this.node.set({
  545. "id": this.json.id,
  546. "MWFType": this.json.type,
  547. "events": {
  548. "click": function (ev) {
  549. this.clickSelect( ev );
  550. }.bind(this)
  551. //this.clickSelect.bind(this)
  552. }
  553. });
  554. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) this.iconNode = new Element("div", {
  555. "styles": this.form.css[this.iconStyle],
  556. "events": {
  557. "click": function (ev) {
  558. this.clickSelect( ev );
  559. }.bind(this)
  560. //this.clickSelect.bind(this)
  561. }
  562. }).inject(this.node, "before");
  563. this.node.getFirst().setStyle("height", "auto");
  564. this.node.getFirst().addEvent("change", function(){
  565. this.validationMode();
  566. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  567. }.bind(this));
  568. },
  569. getDataText: function(data){
  570. if (typeOf(data)=="string") return data;
  571. var text = "";
  572. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  573. switch (flag.toLowerCase()){
  574. case "@i":
  575. text = data.name+"("+data.unitName+")";
  576. break;
  577. case "@p":
  578. text = data.name+"("+data.employee+")";
  579. break;
  580. case "@u":
  581. text = data.name;
  582. break;
  583. case "@g":
  584. text = data.name;
  585. break;
  586. default:
  587. text = data.name;
  588. }
  589. return text;
  590. },
  591. addData: function(value){
  592. if (!value) return false;
  593. value.each(function(v){
  594. var vtype = typeOf(v);
  595. if (vtype==="string"){
  596. var data;
  597. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  598. if (data) this.combox.addNewValue(this.getDataText(data), data);
  599. }
  600. if (vtype==="object"){
  601. this.combox.addNewValue(this.getDataText(v), v);
  602. }
  603. }.bind(this));
  604. },
  605. setData: function(value){
  606. if (!value) return false;
  607. var oldValues = this.getData();
  608. var values = [];
  609. var comboxValues = [];
  610. debugger;
  611. var type = typeOf(value);
  612. if (type==="array"){
  613. value.each(function(v){
  614. var vtype = typeOf(v);
  615. var data = null;
  616. if (vtype==="string"){
  617. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  618. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, false); }.bind(this), error, v, false);
  619. }
  620. if (vtype==="object") {
  621. data = MWF.org.parseOrgData(v, false);
  622. if(data.woPerson)delete data.woPerson;
  623. }
  624. if (data){
  625. values.push(data);
  626. comboxValues.push({"text": this.getDataText(data),"value": data});
  627. }
  628. }.bind(this));
  629. }
  630. if (type==="string"){
  631. var vData;
  632. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  633. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, false); }.bind(this), error, value, false);
  634. if (vData){
  635. values.push(vData);
  636. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  637. }
  638. }
  639. if (type==="object"){
  640. var vData = MWF.org.parseOrgData(value, false);
  641. if(vData.woPerson)delete vData.woPerson;
  642. values.push( vData );
  643. comboxValues.push({"text": this.getDataText(value),"value": vData});
  644. }
  645. var change = false;
  646. if (oldValues.length && values.length){
  647. if (oldValues.length === values.length){
  648. for (var i=0; i<oldValues.length; i++){
  649. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  650. change = true;
  651. break;
  652. }
  653. }
  654. }else{
  655. change = true;
  656. }
  657. }else if (values.length || oldValues.length) {
  658. change = true;
  659. }
  660. this._setBusinessData(values);
  661. if (change) this.fireEvent("change");
  662. if (this.json.isInput){
  663. if (this.combox){
  664. this.combox.clear();
  665. this.combox.addNewValues(comboxValues);
  666. }else{
  667. var node = this.node.getFirst();
  668. if (node){
  669. comboxValues.each(function(v, i){
  670. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  671. }.bind(this));
  672. }
  673. }
  674. //
  675. // this.combox.clear();
  676. // values.each(function(v){
  677. // var vtype = typeOf(v);
  678. // if (vtype==="string"){
  679. // var data;
  680. // this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
  681. // if (data) this.combox.addNewValue(this.getDataText(data), data);
  682. // }
  683. // if (vtype==="object"){
  684. // this.combox.addNewValue(this.getDataText(v), v);
  685. // }
  686. // }.bind(this));
  687. }else{
  688. if (this.node.getFirst()){
  689. var node = this.node.getFirst();
  690. node.empty();
  691. this.loadOrgWidget(values, node)
  692. }else{
  693. this.node.empty();
  694. this.loadOrgWidget(values, this.node);
  695. }
  696. }
  697. },
  698. creteShowNode: function(data, islast){
  699. var nodeText = (data.text) ? data.text : data;
  700. if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
  701. var node = new Element("div", {
  702. "styles": {
  703. "float": "left",
  704. "margin-right": "5px"
  705. },
  706. "text": nodeText
  707. });
  708. var text = "";
  709. if (data.value){
  710. var flag = data.value.distinguishedName.substr(data.value.distinguishedName.length-2, 2);
  711. switch (flag.toLowerCase()){
  712. case "@i":
  713. text = data.value.name+"("+data.value.unitName+")";
  714. break;
  715. case "@p":
  716. text = data.value.name+"("+data.value.employee+")";
  717. break;
  718. case "@u":
  719. text = data.value.levelName;
  720. break;
  721. case "@g":
  722. text = data.value.name;
  723. break;
  724. default:
  725. text = data.value.name;
  726. }
  727. var inforNode = new Element("div").set({
  728. "styles": {"font-size": "14px", "color": ""},
  729. "text": text
  730. });
  731. new mBox.Tooltip({
  732. content: inforNode,
  733. setStyles: {content: {padding: 15, lineHeight: 20}},
  734. attach: node,
  735. transition: 'flyin'
  736. });
  737. }
  738. return node;
  739. },
  740. _setValue: function(value){
  741. if (value.length==1 && !(value[0])) value=[];
  742. var values = [];
  743. var comboxValues = [];
  744. var type = typeOf(value);
  745. if (type==="array"){
  746. value.each(function(v){
  747. var data=null;
  748. var vtype = typeOf(v);
  749. if (vtype==="string"){
  750. var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
  751. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), error, v, false);
  752. }
  753. if (vtype==="object") data = v;
  754. if (data){
  755. values.push(data);
  756. comboxValues.push({"text": this.getDataText(data),"value": data});
  757. }
  758. }.bind(this));
  759. }
  760. if (type==="string"){
  761. var vData;
  762. var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
  763. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = json.data }.bind(this), error, value, false);
  764. if (vData){
  765. values.push(vData);
  766. comboxValues.push({"text": this.getDataText(vData),"value": vData});
  767. }
  768. }
  769. if (type==="object"){
  770. values.push(value);
  771. comboxValues.push({"text": this.getDataText(value),"value": value});
  772. }
  773. this._setBusinessData(values);
  774. if (this.json.isInput){
  775. if (this.combox){
  776. this.combox.clear();
  777. this.combox.addNewValues(comboxValues);
  778. // values.each(function(v){
  779. // if (typeOf(v)=="string"){
  780. // this.combox.addNewValue(v);
  781. // }else{
  782. // this.combox.addNewValue(this.getDataText(v), v);
  783. // }
  784. // }.bind(this));
  785. }else{
  786. var node = this.node.getFirst();
  787. if (node){
  788. comboxValues.each(function(v, i){
  789. this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
  790. }.bind(this));
  791. }
  792. }
  793. }else{
  794. if (this.node.getFirst()){
  795. var node = this.node.getFirst();
  796. this.loadOrgWidget(values, node)
  797. }else{
  798. this.loadOrgWidget(values, this.node);
  799. }
  800. }
  801. //if (this.readonly) this.loadOrgWidget(values, this.node)
  802. //this.node.set("text", value);
  803. },
  804. getValueMethod: function(value){
  805. if (value){
  806. var flag = value.substr(value.length-1, 1);
  807. switch (flag.toLowerCase()){
  808. case "i":
  809. return "getIdentity";
  810. case "p":
  811. return "getPerson";
  812. case "u":
  813. return "getUnit";
  814. case "g":
  815. return "getGroup";
  816. default:
  817. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  818. }
  819. }
  820. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  821. },
  822. loadOrgWidget: function(value, node){
  823. var height = node.getStyle("height").toInt();
  824. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  825. if (value && value.length){
  826. value.each(function(data){
  827. var flag = data.distinguishedName.substr(data.distinguishedName.length-2, 2);
  828. var copyData = Object.clone(data);
  829. switch (flag.toLowerCase()){
  830. case "@i":
  831. new MWF.widget.O2Identity(copyData, node, {"style": "xform"});
  832. break;
  833. case "@p":
  834. new MWF.widget.O2Person(copyData, node, {"style": "xform"});
  835. break;
  836. case "@u":
  837. new MWF.widget.O2Unit(copyData, node, {"style": "xform"});
  838. break;
  839. case "@g":
  840. new MWF.widget.O2Group(copyData, node, {"style": "xform"});
  841. break;
  842. default:
  843. new MWF.widget.O2Other(copyData, node, {"style": "xform"});
  844. }
  845. }.bind(this));
  846. }
  847. },
  848. _loadStyles: function(){
  849. if (this.readonly || this.json.isReadonly){
  850. if (this.json.styles) this.node.setStyles(this.json.styles);
  851. }else{
  852. if (this.json.styles) this.node.setStyles(this.json.styles);
  853. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  854. if (this.iconNode && this.iconNode.offsetParent !== null ){
  855. var size = this.node.getSize();
  856. this.iconNode.setStyle("height", ""+size.y+"px");
  857. }
  858. }
  859. }
  860. });