snappymail/dev/View/Popup/Languages.js

96 lines
2 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'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-09-05 06:49:03 +08:00
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends AbstractView
2014-08-21 23:08:34 +08:00
*/
function LanguagesPopupView()
2014-08-21 23:08:34 +08:00
{
AbstractView.call(this, 'Popups', 'PopupsLanguages');
2014-08-21 23:08:34 +08:00
2015-03-28 06:06:56 +08:00
var self = this;
2015-03-28 06:06:56 +08:00
this.fLang = null;
2015-04-17 21:56:29 +08:00
this.userLanguage = ko.observable('');
2015-03-28 06:06:56 +08:00
this.langs = ko.observableArray([]);
2014-08-21 23:08:34 +08:00
this.languages = ko.computed(function () {
2015-04-17 21:56:29 +08:00
var sUserLanguage = self.userLanguage();
2015-03-28 06:06:56 +08:00
return _.map(self.langs(), function (sLanguage) {
2014-08-21 23:08:34 +08:00
return {
'key': sLanguage,
2015-04-17 21:56:29 +08:00
'user': sLanguage === sUserLanguage,
2014-08-21 23:08:34 +08:00
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
2015-03-28 06:06:56 +08:00
});
2015-03-16 21:54:56 +08:00
2015-03-28 06:06:56 +08:00
this.langs.subscribe(function () {
this.setLanguageSelection();
2014-08-21 23:08:34 +08:00
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Languages', 'PopupsLanguagesViewModel'], LanguagesPopupView);
_.extend(LanguagesPopupView.prototype, AbstractView.prototype);
2014-08-21 23:08:34 +08:00
2015-03-28 06:06:56 +08:00
LanguagesPopupView.prototype.languageTooltipName = function (sLanguage)
2014-08-21 23:08:34 +08:00
{
var sResult = Utils.convertLangName(sLanguage, true);
2015-03-28 06:06:56 +08:00
return Utils.convertLangName(sLanguage, false) === sResult ? '' : sResult;
2014-08-21 23:08:34 +08:00
};
2015-03-28 06:06:56 +08:00
LanguagesPopupView.prototype.setLanguageSelection = function ()
2014-08-21 23:08:34 +08:00
{
2016-06-28 04:54:38 +08:00
var currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
_.each(this.languages(), function (item) {
item.selected(item.key === currentLang);
});
2014-08-21 23:08:34 +08:00
};
2015-04-23 05:33:02 +08:00
LanguagesPopupView.prototype.onBeforeShow = function ()
{
this.fLang = null;
this.userLanguage('');
this.langs([]);
};
2015-03-28 06:06:56 +08:00
LanguagesPopupView.prototype.onShow = function (fLanguage, aLangs, sUserLanguage)
2014-08-21 23:08:34 +08:00
{
2015-03-28 06:06:56 +08:00
this.fLang = fLanguage;
2015-04-17 21:56:29 +08:00
this.userLanguage(sUserLanguage || '');
2015-03-28 06:06:56 +08:00
this.langs(aLangs);
2014-08-21 23:08:34 +08:00
};
LanguagesPopupView.prototype.changeLanguage = function (sLang)
2014-08-21 23:08:34 +08:00
{
2015-03-28 06:06:56 +08:00
if (this.fLang)
{
this.fLang(sLang);
}
2014-08-21 23:08:34 +08:00
this.cancelCommand();
};
module.exports = LanguagesPopupView;
2014-08-21 23:08:34 +08:00
2016-06-28 04:54:38 +08:00
}());