/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
- Ext.define('Pandora.controller.Song', {
- extend: 'Ext.app.Controller',
- refs: [{
- ref: 'songInfo',
- selector: 'songinfo'
- }, {
- ref: 'recentlyPlayedScroller',
- selector: 'recentlyplayedscroller'
- }],
- stores: ['RecentSongs'],
-
- init: function() {
- this.control({
- 'recentlyplayedscroller': {
- selectionchange: this.onSongSelect
- }
- });
-
- this.application.on({
- stationstart: this.onStationStart,
- scope: this
- });
- },
-
- onStationStart: function(station) {
- var store = this.getRecentSongsStore();
- store.load({
- callback: this.onRecentSongsLoad,
- params: {
- station: station.get('id')
- },
- scope: this
- });
- },
-
- onRecentSongsLoad: function(songs, request) {
- var store = this.getRecentSongsStore(),
- selModel = this.getRecentlyPlayedScroller().getSelectionModel();
-
- // The data should already be filtered on the serverside but since we
- // are loading static data we need to do this after we loaded all the data
- store.filter('station', request.params.station);
- store.sort('played_date', 'ASC');
- selModel.select(store.last());
- },
-
- onSongSelect: function(selModel, selection) {
- this.getSongInfo().update(selection[0]);
- }
- });