2013-11-16 06:21:12 +08:00
|
|
|
|
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
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function LanguagesPopupView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsLanguages');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.LanguageStore = require('Stores/Language');
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.exp = ko.observable(false);
|
|
|
|
|
|
|
|
this.languages = ko.computed(function () {
|
2015-01-27 05:06:00 +08:00
|
|
|
return _.map(this.LanguageStore.languages(), function (sLanguage) {
|
2014-08-21 23:08:34 +08:00
|
|
|
return {
|
|
|
|
'key': sLanguage,
|
|
|
|
'selected': ko.observable(false),
|
|
|
|
'fullName': Utils.convertLangName(sLanguage)
|
|
|
|
};
|
|
|
|
});
|
2014-09-02 08:15:31 +08:00
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-03-16 21:54:56 +08:00
|
|
|
this.languagesTop = ko.computed(function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
aTop = this.LanguageStore.languagesTop(),
|
|
|
|
aLangs = this.languages()
|
|
|
|
;
|
|
|
|
|
|
|
|
return 0 < aTop.length ? _.compact(_.map(aTop, function (sLang) {
|
|
|
|
return _.find(aLangs, function (aItem) {
|
|
|
|
return aItem && sLang === aItem.key;
|
|
|
|
});
|
|
|
|
})) : [];
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.languagesBottom = ko.computed(function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
aTop = this.languagesTop(),
|
|
|
|
aLangs = this.languages()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (0 < aTop.length)
|
|
|
|
{
|
|
|
|
return _.filter(aLangs, function (aItem) {
|
|
|
|
return -1 === Utils.inArray(aItem, aTop);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return aLangs;
|
|
|
|
|
|
|
|
}, this);
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.LanguageStore.language.subscribe(function () {
|
2014-08-21 23:08:34 +08:00
|
|
|
this.resetMainLanguage();
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/Languages', 'PopupsLanguagesViewModel'], LanguagesPopupView);
|
|
|
|
_.extend(LanguagesPopupView.prototype, AbstractView.prototype);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
LanguagesPopupView.prototype.languageEnName = function (sLanguage)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-12-02 01:34:21 +08:00
|
|
|
var sResult = Utils.convertLangName(sLanguage, true);
|
|
|
|
return 'English' === sResult ? '' : sResult;
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
LanguagesPopupView.prototype.resetMainLanguage = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
var sCurrent = this.LanguageStore.language();
|
2014-08-21 23:08:34 +08:00
|
|
|
_.each(this.languages(), function (oItem) {
|
|
|
|
oItem['selected'](oItem['key'] === sCurrent);
|
2013-11-16 06:21:12 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
LanguagesPopupView.prototype.onShow = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.exp(true);
|
2013-11-20 01:41:21 +08:00
|
|
|
|
|
|
|
this.resetMainLanguage();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
LanguagesPopupView.prototype.onHide = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.exp(false);
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
LanguagesPopupView.prototype.changeLanguage = function (sLang)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
this.LanguageStore.language(sLang);
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = LanguagesPopupView;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|