koel/resources/assets/js/mixins/has-song-list.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-01-14 08:02:59 +00:00
/**
* Add necessary functionalities into a view that contains a song-list component.
*/
import { assign } from 'lodash';
2016-01-14 08:02:59 +00:00
import playback from '../services/playback';
import addToMenu from '../components/shared/add-to-menu.vue';
import songList from '../components/shared/song-list.vue';
export default {
components: { addToMenu, songList },
data() {
return {
/**
* Whether or not to show the "Add To" button in the header.
*
2016-01-14 08:02:59 +00:00
* @type {Boolean}
*/
showingAddToMenu: false,
/**
* An array of selected songs in the list.
*
2016-01-17 14:26:24 +00:00
* @type {Array.<Object>}
2016-01-14 08:02:59 +00:00
*/
selectedSongs: [],
meta: {
songCount: 0,
totalLength: '00:00',
},
};
},
methods: {
/**
* Shuffles the currently selected songs.
*/
shuffleSelected() {
if (this.selectedSongs.length < 2) {
return;
}
playback.queueAndPlay(this.selectedSongs, true);
},
},
events: {
/**
* Listen to add-to-menu:close event to set showingAddToMenu to false (and subsequently close the menu).
*/
'add-to-menu:close': function () {
this.showingAddToMenu = false;
},
'songlist:changed': function (meta) {
this.meta = assign(this.meta, meta);
2016-01-14 08:02:59 +00:00
},
},
};