trilium/public/javascripts/dialogs/settings.js

196 lines
5.2 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 02:31:53 +08:00
const settings = (function() {
const dialogEl = $("#settings-dialog");
const tabsEl = $("#settings-tabs");
2017-11-05 02:31:53 +08:00
const settingModules = [];
function addModule(module) {
settingModules.push(module);
}
2017-11-05 02:31:53 +08:00
async function showDialog() {
2017-11-05 05:03:15 +08:00
glob.activeDialog = dialogEl;
const settings = await server.get('settings');
2017-11-05 02:31:53 +08:00
dialogEl.dialog({
modal: true,
2017-12-16 13:05:37 +08:00
width: 900
2017-11-05 02:31:53 +08:00
});
2017-09-13 10:23:57 +08:00
2017-11-05 02:31:53 +08:00
tabsEl.tabs();
2017-09-13 10:23:57 +08:00
for (const module of settingModules) {
2017-11-21 13:25:53 +08:00
if (module.settingsLoaded) {
module.settingsLoaded(settings);
}
2017-11-05 02:31:53 +08:00
}
}
async function saveSettings(settingName, settingValue) {
await server.post('settings', {
name: settingName,
value: settingValue
2017-11-05 02:31:53 +08:00
});
showMessage("Settings change have been saved.");
2017-11-05 02:31:53 +08:00
}
return {
showDialog,
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) {
2017-09-13 10:23:57 +08:00
}
2017-11-05 02:31:53 +08:00
formEl.submit(() => {
const oldPassword = oldPasswordEl.val();
const newPassword1 = newPassword1El.val();
const newPassword2 = newPassword2El.val();
oldPasswordEl.val('');
newPassword1El.val('');
newPassword2El.val('');
if (newPassword1 !== newPassword2) {
alert("New passwords are not the same.");
return false;
}
server.post('password/change', {
'current_password': oldPassword,
'new_password': newPassword1
}).then(result => {
if (result.success) {
alert("Password has been changed. Trilium will be reloaded after you press OK.");
// password changed so current protected session is invalid and needs to be cleared
protected_session.resetProtectedSession();
}
else {
showError(result.message);
}
2017-11-05 02:31:53 +08:00
});
return false;
2017-09-13 10:23:57 +08:00
});
2017-11-05 02:31:53 +08:00
return {
settingsLoaded
};
})());
settings.addModule((function() {
const formEl = $("#protected-session-timeout-form");
const protectedSessionTimeoutEl = $("#protected-session-timeout-in-seconds");
const settingName = 'protected_session_timeout';
2017-11-05 02:31:53 +08:00
function settingsLoaded(settings) {
protectedSessionTimeoutEl.val(settings[settingName]);
2017-11-05 02:31:53 +08:00
}
2017-11-05 02:31:53 +08:00
formEl.submit(() => {
const protectedSessionTimeout = protectedSessionTimeoutEl.val();
settings.saveSettings(settingName, protectedSessionTimeout).then(() => {
protected_session.setProtectedSessionTimeout(protectedSessionTimeout);
2017-11-05 02:31:53 +08:00
});
return false;
});
2017-11-05 02:31:53 +08:00
return {
settingsLoaded
};
})());
settings.addModule((function () {
const formEl = $("#history-snapshot-time-interval-form");
const timeIntervalEl = $("#history-snapshot-time-interval-in-seconds");
const settingName = 'history_snapshot_time_interval';
function settingsLoaded(settings) {
timeIntervalEl.val(settings[settingName]);
}
formEl.submit(() => {
settings.saveSettings(settingName, timeIntervalEl.val());
return false;
});
2017-11-14 12:35:23 +08:00
return {
settingsLoaded
};
})());
2017-11-21 13:25:53 +08:00
settings.addModule((async function () {
const appVersionEl = $("#app-version");
const dbVersionEl = $("#db-version");
2017-11-14 12:35:23 +08:00
const buildDateEl = $("#build-date");
const buildRevisionEl = $("#build-revision");
const appInfo = await server.get('app-info');
2017-11-14 12:35:23 +08:00
2017-11-21 13:25:53 +08:00
appVersionEl.html(appInfo.app_version);
dbVersionEl.html(appInfo.db_version);
buildDateEl.html(appInfo.build_date);
buildRevisionEl.html(appInfo.build_revision);
buildRevisionEl.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.build_revision);
return {};
})());
settings.addModule((async function () {
const forceFullSyncButton = $("#force-full-sync-button");
const fillSyncRowsButton = $("#fill-sync-rows-button");
const anonymizeButton = $("#anonymize-button");
const cleanupSoftDeletedButton = $("#cleanup-soft-deleted-items-button");
const vacuumDatabaseButton = $("#vacuum-database-button");
forceFullSyncButton.click(async () => {
await server.post('sync/force-full-sync');
showMessage("Full sync triggered");
});
fillSyncRowsButton.click(async () => {
await server.post('sync/fill-sync-rows');
showMessage("Sync rows filled successfully");
});
2017-12-16 13:05:37 +08:00
anonymizeButton.click(async () => {
await server.post('anonymization/anonymize');
showMessage("Created anonymized database");
});
cleanupSoftDeletedButton.click(async () => {
if (confirm("Do you really want to clean up soft-deleted items?")) {
await server.post('cleanup/cleanup-soft-deleted-items');
showMessage("Soft deleted items have been cleaned up");
}
});
vacuumDatabaseButton.click(async () => {
await server.post('cleanup/vacuum-database');
showMessage("Database has been vacuumed");
});
2017-11-21 13:25:53 +08:00
return {};
2017-11-05 02:31:53 +08:00
})());