]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * Books controller\r | |
3 | * Used to manage books; showing the first book, showing a spefied book, loading books, and showing their\r | |
4 | * related views\r | |
5 | */\r | |
6 | Ext.define('Books.controller.Books', {\r | |
7 | extend: 'Ext.app.Controller',\r | |
8 | \r | |
9 | models: ['Book'],\r | |
10 | stores: ['Books', 'Reviews'],\r | |
11 | \r | |
12 | refs: [\r | |
13 | {ref: 'bookSideBar', selector: 'booksidebar'},\r | |
14 | {ref: 'bookView', selector: 'bookview'},\r | |
15 | {ref: 'reviewList', selector: 'reviewlist'}\r | |
16 | ],\r | |
17 | \r | |
18 | init: function() {\r | |
19 | var me = this;\r | |
20 | \r | |
21 | me.control({\r | |
22 | 'booksidebar': {\r | |
23 | selectionchange: me.onSideBarSelectionChange\r | |
24 | }\r | |
25 | });\r | |
26 | \r | |
27 | me.getBooksStore().on({\r | |
28 | scope: me,\r | |
29 | load : me.onBooksStoreLoad\r | |
30 | });\r | |
31 | },\r | |
32 | \r | |
33 | onLaunch: function() {\r | |
34 | this.getBookSideBar().bindStore(this.getBooksStore());\r | |
35 | },\r | |
36 | \r | |
37 | onSideBarSelectionChange: function(view, records) {\r | |
38 | if (records.length) {\r | |
39 | this.showBook(records[0]);\r | |
40 | }\r | |
41 | },\r | |
42 | \r | |
43 | /**\r | |
44 | * Called when the books store is loaded.\r | |
45 | * Checks if there are any records, and if there are, it delegates to show the first record\r | |
46 | * as well as selecting that record in the sidebar\r | |
47 | */\r | |
48 | onBooksStoreLoad: function(store, records) {\r | |
49 | Ext.defer(function() {\r | |
50 | if (records.length) {\r | |
51 | var record = records[0],\r | |
52 | me = this;\r | |
53 | \r | |
54 | me.getBookSideBar().getSelectionModel().select(record);\r | |
55 | }\r | |
56 | }, 500, this);\r | |
57 | },\r | |
58 | \r | |
59 | /**\r | |
60 | * Shows a specified record by binding it to\r | |
61 | */\r | |
62 | showBook: function(record) {\r | |
63 | var me = this;\r | |
64 | \r | |
65 | me.getBookView().bind(record);\r | |
66 | me.getReviewList().bind(record, me.getReviewsStore());\r | |
67 | }\r | |
68 | }); |