snappymail/dev/ViewModels/Popups/PopupsLanguagesViewModel.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
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'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
Data = require('Storage:RainLoop:Data'),
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.exp = ko.observable(false);
this.languages = ko.computed(function () {
return _.map(Data.languages(), function (sLanguage) {
return {
'key': sLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
});
Data.mainLanguage.subscribe(function () {
this.resetMainLanguage();
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsLanguagesViewModel', PopupsLanguagesViewModel);
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
{
return Utils.convertLangName(sLanguage, true);
};
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
{
var sCurrent = Data.mainLanguage();
_.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)
{
Data.mainLanguage(sLang);
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));