Personfield.js 35 KB

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