O2Identity.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. o2.require("o2.xDesktop.Common", null, false);
  4. o2.require("o2.xDesktop.Actions.RestActions", null, false);
  5. o2.widget.O2Identity = new Class({
  6. Implements: [Options, Events],
  7. Extends: o2.widget.Common,
  8. options: {
  9. "style": "default",
  10. "canRemove": false,
  11. "lazy": true,
  12. "disableInfor" : false
  13. },
  14. initialize: function(data, container, options){
  15. debugger;
  16. this.setOptions(options);
  17. this.loadedInfor = false;
  18. this.path = o2.session.path+"/widget/$O2Identity/";
  19. this.cssPath = o2.session.path+"/widget/$O2Identity/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.container = $(container);
  22. this.data = data;
  23. this.style = this.css;
  24. this.action = new o2.xDesktop.Actions.RestActions("", "x_organization_assemble_control", "x_component_Org");
  25. // this.explorer = explorer;
  26. // this.removeAction = removeAction;
  27. this.load();
  28. //o2.widget.O2Identity.iditems.push(this);
  29. },
  30. setText: function(){
  31. var disply;
  32. if( this.data.displayName ){
  33. disply = this.data.displayName;
  34. }else{
  35. var name = this.data.name || o2.name.cn(this.data.distinguishedName);
  36. var unit;
  37. if(this.data.unitName){
  38. unit = this.data.unitName;
  39. }else if( this.data.unitLevelName ){
  40. var list = this.data.unitLevelName.split("/");
  41. unit = list[ list.length - 1 ];
  42. }
  43. disply = name + (unit ? "("+unit+")" : "")
  44. }
  45. this.node.set("text", this.data.displayName || disply );
  46. },
  47. load: function(){
  48. var style = ( layout.mobile && this.style.identityNode_mobile ) ?
  49. this.style.identityNode_mobile : this.style.identityNode;
  50. if (!this.options.lazy && !this.options.disableInfor) this.getPersonData();
  51. this.node = new Element("div", {"styles": style }).inject(this.container);
  52. this.setText();
  53. if (this.options.canRemove){
  54. this.removeNode = new Element("div", {"styles": this.style.identityRemoveNode}).inject(this.node);
  55. this.removeNode.addEvent("click", function(e){
  56. this.fireEvent("remove", [this, e]);
  57. e.stopPropagation();
  58. }.bind(this));
  59. }
  60. if( !this.options.disableInfor && !layout.mobile){
  61. if (!this.options.lazy ){
  62. this.createInforNode(function(){
  63. this.fireEvent("loadedInfor", [this]);
  64. }.bind(this));
  65. }else{
  66. this.node.addEvents({
  67. "mouseover": function(){
  68. if (!this.loadedInfor){
  69. this.getPersonData();
  70. this.createInforNode(function(){
  71. this.fireEvent("loadedInfor", [this]);
  72. }.bind(this));
  73. }
  74. }.bind(this)
  75. });
  76. }
  77. }
  78. this.setEvent();
  79. this.node.addEvents({
  80. "mouseover": function(){
  81. var style_over = ( layout.mobile && this.style.identityNode_over_mobile ) ?
  82. this.style.identityNode_over_mobile : this.style.identityNode_over;
  83. this.node.setStyles( style_over );
  84. }.bind(this),
  85. "mouseout": function(){
  86. var style = ( layout.mobile && this.style.identityNode_mobile ) ?
  87. this.style.identityNode_mobile : this.style.identityNode;
  88. this.node.setStyles(style);
  89. }.bind(this)
  90. });
  91. },
  92. setEvent: function(){},
  93. getPersonData: function(){
  94. if (!this.data.dutys){
  95. var action = o2.Actions.get("x_organization_assemble_control");
  96. var id = this.data.distinguishedName || this.data.id || this.data.unique;
  97. if (id) action.listUnitdutyByIdentity(id, function(json){
  98. this.data.dutys = json.data;
  99. }.bind(this), null, false);
  100. }
  101. if (!this.data.woPerson){
  102. // var uri = "/jaxrs/person/{flag}";
  103. // //uri = uri.replace("{flag}", this.data.person);
  104. // var uriIdentity = "/jaxrs/identity/{id}";
  105. this.action.actions = {
  106. "getPerson": {"uri": "/jaxrs/person/{flag}"},
  107. "getIdentity": {"uri": "/jaxrs/identity/{id}"}
  108. };
  109. var woPerson;
  110. if (this.data.person){
  111. this.action.invoke({"name": "getPerson", "async": false, "parameter": {"flag": this.data.person}, "success": function(json){
  112. this.data.woPerson = woPerson;
  113. woPerson = json.data;
  114. }.bind(this)});
  115. }else{
  116. this.action.invoke({"name": "getIdentity", "async": false, "parameter": {"id": this.data.id || this.data.name}, "success": function(json){
  117. this.data = json.data;
  118. woPerson = json.data.woPerson;
  119. }.bind(this)});
  120. }
  121. return woPerson;
  122. }else{
  123. return this.data.woPerson;
  124. }
  125. //listDutyNameWithIdentity
  126. },
  127. createInforNode: function(callback){
  128. var person = this.getPersonData();
  129. if (person){
  130. this.inforNode = new Element("div", {
  131. "styles": this.style.identityInforNode
  132. });
  133. var nameNode = new Element("div", {
  134. "styles": this.style.identityInforNameNode
  135. }).inject(this.inforNode);
  136. var uri = "/jaxrs/person/{flag}/icon";
  137. uri = uri.replace("{flag}", person.id);
  138. this.action.getAddress();
  139. uri = this.action.address+uri;
  140. uri = o2.filterUrl(uri);
  141. img = "<img width='50' height='50' border='0' src='"+uri+"' style='border-radius:25px'/>";
  142. var picNode = new Element("div", {
  143. "styles": this.style.identityInforPicNode,
  144. "html": img
  145. }).inject(nameNode);
  146. var rightNode = new Element("div", {
  147. "styles": this.style.identityInforRightTextNode
  148. }).inject(nameNode);
  149. var nameTextNode = new Element("div", {
  150. "styles": this.style.identityInforNameTextNode,
  151. "text": person.name
  152. }).inject(rightNode);
  153. var employeeTextNode = new Element("div", {
  154. "styles": this.style.identityInforEmployeeTextNode,
  155. "text": person.employee || ""
  156. }).inject(rightNode);
  157. // var phoneNode = new Element("div", {
  158. // "styles": this.style.identityInforPhoneNode,
  159. // "html": "<div style='width:30px; float:left'>"+o2.LP.desktop.person.personMobile+": </div><div style='width:90px; float:left; margin-left:10px'>"+(person.mobile || "")+"</div>"
  160. // }).inject(this.inforNode);
  161. // var mailNode = new Element("div", {
  162. // "styles": this.style.identityInforPhoneNode,
  163. // "html": "<div style='width:30px; float:left'>"+o2.LP.desktop.person.personMail+": </div><div style='width:90px; float:left; margin-left:10px'>"+(person.mail || "")+"</div>"
  164. // }).inject(this.inforNode);
  165. var dutys = [];
  166. if (this.data.dutys && this.data.dutys.length){
  167. this.data.dutys.each(function(d){
  168. var n = d.name+"("+d.woUnit.levelName+")";
  169. dutys.push(n);
  170. });
  171. }
  172. var dutyNode = new Element("div", {
  173. "styles": this.style.identityInforPhoneNode,
  174. "html": "<div style='width:30px; float:left'>"+o2.LP.desktop.person.duty+": </div><div style='width:160px; float:left; margin-left:10px'>"+(dutys.join(","))+"</div>"
  175. }).inject(this.inforNode);
  176. this.loadedInfor = true;
  177. this.tooltip = new mBox.Tooltip({
  178. content: this.inforNode,
  179. setStyles: {content: {padding: 15, lineHeight: 20}},
  180. attach: this.node,
  181. transition: 'flyin'
  182. });
  183. }
  184. if (callback) callback();
  185. },
  186. destroy: function(){
  187. if (this.tooltip) this.tooltip.destroy();
  188. this.node.destroy();
  189. o2.release(this);
  190. }
  191. });
  192. // o2.widget.Person = new Class({
  193. // Implements: [Options, Events],
  194. // Extends: o2.widget.Identity,
  195. // getPerson: function(callback){
  196. // if (this.data.name && this.data.id){
  197. // if (callback) callback({"data": this.data});
  198. // }else{
  199. // var key = this.data.name;
  200. // this.explorer.actions["getPerson"](function(json){
  201. // if (callback) callback(json);
  202. // }, null, key);
  203. // }
  204. // }
  205. // });
  206. o2.widget.O2Person = new Class({
  207. Extends: o2.widget.O2Identity,
  208. getPersonData: function(){
  209. if (!this.data.distinguishedName){
  210. this.action.actions = {"getPerson": {"uri": "/jaxrs/person/{id}"}};
  211. this.action.invoke({"name": "getPerson", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  212. this.data = json.data;
  213. }.bind(this)});
  214. }
  215. return this.data;
  216. },
  217. setText: function(){
  218. this.node.set("text", this.data.displayName || this.data.name);
  219. }
  220. });
  221. o2.widget.O2Unit = new Class({
  222. Extends: o2.widget.O2Identity,
  223. getPersonData: function(){
  224. if (!this.data.distinguishedName || !this.data.levelName){
  225. this.action.actions = {"getUnit": {"uri": "/jaxrs/unit/{id}"}};
  226. this.action.invoke({"name": "getUnit", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  227. this.data = json.data;
  228. }.bind(this)});
  229. }
  230. },
  231. createInforNode: function(){
  232. this.inforNode = new Element("div", {
  233. "styles": this.style.identityInforNode
  234. });
  235. var nameNode = new Element("div", {
  236. "styles": this.style.identityInforNameNode,
  237. "text": this.data.levelName
  238. }).inject(this.inforNode);
  239. this.tooltip = new mBox.Tooltip({
  240. content: this.inforNode,
  241. setStyles: {content: {padding: 15, lineHeight: 20}},
  242. attach: this.node,
  243. transition: 'flyin'
  244. });
  245. },
  246. setText: function(){
  247. this.node.set("text", this.data.displayName || this.data.name);
  248. }
  249. });
  250. o2.widget.O2Duty = new Class({
  251. Extends: o2.widget.O2Identity,
  252. getPersonData: function(){
  253. if (!this.data.woUnit){
  254. this.action.actions = {"getUnitduty": {"uri": "/jaxrs/unitduty/{id}"}};
  255. this.action.invoke({"name": "getUnitduty", "async": false, "parameter": {"id": (this.data.dutyId || this.data.name)}, "success": function(json){
  256. this.data = json.data;
  257. }.bind(this)});
  258. }
  259. },
  260. createInforNode: function(){
  261. this.inforNode = new Element("div", {
  262. "styles": this.style.identityInforNode
  263. });
  264. var nameNode = new Element("div", {
  265. "styles": this.style.identityInforNameNode,
  266. "text": this.data.woUnit.levelName
  267. }).inject(this.inforNode);
  268. this.tooltip = new mBox.Tooltip({
  269. content: this.inforNode,
  270. setStyles: {content: {padding: 15, lineHeight: 20}},
  271. attach: this.node,
  272. transition: 'flyin'
  273. });
  274. },
  275. setText: function(){
  276. this.node.set("text", this.data.displayName || this.data.name);
  277. }
  278. });
  279. o2.widget.O2Group = new Class({
  280. Extends: o2.widget.O2Unit,
  281. getPersonData: function(){
  282. if (!this.data.distinguishedName){
  283. this.action.actions = {"getGroup": {"uri": "/jaxrs/group/{id}"}};
  284. this.action.invoke({"name": "getGroup", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  285. this.data = json.data;
  286. }.bind(this)});
  287. }
  288. },
  289. setText: function(){
  290. this.node.set("text", this.data.displayName || this.data.name);
  291. },
  292. createInforNode: function(){
  293. return false;
  294. }
  295. });
  296. o2.widget.O2Application = new Class({
  297. Extends: o2.widget.O2Group,
  298. getPersonData: function(){
  299. if (!this.data.name){
  300. this.action = new o2.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  301. this.action.actions = {"getApplication": {"uri": "/jaxrs/application/{id}"}};
  302. this.action.invoke({"name": "getApplication", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  303. this.data = json.data;
  304. }.bind(this)});
  305. }
  306. }
  307. });
  308. o2.widget.O2CMSApplication = new Class({
  309. Extends: o2.widget.O2Group,
  310. getPersonData: function(){
  311. if (!this.data.name){
  312. o2.Actions.get("x_cms_assemble_control").getApplication((this.data.id || this.data.name), function(json){
  313. this.data = json.data;
  314. }.bind(this), null, false);
  315. // this.action = new o2.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  316. // this.action.actions = {"getApplication": {"uri": "/jaxrs/application/{id}"}};
  317. // this.action.invoke({"name": "getApplication", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  318. // this.data = json.data;
  319. // }.bind(this)});
  320. }
  321. }
  322. });
  323. o2.widget.O2Process = new Class({
  324. Extends: o2.widget.O2Group,
  325. getPersonData: function(){
  326. if (!this.data.name){
  327. this.action = new o2.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  328. this.action.actions = {"getProces": {"uri": "/jaxrs/process/{id}/complex"}};
  329. this.action.invoke({"name": "getProces", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  330. this.data = json.data;
  331. }.bind(this)});
  332. }
  333. },
  334. createInforNode: function(){
  335. this.inforNode = new Element("div", {
  336. "styles": this.style.identityInforNode
  337. });
  338. var nameNode = new Element("div", {
  339. "styles": this.style.identityInforNameNode,
  340. "text": this.data.name || this.data.applicationName || this.data.appName
  341. }).inject(this.inforNode);
  342. this.tooltip = new mBox.Tooltip({
  343. content: this.inforNode,
  344. setStyles: {content: {padding: 15, lineHeight: 20}},
  345. attach: this.node,
  346. transition: 'flyin'
  347. });
  348. }
  349. });
  350. o2.widget.O2CMSCategory = new Class({
  351. Extends: o2.widget.O2Group,
  352. getPersonData: function(){
  353. if (!this.data.name){
  354. o2.Actions.get("x_cms_assemble_control").getCategory((this.data.id || this.data.name), function(json){
  355. this.data = json.data;
  356. }.bind(this), null, false);
  357. }
  358. },
  359. createInforNode: function(){
  360. this.inforNode = new Element("div", {
  361. "styles": this.style.identityInforNode
  362. });
  363. var nameNode = new Element("div", {
  364. "styles": this.style.identityInforNameNode,
  365. "text": this.data.applicationName || this.data.appName
  366. }).inject(this.inforNode);
  367. this.tooltip = new mBox.Tooltip({
  368. content: this.inforNode,
  369. setStyles: {content: {padding: 15, lineHeight: 20}},
  370. attach: this.node,
  371. transition: 'flyin'
  372. });
  373. }
  374. });
  375. o2.widget.O2View = new Class({
  376. Extends: o2.widget.O2Group,
  377. getPersonData: function(){
  378. if (!this.data.query){
  379. var data = null;
  380. o2.Actions.get("x_query_assemble_surface").getStatById(this.data.id, function(json){
  381. data = json.data
  382. }, null, false);
  383. this.data = data;
  384. return data;
  385. }else{
  386. return this.data;
  387. }
  388. },
  389. createInforNode: function(){
  390. this.inforNode = new Element("div", {
  391. "styles": this.style.identityInforNode
  392. });
  393. var nameNode = new Element("div", {
  394. "styles": this.style.identityInforNameNode,
  395. "text": this.data.applicationName || this.data.appName || this.data.name
  396. }).inject(this.inforNode);
  397. this.tooltip = new mBox.Tooltip({
  398. content: this.inforNode,
  399. setStyles: {content: {padding: 15, lineHeight: 20}},
  400. attach: this.node,
  401. transition: 'flyin'
  402. });
  403. }
  404. });
  405. o2.widget.O2CMSView = new Class({
  406. Extends: o2.widget.O2View
  407. });
  408. o2.widget.O2QueryView = new Class({
  409. Extends: o2.widget.O2View,
  410. getPersonData: function(){
  411. if (!this.data.query){
  412. var data = null;
  413. o2.Actions.get("x_query_assemble_surface").getViewById(this.data.id, function(json){
  414. data = json.data
  415. }, null, false);
  416. this.data = data;
  417. return data;
  418. }else{
  419. return this.data;
  420. }
  421. }
  422. });
  423. o2.widget.O2QueryStat = new Class({
  424. Extends: o2.widget.O2View,
  425. getPersonData: function(){
  426. if (!this.data.query){
  427. var data = null;
  428. o2.Actions.get("x_query_assemble_surface").getStatById(this.data.id, function(json){
  429. data = json.data
  430. }, null, false);
  431. this.data = data;
  432. return data;
  433. }else{
  434. return this.data;
  435. }
  436. }
  437. });
  438. o2.widget.O2QueryTable = new Class({
  439. Extends: o2.widget.O2View,
  440. getPersonData: function(){
  441. if (!this.data.query){
  442. var data = null;
  443. o2.Actions.get("x_query_assemble_surface").getTableById(this.data.id, function(json){
  444. data = json.data
  445. }, null, false);
  446. this.data = data;
  447. return data;
  448. }else{
  449. return this.data;
  450. }
  451. }
  452. });
  453. o2.widget.O2FormField = new Class({
  454. Extends: o2.widget.O2Group,
  455. getPersonData: function(){
  456. return this.data;
  457. }
  458. });
  459. o2.widget.O2Role = new Class({
  460. Extends: o2.widget.O2Group,
  461. getPersonData: function(){
  462. if (!this.data.distinguishedName){
  463. this.action.actions = {"getRole": {"uri": "/jaxrs/role/{id}"}};
  464. this.action.invoke({"name": "getRole", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  465. this.data = json.data;
  466. }.bind(this)});
  467. }
  468. }
  469. });
  470. o2.widget.O2File = new Class({
  471. Extends: o2.widget.O2Group,
  472. createInforNode: function(){
  473. this.inforNode = new Element("div", {
  474. "styles": this.style.identityInforNode
  475. });
  476. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  477. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  478. var url = (this.data.portal) ? MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal) : MWF.xDesktop.getProcessFileUr(this.data.id, this.data.application);
  479. var img = new Element("img", {"src": url, "styles": {"max-width": "280px", "max-height": "140px"}}).inject(this.inforNode);
  480. }else{
  481. var nameNode = new Element("div", {
  482. "styles": this.style.identityInforNameNode,
  483. "text": this.data.applicationName || this.data.appName || this.data.name
  484. }).inject(this.inforNode);
  485. }
  486. this.tooltip = new mBox.Tooltip({
  487. content: this.inforNode,
  488. setStyles: {content: {padding: 15, lineHeight: 20}},
  489. attach: this.node,
  490. transition: 'flyin'
  491. });
  492. },
  493. getPersonData: function(){
  494. return this.data;
  495. }
  496. });
  497. o2.widget.O2Other = new Class({
  498. Extends: o2.widget.O2Group,
  499. getPersonData: function(){
  500. return this.data;
  501. }
  502. });
  503. /**
  504. * @return {null}
  505. */
  506. o2.widget.O2Org = function(value, container, options){
  507. var v = (o2.typeOf(value)==="string") ? {"name": value} : value.distinguishedName;
  508. var t = v.distinguishedName || v.name || "";
  509. if (t) {
  510. var flag = t.substr(t.length - 1, 1);
  511. switch (flag.toLowerCase()) {
  512. case "i":
  513. return new o2.widget.O2Identity(v, container, options);
  514. case "p":
  515. return new o2.widget.O2Person(v, container, options);
  516. case "u":
  517. return new o2.widget.O2Unit(v, container, options);
  518. case "g":
  519. return new o2.widget.O2Group(v, container, options);
  520. case "r":
  521. return new o2.widget.O2Role(v, container, options);
  522. case "d":
  523. return new o2.widget.O2Duty(v, container, options);
  524. default:
  525. return new o2.widget.O2Other(v, container, options);
  526. }
  527. }
  528. return null;
  529. };
  530. // o2.widget.O2Identity.iditems = o2.widget.O2Identity.iditems || [];
  531. // o2.widget.O2Identity.intervalId = window.setInterval(function(){
  532. // if (o2.widget.O2Identity.iditems && o2.widget.O2Identity.iditems.length){
  533. // o2.widget.O2Identity.iditems.each(function(item){
  534. // if (item.tooltip){
  535. // debugger;
  536. // if (item.tooltip.options.attach){
  537. //
  538. // }
  539. // }
  540. // });
  541. // }
  542. // }, 10000);