Main.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. MWF.xApplication.DesignCenter.Main = new Class({
  2. Extends: MWF.xApplication.Common.Main,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "name": "DesignCenter",
  7. "icon": "icon.png",
  8. "width": "800",
  9. "isResize": false,
  10. "isMax": false,
  11. "height": "280",
  12. "title": MWF.xApplication.DesignCenter.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.DesignCenter.LP;
  57. },
  58. loadApplication: function(callback){
  59. this.layout = this.desktop;
  60. this.apps = [];
  61. if (this.options.event){
  62. this.css.contentNode.left = this.options.event.page.x;
  63. this.css.contentNode.top = this.options.event.page.y;
  64. // options.fromTop = this.options.event.page.y;
  65. // options.fromLeft = this.options.event.page.x;
  66. }
  67. this.node = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
  68. var morph = new Fx.Morph(this.node, {
  69. "duration": "100",
  70. "transition": Fx.Transitions.Sine.easeOut
  71. });
  72. this.css.contentNodeTo.width = ""+this.options.width+"px";
  73. morph.start(this.css.contentNodeTo).chain(function(){
  74. this.setNodeResize();
  75. this.node.addEvent("selectstart", function(e){e.target.setStyle("-webkit-user-select", "none")}.bind(this));
  76. this.titleAreaNode = new Element("div", {"styles": this.css.titleAreaNode}).inject(this.node);
  77. this.closeNode = new Element("div", {"styles": this.css.closeNode}).inject(this.titleAreaNode);
  78. this.closeNode.addEvent("click", function(){this.close();}.bind(this));
  79. this.titleNode = new Element("div", {"styles": this.css.titleAreaTextNode, "text": this.lp.titleInfor}).inject(this.titleAreaNode);
  80. this.contentNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.node);
  81. this.loadApplications();
  82. }.bind(this));
  83. //this.loadTitle();
  84. //this.content.setStyle("background-color", "#555555");
  85. // this.node = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
  86. // this.titleNode = new Element("div", {"styles": this.css.titleAreaNode, "text": this.lp.titleInfor}).inject(this.node);
  87. // this.contentNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.node);
  88. // // this.setContentSize();
  89. // // this.addEvent("resize", this.setContentSize);
  90. // this.loadApplications();
  91. },
  92. loadTitle: function(){
  93. this.titleBar = new Element("div", {"styles": this.css.titleBar}).inject(this.content);
  94. this.taskTitleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": this.lp.title}).inject(this.titleBar);
  95. },
  96. setContentSize: function(){
  97. var size = this.node.getSize();
  98. var w = size.x*0.9;
  99. var count = (w/120).toInt();
  100. w = Math.min(count, this.apps.length)*120;
  101. this.contentNode.setStyles({"width": ""+w+"px"});
  102. },
  103. loadApplications: function(){
  104. COMMON.JSON.get(this.path+"applications.json", function(catalog){
  105. var user = this.layout.session.user;
  106. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  107. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  108. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  109. catalog.each(function(value, key){
  110. var isAllow = true;
  111. if (value.allowList) isAllow = (value.allowList.length) ? (value.allowList.isIntersect(currentNames)) : true;
  112. var isDeny = false;
  113. if (value.denyList) isDeny = (value.denyList.length) ? (value.denyList.isIntersect(currentNames)!==-1) : false;
  114. if ((!isDeny && isAllow) || MWF.AC.isAdministrator()){
  115. this.apps.push({"value":value, "key":key});
  116. this.createApplicationMenu(value, key);
  117. }
  118. this.setContentSize();
  119. this.addEvent("resize", this.setContentSize);
  120. }.bind(this));
  121. }.bind(this));
  122. },
  123. createApplicationMenu: function(value, key){
  124. var applicationMenuNode = new Element("div", {
  125. "styles": this.css.applicationMenuNode,
  126. "title": value.title
  127. }).inject(this.contentNode);
  128. var applicationMenuIconNode = new Element("div", {
  129. "styles": this.css.applicationMenuIconNode
  130. }).inject(applicationMenuNode);
  131. var icon = "../x_component_"+value.path.replace(/\./g, "_")+"/$Main/"+value.iconPath;
  132. applicationMenuIconNode.setStyle("background-image", "url("+icon+")");
  133. new Element("div", {
  134. "styles": this.css.applicationMenuTextNode,
  135. "text": value.title
  136. }).inject(applicationMenuNode);
  137. applicationMenuNode.addEvent("click", function(e){
  138. this.layout.openApplication(e, value.path);
  139. //this.closeApplicationMenu();
  140. }.bind(this));
  141. applicationMenuNode.makeLnk({
  142. "par": {"icon": icon, "title": value.title, "par": value.path},
  143. "onStart": function(){
  144. this.applicationMenuAreaMark.fade("out");
  145. this.applicationMenuArea.fade("out");
  146. }.bind(this),
  147. "onComplete": function(){
  148. //this.showApplicationMenu();
  149. }.bind(this)
  150. });
  151. var appName = value.path;
  152. }
  153. });