]> git.proxmox.com Git - extjs.git/blame - extjs/templates/executive-dashboard/app/view/main/MainController.js
add extjs 6.0.1 sources
[extjs.git] / extjs / templates / executive-dashboard / app / view / main / MainController.js
CommitLineData
6527f429
DM
1/**\r
2 * This class is the main view for the application. It is specified in app.js as the\r
3 * "autoCreateViewport" property. That setting automatically applies the "viewport"\r
4 * plugin to promote that instance of this class to the body element.\r
5 *\r
6 * The primary role of this controller is to manage routing.\r
7 */\r
8Ext.define('ExecDashboard.view.main.MainController', {\r
9 extend: 'Ext.app.ViewController',\r
10 alias: 'controller.main',\r
11\r
12 routes: {\r
13 '!:id': {\r
14 action: 'onNavigate',\r
15 before: 'beforeNavigate'\r
16 },\r
17\r
18 '!:id/:state': {\r
19 action: 'onNavigateDeep',\r
20 before: 'beforeNavigateDeep'\r
21 }\r
22 },\r
23\r
24 listen: {\r
25 controller: {\r
26 '*': {\r
27 // We delegate all changes of router history to this controller by firing\r
28 // the "changeroute" event from other controllers.\r
29 changeroute: 'changeRoute',\r
30\r
31 unmatchedroute: 'onUnmatchedRoute'\r
32 }\r
33 }\r
34 },\r
35\r
36 destroy: function () {\r
37 Ext.destroyMembers(this, 'menu');\r
38 this.callParent();\r
39 },\r
40\r
41 beforeNavigate: function (id, action) {\r
42 var view = this.getView();\r
43 var tab = view.getComponent(id);\r
44\r
45 if (tab) {\r
46 action.resume();\r
47 } else {\r
48 this.onBadRoute();\r
49 }\r
50 },\r
51\r
52 beforeNavigateDeep: function (id, state, action) {\r
53 var view = this.getView();\r
54 var tab = view.getComponent(id);\r
55 var valid;\r
56\r
57 if (tab.isValidState) {\r
58 valid = tab.isValidState(state);\r
59 }\r
60\r
61 if (valid) {\r
62 action.resume();\r
63 } else {\r
64 this.onBadRoute();\r
65 }\r
66 },\r
67\r
68 changeRoute: function (controller, route) {\r
69 // Since we parse\r
70 if (route.substring(0, 1) !== '!') {\r
71 route = '!' + route;\r
72 }\r
73\r
74 this.redirectTo(route);\r
75 },\r
76\r
77 getTabRoute: function (tab) {\r
78 var route = tab.xtype;\r
79\r
80 if (tab.getActiveState) {\r
81 route += '/' + (tab.getActiveState() || tab.getDefaultActiveState());\r
82 }\r
83\r
84 return route;\r
85 },\r
86\r
87 onBadRoute: function () {\r
88 var app = ExecDashboard.app.getApplication();\r
89 this.changeRoute(this, app.getDefaultToken());\r
90 },\r
91\r
92 onNavigate: function (id) {\r
93 //Ext.log('navigate: ' + id);\r
94 var tabs = this.getView();\r
95\r
96 var tab = tabs.setActiveTab(id);\r
97 if (tab) {\r
98 // if we changed active tabs...\r
99 var route = this.getTabRoute(tab);\r
100 if (route && route !== id) {\r
101 this.changeRoute(this, route);\r
102 }\r
103 }\r
104 },\r
105\r
106 onNavigateDeep: function (id, state) {\r
107 //Ext.log('navigate: ' + id + ' / ' + state);\r
108 var tabs = this.getView();\r
109 var tab = tabs.setActiveTab(id) || tabs.getActiveTab();\r
110\r
111 tab.setActiveState(state);\r
112 },\r
113\r
114 onTabChange: function (mainView, newTab) {\r
115 var route = this.getTabRoute(newTab);\r
116 this.changeRoute(this, route);\r
117 },\r
118\r
119 onMenuClick: function (menu, item) {\r
120 this.getView().setActiveTab(menu.items.indexOf(item) + 1); // +1 for invisible first tab\r
121 },\r
122\r
123 onSwitchTool: function (e) {\r
124 var menu = this.menu;\r
125\r
126 if (!menu) {\r
127 menu = this.getView().assistiveMenu;\r
128 this.menu = menu = new Ext.menu.Menu(menu);\r
129 }\r
130\r
131 menu.showAt(e.getXY());\r
132 },\r
133\r
134 onUnmatchedRoute: function(token) {\r
135 if (token) {\r
136 this.onBadRoute();\r
137 }\r
138 }\r
139});\r