Personfield.js 34 KB

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