O2Identity.js 17 KB

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