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'),
|
|
|
|
Globals = require('Common/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');
|
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
this.Data = Globals.__APP.data(); // TODO
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.exp = ko.observable(false);
|
|
|
|
|
|
|
|
this.languages = ko.computed(function () {
|
2014-09-02 08:15:31 +08:00
|
|
|
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)
|
|
|
|
};
|
|
|
|
});
|
2014-09-02 08:15:31 +08:00
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
this.Data.mainLanguage.subscribe(function () {
|
2014-08-21 23:08:34 +08:00
|
|
|
this.resetMainLanguage();
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
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 ()
|
|
|
|
{
|
2014-09-02 08:15:31 +08:00
|
|
|
var sCurrent = this.Data.mainLanguage();
|
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
|
|
|
};
|
|
|
|
|
|
|
|
PopupsLanguagesViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.exp(true);
|
2013-11-20 01:41:21 +08:00
|
|
|
|
|
|
|
this.resetMainLanguage();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PopupsLanguagesViewModel.prototype.onHide = function ()
|
|
|
|
{
|
|
|
|
this.exp(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
|
|
|
|
{
|
2014-09-02 08:15:31 +08:00
|
|
|
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-09-05 06:49:03 +08:00
|
|
|
}());
|