]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('Admin.view.main.MainController', {\r |
2 | extend: 'Ext.app.ViewController',\r | |
3 | alias: 'controller.main',\r | |
4 | \r | |
5 | listen : {\r | |
6 | controller : {\r | |
7 | '#' : {\r | |
8 | unmatchedroute : 'onRouteChange'\r | |
9 | }\r | |
10 | }\r | |
11 | },\r | |
12 | \r | |
13 | routes: {\r | |
14 | ':node': 'onRouteChange'\r | |
15 | },\r | |
16 | \r | |
17 | lastView: null,\r | |
18 | \r | |
19 | setCurrentView: function(hashTag) {\r | |
20 | hashTag = (hashTag || '').toLowerCase();\r | |
21 | \r | |
22 | var me = this,\r | |
23 | refs = me.getReferences(),\r | |
24 | mainCard = refs.mainCardPanel,\r | |
25 | mainLayout = mainCard.getLayout(),\r | |
26 | navigationList = refs.navigationTreeList,\r | |
27 | store = navigationList.getStore(),\r | |
28 | node = store.findNode('routeId', hashTag) ||\r | |
29 | store.findNode('viewType', hashTag),\r | |
30 | view = (node && node.get('viewType')) || 'page404',\r | |
31 | lastView = me.lastView,\r | |
32 | existingItem = mainCard.child('component[routeId=' + hashTag + ']'),\r | |
33 | newView;\r | |
34 | \r | |
35 | // Kill any previously routed window\r | |
36 | if (lastView && lastView.isWindow) {\r | |
37 | lastView.destroy();\r | |
38 | }\r | |
39 | \r | |
40 | lastView = mainLayout.getActiveItem();\r | |
41 | \r | |
42 | if (!existingItem) {\r | |
43 | newView = Ext.create({\r | |
44 | xtype: view,\r | |
45 | routeId: hashTag, // for existingItem search later\r | |
46 | hideMode: 'offsets'\r | |
47 | });\r | |
48 | }\r | |
49 | \r | |
50 | if (!newView || !newView.isWindow) {\r | |
51 | // !newView means we have an existing view, but if the newView isWindow\r | |
52 | // we don't add it to the card layout.\r | |
53 | if (existingItem) {\r | |
54 | // We don't have a newView, so activate the existing view.\r | |
55 | if (existingItem !== lastView) {\r | |
56 | mainLayout.setActiveItem(existingItem);\r | |
57 | }\r | |
58 | newView = existingItem;\r | |
59 | }\r | |
60 | else {\r | |
61 | // newView is set (did not exist already), so add it and make it the\r | |
62 | // activeItem.\r | |
63 | Ext.suspendLayouts();\r | |
64 | mainLayout.setActiveItem(mainCard.add(newView));\r | |
65 | Ext.resumeLayouts(true);\r | |
66 | }\r | |
67 | }\r | |
68 | \r | |
69 | navigationList.setSelection(node);\r | |
70 | \r | |
71 | if (newView.isFocusable(true)) {\r | |
72 | newView.focus();\r | |
73 | }\r | |
74 | \r | |
75 | me.lastView = newView;\r | |
76 | },\r | |
77 | \r | |
78 | onNavigationTreeSelectionChange: function (tree, node) {\r | |
79 | var to = node && (node.get('routeId') || node.get('viewType'));\r | |
80 | \r | |
81 | if (to) {\r | |
82 | this.redirectTo(to);\r | |
83 | }\r | |
84 | },\r | |
85 | \r | |
86 | onToggleNavigationSize: function () {\r | |
87 | var me = this,\r | |
88 | refs = me.getReferences(),\r | |
89 | navigationList = refs.navigationTreeList,\r | |
90 | wrapContainer = refs.mainContainerWrap,\r | |
91 | collapsing = !navigationList.getMicro(),\r | |
92 | new_width = collapsing ? 64 : 250;\r | |
93 | \r | |
94 | if (Ext.isIE9m || !Ext.os.is.Desktop) {\r | |
95 | Ext.suspendLayouts();\r | |
96 | \r | |
97 | refs.senchaLogo.setWidth(new_width);\r | |
98 | \r | |
99 | navigationList.setWidth(new_width);\r | |
100 | navigationList.setMicro(collapsing);\r | |
101 | \r | |
102 | Ext.resumeLayouts(); // do not flush the layout here...\r | |
103 | \r | |
104 | // No animation for IE9 or lower...\r | |
105 | wrapContainer.layout.animatePolicy = wrapContainer.layout.animate = null;\r | |
106 | wrapContainer.updateLayout(); // ... since this will flush them\r | |
107 | }\r | |
108 | else {\r | |
109 | if (!collapsing) {\r | |
110 | // If we are leaving micro mode (expanding), we do that first so that the\r | |
111 | // text of the items in the navlist will be revealed by the animation.\r | |
112 | navigationList.setMicro(false);\r | |
113 | }\r | |
114 | \r | |
115 | // Start this layout first since it does not require a layout\r | |
116 | refs.senchaLogo.animate({dynamic: true, to: {width: new_width}});\r | |
117 | \r | |
118 | // Directly adjust the width config and then run the main wrap container layout\r | |
119 | // as the root layout (it and its chidren). This will cause the adjusted size to\r | |
120 | // be flushed to the element and animate to that new size.\r | |
121 | navigationList.width = new_width;\r | |
122 | wrapContainer.updateLayout({isRoot: true});\r | |
123 | navigationList.el.addCls('nav-tree-animating');\r | |
124 | \r | |
125 | // We need to switch to micro mode on the navlist *after* the animation (this\r | |
126 | // allows the "sweep" to leave the item text in place until it is no longer\r | |
127 | // visible.\r | |
128 | if (collapsing) {\r | |
129 | navigationList.on({\r | |
130 | afterlayoutanimation: function () {\r | |
131 | navigationList.setMicro(true);\r | |
132 | navigationList.el.removeCls('nav-tree-animating');\r | |
133 | },\r | |
134 | single: true\r | |
135 | });\r | |
136 | }\r | |
137 | }\r | |
138 | },\r | |
139 | \r | |
140 | onMainViewRender:function() {\r | |
141 | if (!window.location.hash) {\r | |
142 | this.redirectTo("dashboard");\r | |
143 | }\r | |
144 | },\r | |
145 | \r | |
146 | onRouteChange:function(id){\r | |
147 | this.setCurrentView(id);\r | |
148 | },\r | |
149 | \r | |
150 | onSearchRouteChange: function () {\r | |
151 | this.setCurrentView('searchresults');\r | |
152 | },\r | |
153 | \r | |
154 | onSwitchToModern: function () {\r | |
155 | Ext.Msg.confirm('Switch to Modern', 'Are you sure you want to switch toolkits?',\r | |
156 | this.onSwitchToModernConfirmed, this);\r | |
157 | },\r | |
158 | \r | |
159 | onSwitchToModernConfirmed: function (choice) {\r | |
160 | if (choice === 'yes') {\r | |
161 | var s = location.search;\r | |
162 | \r | |
163 | // Strip "?classic" or "&classic" with optionally more "&foo" tokens\r | |
164 | // following and ensure we don't start with "?".\r | |
165 | s = s.replace(/(^\?|&)classic($|&)/, '').replace(/^\?/, '');\r | |
166 | \r | |
167 | // Add "?modern&" before the remaining tokens and strip & if there are\r | |
168 | // none.\r | |
169 | location.search = ('?modern&' + s).replace(/&$/, '');\r | |
170 | }\r | |
171 | },\r | |
172 | \r | |
173 | onEmailRouteChange: function () {\r | |
174 | this.setCurrentView('email');\r | |
175 | }\r | |
176 | });\r |