Skip to content

Commit

Permalink
Standardized 'actions' models and deferred SpinnerView loading
Browse files Browse the repository at this point in the history
  • Loading branch information
MeoMix committed May 20, 2015
1 parent 219308f commit 390ea98
Show file tree
Hide file tree
Showing 33 changed files with 313 additions and 336 deletions.
45 changes: 15 additions & 30 deletions Streamus Chrome Extension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,22 @@
<Content Include="src\js\foreground\model\contextMenu\contextMenuAction.js" />
<Content Include="src\js\foreground\model\dialog\createPlaylist.js" />
<Content Include="src\js\foreground\model\dialog\editPlaylist.js" />
<Content Include="src\js\foreground\model\element\fixedMenuItem.js" />
<Content Include="src\js\foreground\model\song\songsAction.js" />
<Content Include="src\js\foreground\model\video\mediaSourceWrapper.js" />
<Content Include="src\js\foreground\model\video\sourceBufferWrapper.js" />
<Content Include="src\js\foreground\enum\keyCode.js" />
<Content Include="src\js\foreground\model\tooltip\tooltip.js" />
<Content Include="src\js\foreground\view\behavior\dialogContent.js" />
<Content Include="src\js\foreground\view\behavior\listItemButton.js" />
<Content Include="src\js\foreground\view\behavior\viewModelContainer.js" />
<Content Include="src\js\foreground\view\contextMenu\contextMenuItemsView.js" />
<Content Include="src\js\foreground\view\dialog\aboutStreamusDialogView.js" />
<Content Include="src\js\foreground\view\dialog\aboutStreamusView.js" />
<Content Include="src\js\foreground\view\dialog\clearStreamView.js" />
<Content Include="src\js\foreground\view\dialog\errorView.js" />
<Content Include="src\js\foreground\view\dialog\googleSignInView.js" />
<Content Include="src\js\foreground\view\dialog\linkUserIdView.js" />
<Content Include="src\js\foreground\view\dialog\updateStreamusView.js" />
<Content Include="src\js\foreground\view\element\fixedMenuItemView.js" />
<Content Include="src\js\foreground\view\element\simpleMenuItemsView.js" />
<Content Include="src\js\foreground\view\simpleMenu\simpleMenuItemsView.js" />
<Content Include="src\js\foreground\view\leftPane\activePlaylistAreaView.js" />
<Content Include="src\js\foreground\view\leftPane\leftPaneRegion.js" />
<Content Include="src\js\foreground\view\leftPane\leftPaneView.js" />
Expand Down Expand Up @@ -133,11 +131,8 @@
<Content Include="src\js\test\foreground\view\behavior\tooltipable.spec.js" />
<Content Include="src\js\test\foreground\foregroundSpecLoader.js" />
<Content Include="src\js\test\foreground\view\behavior\viewModelContainer.spec.js" />
<Content Include="src\js\test\foreground\view\contextMenu\contextMenuItemsView.spec.js" />
<Content Include="src\js\test\foreground\view\contextMenu\contextMenuItemView.spec.js" />
<Content Include="src\js\test\foreground\view\contextMenu\contextMenuRegion.spec.js" />
<Content Include="src\js\test\foreground\view\contextMenu\contextMenuSpecLoader.js" />
<Content Include="src\js\test\foreground\view\contextMenu\contextMenuView.spec.js" />
<Content Include="src\js\test\foreground\view\simpleMenu\simpleMenuRegion.spec.js" />
<Content Include="src\js\test\foreground\view\simpleMenu\simpleMenuSpecLoader.js" />
<Content Include="src\js\test\foreground\view\dialog\aboutStreamusDialogView.spec.js" />
<Content Include="src\js\test\foreground\view\dialog\aboutStreamusView.spec.js" />
<Content Include="src\js\test\foreground\view\dialog\clearStreamView.spec.js" />
Expand All @@ -153,10 +148,9 @@
<Content Include="src\js\test\foreground\view\element\radioButtonView.spec.js" />
<Content Include="src\js\test\foreground\view\element\radioGroupView.spec.js" />
<Content Include="src\js\test\foreground\view\element\simpleListItemView.spec.js" />
<Content Include="src\js\test\foreground\view\element\simpleMenuItemsView.spec.js" />
<Content Include="src\js\test\foreground\view\element\fixedMenuItemView.spec.js" />
<Content Include="src\js\test\foreground\view\element\simpleMenuItemView.spec.js" />
<Content Include="src\js\test\foreground\view\element\simpleMenuView.spec.js" />
<Content Include="src\js\test\foreground\view\simpleMenu\simpleMenuItemsView.spec.js" />
<Content Include="src\js\test\foreground\view\simpleMenu\simpleMenuItemView.spec.js" />
<Content Include="src\js\test\foreground\view\simpleMenu\simpleMenuView.spec.js" />
<Content Include="src\js\test\foreground\view\element\spinnerView.spec.js" />
<Content Include="src\js\test\foreground\view\element\switchView.spec.js" />
<Content Include="src\js\test\foreground\view\foregroundAreaView.spec.js" />
Expand Down Expand Up @@ -186,7 +180,6 @@
<Content Include="src\js\test\foreground\view\playlist\playlistSpecLoader.js" />
<Content Include="src\js\test\foreground\view\playlist\playlistsView.spec.js" />
<Content Include="src\js\test\foreground\view\playlist\playlistView.spec.js" />
<Content Include="src\js\test\foreground\view\saveSongs\saveSongsRegion.spec.js" />
<Content Include="src\js\test\foreground\view\search\searchRegion.spec.js" />
<Content Include="src\js\test\foreground\view\search\searchResultsView.spec.js" />
<Content Include="src\js\test\foreground\view\search\searchResultView.spec.js" />
Expand Down Expand Up @@ -220,7 +213,7 @@
<Content Include="src\js\thirdParty\test\mocha.js" />
<Content Include="src\js\thirdParty\test\sinon.js" />
<Content Include="src\template\dialog\aboutStreamus.html" />
<Content Include="src\template\element\menuItem.html" />
<Content Include="src\template\simpleMenu\simpleMenuItem.html" />
<Content Include="src\template\icon\closeIcon_24.svg" />
<Content Include="src\template\icon\deleteIcon_18.svg" />
<Content Include="src\template\icon\menuIcon_24.svg" />
Expand Down Expand Up @@ -319,7 +312,7 @@
<Content Include="src\js\foreground\collection\element\radioButtons.js" />
<Content Include="src\js\foreground\collection\element\radioGroups.js" />
<Content Include="src\js\foreground\collection\element\simpleListItems.js" />
<Content Include="src\js\foreground\collection\element\simpleMenuItems.js" />
<Content Include="src\js\foreground\collection\simpleMenu\simpleMenuItems.js" />
<Content Include="src\js\foreground\collection\element\switches.js" />
<Content Include="src\js\foreground\model\appBar\adminMenuArea.js" />
<Content Include="src\js\foreground\model\element\checkbox.js" />
Expand All @@ -333,8 +326,8 @@
<Content Include="src\js\background\model\tabManager.js" />
<Content Include="src\js\foreground\model\selectionBar\selectionBar.js" />
<Content Include="src\js\foreground\model\element\simpleListItem.js" />
<Content Include="src\js\foreground\model\element\simpleMenu.js" />
<Content Include="src\js\foreground\model\element\simpleMenuItem.js" />
<Content Include="src\js\foreground\model\simpleMenu\simpleMenu.js" />
<Content Include="src\js\foreground\model\simpleMenu\simpleMenuItem.js" />
<Content Include="src\js\foreground\model\element\switch.js" />
<Content Include="src\js\foreground\model\stream\timeArea.js" />
<Content Include="src\js\foreground\view\appBar\appBarRegion.js" />
Expand All @@ -343,12 +336,12 @@
<Content Include="src\js\foreground\view\behavior\scrollable.js" />
<Content Include="src\js\foreground\view\behavior\tooltipable.js" />
<Content Include="src\js\foreground\view\element\checkboxView.js" />
<Content Include="src\js\foreground\view\contextMenu\contextMenuRegion.js" />
<Content Include="src\js\foreground\view\simpleMenu\simpleMenuRegion.js" />
<Content Include="src\js\foreground\view\element\radioButtonView.js" />
<Content Include="src\js\foreground\view\element\radioGroupView.js" />
<Content Include="src\js\foreground\view\element\simpleListItemView.js" />
<Content Include="src\js\foreground\view\element\simpleMenuItemView.js" />
<Content Include="src\js\foreground\view\element\simpleMenuView.js" />
<Content Include="src\js\foreground\view\simpleMenu\simpleMenuItemView.js" />
<Content Include="src\js\foreground\view\simpleMenu\simpleMenuView.js" />
<Content Include="src\js\foreground\view\element\spinnerView.js" />
<Content Include="src\js\foreground\view\element\switchView.js" />
<Content Include="src\js\foreground\view\listItemButton\addPlaylistButtonView.js" />
Expand All @@ -358,7 +351,6 @@
<Content Include="src\js\foreground\view\listItemButton\playPlaylistButtonView.js" />
<Content Include="src\js\foreground\view\dialog\exportPlaylistView.js" />
<Content Include="src\js\foreground\view\dialog\browserSettingsDialogView.js" />
<Content Include="src\js\foreground\view\saveSongs\saveSongsRegion.js" />
<Content Include="src\js\foreground\view\selectionBar\selectionBarRegion.js" />
<Content Include="src\js\foreground\view\selectionBar\selectionBarView.js" />
<Content Include="src\js\foreground\view\stream\activeStreamItemView.js" />
Expand Down Expand Up @@ -387,18 +379,14 @@
<Content Include="src\js\common\enum\repeatButtonState.js" />
<Content Include="src\js\common\enum\youTubePlayerError.js" />
<Content Include="src\js\foreground\application.js" />
<Content Include="src\js\foreground\collection\contextMenu\contextMenuItems.js" />
<Content Include="src\js\foreground\view\foregroundAreaView.js" />
<Content Include="src\js\foreground\main.js" />
<Content Include="src\js\foreground\model\contextMenu\contextMenu.js" />
<Content Include="src\js\foreground\model\dialog\dialog.js" />
<Content Include="src\js\foreground\model\contextMenu\contextMenuItem.js" />
<Content Include="src\js\background\model\search.js" />
<Content Include="src\js\foreground\plugins.js" />
<Content Include="src\js\foreground\view\behavior\slidingRender.js" />
<Content Include="src\js\foreground\view\behavior\sortable.js" />
<Content Include="src\js\foreground\view\behavior\collectionViewMultiSelect.js" />
<Content Include="src\js\foreground\view\contextMenu\contextMenuItemView.js" />
<Content Include="src\js\foreground\view\listItemButton\addSongButtonView.js" />
<Content Include="src\js\foreground\view\listItemButton\listItemButtonsView.js" />
<Content Include="src\js\foreground\view\listItemView.js" />
Expand All @@ -411,7 +399,6 @@
<Content Include="src\js\foreground\view\listItemButton\playPauseSongButtonView.js" />
<Content Include="src\js\foreground\view\playlist\playlistsAreaView.js" />
<Content Include="src\js\foreground\view\playlist\playlistView.js" />
<Content Include="src\js\foreground\view\contextMenu\contextMenuView.js" />
<Content Include="src\js\foreground\view\dialog\createPlaylistView.js" />
<Content Include="src\js\foreground\view\dialog\deletePlaylistView.js" />
<Content Include="src\js\foreground\view\dialog\editPlaylistView.js" />
Expand Down Expand Up @@ -490,13 +477,11 @@
<None Include="src\less\foreground.less" />
<Content Include="src\template\appBar\appBar.html" />
<Content Include="src\template\backgroundArea.html" />
<Content Include="src\template\contextMenu\contextMenu.html" />
<Content Include="src\template\contextMenu\contextMenuItem.html" />
<Content Include="src\template\element\checkbox.html" />
<Content Include="src\template\element\radioButton.html" />
<Content Include="src\template\element\radioGroup.html" />
<Content Include="src\template\element\simpleListItem.html" />
<Content Include="src\template\element\simpleMenu.html" />
<Content Include="src\template\simpleMenu\simpleMenu.html" />
<Content Include="src\template\element\spinner.html" />
<Content Include="src\template\element\switch.html" />
<Content Include="src\template\foregroundArea.html" />
Expand Down
42 changes: 0 additions & 42 deletions src/js/foreground/model/contextMenu/contextMenuAction.js

This file was deleted.

1 change: 0 additions & 1 deletion src/js/foreground/model/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
title: '',
submitButtonText: chrome.i18n.getMessage('ok'),
cancelButtonText: chrome.i18n.getMessage('cancel'),
showSubmitButton: true,
showCancelButton: true,
reminderProperty: '',
reminderText: chrome.i18n.getMessage('remind'),
Expand Down
28 changes: 0 additions & 28 deletions src/js/foreground/model/playlist/playlistAction.js

This file was deleted.

83 changes: 83 additions & 0 deletions src/js/foreground/model/playlist/playlistActions.js
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;
});
63 changes: 63 additions & 0 deletions src/js/foreground/model/song/songActions.js
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;
});

0 comments on commit 390ea98

Please sign in to comment.