O2Identity.js 18 KB

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