snappymail/dev/ViewModels/Popups/PopupsLanguagesViewModel.js

82 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-08-25 23:49:01 +08:00
(function (module, require) {
'use strict';
2014-08-21 23:08:34 +08:00
var
2014-08-25 23:49:01 +08:00
_ = require('_'),
ko = require('ko'),
2014-08-25 15:10:51 +08:00
2014-08-25 23:49:01 +08:00
Utils = require('Utils'),
Globals = require('Globals'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
kn = require('App:Knoin'),
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsLanguagesViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages');
this.Data = Globals.__APP.data(); // TODO
2014-08-21 23:08:34 +08:00
this.exp = ko.observable(false);
this.languages = ko.computed(function () {
return _.map(this.Data.languages(), function (sLanguage) {
2014-08-21 23:08:34 +08:00
return {
'key': sLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
}, this);
2014-08-21 23:08:34 +08:00
this.Data.mainLanguage.subscribe(function () {
2014-08-21 23:08:34 +08:00
this.resetMainLanguage();
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View:Popup:Languages', 'PopupsLanguagesViewModel'], PopupsLanguagesViewModel);
_.extend(PopupsLanguagesViewModel.prototype, KnoinAbstractViewModel.prototype);
2014-08-21 23:08:34 +08:00
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
{
return Utils.convertLangName(sLanguage, true);
};
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
{
var sCurrent = this.Data.mainLanguage();
2014-08-21 23:08:34 +08:00
_.each(this.languages(), function (oItem) {
oItem['selected'](oItem['key'] === sCurrent);
});
2014-08-21 23:08:34 +08:00
};
PopupsLanguagesViewModel.prototype.onShow = function ()
{
this.exp(true);
this.resetMainLanguage();
2014-08-21 23:08:34 +08:00
};
PopupsLanguagesViewModel.prototype.onHide = function ()
{
this.exp(false);
};
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
{
this.Data.mainLanguage(sLang);
2014-08-21 23:08:34 +08:00
this.cancelCommand();
};
2014-08-22 23:08:56 +08:00
module.exports = PopupsLanguagesViewModel;
2014-08-21 23:08:34 +08:00
2014-08-25 23:49:01 +08:00
}(module, require));