szurubooru/public_html/js/Presenters/UserBrowsingSettingsPresenter.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.UserBrowsingSettingsPresenter = function(
2015-06-28 10:07:11 +02:00
jQuery,
util,
promise,
auth,
browsingSettings,
messagePresenter) {
2015-06-28 10:07:11 +02:00
var target;
var templates = {};
var user;
var privileges = {};
2015-06-28 10:07:11 +02:00
function init(params, loaded) {
user = params.user;
target = params.target;
2015-06-28 10:07:11 +02:00
privileges.canChangeBrowsingSettings = auth.isLoggedIn(user.name) && user.name === auth.getCurrentUser().name;
2015-06-28 10:07:11 +02:00
promise.wait(util.promiseTemplate('browsing-settings'))
.then(function(template) {
templates.browsingSettings = template;
render();
loaded();
}).fail(function() {
console.log(arguments);
loaded();
});
}
2015-06-28 10:07:11 +02:00
function render() {
var $el = jQuery(target);
$el.html(templates.browsingSettings({user: user, settings: browsingSettings.getSettings()}));
$el.find('form').submit(browsingSettingsFormSubmitted);
}
2014-09-07 14:50:16 +02:00
2015-06-28 10:07:11 +02:00
function browsingSettingsFormSubmitted(e) {
e.preventDefault();
var $el = jQuery(target);
var $messages = $el.find('.messages');
messagePresenter.hideMessages($messages);
2014-09-17 22:37:49 +02:00
2015-06-28 10:07:11 +02:00
var newSettings = {
endlessScroll: $el.find('[name=endlessScroll]').is(':checked'),
hideDownvoted: $el.find('[name=hideDownvoted]').is(':checked'),
listPosts: {
safe: $el.find('[name=listSafePosts]').is(':checked'),
sketchy: $el.find('[name=listSketchyPosts]').is(':checked'),
unsafe: $el.find('[name=listUnsafePosts]').is(':checked'),
},
keyboardShortcuts: $el.find('[name=keyboardShortcuts]').is(':checked'),
2015-07-19 11:53:34 +02:00
fitMode: $el.find('[name=fitMode]:checked').val(),
2015-07-19 18:30:20 +02:00
upscale: $el.find('[name=upscale]').is(':checked'),
2015-06-28 10:07:11 +02:00
};
2014-09-17 22:37:49 +02:00
2015-06-28 10:07:11 +02:00
promise.wait(browsingSettings.setSettings(newSettings))
.then(function() {
messagePresenter.showInfo($messages, 'Browsing settings updated!');
}).fail(function() {
console.log(arguments);
});
}
2015-06-28 10:07:11 +02:00
function getPrivileges() {
return privileges;
}
2015-06-28 10:07:11 +02:00
return {
init: init,
render: render,
getPrivileges: getPrivileges,
};
2014-09-08 22:02:28 +02:00
};
2014-10-05 10:41:12 +02:00
App.DI.register('userBrowsingSettingsPresenter', ['jQuery', 'util', 'promise', 'auth', 'browsingSettings', 'messagePresenter'], App.Presenters.UserBrowsingSettingsPresenter);