O2Identity.js 21 KB

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