Station.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Ext.define('Pandora.controller.Station', {
  2. extend: 'Ext.app.Controller',
  3. refs: [{
  4. ref: 'stationsList',
  5. selector: 'stationslist'
  6. }],
  7. stores: ['Stations', 'RecentSongs'],
  8. init: function() {
  9. this.control({
  10. 'stationslist': {
  11. selectionchange: this.onStationSelect
  12. },
  13. 'newstation': {
  14. select: this.onNewStationSelect
  15. }
  16. });
  17. },
  18. onLaunch: function() {
  19. var stationsStore = this.getStationsStore();
  20. stationsStore.load({
  21. callback: this.onStationsLoad,
  22. scope: this
  23. });
  24. },
  25. onStationsLoad: function() {
  26. var stationsList = this.getStationsList();
  27. stationsList.getSelectionModel().select(0);
  28. },
  29. onStationSelect: function(selModel, selection) {
  30. this.application.fireEvent('stationstart', selection[0]);
  31. },
  32. onNewStationSelect: function(field, selection) {
  33. var selected = selection[0],
  34. store = this.getStationsStore(),
  35. list = this.getStationsList();
  36. if (selected && !store.getById(selected.get('id'))) {
  37. store.add(selected);
  38. list.getSelectionModel().select(selected);
  39. }
  40. }
  41. });