/ext-4.0.7/examples/app/nested-loading/app/controller/Books.js

https://bitbucket.org/srogerf/javascript · JavaScript · 82 lines · 44 code · 11 blank · 27 comment · 2 complexity · c5ad1bcbe93ae54ba70984be3060b1ba MD5 · raw file

  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This 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.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * Books controller
  11. * Used to manage books; showing the first book, showing a spefied book, loading books, and showing their
  12. * related views
  13. */
  14. Ext.define('Books.controller.Books', {
  15. extend: 'Ext.app.Controller',
  16. models: ['Book'],
  17. stores: ['Books', 'Reviews'],
  18. refs: [
  19. {ref: 'bookSideBar', selector: 'booksidebar'},
  20. {ref: 'bookView', selector: 'bookview'},
  21. {ref: 'reviewList', selector: 'reviewlist'}
  22. ],
  23. init: function() {
  24. var me = this;
  25. me.control({
  26. 'booksidebar': {
  27. selectionchange: me.onSideBarSelectionChange
  28. }
  29. });
  30. me.getBooksStore().on({
  31. scope: me,
  32. load : me.onBooksStoreLoad
  33. });
  34. },
  35. onLaunch: function() {
  36. this.getBookSideBar().bindStore(this.getBooksStore());
  37. },
  38. onSideBarSelectionChange: function(view, records) {
  39. if (records.length) {
  40. this.showBook(records[0]);
  41. }
  42. },
  43. /**
  44. * Called when the books store is loaded.
  45. * Checks if there are any records, and if there are, it delegates to show the first record
  46. * as well as selecting that record in the sidebar
  47. */
  48. onBooksStoreLoad: function(store, records) {
  49. Ext.defer(function() {
  50. if (records.length) {
  51. var record = records[0],
  52. me = this;
  53. me.getBookSideBar().getSelectionModel().select(record);
  54. }
  55. }, 500, this);
  56. },
  57. /**
  58. * Shows a specified record by binding it to
  59. */
  60. showBook: function(record) {
  61. var me = this;
  62. me.getBookView().bind(record);
  63. me.getReviewList().bind(record, me.getReviewsStore());
  64. }
  65. });