radio/lorgar/views/player.js

106 lines
4.0 KiB
JavaScript

"use strict";
(function() {
var moduleName = "views/player"
var deps = [];
deps.push("views/gridLayout");
deps.push("views/button");
deps.push("views/label");
deps.push("views/view");
deps.push("lib/wController/localModel");
deps.push("lib/utils/enum");
define(moduleName, deps, function() {
var GridLayout = require("views/gridLayout");
var Button = require("views/button");
var Label = require("views/label");
var View = require("views/view");
var Model = require("lib/wController/localModel");
var Enum = require("lib/utils/enum");
var Player = GridLayout.inherit({
className: "Player",
constructor: function(ctrl, options) {
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._cpbCtrl = null;
this._infoModels = {
artist: new Model(null, "artist: unknown"),
album: new Model(null, "album: unknown"),
song: new Model(null, "song: unknown")
}
ctrl.on("newElement", this._onNewElement, this);
var artist = new Label(this._infoModels.artist);
var album = new Label(this._infoModels.album);
var song = new Label(this._infoModels.song);
var spacer = new View(helper);
this.append(artist, 0, 2, 1, 1)
this.append(song, 1, 2, 1, 1)
this.append(album, 2, 2, 1, 1)
this.append(spacer, 0, 3, 3, 1);
this._uncyclic.push(this._infoModels.artist.destructor.bind(this._infoModels.artist));
this._uncyclic.push(this._infoModels.song.destructor.bind(this._infoModels.song));
this._uncyclic.push(this._infoModels.album.destructor.bind(this._infoModels.album));
},
destructor: function() {
this._f.off("newElement", this._onNewElement, this);
this._clearCpbCtrl();
GridLayout.fn.destructor.call(this);
},
_clearCpbCtrl: function() {
if (this._cpbCtrl !== null) {
this._cpbCtrl.off("newElement", this._onCpbNewElement, this);
this._cpbCtrl.off("removeElement", this._onCpbRemoveElement, this);
this._cpbCtrl = null;
}
},
_onNewElement: function(ctrl, type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause = new Button(ctrl);
this.append(this._playPause, 0, 1, 3, 1);
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
this._cpbCtrl = ctrl;
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
}
},
_onCpbNewElement: function(key, value) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": " + value.toString());
}
},
_onCpbRemoveElement: function(key) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": unknown");
}
}
});
var helper = new Model();
return Player;
});
})()