snappymail/dev/Settings/User/Themes.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +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
_ = require('_'),
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
2014-10-06 02:37:31 +08:00
Links = require('Common/Links'),
2014-08-22 23:08:56 +08:00
2014-10-18 21:43:44 +08:00
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
2014-10-18 21:43:44 +08:00
function ThemesUserSetting()
2014-08-21 23:08:34 +08:00
{
2014-08-22 23:08:56 +08:00
var self = this;
2014-08-21 23:08:34 +08:00
2014-08-22 23:08:56 +08:00
this.mainTheme = Data.mainTheme;
2014-08-21 23:08:34 +08:00
this.themesObjects = ko.observableArray([]);
this.themeTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
this.iTimer = 0;
this.oThemeAjaxRequest = null;
2014-08-21 23:08:34 +08:00
2014-08-22 23:08:56 +08:00
Data.theme.subscribe(function (sValue) {
2014-08-21 23:08:34 +08:00
_.each(this.themesObjects(), function (oTheme) {
oTheme.selected(sValue === oTheme.name);
});
Utils.changeTheme(sValue, self.themeTrigger);
2014-08-21 23:08:34 +08:00
Remote.saveSettings(null, {
'Theme': sValue
});
}, this);
}
2014-10-18 21:43:44 +08:00
ThemesUserSetting.prototype.onBuild = function ()
2014-08-21 23:08:34 +08:00
{
2014-08-22 23:08:56 +08:00
var sCurrentTheme = Data.theme();
this.themesObjects(_.map(Data.themes(), function (sTheme) {
2014-08-21 23:08:34 +08:00
return {
'name': sTheme,
'nameDisplay': Utils.convertThemeName(sTheme),
'selected': ko.observable(sTheme === sCurrentTheme),
2014-10-06 02:37:31 +08:00
'themePreviewSrc': Links.themePreviewLink(sTheme)
2014-08-21 23:08:34 +08:00
};
}));
};
2014-10-18 21:43:44 +08:00
module.exports = ThemesUserSetting;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());