/ext-4.1.0_b3/examples/MVC/pandora/app/controller/Song.js

https://bitbucket.org/srogerf/javascript · JavaScript · 54 lines · 42 code · 10 blank · 2 comment · 0 complexity · 31d59a135070d035cab62480e2f93ca5 MD5 · raw file

  1. Ext.define('Pandora.controller.Song', {
  2. extend: 'Ext.app.Controller',
  3. refs: [{
  4. ref: 'songInfo',
  5. selector: 'songinfo'
  6. }, {
  7. ref: 'recentlyPlayedScroller',
  8. selector: 'recentlyplayedscroller'
  9. }],
  10. stores: ['RecentSongs'],
  11. init: function() {
  12. this.control({
  13. 'recentlyplayedscroller': {
  14. selectionchange: this.onSongSelect
  15. }
  16. });
  17. this.application.on({
  18. stationstart: this.onStationStart,
  19. scope: this
  20. });
  21. },
  22. onStationStart: function(station) {
  23. var store = this.getRecentSongsStore();
  24. store.load({
  25. callback: this.onRecentSongsLoad,
  26. params: {
  27. station: station.get('id')
  28. },
  29. scope: this
  30. });
  31. },
  32. onRecentSongsLoad: function(songs, request) {
  33. var store = this.getRecentSongsStore(),
  34. selModel = this.getRecentlyPlayedScroller().getSelectionModel();
  35. // The data should already be filtered on the serverside but since we
  36. // are loading static data we need to do this after we loaded all the data
  37. store.filter('station', request.params.station);
  38. store.sort('played_date', 'ASC');
  39. selModel.select(store.last());
  40. },
  41. onSongSelect: function(selModel, selection) {
  42. this.getSongInfo().update(selection[0]);
  43. }
  44. });