]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @class KitchenSink.controller.phone.Main\r | |
3 | * @extends KitchenSink.controller.Main\r | |
4 | *\r | |
5 | * This is the Main controller subclass for the 'phone' profile. Most of the functionality required for this controller\r | |
6 | * is provided by the KitchenSink.controller.Main superclass, but we do need to add a couple of refs and control\r | |
7 | * statements to provide a slightly different behavior for the phone.\r | |
8 | *\r | |
9 | * The Main superclass provides a couple of capabilities that we use here. Firstly it sets up a listener on the main\r | |
10 | * navigation NestedList and redirects to the appropriate url for each view. For example, tapping on the 'Forms' item\r | |
11 | * in the list will redirect to the url 'demos/forms'.\r | |
12 | *\r | |
13 | * Secondly, it sets up a route that listens for urls in the form above and calls the controller's showView function\r | |
14 | * whenever one is detected. The showView function then just shows the appropriate view on the screen.\r | |
15 | *\r | |
16 | */\r | |
17 | Ext.define('KitchenSink.controller.phone.Main', {\r | |
18 | extend: 'KitchenSink.controller.Main',\r | |
19 | \r | |
20 | config: {\r | |
21 | refs: {\r | |
22 | touchEvents: 'touchevents',\r | |
23 | consoleButton: 'button[action=showConsole]'\r | |
24 | },\r | |
25 | \r | |
26 | control: {\r | |
27 | nav: {\r | |
28 | back: 'onBackTap'\r | |
29 | },\r | |
30 | consoleButton: {\r | |
31 | tap: 'showTouchEventConsole'\r | |
32 | }\r | |
33 | }\r | |
34 | },\r | |
35 | \r | |
36 | /**\r | |
37 | * This is called whenever the user taps on an item in the main navigation NestedList\r | |
38 | */\r | |
39 | onNavTap: function(nestedList, list, index, target, record, e) {\r | |
40 | if (record.isLeaf()) {\r | |
41 | this.redirectTo(record);\r | |
42 | } else {\r | |
43 | this.redirectTo('menu/' + record.get('id'));\r | |
44 | }\r | |
45 | },\r | |
46 | \r | |
47 | onNavLeafTap: function(nestedList, list, index, target, record, e) {\r | |
48 | this.showView(record, true);\r | |
49 | },\r | |
50 | \r | |
51 | /**\r | |
52 | * In the Phone Profile only we support routing through to a menu page (urls like "menu/ui"). This function\r | |
53 | * just sets everything up to show that menu\r | |
54 | */\r | |
55 | showMenuById: function(id) {\r | |
56 | var nav = this.getNav(),\r | |
57 | store = nav.getStore(),\r | |
58 | item = (!id || id == 'root') ? store.getRoot() : store.getNodeById(id);\r | |
59 | \r | |
60 | if (item) {\r | |
61 | nav.goToNode(item);\r | |
62 | this.getToolbar().setTitle(item.get('text'));\r | |
63 | this.getSourceButton().setHidden(true);\r | |
64 | this.getSourceOverlay().setHidden(true);\r | |
65 | this.hideSheets();\r | |
66 | }\r | |
67 | },\r | |
68 | \r | |
69 | /**\r | |
70 | * For a given Demo model instance, shows the appropriate view. This is the endpoint for all routes matching\r | |
71 | * 'demo/:id', so is called automatically whenever the user navigates back or forward between demos.\r | |
72 | * @param {KitchenSink.model.Demo} item The Demo model instance for which we want to show a view\r | |
73 | */\r | |
74 | showView: function(item, direct) {\r | |
75 | if (this.isProfile(item)) {\r | |
76 | return;\r | |
77 | }\r | |
78 | \r | |
79 | var nav = this.getNav(),\r | |
80 | title = item.get('text'),\r | |
81 | view = this.createView(item),\r | |
82 | layout = nav.getLayout(),\r | |
83 | anim = item.get('animation'),\r | |
84 | initialAnim = layout.getAnimation(),\r | |
85 | newAnim;\r | |
86 | \r | |
87 | if (nav.getDetailCard() !== view) {\r | |
88 | if (anim) {\r | |
89 | layout.setAnimation(anim);\r | |
90 | newAnim = layout.getAnimation();\r | |
91 | }\r | |
92 | \r | |
93 | nav.setDetailCard(view);\r | |
94 | if (!direct) {\r | |
95 | nav.goToLeaf(item);\r | |
96 | }\r | |
97 | \r | |
98 | if (newAnim) {\r | |
99 | newAnim.on('animationend', function() {\r | |
100 | layout.setAnimation(initialAnim);\r | |
101 | }, this, { single: true });\r | |
102 | }\r | |
103 | }\r | |
104 | \r | |
105 | this.getToolbar().setTitle(title);\r | |
106 | this.getSourceButton().setHidden(false);\r | |
107 | },\r | |
108 | \r | |
109 | /**\r | |
110 | * This is called whenever the user hits the Back button on the main navigation NestedList. It hides the\r | |
111 | * "View Source" button as we do no want to see that when we are in the NestedList itself\r | |
112 | */\r | |
113 | onBackTap: function(nestedList, node) {\r | |
114 | //this means we just hit back out of a detail card\r | |
115 | if (node.isLeaf()) {\r | |
116 | this.getSourceButton().setHidden(true);\r | |
117 | }\r | |
118 | \r | |
119 | this.redirectTo('menu/' + node.parentNode.get('id'));\r | |
120 | },\r | |
121 | \r | |
122 | /**\r | |
123 | * This is called whenever the user hits the 'Console' button on the TouchEvents view. It just makes sure\r | |
124 | * that the view is showing the console card.\r | |
125 | */\r | |
126 | showTouchEventConsole: function(button) {\r | |
127 | this.getTouchEvents().showConsole();\r | |
128 | }\r | |
129 | }); |