cyp/app/js/elements/song.js

42 lines
1 KiB
JavaScript
Raw Normal View History

2020-03-10 05:24:31 +08:00
import * as format from "../format.js";
import * as html from "../html.js";
2020-03-12 05:46:28 +08:00
import Item from "../item.js";
2020-03-10 05:24:31 +08:00
export default class Song extends Item {
constructor(data) {
super();
2020-03-13 17:36:13 +08:00
this.data = data; // FIXME verejne?
this.dataset.songId = data["Id"]; // FIXME toto maji jen ve fronte
2020-03-10 05:24:31 +08:00
}
connectedCallback() {
2020-03-13 17:36:13 +08:00
const data = this.data;
const block = html.node("div", {className:"multiline"}, "", this);
const title = this._buildTitle(data);
block.appendChild(title);
if (data["Track"]) {
const track = html.node("span", {className:"track"}, data["Track"].padStart(2, "0"));
title.insertBefore(html.text(" "), title.firstChild);
title.insertBefore(track, title.firstChild);
}
if (data["Title"]) {
const subtitle = format.subtitle(data);
html.node("span", {className:"subtitle"}, subtitle, block);
}
}
2020-03-11 17:55:18 +08:00
2020-03-13 17:36:13 +08:00
_buildTitle(data) {
return super._buildTitle(data["Title"] || fileName(data));
2020-03-10 22:25:43 +08:00
}
2020-03-10 05:24:31 +08:00
}
customElements.define("cyp-song", Song);
// FIXME vyfaktorovat nekam do haje
function fileName(data) {
return data["file"].split("/").pop();
}