snappymail/dev/View/Popup/Languages.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import { koComputable } from 'External/ko';
2016-06-30 08:02:45 +08:00
import { convertLangName } from 'Common/Translator';
2016-06-30 08:02:45 +08:00
import { AbstractViewPopup } from 'Knoin/AbstractViews';
2016-06-30 08:02:45 +08:00
2022-02-24 21:01:41 +08:00
export class LanguagesPopupView extends AbstractViewPopup {
constructor() {
super('Languages');
this.fLang = null;
this.userLanguage = ko.observable('');
this.langs = ko.observableArray();
this.languages = koComputable(() => {
const userLanguage = this.userLanguage();
return this.langs.map(language => ({
key: language,
user: language === userLanguage,
selected: ko.observable(false),
fullName: convertLangName(language)
}));
});
2016-06-30 08:02:45 +08:00
this.langs.subscribe(() => this.setLanguageSelection());
}
2016-06-30 08:02:45 +08:00
languageTooltipName(language) {
2021-05-06 08:39:59 +08:00
return convertLangName(language, true);
}
2016-06-30 08:02:45 +08:00
setLanguageSelection() {
const currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
this.languages().forEach(item => item.selected(item.key === currentLang));
}
2016-06-30 08:02:45 +08:00
beforeShow() {
this.fLang = null;
this.userLanguage('');
2016-06-30 08:02:45 +08:00
this.langs([]);
}
2016-06-30 08:02:45 +08:00
onShow(fLanguage, langs, userLanguage) {
this.fLang = fLanguage;
this.userLanguage(userLanguage || '');
2016-06-30 08:02:45 +08:00
this.langs(langs);
}
2016-06-30 08:02:45 +08:00
changeLanguage(lang) {
this.fLang && this.fLang(lang);
this.close();
2016-06-30 08:02:45 +08:00
}
}