/ext-4.0.7/examples/app/nested-loading/app/controller/Books.js
JavaScript | 82 lines | 44 code | 11 blank | 27 comment | 2 complexity | c5ad1bcbe93ae54ba70984be3060b1ba MD5 | raw file
1/*
2
3This file is part of Ext JS 4
4
5Copyright (c) 2011 Sencha Inc
6
7Contact: http://www.sencha.com/contact
8
9GNU General Public License Usage
10This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14*/
15/**
16 * Books controller
17 * Used to manage books; showing the first book, showing a spefied book, loading books, and showing their
18 * related views
19 */
20Ext.define('Books.controller.Books', {
21 extend: 'Ext.app.Controller',
22
23 models: ['Book'],
24 stores: ['Books', 'Reviews'],
25
26 refs: [
27 {ref: 'bookSideBar', selector: 'booksidebar'},
28 {ref: 'bookView', selector: 'bookview'},
29 {ref: 'reviewList', selector: 'reviewlist'}
30 ],
31
32 init: function() {
33 var me = this;
34
35 me.control({
36 'booksidebar': {
37 selectionchange: me.onSideBarSelectionChange
38 }
39 });
40
41 me.getBooksStore().on({
42 scope: me,
43 load : me.onBooksStoreLoad
44 });
45 },
46
47 onLaunch: function() {
48 this.getBookSideBar().bindStore(this.getBooksStore());
49 },
50
51 onSideBarSelectionChange: function(view, records) {
52 if (records.length) {
53 this.showBook(records[0]);
54 }
55 },
56
57 /**
58 * Called when the books store is loaded.
59 * Checks if there are any records, and if there are, it delegates to show the first record
60 * as well as selecting that record in the sidebar
61 */
62 onBooksStoreLoad: function(store, records) {
63 Ext.defer(function() {
64 if (records.length) {
65 var record = records[0],
66 me = this;
67
68 me.getBookSideBar().getSelectionModel().select(record);
69 }
70 }, 500, this);
71 },
72
73 /**
74 * Shows a specified record by binding it to
75 */
76 showBook: function(record) {
77 var me = this;
78
79 me.getBookView().bind(record);
80 me.getReviewList().bind(record, me.getReviewsStore());
81 }
82});