Main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. MWF.xApplication.ThreeMember = MWF.xApplication.ThreeMember || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. //MWF.xDesktop.requireApp("ThreeMember", "Access", null, false);
  4. //MWF.xDesktop.requireApp("ThreeMember", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  6. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  7. MWF.xApplication.ThreeMember.options = {
  8. multitask: false,
  9. executable: true
  10. };
  11. MWF.xApplication.ThreeMember.Main = new Class({
  12. Extends: MWF.xApplication.Common.Main,
  13. Implements: [Options, Events],
  14. options: {
  15. "style": "default",
  16. "name": "ThreeMember",
  17. "icon": "icon.png",
  18. "width": "1220",
  19. "height": "700",
  20. "isResize": true,
  21. "isMax": true,
  22. "viewPageNum": 1,
  23. "managerEnabled": true,
  24. "title": MWF.xApplication.ThreeMember.LP.title
  25. },
  26. onQueryLoad: function () {
  27. this.lp = MWF.xApplication.ThreeMember.LP;
  28. },
  29. loadApplication: function (callback) {
  30. this.userName = layout.desktop.session.user.distinguishedName;
  31. this.path = "../x_component_ThreeMember/$Main/" + this.options.style + "/";
  32. this.createNode();
  33. this.loadApplicationContent();
  34. },
  35. loadController: function (callback) {
  36. //this.access = new MWF.xApplication.ThreeMember.Access( this.restActions, this.lp );
  37. if (callback) callback();
  38. },
  39. reload: function () {
  40. this.clear();
  41. this.loadApplicationLayout();
  42. },
  43. isAdmin: function () {
  44. return this.access.isAdmin();
  45. },
  46. createNode: function () {
  47. debugger;
  48. this.content.setStyle("overflow", "hidden");
  49. this.node = new Element("div", {
  50. "styles": this.css.node
  51. }).inject(this.content);
  52. },
  53. loadApplicationContent: function () {
  54. this.loadController(function () {
  55. this.loadApplicationLayout();
  56. }.bind(this))
  57. },
  58. loadApplicationLayout: function () {
  59. this.naviNode = new Element("div.naviNode", {
  60. "styles": this.css.naviNode
  61. }).inject(this.node);
  62. this.contentContainerNode = new Element("div.contentContainerNode", {
  63. "styles": this.css.contentContainerNode
  64. }).inject(this.node);
  65. this.setContentSize();
  66. this.setContentSizeFun = this.setContentSize.bind(this);
  67. this.addEvent("resize", this.setContentSizeFun);
  68. this.loadUser();
  69. this.checkService(function () {
  70. this.loadNavi();
  71. }.bind(this));
  72. // this.loadLogView();
  73. // this.createTopNode();
  74. // this.createContainerNode();
  75. // this.loaNavi();
  76. },
  77. loadUser: function(){
  78. if( !layout.inBrowser )return;
  79. var naviRightNode = new Element("div", {
  80. styles : this.css.naviRightNode
  81. }).inject( this.naviNode );
  82. new Element("div", {
  83. styles : this.css.userNode,
  84. text: this.lp.welcome + layout.session.user.name
  85. }).inject(naviRightNode);
  86. new Element("div", {
  87. styles : this.css.logoutNode,
  88. text: this.lp.logout,
  89. events: {
  90. click: function () {
  91. this.safeLogout();
  92. }.bind(this)
  93. }
  94. }).inject(naviRightNode);
  95. },
  96. safeLogout: function(){
  97. o2.Actions.get("x_organization_assemble_authentication").safeLogout(function () {
  98. if (this.socket) {
  99. this.socket.close();
  100. this.socket = null;
  101. }
  102. if (layout.session && layout.session.user) layout.session.user.token = "";
  103. if (sessionStorage) sessionStorage.removeItem("o2LayoutSessionToken");
  104. // window.location.reload();
  105. window.location = "/";
  106. }.bind(this));
  107. },
  108. checkService: function(success){
  109. if( layout.serviceAddressList["x_auditlog_assemble_control"] ){
  110. success();
  111. }else{
  112. this.contentContainerNode.setStyle("background-color","#fff");
  113. new Element("div", {
  114. "styles": this.css.noServiceNode,
  115. "text": this.lp.noServiceNote
  116. }).inject( this.contentContainerNode );
  117. }
  118. },
  119. loadNavi : function(){
  120. this.managerEnabled = this.options.managerEnabled && o2.AC.isManager();
  121. var naviJson = [
  122. {
  123. "id": "logview",
  124. "title": this.lp.log,
  125. "action": "loadLogView",
  126. "icon": "log",
  127. "display": o2.AC.isSystemManager() || o2.AC.isAuditManager() || this.managerEnabled
  128. },
  129. {
  130. "id": "organizationview",
  131. "title": this.lp.org,
  132. "action": "loadOrganizationView",
  133. "icon": "org",
  134. "display": o2.AC.isSystemManager() || o2.AC.isSecurityManager() || this.managerEnabled
  135. },
  136. {
  137. "id": "passwordview",
  138. "title": this.lp.password,
  139. "action": "loadPasswordView",
  140. "icon": "password",
  141. "display": o2.AC.isSystemManager() || this.managerEnabled
  142. },
  143. {
  144. "id": "permissionview",
  145. "title": this.lp.permission1,
  146. "action": "loadPermissionView",
  147. "icon": "permission",
  148. "display": o2.AC.isSecurityManager() || this.managerEnabled
  149. },
  150. {
  151. "id": "gohome",
  152. "title": this.lp.home,
  153. "action": "goHome",
  154. "icon": "home",
  155. "display": this.inBrowser && (o2.AC.isSystemManager() || this.managerEnabled)
  156. }
  157. ];
  158. var displayNaviJson = naviJson.filter(function (d) { return d.display });
  159. this.displayNaviId = displayNaviJson.map( function(d){ return d.id } );
  160. displayNaviJson.each( function( d, idx ){
  161. this.createNaviNode( d , idx, idx === 0 );
  162. }.bind(this));
  163. if( displayNaviJson.length === 0 ){
  164. this.contentContainerNode.setStyle("background-color","#fff");
  165. new Element("div", {
  166. "styles": this.css.noPermissionNode,
  167. "text": this.lp.noPermissionText
  168. }).inject(this.contentContainerNode)
  169. }
  170. },
  171. createNaviNode : function( d, index, isFirst ){
  172. var _self = this;
  173. var node = new Element("div",{
  174. text : d.title,
  175. styles : this.css.naviItemNode,
  176. events : {
  177. click : function( ev ){
  178. if( _self.currentAction == d.action )return;
  179. ev.target.setStyles( _self.css.naviItemNode_selected );
  180. ev.target.setStyle("background-image", "url("+_self.path + "icon/" + d.icon + "_click.png)" );
  181. if(_self.currentNaviItemNode){
  182. var data = _self.currentNaviItemNode.retrieve("data");
  183. _self.currentNaviItemNode.setStyles( _self.css.naviItemNode );
  184. _self.currentNaviItemNode.setStyle("background-image", "url("+_self.path + "icon/" + data.icon + ".png)" );
  185. }
  186. _self.currentNaviItemNode = ev.target;
  187. _self.currentAction = d.action;
  188. _self[ d.action ]();
  189. }
  190. }
  191. }).inject( this.naviNode );
  192. node.store("data", d);
  193. node.setStyle("background-image", "url("+this.path + "icon/" + d.icon + ".png)" );
  194. debugger;
  195. if( this.status && this.status.es && this.displayNaviId.contains(this.status.es.explorer) && this.status.es.explorer ){
  196. if(this.status.es.explorer === d.id)node.click();
  197. }else if( isFirst ){
  198. node.click();
  199. }
  200. },
  201. setContentSize: function(){
  202. var size = this.content.getSize();
  203. var h = size.y - this.getOffsetY(this.content);
  204. h = h - this.getOffsetY(this.node);
  205. h = h - this.naviNode.getSize().y - this.getOffsetY(this.naviNode);
  206. this.contentContainerNode.setStyle("height", h+"px");
  207. },
  208. clear: function () {
  209. if(this.currentView)this.currentView.clear();
  210. // if (this.setContentSizeFun) this.removeEvent("resize", this.setContentSizeFun);
  211. },
  212. goHome: function(){
  213. window.location = o2.filterUrl( window.location.protocol + "//" + window.location.host );
  214. },
  215. loadLogView: function(){
  216. if(this.currentView)this.currentView.clear();
  217. MWF.xDesktop.requireApp("ThreeMember", "LogView", null, false);
  218. var options = {};
  219. if( this.status && this.status.es && this.status.es.explorer === "logview" ){
  220. options = this.status.es;
  221. }
  222. this.currentView = new MWF.xApplication.ThreeMember.LogView(this.contentContainerNode, this, options)
  223. },
  224. loadPermissionView: function(){
  225. if(this.currentView)this.currentView.clear();
  226. MWF.xDesktop.requireApp("ThreeMember", "PermissionView", null, false);
  227. var options = {};
  228. if( this.status && this.status.es && this.status.es.explorer === "permissionview" ){
  229. options = this.status.es;
  230. }
  231. this.currentView = new MWF.xApplication.ThreeMember.PermissionView(this.contentContainerNode, this, options)
  232. },
  233. loadPasswordView: function(){
  234. if(this.currentView)this.currentView.clear();
  235. MWF.xDesktop.requireApp("ThreeMember", "PasswordView", null, false);
  236. var options = {};
  237. if( this.status && this.status.es && this.status.es.explorer === "passwordview" ){
  238. options = this.status.es;
  239. }
  240. this.currentView = new MWF.xApplication.ThreeMember.PasswordView(this.contentContainerNode, this, options)
  241. },
  242. loadOrganizationView: function(){
  243. if(this.currentView)this.currentView.clear();
  244. MWF.xApplication.Org = MWF.xApplication.Org || {};
  245. MWF.xDesktop.requireApp("Org", "lp."+o2.language, null, false);
  246. MWF.xDesktop.requireApp("Org", "Main", null, false);
  247. var options = {};
  248. if( this.status && this.status.es && this.status.es.explorer === "organizationview" ){
  249. options = this.status.es;
  250. }
  251. options.embededParent = this.contentContainerNode;
  252. this.currentView = new MWF.xApplication.Org.Main(this.desktop, options);
  253. this.currentView.status = options;
  254. this.currentView.clear = function () {
  255. this.content.empty();
  256. this.close();
  257. }.bind(this.currentView);
  258. this.currentView.load();
  259. this.currentView.setEventTarget(this);
  260. },
  261. getOffsetY: function (node) {
  262. return (node.getStyle("margin-top").toInt() || 0) +
  263. (node.getStyle("margin-bottom").toInt() || 0) +
  264. (node.getStyle("padding-top").toInt() || 0) +
  265. (node.getStyle("padding-bottom").toInt() || 0) +
  266. (node.getStyle("border-top-width").toInt() || 0) +
  267. (node.getStyle("border-bottom-width").toInt() || 0);
  268. },
  269. recordStatus: function () {
  270. var status = {};
  271. var explorerStatus;
  272. if( !this.currentView ){
  273. explorerStatus = ""
  274. }else if( this.currentView.options.name === "Org" ){
  275. explorerStatus = this.currentView.recordStatus();
  276. explorerStatus.explorer = "organizationview";
  277. }else{
  278. explorerStatus = this.currentView.recordStatus();
  279. }
  280. if( explorerStatus )status.es = explorerStatus;
  281. return status
  282. }
  283. });