-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardized 'actions' models and deferred SpinnerView loading
- Loading branch information
Showing
33 changed files
with
313 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var DeletePlaylistDialogView = require('foreground/view/dialog/deletePlaylistDialogView'); | ||
var EditPlaylistDialogView = require('foreground/view/dialog/editPlaylistDialogView'); | ||
var ExportPlaylistDialogView = require('foreground/view/dialog/exportPlaylistDialogView'); | ||
|
||
var PlaylistActions = Backbone.Model.extend({ | ||
showContextMenu: function(playlist, top, left) { | ||
var isEmpty = playlist.get('items').isEmpty(); | ||
|
||
Streamus.channels.simpleMenu.commands.trigger('show:simpleMenu', { | ||
isContextMenu: true, | ||
top: top, | ||
left: left, | ||
simpleMenuItems: [{ | ||
text: chrome.i18n.getMessage('edit'), | ||
onClick: this._showEditPlaylistDialog.bind(this, playlist) | ||
}, { | ||
// No point in sharing an empty playlist. | ||
disabled: isEmpty, | ||
text: chrome.i18n.getMessage('copyUrl'), | ||
onClick: this._copyPlaylistUrl.bind(this, playlist) | ||
}, { | ||
// No point in exporting an empty playlist. | ||
disabled: isEmpty, | ||
text: chrome.i18n.getMessage('export'), | ||
onClick: this._showExportPlaylistDialog.bind(this, playlist) | ||
}] | ||
}); | ||
}, | ||
|
||
deletePlaylist: function(playlist) { | ||
// No need to notify if the playlist is empty. | ||
if (playlist.get('items').length === 0) { | ||
playlist.destroy(); | ||
} else { | ||
this._showDeletePlaylistDialog.call(this, playlist); | ||
} | ||
}, | ||
|
||
_copyPlaylistUrl: function(playlist) { | ||
playlist.getShareCode({ | ||
success: this._onGetShareCodeSuccess, | ||
error: this._onGetShareCodeError | ||
}); | ||
}, | ||
|
||
_onGetShareCodeSuccess: function(shareCode) { | ||
shareCode.copyUrl(); | ||
|
||
Streamus.channels.notification.commands.trigger('show:notification', { | ||
message: chrome.i18n.getMessage('urlCopied') | ||
}); | ||
}, | ||
|
||
_onGetShareCodeError: function() { | ||
Streamus.channels.notification.commands.trigger('show:notification', { | ||
message: chrome.i18n.getMessage('copyFailed') | ||
}); | ||
}, | ||
|
||
_showDeletePlaylistDialog: function(playlist) { | ||
Streamus.channels.dialog.commands.trigger('show:dialog', DeletePlaylistDialogView, { | ||
playlist: playlist | ||
}); | ||
}, | ||
|
||
_showEditPlaylistDialog: function(playlist) { | ||
Streamus.channels.dialog.commands.trigger('show:dialog', EditPlaylistDialogView, { | ||
playlist: playlist | ||
}); | ||
}, | ||
|
||
_showExportPlaylistDialog: function(playlist) { | ||
Streamus.channels.dialog.commands.trigger('show:dialog', ExportPlaylistDialogView, { | ||
playlist: playlist | ||
}); | ||
} | ||
}); | ||
|
||
return PlaylistActions; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var CreatePlaylistDialogView = require('foreground/view/dialog/createPlaylistDialogView'); | ||
|
||
var SongActions = Backbone.Model.extend({ | ||
showSaveMenu: function(songs, top, left, playlists) { | ||
songs = songs instanceof Backbone.Collection ? songs.models : _.isArray(songs) ? songs : [songs]; | ||
|
||
var simpleMenuItems = playlists.map(function(playlist) { | ||
return { | ||
active: playlist.get('active'), | ||
text: playlist.get('title'), | ||
value: playlist.get('id'), | ||
onClick: function(model) { | ||
var playlistId = model.get('value'); | ||
playlists.get(playlistId).get('items').addSongs(songs); | ||
}.bind(this) | ||
}; | ||
}, this); | ||
|
||
Streamus.channels.simpleMenu.commands.trigger('show:simpleMenu', { | ||
top: top, | ||
left: left, | ||
simpleMenuItems: simpleMenuItems, | ||
fixedMenuItem: { | ||
text: chrome.i18n.getMessage('createPlaylist'), | ||
onClick: function() { | ||
Streamus.channels.dialog.commands.trigger('show:dialog', CreatePlaylistDialogView, { | ||
songs: songs | ||
}); | ||
}.bind(this) | ||
} | ||
}); | ||
}, | ||
|
||
showContextMenu: function(song, top, left, player) { | ||
Streamus.channels.simpleMenu.commands.trigger('show:simpleMenu', { | ||
isContextMenu: true, | ||
top: top, | ||
left: left, | ||
simpleMenuItems: [{ | ||
text: chrome.i18n.getMessage('copyUrl'), | ||
onClick: function() { | ||
song.copyUrl(); | ||
}.bind(this) | ||
}, { | ||
text: chrome.i18n.getMessage('copyTitleAndUrl'), | ||
onClick: function() { | ||
song.copyTitleAndUrl(); | ||
}.bind(this) | ||
}, { | ||
text: chrome.i18n.getMessage('watchOnYouTube'), | ||
onClick: function() { | ||
player.watchInTab(song); | ||
}.bind(this) | ||
}] | ||
}); | ||
} | ||
}); | ||
|
||
return SongActions; | ||
}); |
Oops, something went wrong.