]>
git.proxmox.com Git - sencha-touch.git/blob - src/examples/kitchensink/app/controller/Main.js
2 * @class Kitchensink.controller.Main
3 * @extends Ext.app.Controller
5 * This is an abstract base class that is extended by both the phone and tablet versions. This controller is
6 * never directly instantiated, it just provides a set of common functionality that the phone and tablet
7 * subclasses both extend.
9 Ext
.define('Kitchensink.controller.Main', {
10 extend
: 'Ext.app.Controller',
19 nav
: '#mainNestedList',
21 toolbar
: '#mainNavigationBar',
22 sourceButton
: 'button[action=viewSource]',
23 themeToggleButton
: 'button[action=toggleTheme]',
27 selector
: 'sourceoverlay',
28 xtype
: 'sourceoverlay',
38 tap
: 'onThemeToggleTap'
46 'demo/:id': 'showViewById',
47 'menu/:id': 'showMenuById',
52 * @cfg {Ext.data.Model} currentDemo The Demo that is currently loaded. This is set whenever showViewById
53 * is called and used by functions like onSourceTap to fetch the source code for the current demo.
55 currentDemo
: undefined
59 * Finds a given view by ID and shows it. End-point of the "demo/:id" route
61 showViewById: function (id
) {
62 var nav
= this.getNav(),
63 view
= nav
.getStore().getNodeById(id
);
66 this.setCurrentDemo(view
);
71 * Shows the source code for the {@link #currentDemo} in an overlay
73 onSourceTap: function () {
74 var overlay
= this.getSourceOverlay(),
75 demo
= this.getCurrentDemo();
77 if (!overlay
.getParent()) {
78 Ext
.Viewport
.add(overlay
);
85 message
: 'Loading Source'
90 url
: '../../examples/kitchensink/app/view/' + (demo
.get('view') || demo
.get('text')) + '.js',
92 callback: function (request
, success
, response
) {
93 setTimeout(function() {
95 overlay
.setHtml(response
.responseText
);
102 onThemeToggleTap: function() {
103 switch(Ext
.theme
.name
) {
105 if (!Kitchensink
.app
.getThemeVariationTransitionCls()) {
106 Kitchensink
.app
.setThemeVariationTransitionCls("tizenThemeTransition");
109 if (Kitchensink
.app
.getThemeVariation() === "light") {
110 Kitchensink
.app
.setThemeVariation("dark");
112 Kitchensink
.app
.setThemeVariation("light");
121 * In the kitchen sink we have a large number of dynamic views. If we were to keep all of them rendered
122 * we'd risk causing the browser to run out of memory, especially on older devices. If we destroy them as
123 * soon as we're done with them, the app can appear sluggish. Instead, we keep a small number of rendered
124 * views in a viewCache so that we can easily reuse recently used views while destroying those we haven't
126 * @param {String} name The full class name of the view to create (e.g. "Kitchensink.view.Forms")
127 * @return {Ext.Component} The component, which may be from the cache
129 createView: function (item
) {
130 var name
= this.getViewName(item
),
131 cache
= this.getViewCache(),
133 limit
= item
.get('limit') || 20,
134 view
, i
= 0, j
, oldView
;
136 for (; i
< ln
; i
++) {
137 if (cache
[i
].viewName
=== name
) {
143 for (i
= 0, j
= 0; i
< ln
; i
++) {
145 if (!oldView
.isPainted()) {
148 cache
[j
++] = oldView
;
154 view
= Ext
.create(name
);
155 view
.viewName
= name
;
157 this.setViewCache(cache
);
164 * Returns the full class name of the view to construct for a given Demo
165 * @param {Kitchensink.model.Demo} item The demo
166 * @return {String} The full class name of the view
168 getViewName: function (item
) {
169 var name
= item
.get('view') || item
.get('text'),
170 ns
= 'Kitchensink.view.';
172 if (name
== 'TouchEvents') {
173 if (this.getApplication().getCurrentProfile().getName() === 'Tablet') {
174 return ns
+ 'tablet.' + name
;
176 return ns
+ 'phone.' + name
;
184 * we iterate over all of the floating sheet components and make sure they're hidden when we
185 * navigate to a new view. This stops things like Picker overlays staying visible when you hit
186 * the browser's back button
188 hideSheets: function () {
189 Ext
.each(Ext
.ComponentQuery
.query('sheet, #editorPanel'), function (sheet
) {
190 if(sheet
instanceof Ext
.Menu
) {
191 Ext
.Viewport
.hideMenu(sheet
);
193 sheet
.setHidden(true);