]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('Router.controller.Navigation', {\r |
2 | extend : 'Ext.app.Controller',\r | |
3 | \r | |
4 | config : {\r | |
5 | control : {\r | |
6 | '#main-tabs' : {\r | |
7 | tabchange : 'onTabChange'\r | |
8 | },\r | |
9 | '#tab6' : {\r | |
10 | tabchange : 'onChildTabChange'\r | |
11 | }\r | |
12 | },\r | |
13 | refs : {\r | |
14 | tabPanel : '#main-tabs'\r | |
15 | },\r | |
16 | routes : {\r | |
17 | 'main-tabs:id:subid' : {\r | |
18 | action : 'showTab',\r | |
19 | before : 'beforeShowTab',\r | |
20 | conditions : {\r | |
21 | //take control of the :id & :subid parameters, make them optional but delimited by colon\r | |
22 | ':id' : '(?:(?::){1}([%a-zA-Z0-9\-\_\s,]+))?',\r | |
23 | ':subid' : '(?:(?::){1}([%a-zA-Z0-9\-\_\s,]+))?'\r | |
24 | }\r | |
25 | }\r | |
26 | }\r | |
27 | },\r | |
28 | \r | |
29 | onTabChange : function(tabPanel, newItem) {\r | |
30 | var id = newItem.getId(),\r | |
31 | child = newItem.child('tabpanel'),\r | |
32 | subid = '',\r | |
33 | hash = 'main-tabs:' + id;\r | |
34 | \r | |
35 | if (child) {\r | |
36 | newItem = child.getActiveTab();\r | |
37 | subid = ':' + newItem.getId();\r | |
38 | \r | |
39 | hash += subid;\r | |
40 | }\r | |
41 | \r | |
42 | this.redirectTo(hash);\r | |
43 | },\r | |
44 | \r | |
45 | onChildTabChange : function(tabPanel, newItem) {\r | |
46 | var parentTab = tabPanel.up(),\r | |
47 | parentId = parentTab.getId(),\r | |
48 | hash = 'main-tabs:' + parentId + ':' + newItem.getId();\r | |
49 | \r | |
50 | this.redirectTo(hash);\r | |
51 | },\r | |
52 | \r | |
53 | beforeShowTab : function(id, subid, action) {\r | |
54 | var tabPanel = this.getTabPanel(),\r | |
55 | child;\r | |
56 | \r | |
57 | if (!id) {\r | |
58 | //no id was specified, use 0 index to resolve child\r | |
59 | id = 0;\r | |
60 | }\r | |
61 | \r | |
62 | child = tabPanel.getComponent(id);\r | |
63 | \r | |
64 | if (child) {\r | |
65 | //tab found, resume the action\r | |
66 | action.resume();\r | |
67 | } else {\r | |
68 | Ext.Msg.alert('Tab Not Found', 'Tab with id or index "<b>' + id + '</b>" was not found!');\r | |
69 | \r | |
70 | //child not found, stop action\r | |
71 | action.stop();\r | |
72 | }\r | |
73 | },\r | |
74 | \r | |
75 | showTab : function(id, subid) {\r | |
76 | var tabPanel = this.getTabPanel(),\r | |
77 | child, childTabPanel;\r | |
78 | \r | |
79 | if (!id) {\r | |
80 | //no id was specified, use 0 index to resolve child\r | |
81 | id = 0;\r | |
82 | }\r | |
83 | \r | |
84 | child = tabPanel.getComponent(id);\r | |
85 | \r | |
86 | childTabPanel = child.child('tabpanel');\r | |
87 | \r | |
88 | tabPanel.setActiveTab(child);\r | |
89 | \r | |
90 | if (childTabPanel) {\r | |
91 | if (!subid) {\r | |
92 | subid = 0;\r | |
93 | }\r | |
94 | \r | |
95 | childTabPanel.setActiveTab(subid);\r | |
96 | }\r | |
97 | }\r | |
98 | });\r | |
99 | \r | |
100 | Ext.application({\r | |
101 | name : 'Router',\r | |
102 | \r | |
103 | requires : [\r | |
104 | 'Ext.tab.Panel',\r | |
105 | 'Ext.window.MessageBox'\r | |
106 | ],\r | |
107 | \r | |
108 | controllers : [\r | |
109 | 'Navigation'\r | |
110 | ],\r | |
111 | \r | |
112 | defaultToken : 'main-tabs',\r | |
113 | \r | |
114 | launch : function() {\r | |
115 | \r | |
116 | Ext.create('Ext.tab.Panel', {\r | |
117 | renderTo : Ext.getBody(),\r | |
118 | id : 'main-tabs',\r | |
119 | height : 300,\r | |
120 | width : 600,\r | |
121 | activeTab : 0,\r | |
122 | defaults : {\r | |
123 | padding : 10\r | |
124 | },\r | |
125 | items : [\r | |
126 | {\r | |
127 | title : 'Tab 1',\r | |
128 | id : 'tab1',\r | |
129 | layout : 'fit',\r | |
130 | items : [\r | |
131 | {\r | |
132 | xtype : 'tabpanel',\r | |
133 | id : 'tab6',\r | |
134 | items : [\r | |
135 | {\r | |
136 | title : 'Sub-tab 1',\r | |
137 | id : 'subtab1'\r | |
138 | },\r | |
139 | {\r | |
140 | title : 'Sub-tab 2',\r | |
141 | id : 'subtab2'\r | |
142 | },\r | |
143 | {\r | |
144 | title : 'Sub-tab 3',\r | |
145 | id : 'subtab3'\r | |
146 | }\r | |
147 | ]\r | |
148 | }\r | |
149 | ]\r | |
150 | },\r | |
151 | {\r | |
152 | title : 'Tab 2',\r | |
153 | id : 'tab2',\r | |
154 | html : 'Tab 2 content'\r | |
155 | },\r | |
156 | {\r | |
157 | title : 'Tab 3',\r | |
158 | id : 'tab3',\r | |
159 | html : 'Tab 3 content'\r | |
160 | },\r | |
161 | {\r | |
162 | title : 'Tab 4',\r | |
163 | id : 'tab4',\r | |
164 | html : 'Tab 4 content'\r | |
165 | },\r | |
166 | {\r | |
167 | title : 'Tab 5',\r | |
168 | id : 'tab5',\r | |
169 | html : 'Tab 5 content'\r | |
170 | }\r | |
171 | ]\r | |
172 | });\r | |
173 | \r | |
174 | }\r | |
175 | }); |