Personfield.js 34 KB

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