radio/lorgar/views/mainLayout.js

99 lines
4.3 KiB
JavaScript

"use strict";
(function mainLayout_js() {
var moduleName = "views/mainLayout";
var defineArray = [];
defineArray.push("views/gridLayout");
defineArray.push("views/label");
defineArray.push("views/view");
defineArray.push("views/navigationPanel");
defineArray.push("views/layout");
defineArray.push("views/enumeration");
defineArray.push("views/player");
defineArray.push("lib/wController/localModel");
define(moduleName, defineArray, function mainLayout_module() {
var GridLayout = require("views/gridLayout");
var ViewLabel = require("views/label");
var View = require("views/view");
var ViewNavigationPanel = require("views/navigationPanel");
var Layout = require("views/layout");
var Enumeration = require("views/enumeration");
var Player = require("views/player");
var LocalModel = require("lib/wController/localModel");
var MainLayout = GridLayout.inherit({
"className": "MainLayout",
"constructor": function(controller, options) {
GridLayout.fn.constructor.call(this, controller, options);
this._statusBarPosition = 2;
this._player = undefined;
this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"});
this._statusBarModel = new LocalModel({backgroundColor: "secondaryColor"});
this._uncyclic.push(this._statusBarModel.destructor.bind(this._statusBarModel));
this._uncyclic.push(this._mainColorHelper.destructor.bind(this._mainColorHelper));
var spacerL = new View(this._mainColorHelper, {maxWidth: 50});
var spacerR = new View(this._mainColorHelper, {maxWidth: 50});
this.append(spacerL, 1, 0, 1, 1);
this.append(spacerR, 1, 2, 1, 1);
this._statusBar = new GridLayout(this._statusBarModel);
this._statusBar.append(new View(this._statusBarModel), 0, 1, 1, 1);
this.append(this._statusBar, 3, 0, 1, 3);
},
"_onNewController": function(controller) {
GridLayout.fn._onNewController.call(this, controller);
var view;
switch (controller.name) {
case "version":
view = new ViewLabel(controller);
this._statusBar.append(view, 0, 0, 1, 1, Layout.Aligment.LeftCenter);
break;
case "navigationPanel":
view = new ViewNavigationPanel(controller);
this.append(view, 0, 0, 1, 3);
break;
case "themes":
break;
default:
//this.trigger("serviceMessage", "Unsupported view: " + name + " (" + type + ")", 1);
break;
}
},
addState: function(name, state) {
var lm = new LocalModel({fontFamily: "casualFont"});
lm.setData(name + ": ");
var lv = new ViewLabel(lm);
var e = new Enumeration(state);
this._statusBar.append(lv, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter);
this._statusBar.append(e, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter);
this._uncyclic.push(lm.destructor.bind(lm));
},
appendPlayer: function(playerModel) {
if (this._player !== undefined) {
throw new Error("An attempt to add player to main layout for the second time");
}
this._player = new Player(playerModel);
this.append(this._player, 2, 0, 1, 3);
},
removePlayer: function() {
if (this._player === undefined) {
throw new Error("An attempt to remove non existing player from mainLayout");
}
this.removeChild(this._player);
this._player.destructor();
this._player = undefined;
}
});
return MainLayout;
});
})();