Main.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. MWF.xApplication.Template = MWF.xApplication.Template || {};
  2. MWF.require("MWF.widget.Identity", null,false);
  3. MWF.xDesktop.requireApp("Template", "Actions.RestActions", null, false);
  4. MWF.xApplication.Template.options = {
  5. multitask: true,
  6. executable: true
  7. }
  8. MWF.xApplication.Template.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "Template",
  14. "icon": "icon.png",
  15. "width": "1200",
  16. "height": "700",
  17. "isResize": false,
  18. "isMax": true,
  19. "title": MWF.xApplication.Template.LP.title
  20. },
  21. onQueryLoad: function(){
  22. this.lp = MWF.xApplication.Template.LP;
  23. },
  24. loadApplication: function(callback){
  25. this.manageDepartments =[];
  26. this.manageCompanys = [];
  27. this.restActions = new MWF.xApplication.Template.Actions.RestActions();
  28. this.createNode();
  29. this.loadApplicationContent();
  30. },
  31. isAdmin: function(){
  32. return this.isCompanyManager() || MWF.AC.isAdministrator()
  33. },
  34. isDepartmentManager : function(){
  35. return this.manageDepartments.length > 0;
  36. },
  37. isCompanyManager : function(){
  38. return this.manageCompanys.length > 0;
  39. },
  40. loadController: function(callback){
  41. //this.restActions.listPermission( function( json ){
  42. // json.data.each(function(item){
  43. // if( item.adminLevel == "COMPANY" && item.adminName == layout.desktop.session.user.name){
  44. // this.manageCompanys.push( item.organizationName )
  45. // }else if( item.adminLevel == "DEPT" && item.adminName == layout.desktop.session.user.name ){
  46. // this.manageDepartments.push( item.organizationName )
  47. // }
  48. // }.bind(this))
  49. // if(callback)callback(json);
  50. //}.bind(this));
  51. if(callback)callback();
  52. },
  53. createNode: function(){
  54. this.content.setStyle("overflow", "hidden");
  55. this.node = new Element("div", {
  56. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  57. }).inject(this.content);
  58. },
  59. loadApplicationContent: function(){
  60. this.loadController(function(){
  61. this.loaNavi();
  62. }.bind(this))
  63. //this.loadApplicationLayout();
  64. },
  65. loaNavi: function(callback){
  66. this.naviNode = new Element("div.naviNode", {
  67. "styles": this.css.naviNode
  68. }).inject(this.node);
  69. var curNavi = { "id" : "" }
  70. if( this.status ){
  71. curNavi.id = this.status.id
  72. }
  73. this.navi = new MWF.xApplication.Template.Navi(this, this.naviNode, curNavi );
  74. },
  75. clearContent: function(){
  76. if (this.explorerContent){
  77. if (this.explorer) delete this.explorer;
  78. this.explorerContent.destroy();
  79. this.explorerContent = null;
  80. }
  81. },
  82. openExplorer : function(){
  83. MWF.xDesktop.requireApp("Template", "Explorer", function(){
  84. this.clearContent();
  85. this.explorerContent = new Element("div", {
  86. "styles": this.css.rightContentNode
  87. }).inject(this.node);
  88. this.explorer = new MWF.xApplication.Template.Explorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  89. this.explorer.load();
  90. }.bind(this));
  91. },
  92. openDepartmentIndex : function(){
  93. MWF.xDesktop.requireApp("Template", "DepartmentIndex", function(){
  94. this.clearContent();
  95. this.explorerContent = new Element("div", {
  96. "styles": this.css.rightContentNode
  97. }).inject(this.node);
  98. this.explorer = new MWF.xApplication.Template.DepartmentIndex(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  99. this.explorer.load();
  100. }.bind(this));
  101. },
  102. openHolidaySetting : function(){
  103. MWF.xDesktop.requireApp("Template", "HolidayExplorer", function(){
  104. this.clearContent();
  105. this.explorerContent = new Element("div", {
  106. "styles": this.css.rightContentNode
  107. }).inject(this.node);
  108. this.explorer = new MWF.xApplication.Template.HolidayExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  109. this.explorer.load();
  110. }.bind(this));
  111. },
  112. recordStatus: function(){
  113. return this.navi && this.navi.currentItem ? this.navi.currentItem.retrieve("data") : {};
  114. }
  115. });
  116. MWF.xApplication.Template.Navi = new Class({
  117. Implements: [Options, Events],
  118. options : {
  119. "id" : ""
  120. },
  121. initialize: function(app, node, options){
  122. this.setOptions(options);
  123. this.app = app;
  124. this.node = $(node);
  125. this.css = this.app.css;
  126. this.currentMenu = null;
  127. this.currentItem = null;
  128. this.menus = {};
  129. this.items = {};
  130. this.elements = [];
  131. this.load();
  132. },
  133. load: function(){
  134. var naviUrl = this.app.path+"navi.json";
  135. MWF.getJSON(naviUrl, function(json){
  136. json.each(function(navi){
  137. if( navi.access && navi.access == "admin" ){
  138. if( this.app.isAdmin() )this.createNaviNode(navi);
  139. }else if( navi.access && navi.access == "admin_dept" ){
  140. if( this.app.isDepartmentManager() || this.app.isAdmin() )this.createNaviNode(navi);
  141. }else{
  142. this.createNaviNode(navi);
  143. }
  144. }.bind(this));
  145. if( this.options.id == "" )this.elements[0].click();
  146. }.bind(this));
  147. },
  148. createNaviNode :function(data){
  149. if( data.type == "sep" ){
  150. var flag = true;
  151. if( data.access == "admin" ){
  152. if( !this.app.isAdmin() )flag = false;
  153. }else if( data.access && data.access == "admin_dept" ){
  154. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )flag = false;
  155. }
  156. if( flag ){
  157. new Element("div", { "styles": this.css.viewNaviSepartorNode }).inject(this.node);
  158. }
  159. }else if( data.sub && data.sub.length > 0 ){
  160. this.createNaviMenuNode(data);
  161. }else{
  162. this.menus[data.id] = {};
  163. this.createNaviItemNode(data, data.id);
  164. }
  165. },
  166. createNaviMenuNode :function(data){
  167. if( data.access == "admin" ){
  168. if( !this.app.isAdmin() )return;
  169. }else if(data.access == "admin_dept"){
  170. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  171. }
  172. var _self = this;
  173. var menuNode = new Element("div", {
  174. "styles": this.css.naviMenuNode
  175. });
  176. menuNode.store("data", data);
  177. menuNode.store("type", "menu");
  178. var textNode = new Element("div", {
  179. "styles": this.css.naviMenuTextNode,
  180. "text": data.title
  181. });
  182. textNode.inject(menuNode);
  183. menuNode.inject(this.node);
  184. this.menus[data.id] = {};
  185. this.menus[data.id].node = menuNode;
  186. this.elements.push(menuNode);
  187. menuNode.addEvents({
  188. "mouseover": function(){ if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  189. "mouseout": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode);},
  190. "mousedown": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_down);},
  191. "mouseup": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  192. "click": function(){
  193. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  194. _self.clickMenu.apply(_self, [this]);
  195. }
  196. });
  197. data.sub.each(function( d ){
  198. this.createNaviItemNode( d, data.id, menuNode )
  199. }.bind(this))
  200. },
  201. clickMenu: function(naviNode) {
  202. var navi = naviNode.retrieve("data");
  203. var action = navi.action;
  204. this.closeCurrentMenu();
  205. if( this.menus[navi.id].itemNodes ) {
  206. this.menus[navi.id].itemNodes.each( function(itemNode){
  207. itemNode.setStyle("display","block");
  208. })
  209. }
  210. var type = naviNode.retrieve("type");
  211. if (!navi.target || navi.target != "_blank") {
  212. naviNode.setStyles( this.css.naviMenuNode_current );
  213. this.currentMenu = naviNode;
  214. }
  215. },
  216. closeCurrentMenu:function(){
  217. if( this.currentMenu ) {
  218. var data = this.currentMenu.retrieve("data");
  219. if (this.menus[data.id].itemNodes) {
  220. this.menus[data.id].itemNodes.each(function (itemNode) {
  221. itemNode.setStyle("display", "none");
  222. })
  223. }
  224. this.currentMenu.setStyles( this.css.naviMenuNode);
  225. }
  226. },
  227. createNaviItemNode : function( data,menuId ){
  228. if( data.access == "admin" ){
  229. if( !this.app.isAdmin() )return;
  230. }else if( data.access && data.access == "admin_dept" ){
  231. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  232. }
  233. var _self = this;
  234. var items = this.menus[menuId].itemNodes = this.menus[menuId].itemNodes || [];
  235. var itemNode = new Element("div", {
  236. "styles": this.css.naviItemNode
  237. });
  238. itemNode.setStyle("display","block");
  239. items.push(itemNode);
  240. itemNode.store("data", data);
  241. itemNode.store("type", "item");
  242. var textNode = new Element("div", {
  243. "styles": this.css.naviItemTextNode,
  244. "text": data.title
  245. });
  246. textNode.inject(itemNode);
  247. itemNode.inject(this.node);
  248. this.elements.push(itemNode);
  249. this.items[data.id] = itemNode;
  250. itemNode.addEvents({
  251. "mouseover": function(){ if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  252. "mouseout": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode);},
  253. "mousedown": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_down);},
  254. "mouseup": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  255. "click": function(){
  256. _self.clickItem.apply(_self, [this]);
  257. }
  258. });
  259. if( data.id == this.options.id ){
  260. itemNode.click();
  261. }
  262. },
  263. clickItem : function(naviNode) {
  264. var navi = naviNode.retrieve("data");
  265. var action = navi.action;
  266. var type = naviNode.retrieve("type");
  267. if (!navi.target || navi.target != "_blank") {
  268. if (this.currentItem) this.currentItem.setStyles(this.css.naviItemNode);
  269. naviNode.setStyles(this.css.naviItemNode_current);
  270. this.currentItem = naviNode;
  271. }
  272. if (navi.action && this.app[navi.action]) {
  273. this.app[navi.action].call(this.app, navi);
  274. }
  275. }
  276. });