O2Identity.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. img = "<img width='50' height='50' border='0' src='"+uri+"' style='border-radius:25px'/>";
  125. var picNode = new Element("div", {
  126. "styles": this.style.identityInforPicNode,
  127. "html": img
  128. }).inject(nameNode);
  129. var rightNode = new Element("div", {
  130. "styles": this.style.identityInforRightTextNode
  131. }).inject(nameNode);
  132. var nameTextNode = new Element("div", {
  133. "styles": this.style.identityInforNameTextNode,
  134. "text": person.name
  135. }).inject(rightNode);
  136. var employeeTextNode = new Element("div", {
  137. "styles": this.style.identityInforEmployeeTextNode,
  138. "text": person.employee || ""
  139. }).inject(rightNode);
  140. // var phoneNode = new Element("div", {
  141. // "styles": this.style.identityInforPhoneNode,
  142. // "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>"
  143. // }).inject(this.inforNode);
  144. // var mailNode = new Element("div", {
  145. // "styles": this.style.identityInforPhoneNode,
  146. // "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>"
  147. // }).inject(this.inforNode);
  148. var dutys = [];
  149. if (this.data.dutys && this.data.dutys.length){
  150. this.data.dutys.each(function(d){
  151. var n = d.name+"("+d.woUnit.levelName+")";
  152. dutys.push(n);
  153. });
  154. }
  155. var dutyNode = new Element("div", {
  156. "styles": this.style.identityInforPhoneNode,
  157. "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>"
  158. }).inject(this.inforNode);
  159. this.loadedInfor = true;
  160. this.tooltip = new mBox.Tooltip({
  161. content: this.inforNode,
  162. setStyles: {content: {padding: 15, lineHeight: 20}},
  163. attach: this.node,
  164. transition: 'flyin'
  165. });
  166. }
  167. if (callback) callback();
  168. },
  169. destroy: function(){
  170. if (this.tooltip) this.tooltip.destroy();
  171. this.node.destroy();
  172. o2.release(this);
  173. }
  174. });
  175. // o2.widget.Person = new Class({
  176. // Implements: [Options, Events],
  177. // Extends: o2.widget.Identity,
  178. // getPerson: function(callback){
  179. // if (this.data.name && this.data.id){
  180. // if (callback) callback({"data": this.data});
  181. // }else{
  182. // var key = this.data.name;
  183. // this.explorer.actions["getPerson"](function(json){
  184. // if (callback) callback(json);
  185. // }, null, key);
  186. // }
  187. // }
  188. // });
  189. o2.widget.O2Person = new Class({
  190. Extends: o2.widget.O2Identity,
  191. getPersonData: function(){
  192. if (!this.data.distinguishedName){
  193. this.action.actions = {"getPerson": {"uri": "/jaxrs/person/{id}"}};
  194. this.action.invoke({"name": "getPerson", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  195. this.data = json.data;
  196. }.bind(this)});
  197. }
  198. return this.data;
  199. },
  200. setText: function(){
  201. this.node.set("text", this.data.displayName || this.data.name);
  202. }
  203. });
  204. o2.widget.O2Unit = new Class({
  205. Extends: o2.widget.O2Identity,
  206. getPersonData: function(){
  207. if (!this.data.distinguishedName){
  208. this.action.actions = {"getUnit": {"uri": "/jaxrs/unit/{id}"}};
  209. this.action.invoke({"name": "getUnit", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  210. this.data = json.data;
  211. }.bind(this)});
  212. }
  213. },
  214. createInforNode: function(){
  215. this.inforNode = new Element("div", {
  216. "styles": this.style.identityInforNode
  217. });
  218. var nameNode = new Element("div", {
  219. "styles": this.style.identityInforNameNode,
  220. "text": this.data.levelName
  221. }).inject(this.inforNode);
  222. this.tooltip = new mBox.Tooltip({
  223. content: this.inforNode,
  224. setStyles: {content: {padding: 15, lineHeight: 20}},
  225. attach: this.node,
  226. transition: 'flyin'
  227. });
  228. },
  229. setText: function(){
  230. this.node.set("text", this.data.displayName || this.data.name);
  231. }
  232. });
  233. o2.widget.O2Duty = new Class({
  234. Extends: o2.widget.O2Identity,
  235. getPersonData: function(){
  236. if (!this.data.woUnit){
  237. this.action.actions = {"getUnitduty": {"uri": "/jaxrs/unitduty/{id}"}};
  238. this.action.invoke({"name": "getUnitduty", "async": false, "parameter": {"id": (this.data.dutyId || this.data.name)}, "success": function(json){
  239. this.data = json.data;
  240. }.bind(this)});
  241. }
  242. },
  243. createInforNode: function(){
  244. this.inforNode = new Element("div", {
  245. "styles": this.style.identityInforNode
  246. });
  247. var nameNode = new Element("div", {
  248. "styles": this.style.identityInforNameNode,
  249. "text": this.data.woUnit.levelName
  250. }).inject(this.inforNode);
  251. this.tooltip = new mBox.Tooltip({
  252. content: this.inforNode,
  253. setStyles: {content: {padding: 15, lineHeight: 20}},
  254. attach: this.node,
  255. transition: 'flyin'
  256. });
  257. },
  258. setText: function(){
  259. this.node.set("text", this.data.displayName || this.data.name);
  260. }
  261. });
  262. o2.widget.O2Group = new Class({
  263. Extends: o2.widget.O2Unit,
  264. getPersonData: function(){
  265. if (!this.data.distinguishedName){
  266. this.action.actions = {"getGroup": {"uri": "/jaxrs/group/{id}"}};
  267. this.action.invoke({"name": "getGroup", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  268. this.data = json.data;
  269. }.bind(this)});
  270. }
  271. },
  272. setText: function(){
  273. this.node.set("text", this.data.displayName || this.data.name);
  274. },
  275. createInforNode: function(){
  276. return false;
  277. }
  278. });
  279. o2.widget.O2Application = new Class({
  280. Extends: o2.widget.O2Group,
  281. getPersonData: function(){
  282. if (!this.data.name){
  283. this.action = new o2.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  284. this.action.actions = {"getApplication": {"uri": "/jaxrs/application/{id}"}};
  285. this.action.invoke({"name": "getApplication", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  286. this.data = json.data;
  287. }.bind(this)});
  288. }
  289. }
  290. });
  291. o2.widget.O2CMSApplication = new Class({
  292. Extends: o2.widget.O2Group,
  293. getPersonData: function(){
  294. if (!this.data.name){
  295. o2.Actions.get("x_cms_assemble_control").getApplication((this.data.id || this.data.name), function(json){
  296. this.data = json.data;
  297. }.bind(this), null, false);
  298. // this.action = new o2.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  299. // this.action.actions = {"getApplication": {"uri": "/jaxrs/application/{id}"}};
  300. // this.action.invoke({"name": "getApplication", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  301. // this.data = json.data;
  302. // }.bind(this)});
  303. }
  304. }
  305. });
  306. o2.widget.O2Process = new Class({
  307. Extends: o2.widget.O2Group,
  308. getPersonData: function(){
  309. if (!this.data.name){
  310. this.action = new o2.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  311. this.action.actions = {"getProces": {"uri": "/jaxrs/process/{id}/complex"}};
  312. this.action.invoke({"name": "getProces", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  313. this.data = json.data;
  314. }.bind(this)});
  315. }
  316. },
  317. createInforNode: function(){
  318. this.inforNode = new Element("div", {
  319. "styles": this.style.identityInforNode
  320. });
  321. var nameNode = new Element("div", {
  322. "styles": this.style.identityInforNameNode,
  323. "text": this.data.name || this.data.applicationName || this.data.appName
  324. }).inject(this.inforNode);
  325. this.tooltip = new mBox.Tooltip({
  326. content: this.inforNode,
  327. setStyles: {content: {padding: 15, lineHeight: 20}},
  328. attach: this.node,
  329. transition: 'flyin'
  330. });
  331. }
  332. });
  333. o2.widget.O2CMSCategory = new Class({
  334. Extends: o2.widget.O2Group,
  335. getPersonData: function(){
  336. if (!this.data.name){
  337. o2.Actions.get("x_cms_assemble_control").getCategory((this.data.id || this.data.name), function(json){
  338. this.data = json.data;
  339. }.bind(this), null, false);
  340. }
  341. },
  342. createInforNode: function(){
  343. this.inforNode = new Element("div", {
  344. "styles": this.style.identityInforNode
  345. });
  346. var nameNode = new Element("div", {
  347. "styles": this.style.identityInforNameNode,
  348. "text": this.data.applicationName || this.data.appName
  349. }).inject(this.inforNode);
  350. this.tooltip = new mBox.Tooltip({
  351. content: this.inforNode,
  352. setStyles: {content: {padding: 15, lineHeight: 20}},
  353. attach: this.node,
  354. transition: 'flyin'
  355. });
  356. }
  357. });
  358. o2.widget.O2View = new Class({
  359. Extends: o2.widget.O2Group,
  360. getPersonData: function(){
  361. if (!this.data.query){
  362. var data = null;
  363. o2.Actions.get("x_query_assemble_surface").getStatById(this.data.id, function(json){
  364. data = json.data
  365. }, null, false);
  366. this.data = data;
  367. return data;
  368. }else{
  369. return this.data;
  370. }
  371. },
  372. createInforNode: function(){
  373. this.inforNode = new Element("div", {
  374. "styles": this.style.identityInforNode
  375. });
  376. var nameNode = new Element("div", {
  377. "styles": this.style.identityInforNameNode,
  378. "text": this.data.applicationName || this.data.appName || this.data.name
  379. }).inject(this.inforNode);
  380. this.tooltip = new mBox.Tooltip({
  381. content: this.inforNode,
  382. setStyles: {content: {padding: 15, lineHeight: 20}},
  383. attach: this.node,
  384. transition: 'flyin'
  385. });
  386. }
  387. });
  388. o2.widget.O2CMSView = new Class({
  389. Extends: o2.widget.O2View
  390. });
  391. o2.widget.O2QueryView = new Class({
  392. Extends: o2.widget.O2View,
  393. getPersonData: function(){
  394. if (!this.data.query){
  395. var data = null;
  396. o2.Actions.get("x_query_assemble_surface").getViewById(this.data.id, function(json){
  397. data = json.data
  398. }, null, false);
  399. this.data = data;
  400. return data;
  401. }else{
  402. return this.data;
  403. }
  404. }
  405. });
  406. o2.widget.O2QueryStat = new Class({
  407. Extends: o2.widget.O2View,
  408. getPersonData: function(){
  409. if (!this.data.query){
  410. var data = null;
  411. o2.Actions.get("x_query_assemble_surface").getStatById(this.data.id, function(json){
  412. data = json.data
  413. }, null, false);
  414. this.data = data;
  415. return data;
  416. }else{
  417. return this.data;
  418. }
  419. }
  420. });
  421. o2.widget.O2QueryTable = new Class({
  422. Extends: o2.widget.O2View,
  423. getPersonData: function(){
  424. if (!this.data.query){
  425. var data = null;
  426. o2.Actions.get("x_query_assemble_surface").getTableById(this.data.id, function(json){
  427. data = json.data
  428. }, null, false);
  429. this.data = data;
  430. return data;
  431. }else{
  432. return this.data;
  433. }
  434. }
  435. });
  436. o2.widget.O2FormField = new Class({
  437. Extends: o2.widget.O2Group,
  438. getPersonData: function(){
  439. return this.data;
  440. }
  441. });
  442. o2.widget.O2Role = new Class({
  443. Extends: o2.widget.O2Group,
  444. getPersonData: function(){
  445. if (!this.data.distinguishedName){
  446. this.action.actions = {"getRole": {"uri": "/jaxrs/role/{id}"}};
  447. this.action.invoke({"name": "getRole", "async": false, "parameter": {"id": (this.data.id || this.data.name)}, "success": function(json){
  448. this.data = json.data;
  449. }.bind(this)});
  450. }
  451. }
  452. });
  453. o2.widget.O2File = new Class({
  454. Extends: o2.widget.O2Group,
  455. createInforNode: function(){
  456. this.inforNode = new Element("div", {
  457. "styles": this.style.identityInforNode
  458. });
  459. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  460. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  461. var url = (this.data.portal) ? MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal) : MWF.xDesktop.getProcessFileUr(this.data.id, this.data.application);
  462. var img = new Element("img", {"src": url, "styles": {"max-width": "280px", "max-height": "140px"}}).inject(this.inforNode);
  463. }else{
  464. var nameNode = new Element("div", {
  465. "styles": this.style.identityInforNameNode,
  466. "text": this.data.applicationName || this.data.appName || this.data.name
  467. }).inject(this.inforNode);
  468. }
  469. this.tooltip = new mBox.Tooltip({
  470. content: this.inforNode,
  471. setStyles: {content: {padding: 15, lineHeight: 20}},
  472. attach: this.node,
  473. transition: 'flyin'
  474. });
  475. },
  476. getPersonData: function(){
  477. return this.data;
  478. }
  479. });
  480. o2.widget.O2Other = new Class({
  481. Extends: o2.widget.O2Group,
  482. getPersonData: function(){
  483. return this.data;
  484. }
  485. });
  486. /**
  487. * @return {null}
  488. */
  489. o2.widget.O2Org = function(value, container, options){
  490. var v = (o2.typeOf(value)==="string") ? {"name": value} : value.distinguishedName;
  491. var t = v.distinguishedName || v.name || "";
  492. if (t) {
  493. var flag = t.substr(t.length - 1, 1);
  494. switch (flag.toLowerCase()) {
  495. case "i":
  496. return new o2.widget.O2Identity(v, container, options);
  497. case "p":
  498. return new o2.widget.O2Person(v, container, options);
  499. case "u":
  500. return new o2.widget.O2Unit(v, container, options);
  501. case "g":
  502. return new o2.widget.O2Group(v, container, options);
  503. case "r":
  504. return new o2.widget.O2Role(v, container, options);
  505. case "d":
  506. return new o2.widget.O2Duty(v, container, options);
  507. default:
  508. return new o2.widget.O2Other(v, container, options);
  509. }
  510. }
  511. return null;
  512. };
  513. // o2.widget.O2Identity.iditems = o2.widget.O2Identity.iditems || [];
  514. // o2.widget.O2Identity.intervalId = window.setInterval(function(){
  515. // if (o2.widget.O2Identity.iditems && o2.widget.O2Identity.iditems.length){
  516. // o2.widget.O2Identity.iditems.each(function(item){
  517. // if (item.tooltip){
  518. // debugger;
  519. // if (item.tooltip.options.attach){
  520. //
  521. // }
  522. // }
  523. // });
  524. // }
  525. // }, 10000);