Main.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. MWF.xApplication.ControlPanel.Main = new Class({
  2. Extends: MWF.xApplication.Common.Main,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "name": "ControlPanel",
  7. "icon": "icon.png",
  8. "width": "840",
  9. "isResize": false,
  10. "isMax": false,
  11. "height": "280",
  12. "title": MWF.xApplication.ControlPanel.LP.title
  13. },
  14. loadWindow: function(isCurrent){
  15. this.fireAppEvent("queryLoadWindow");
  16. this.window = new MWF.xDesktop.WindowTransparent(this, {"container": this.desktop.node});
  17. this.fireAppEvent("loadWindow");
  18. this.window.show();
  19. this.content = this.window.content;
  20. if (isCurrent) this.setCurrent();
  21. this.fireAppEvent("postLoadWindow");
  22. this.fireAppEvent("queryLoadApplication");
  23. this.loadApplication(function(){
  24. this.fireAppEvent("postLoadApplication");
  25. }.bind(this));
  26. },
  27. setNodeResize: function(){
  28. this.setNodePositionAndSizeFun = this.setNodePositionAndSize.bind(this);
  29. this.setNodePositionAndSizeFun();
  30. $(window).addEvent("resize", this.setNodePositionAndSizeFun);
  31. this.addEvent("queryClose", function(){
  32. $(window).removeEvent("resize", this.setNodePositionAndSizeFun);
  33. }.bind(this));
  34. },
  35. setNodePositionAndSize: function(){
  36. if (this.status && this.status.size){
  37. this.node.setStyles({
  38. "top": this.status.size.y,
  39. "left": this.status.size.x
  40. });
  41. }else{
  42. this.node.position({
  43. relativeTo: this.desktop.node,
  44. position: 'center',
  45. edge: 'center',
  46. "offset": {
  47. "y": "-120"
  48. }
  49. });
  50. }
  51. },
  52. recordStatus: function(){
  53. return {"size": this.node.getPosition()};
  54. },
  55. onQueryLoad: function(){
  56. this.lp = MWF.xApplication.ControlPanel.LP;
  57. },
  58. loadApplication: function(callback){
  59. this.layout = this.desktop;
  60. this.apps = [];
  61. //this.loadTitle();
  62. //this.content.setStyle("background-color", "#555555");
  63. if (this.options.event){
  64. this.css.contentNode.left = this.options.event.page.x;
  65. this.css.contentNode.top = this.options.event.page.y;
  66. // options.fromTop = this.options.event.page.y;
  67. // options.fromLeft = this.options.event.page.x;
  68. }
  69. this.node = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
  70. var morph = new Fx.Morph(this.node, {
  71. "duration": "100",
  72. "transition": Fx.Transitions.Sine.easeOut
  73. });
  74. morph.start(this.css.contentNodeTo).chain(function(){
  75. this.setNodeResize();
  76. this.node.addEvent("selectstart", function(e){e.target.setStyle("-webkit-user-select", "none")}.bind(this));
  77. this.titleAreaNode = new Element("div", {"styles": this.css.titleAreaNode}).inject(this.node);
  78. this.closeNode = new Element("div", {"styles": this.css.closeNode}).inject(this.titleAreaNode);
  79. this.closeNode.addEvent("click", this.close.bind(this));
  80. this.titleNode = new Element("div", {"styles": this.css.titleAreaTextNode, "text": this.lp.titleInfor}).inject(this.titleAreaNode);
  81. this.contentNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.node);
  82. this.loadApplications();
  83. }.bind(this));
  84. },
  85. loadTitle: function(){
  86. this.titleBar = new Element("div", {"styles": this.css.titleBar}).inject(this.content);
  87. this.taskTitleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": this.lp.title}).inject(this.titleBar);
  88. },
  89. setContentSize: function(){
  90. var size = this.node.getSize();
  91. var w = size.x*0.9;
  92. var count = (w/120).toInt();
  93. w = Math.min(count, this.apps.length)*120;
  94. this.contentNode.setStyles({"width": ""+w+"px"});
  95. },
  96. loadApplications: function(){
  97. debugger;
  98. COMMON.JSON.get(this.path+"applications.json", function(catalog){
  99. var user = this.layout.session.user;
  100. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  101. if (user.roleList){
  102. user.roleList.each(function(role){
  103. currentNames.push(MWF.name.cn(role));
  104. currentNames.push(role);
  105. });
  106. }
  107. //currentNames = currentNames.concat(user.roleList);
  108. if (user.groupList){
  109. user.groupList.each(function(group){
  110. currentNames.push(MWF.name.cn(group));
  111. currentNames.push(group);
  112. });
  113. }
  114. //currentNames = currentNames.concat(user.groupList);
  115. catalog.each(function(value, key){
  116. var isAllow = true;
  117. if (value.allowList) isAllow = (value.allowList.length) ? (value.allowList.isIntersect(currentNames)) : true;
  118. var isDeny = false;
  119. if (value.denyList) isDeny = (value.denyList.length) ? (value.denyList.isIntersect(currentNames)!==-1) : false;
  120. if ((!isDeny && isAllow)){
  121. this.apps.push({"value":value, "key":key});
  122. this.createApplicationMenu(value, key);
  123. }
  124. this.setContentSize();
  125. this.addEvent("resize", this.setContentSize);
  126. }.bind(this));
  127. }.bind(this));
  128. },
  129. createApplicationMenu: function(value, key){
  130. var applicationMenuNode = new Element("div", {
  131. "styles": this.css.applicationMenuNode,
  132. "title": value.title
  133. }).inject(this.contentNode);
  134. var applicationMenuIconNode = new Element("div", {
  135. "styles": this.css.applicationMenuIconNode
  136. }).inject(applicationMenuNode);
  137. var icon = "/x_component_"+value.path.replace(/\./g, "_")+"/$Main/"+value.iconPath;
  138. applicationMenuIconNode.setStyle("background-image", "url("+icon+")");
  139. new Element("div", {
  140. "styles": this.css.applicationMenuTextNode,
  141. "text": value.title
  142. }).inject(applicationMenuNode);
  143. applicationMenuNode.addEvent("click", function(e){
  144. this.layout.openApplication(e, value.path);
  145. //this.closeApplicationMenu();
  146. }.bind(this));
  147. applicationMenuNode.makeLnk({
  148. "par": {"icon": icon, "title": value.title, "par": value.path},
  149. "onStart": function(){
  150. this.applicationMenuAreaMark.fade("out");
  151. this.applicationMenuArea.fade("out");
  152. }.bind(this),
  153. "onComplete": function(){
  154. //this.showApplicationMenu();
  155. }.bind(this)
  156. });
  157. var appName = value.path;
  158. }
  159. });