Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created February 2, 2016 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeoMix/0cebf38454f015b1d8a7 to your computer and use it in GitHub Desktop.
Save MeoMix/0cebf38454f015b1d8a7 to your computer and use it in GitHub Desktop.
import { LayoutView } from 'marionette';
import template from './share.hbs!';
import styles from './share.css!';
import Playlist from 'playlist/playlist';
import PlaylistView from 'playlist/playlistView';
import RouteType from 'common/enum/routeType';
export default LayoutView.extend({
className: styles.share,
template,
templateHelpers: {
styles: styles,
shareRouteType: RouteType.Share
},
regions: {
playlist: 'playlist'
},
modelEvents: {
'change:isLoading': '_onChangeIsLoading',
'change:hasError': '_onChangeHasError',
'change:hasPlaylist': '_onChangeHasPlaylist'
},
onRender() {
// If the view was initialized with a ShareCode then go ahead and load it.
// Otherwise, just let the user know no ShareCode is present and they can act accordingly.
const shareCode = this.model.get('shareCode');
if (shareCode) {
this._loadEntity(shareCode);
}
},
_onChangeIsLoading(model, isLoading) {
this.el.classList.toggle(styles.isLoading, isLoading);
},
_onChangeHasError(model, hasError) {
this.el.classList.toggle(styles.hasError, hasError);
},
_onChangeHasPlaylist(model, hasPlaylist) {
this.el.classList.toggle(styles.hasPlaylist, hasPlaylist);
},
_loadEntity(shareCode) {
this.model.set({
isLoading: true,
hasPlaylist: false
});
// Figure out the actual entity ID from the ShareCode by asking the server for more information.
shareCode.fetchByShortIdAndEntityTitle().then(this._onFetchResolve.bind(this), this._onFetchReject.bind(this));
},
_onFetchResolve() {
this.model.set({
isLoading: false,
hasPlaylist: true
});
this.showChildView('playlist', new PlaylistView({
model: new Playlist({
id: this.model.get('shareCode').get('entityId')
})
}));
},
_onFetchReject() {
this.model.set({
isLoading: false,
hasError: true
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment