Personfield.js 34 KB

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