(function (module, require) { 'use strict'; var _ = require('_'), ko = require('ko'), Utils = require('Utils'), Globals = require('Globals'), kn = require('App:Knoin'), KnoinAbstractViewModel = require('Knoin:AbstractViewModel') ; /** * @constructor * @extends KnoinAbstractViewModel */ function PopupsLanguagesViewModel() { KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages'); this.Data = Globals.__APP.data(); // TODO this.exp = ko.observable(false); this.languages = ko.computed(function () { return _.map(this.Data.languages(), function (sLanguage) { return { 'key': sLanguage, 'selected': ko.observable(false), 'fullName': Utils.convertLangName(sLanguage) }; }); }, this); this.Data.mainLanguage.subscribe(function () { this.resetMainLanguage(); }, this); kn.constructorEnd(this); } kn.extendAsViewModel(['View:Popup:Languages', 'PopupsLanguagesViewModel'], PopupsLanguagesViewModel); _.extend(PopupsLanguagesViewModel.prototype, KnoinAbstractViewModel.prototype); PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage) { return Utils.convertLangName(sLanguage, true); }; PopupsLanguagesViewModel.prototype.resetMainLanguage = function () { var sCurrent = this.Data.mainLanguage(); _.each(this.languages(), function (oItem) { oItem['selected'](oItem['key'] === sCurrent); }); }; PopupsLanguagesViewModel.prototype.onShow = function () { this.exp(true); this.resetMainLanguage(); }; PopupsLanguagesViewModel.prototype.onHide = function () { this.exp(false); }; PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang) { this.Data.mainLanguage(sLang); this.cancelCommand(); }; module.exports = PopupsLanguagesViewModel; }(module, require));