VulpesOS/gaia/apps/music/views/playlist-detail/view.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

65 lines
1.6 KiB
JavaScript
Executable file

/* global View, IntlHelper */
'use strict';
var PlaylistDetailView = View.extend(function PlaylistDetailView() {
View.call(this); // super();
this.list = document.getElementById('list');
this.list.addEventListener('click', (evt) => {
var link = evt.target.closest('a[data-file-path]');
if (link) {
this.queuePlaylist(link.dataset.filePath);
}
});
this.client.on('databaseChange', () => this.update());
this.update();
});
PlaylistDetailView.prototype.update = function() {
return this.getPlaylist().then((songs) => {
this.songs = songs;
return this.render();
});
};
PlaylistDetailView.prototype.destroy = function() {
this.client.destroy();
View.prototype.destroy.call(this); // super(); // Always call *last*
};
PlaylistDetailView.prototype.render = function() {
return this.list.setModel(this.songs)
.then(this.onRenderDone);
};
PlaylistDetailView.prototype.getPlaylist = function() {
var unpaddedIndex = IntlHelper.get('unpaddedIndex');
return this.fetch('/api/playlists/info/' + this.params.id)
.then(response => response.json())
.then(songs => {
return songs.map((song, index) => {
return {
index: unpaddedIndex.format(index + 1),
name: song.name,
title: song.metadata.title,
artist: song.metadata.artist
};
});
});
};
PlaylistDetailView.prototype.queuePlaylist = function(filePath) {
this.fetch('/api/queue/playlist/' + this.params.id + '/song/' + filePath);
};
IntlHelper.define('unpaddedIndex', 'number', {
style: 'decimal',
useGrouping: false,
minimumIntegerDigits: 1
});
window.view = new PlaylistDetailView();