Skip to content

Commit

Permalink
fix usersetting not beeing applied
Browse files Browse the repository at this point in the history
Signed-off-by: Felix N眉sse <[email protected]>
  • Loading branch information
newhinton committed Oct 3, 2022
1 parent 9b4c835 commit 72428ef
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
85 changes: 85 additions & 0 deletions js/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
(function() {
function initialize() {
this._timer = [];
this.saveUrl = document.getElementById('unsplash-settings').dataset.save;

let settings = document.querySelectorAll('[data-setting]');
for(let setting of settings) {
setting.addEventListener(
'change',
(e) => {
let key = e.target.dataset.setting,
value = e.target.value,
type = e.target.getAttribute('type');

if(type === 'checkbox') {
value = e.target.checked ? 'true':'false';
}

if(type === 'select') {
value = e.target.value;
}

if(key === 'style/tint') {
console.log("change"+value)
let enable = false
if(value === "true"){
enable = true
}
document.getElementById('unsplash-style-color-strenght').disabled = !enable;
}

_setValue(key, value, type);
}
);
}
}

/**
* Update configuration value
*
* @param key
* @param value
* @private
*/
function _setValue(key, value, type) {
let headers = new Headers();
headers.append('requesttoken', OC.requestToken);
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');

let body = JSON.stringify({key, value}),
options = {headers, body, method: 'POST', redirect: 'error'},
request = new Request(this.saveUrl, options);

fetch(request)
.then(() => {
_showMessage('success');
if(type === 'select') {
getCustomization(value)
}
})
.catch((e) => {
console.error(e);
_showMessage('error');
});
}

/**
* Show save success/fail message
*
* @param type
* @private
*/
function _showMessage(type) {
let element = document.querySelector(`#unsplash-settings .msg.${type}`);

element.classList.remove('active');
element.classList.add('active');

clearTimeout(this._timer[type]);
this._timer[type] = setTimeout(() => { element.classList.remove('active'); }, 1000);
}

initialize();
})();
2 changes: 1 addition & 1 deletion templates/settings/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* and licensed under the AGPL.
*/

script('unsplash', 'settings');
script('unsplash', 'user');
style('unsplash', 'settings');

?>
Expand Down

0 comments on commit 72428ef

Please sign in to comment.