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