mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
converted settings to module(s)
This commit is contained in:
parent
fd48a97c6d
commit
819c01bb04
@ -1,30 +1,72 @@
|
|||||||
function displaySettings() {
|
const settings = (function() {
|
||||||
$.ajax({
|
const dialogEl = $("#settings-dialog");
|
||||||
|
const tabsEl = $("#settings-tabs");
|
||||||
|
|
||||||
|
const settingModules = [];
|
||||||
|
|
||||||
|
function addModule(module) {
|
||||||
|
settingModules.push(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showDialog() {
|
||||||
|
const settings = await $.ajax({
|
||||||
url: baseApiUrl + 'settings',
|
url: baseApiUrl + 'settings',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
success: result => {
|
error: () => error("Error getting settings.")
|
||||||
$("#encryption-timeout-in-seconds").val(result['encryption_session_timeout']);
|
|
||||||
$("#history-snapshot-time-interval-in-seconds").val(result['history_snapshot_time_interval']);
|
|
||||||
},
|
|
||||||
error: () => alert("Error getting settings.")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#settings-dialog").dialog({
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
width: 600
|
width: 600
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#settings-tabs").tabs();
|
tabsEl.tabs();
|
||||||
|
|
||||||
|
for (module of settingModules) {
|
||||||
|
module.settingsLoaded(settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#change-password-form").submit(() => {
|
function saveSettings(settingName, settingValue) {
|
||||||
const oldPassword = $("#old-password").val();
|
return $.ajax({
|
||||||
const newPassword1 = $("#new-password1").val();
|
url: baseApiUrl + 'settings',
|
||||||
const newPassword2 = $("#new-password2").val();
|
type: 'POST',
|
||||||
|
data: JSON.stringify({
|
||||||
|
name: settingName,
|
||||||
|
value: settingValue
|
||||||
|
}),
|
||||||
|
contentType: "application/json",
|
||||||
|
success: () => {
|
||||||
|
message("Settings change have been saved.");
|
||||||
|
},
|
||||||
|
error: () => alert("Error occurred during saving settings change.")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$("#old-password").val('');
|
return {
|
||||||
$("#new-password1").val('');
|
showDialog,
|
||||||
$("#new-password2").val('');
|
saveSettings,
|
||||||
|
addModule
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
settings.addModule((function() {
|
||||||
|
const formEl = $("#change-password-form");
|
||||||
|
const oldPasswordEl = $("#old-password");
|
||||||
|
const newPassword1El = $("#new-password1");
|
||||||
|
const newPassword2El = $("#new-password2");
|
||||||
|
|
||||||
|
function settingsLoaded(settings) {
|
||||||
|
}
|
||||||
|
|
||||||
|
formEl.submit(() => {
|
||||||
|
const oldPassword = oldPasswordEl.val();
|
||||||
|
const newPassword1 = newPassword1El.val();
|
||||||
|
const newPassword2 = newPassword2El.val();
|
||||||
|
|
||||||
|
oldPasswordEl.val('');
|
||||||
|
newPassword1El.val('');
|
||||||
|
newPassword2El.val('');
|
||||||
|
|
||||||
if (newPassword1 !== newPassword2) {
|
if (newPassword1 !== newPassword2) {
|
||||||
alert("New passwords are not the same.");
|
alert("New passwords are not the same.");
|
||||||
@ -60,44 +102,51 @@ $("#change-password-form").submit(() => {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#encryption-timeout-form").submit(() => {
|
return {
|
||||||
const encryptionTimeout = $("#encryption-timeout-in-seconds").val();
|
settingsLoaded
|
||||||
|
};
|
||||||
|
})());
|
||||||
|
|
||||||
$.ajax({
|
settings.addModule((function() {
|
||||||
url: baseApiUrl + 'settings',
|
const formEl = $("#encryption-timeout-form");
|
||||||
type: 'POST',
|
const encryptionTimeoutEl = $("#encryption-timeout-in-seconds");
|
||||||
data: JSON.stringify({
|
const settingName = 'encryption_session_timeout';
|
||||||
name: 'encryption_session_timeout',
|
|
||||||
value: encryptionTimeout
|
|
||||||
}),
|
|
||||||
contentType: "application/json",
|
|
||||||
success: () => {
|
|
||||||
alert("Encryption timeout has been changed.");
|
|
||||||
|
|
||||||
|
function settingsLoaded(settings) {
|
||||||
|
encryptionTimeoutEl.val(settings[settingName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
formEl.submit(() => {
|
||||||
|
const encryptionTimeout = encryptionTimeoutEl.val();
|
||||||
|
|
||||||
|
settings.saveSettings(settingName, encryptionTimeout).then(() => {
|
||||||
glob.encryptionSessionTimeout = encryptionTimeout;
|
glob.encryptionSessionTimeout = encryptionTimeout;
|
||||||
},
|
|
||||||
error: () => alert("Error occurred during changing encryption timeout.")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#history-snapshot-time-interval-form").submit(() => {
|
return {
|
||||||
const historySnapshotTimeInterval = $("#history-snapshot-time-interval-in-seconds").val();
|
settingsLoaded
|
||||||
|
};
|
||||||
|
})());
|
||||||
|
|
||||||
$.ajax({
|
settings.addModule((function () {
|
||||||
url: baseApiUrl + 'settings',
|
const formEl = $("#history-snapshot-time-interval-form");
|
||||||
type: 'POST',
|
const timeIntervalEl = $("#history-snapshot-time-interval-in-seconds");
|
||||||
data: JSON.stringify({
|
const settingName = 'history_snapshot_time_interval';
|
||||||
name: 'history_snapshot_time_interval',
|
|
||||||
value: historySnapshotTimeInterval
|
function settingsLoaded(settings) {
|
||||||
}),
|
timeIntervalEl.val(settings[settingName]);
|
||||||
contentType: "application/json",
|
}
|
||||||
success: () => {
|
|
||||||
alert("History snapshot time interval has been changed.");
|
formEl.submit(() => {
|
||||||
},
|
settings.saveSettings(settingName, timeIntervalEl.val());
|
||||||
error: () => alert("Error occurred during changing history snapshot time interval.")
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
settingsLoaded
|
||||||
|
};
|
||||||
|
})());
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<button class="btn btn-xs" onclick="syncNow();">Sync now (<span id="changesToPushCount">0</span>)</button>
|
<button class="btn btn-xs" onclick="syncNow();">Sync now (<span id="changesToPushCount">0</span>)</button>
|
||||||
|
|
||||||
<button class="btn btn-xs" onclick="displaySettings();">Settings</button>
|
<button class="btn btn-xs" onclick="settings.showDialog();">Settings</button>
|
||||||
|
|
||||||
<form action="logout" method="POST" style="display: inline;">
|
<form action="logout" method="POST" style="display: inline;">
|
||||||
<input type="submit" class="btn btn-xs" value="Logout">
|
<input type="submit" class="btn btn-xs" value="Logout">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user