Personfield.js 36 KB

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