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
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2015-02-05 13:14:13 +08:00
|
|
|
$ = require('$'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-11-08 04:21:10 +08:00
|
|
|
Jua = require('Jua'),
|
|
|
|
|
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'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
ThemeStore = require('Stores/Theme'),
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
2014-10-18 21:43:44 +08:00
|
|
|
Remote = require('Storage/User/Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
function ThemesUserSettings()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
this.theme = ThemeStore.theme;
|
|
|
|
this.themes = ThemeStore.themes;
|
2014-08-21 23:08:34 +08:00
|
|
|
this.themesObjects = ko.observableArray([]);
|
|
|
|
|
2014-11-08 04:21:10 +08:00
|
|
|
this.background = {};
|
2015-01-27 05:06:00 +08:00
|
|
|
this.background.name = ThemeStore.themeBackgroundName;
|
|
|
|
this.background.hash = ThemeStore.themeBackgroundHash;
|
2014-11-08 04:21:10 +08:00
|
|
|
this.background.uploaderButton = ko.observable(null);
|
|
|
|
this.background.loading = ko.observable(false);
|
|
|
|
this.background.error = ko.observable('');
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.capaUserBackground = ko.observable(Settings.capa(Enums.Capa.UserBackground));
|
2014-11-08 04:21:10 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.themeTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
|
|
|
|
|
|
|
|
this.iTimer = 0;
|
2014-09-05 23:53:44 +08:00
|
|
|
this.oThemeAjaxRequest = null;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
this.theme.subscribe(function (sValue) {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
_.each(this.themesObjects(), function (oTheme) {
|
|
|
|
oTheme.selected(sValue === oTheme.name);
|
|
|
|
});
|
|
|
|
|
2015-02-05 13:14:13 +08:00
|
|
|
Utils.changeTheme(sValue, this.themeTrigger);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'Theme': sValue
|
|
|
|
});
|
|
|
|
|
|
|
|
}, this);
|
2014-11-08 04:21:10 +08:00
|
|
|
|
|
|
|
this.background.hash.subscribe(function (sValue) {
|
2015-02-05 13:14:13 +08:00
|
|
|
|
|
|
|
var $oBg = $('#rl-bg');
|
|
|
|
if (!sValue)
|
|
|
|
{
|
|
|
|
if ($oBg.data('backstretch'))
|
|
|
|
{
|
|
|
|
$oBg.backstretch('destroy').attr('style', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#rl-bg').attr('style', 'background-image: none !important;').backstretch(
|
|
|
|
Links.userBackground(sValue), {
|
|
|
|
'fade': 1000, 'centeredX': true, 'centeredY': true
|
|
|
|
}).removeAttr('style');
|
|
|
|
}
|
|
|
|
|
2014-11-08 04:21:10 +08:00
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
ThemesUserSettings.prototype.onBuild = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
var sCurrentTheme = this.theme();
|
|
|
|
this.themesObjects(_.map(this.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-11-08 04:21:10 +08:00
|
|
|
|
|
|
|
this.initUploader();
|
|
|
|
};
|
|
|
|
|
|
|
|
ThemesUserSettings.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.background.error('');
|
|
|
|
};
|
|
|
|
|
|
|
|
ThemesUserSettings.prototype.clearBackground = function ()
|
|
|
|
{
|
|
|
|
if (this.capaUserBackground())
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
Remote.clearUserBackground(function () {
|
|
|
|
self.background.name('');
|
|
|
|
self.background.hash('');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ThemesUserSettings.prototype.initUploader = function ()
|
|
|
|
{
|
|
|
|
if (this.background.uploaderButton() && this.capaUserBackground())
|
|
|
|
{
|
|
|
|
var
|
|
|
|
oJua = new Jua({
|
|
|
|
'action': Links.uploadBackground(),
|
|
|
|
'name': 'uploader',
|
|
|
|
'queueSize': 1,
|
|
|
|
'multipleSizeLimit': 1,
|
|
|
|
'disableDragAndDrop': true,
|
|
|
|
'disableMultiple': true,
|
|
|
|
'clickElement': this.background.uploaderButton()
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
oJua
|
|
|
|
.on('onStart', _.bind(function () {
|
|
|
|
|
|
|
|
this.background.loading(true);
|
|
|
|
this.background.error('');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}, this))
|
|
|
|
.on('onComplete', _.bind(function (sId, bResult, oData) {
|
|
|
|
|
|
|
|
this.background.loading(false);
|
|
|
|
|
|
|
|
if (bResult && sId && oData && oData.Result && oData.Result.Name && oData.Result.Hash)
|
|
|
|
{
|
|
|
|
this.background.name(oData.Result.Name);
|
|
|
|
this.background.hash(oData.Result.Hash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.background.name('');
|
|
|
|
this.background.hash('');
|
|
|
|
|
|
|
|
var sError = '';
|
|
|
|
if (oData.ErrorCode)
|
|
|
|
{
|
|
|
|
switch (oData.ErrorCode)
|
|
|
|
{
|
|
|
|
case Enums.UploadErrorCode.FileIsTooBig:
|
2015-01-26 07:09:22 +08:00
|
|
|
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_IS_TOO_BIG');
|
2014-11-08 04:21:10 +08:00
|
|
|
break;
|
|
|
|
case Enums.UploadErrorCode.FileType:
|
2015-01-26 07:09:22 +08:00
|
|
|
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_TYPE_ERROR');
|
2014-11-08 04:21:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sError && oData.ErrorMessage)
|
|
|
|
{
|
|
|
|
sError = oData.ErrorMessage;
|
|
|
|
}
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
this.background.error(sError || Translator.i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
|
2014-11-08 04:21:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}, this))
|
|
|
|
;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
module.exports = ThemesUserSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|