aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunternif2019-04-13 18:18:22 +0700
committerHunternif2019-04-13 18:45:11 +0700
commit9a8f4e31046f197326cacbdd141b6abf07b2a078 (patch)
tree7d3224df5fe459c219d5d3ecaa74981dffe0155b
parente88676b69b7c74558e7b1b586ffd1cda101b9077 (diff)
Settings stored locally per user and include default upload safety
-rw-r--r--client/css/settings.styl10
-rw-r--r--client/html/settings.tpl24
-rw-r--r--client/js/controllers/post_upload_controller.js2
-rw-r--r--client/js/models/settings.js14
-rw-r--r--client/js/views/post_upload_view.js1
-rw-r--r--client/js/views/settings_view.js9
6 files changed, 56 insertions, 4 deletions
diff --git a/client/css/settings.styl b/client/css/settings.styl
new file mode 100644
index 0000000..95e037b
--- /dev/null
+++ b/client/css/settings.styl
@@ -0,0 +1,10 @@
+#settings
+ .uploadSafety
+ &>label
+ width: 100%
+ .radio-wrapper
+ display: flex
+ flex-wrap: wrap
+ .radio-wrapper label
+ flex-grow: 1
+ display: inline-block \ No newline at end of file
diff --git a/client/html/settings.tpl b/client/html/settings.tpl
index 6d65d01..f85b012 100644
--- a/client/html/settings.tpl
+++ b/client/html/settings.tpl
@@ -11,6 +11,30 @@
}) %>
</li>
+ <li class='uploadSafety'>
+ <label>Safety</label>
+ <div class='radio-wrapper'>
+ <%= ctx.makeRadio({
+ name: 'safety',
+ class: 'safety-safe',
+ value: 'safe',
+ selectedValue: ctx.browsingSettings.uploadSafety,
+ text: 'Safe'}) %>
+ <%= ctx.makeRadio({
+ name: 'safety',
+ class: 'safety-sketchy',
+ value: 'sketchy',
+ selectedValue: ctx.browsingSettings.uploadSafety,
+ text: 'Sketchy'}) %>
+ <%= ctx.makeRadio({
+ name: 'safety',
+ value: 'unsafe',
+ selectedValue: ctx.browsingSettings.uploadSafety,
+ class: 'safety-unsafe',
+ text: 'Unsafe'}) %>
+ </div>
+ </li>
+
<li>
<%= ctx.makeNumericInput({
text: 'Number of posts per page',
diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js
index 7bdce9c..4982530 100644
--- a/client/js/controllers/post_upload_controller.js
+++ b/client/js/controllers/post_upload_controller.js
@@ -6,6 +6,7 @@ const uri = require('../util/uri.js');
const misc = require('../util/misc.js');
const progress = require('../util/progress.js');
const topNavigation = require('../models/top_navigation.js');
+const settings = require('../models/settings.js');
const Post = require('../models/post.js');
const Tag = require('../models/tag.js');
const PostUploadView = require('../views/post_upload_view.js');
@@ -31,6 +32,7 @@ class PostUploadController {
canUploadAnonymously: api.hasPrivilege('posts:create:anonymous'),
canViewPosts: api.hasPrivilege('posts:view'),
enableSafety: api.safetyEnabled(),
+ defaultSafety: settings.get().uploadSafety
});
this._view.addEventListener('change', e => this._evtChange(e));
this._view.addEventListener('submit', e => this._evtSubmit(e));
diff --git a/client/js/models/settings.js b/client/js/models/settings.js
index beaeb4d..bef7804 100644
--- a/client/js/models/settings.js
+++ b/client/js/models/settings.js
@@ -1,6 +1,7 @@
'use strict';
const events = require('../events.js');
+const api = require('../api.js');
const defaultSettings = {
listPosts: {
@@ -8,20 +9,21 @@ const defaultSettings = {
sketchy: true,
unsafe: false,
},
+ uploadSafety: 'safe',
upscaleSmallPosts: false,
endlessScroll: false,
keyboardShortcuts: true,
- transparencyGrid: true,
+ transparencyGrid: false,
fitMode: 'fit-both',
tagSuggestions: true,
autoplayVideos: false,
- postsPerPage: 42,
+ postsPerPage: 40,
};
class Settings extends events.EventTarget {
save(newSettings, silent) {
newSettings = Object.assign(this.get(), newSettings);
- localStorage.setItem('settings', JSON.stringify(newSettings));
+ localStorage.setItem(this._settingsKey, JSON.stringify(newSettings));
if (silent !== true) {
this.dispatchEvent(new CustomEvent('change', {
detail: {
@@ -34,11 +36,15 @@ class Settings extends events.EventTarget {
get() {
let ret = Object.assign({}, defaultSettings);
try {
- Object.assign(ret, JSON.parse(localStorage.getItem('settings')));
+ Object.assign(ret, JSON.parse(localStorage.getItem(this._settingsKey)));
} catch (e) {
}
return ret;
}
+
+ get _settingsKey() {
+ return 'settings-' + api.userName
+ }
};
module.exports = new Settings();
diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js
index 1b9c3c9..a19d6ec 100644
--- a/client/js/views/post_upload_view.js
+++ b/client/js/views/post_upload_view.js
@@ -226,6 +226,7 @@ class PostUploadView extends events.EventTarget {
this._formNode.classList.remove('inactive');
let duplicatesFound = 0;
for (let uploadable of uploadables) {
+ uploadable.safety = this._ctx.defaultSafety || uploadable.safety;
if (this._uploadables.find(uploadable) !== -1) {
duplicatesFound++;
continue;
diff --git a/client/js/views/settings_view.js b/client/js/views/settings_view.js
index 41c661e..eb5fa6d 100644
--- a/client/js/views/settings_view.js
+++ b/client/js/views/settings_view.js
@@ -37,6 +37,11 @@ class SettingsView extends events.EventTarget {
tagSuggestions: this._find('tag-suggestions').checked,
autoplayVideos: this._find('autoplay-videos').checked,
postsPerPage: this._find('posts-per-page').value,
+ uploadSafety: this._safetyButtonNodes.length ?
+ Array.from(this._safetyButtonNodes)
+ .filter(node => node.checked)[0]
+ .value.toLowerCase() :
+ undefined,
},
}));
}
@@ -45,6 +50,10 @@ class SettingsView extends events.EventTarget {
return this._hostNode.querySelector('form');
}
+ get _safetyButtonNodes() {
+ return this._formNode.querySelectorAll('.uploadSafety input');
+ }
+
_find(nodeName) {
return this._formNode.querySelector('[name=' + nodeName + ']');
}

© 2015 - 2026 Jakob L. Kreuze