2017-09-11 11:10:32 +08:00
|
|
|
function displaySettings() {
|
2017-09-13 11:04:17 +08:00
|
|
|
$.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'settings',
|
2017-09-13 11:04:17 +08:00
|
|
|
type: 'GET',
|
2017-10-10 06:53:11 +08:00
|
|
|
success: result => {
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#encryption-timeout-in-seconds").val(result['encryption_session_timeout']);
|
|
|
|
$("#history-snapshot-time-interval-in-seconds").val(result['history_snapshot_time_interval']);
|
2017-09-13 11:04:17 +08:00
|
|
|
},
|
|
|
|
error: () => alert("Error getting settings.")
|
|
|
|
});
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#settings-dialog").dialog({
|
2017-09-11 11:10:32 +08:00
|
|
|
modal: true,
|
|
|
|
width: 600
|
|
|
|
});
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#settings-tabs").tabs();
|
2017-09-11 11:10:32 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#change-password-form").submit(() => {
|
|
|
|
const oldPassword = $("#old-password").val();
|
|
|
|
const newPassword1 = $("#new-password1").val();
|
|
|
|
const newPassword2 = $("#new-password2").val();
|
2017-09-13 10:23:57 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#old-password").val('');
|
|
|
|
$("#new-password1").val('');
|
|
|
|
$("#new-password2").val('');
|
2017-09-13 10:23:57 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
if (newPassword1 !== newPassword2) {
|
2017-09-13 10:23:57 +08:00
|
|
|
alert("New passwords are not the same.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'password/change',
|
2017-09-13 10:23:57 +08:00
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({
|
|
|
|
'current_password': oldPassword,
|
|
|
|
'new_password': newPassword1
|
|
|
|
}),
|
|
|
|
contentType: "application/json",
|
2017-10-10 06:53:11 +08:00
|
|
|
success: result => {
|
2017-09-13 10:23:57 +08:00
|
|
|
if (result.success) {
|
2017-09-13 11:07:08 +08:00
|
|
|
// encryption password changed so current encryption session is invalid and needs to be cleared
|
|
|
|
resetEncryptionSession();
|
|
|
|
|
2017-09-17 12:18:03 +08:00
|
|
|
globalEncryptedDataKey = result.new_encrypted_data_key;
|
|
|
|
|
2017-09-13 10:23:57 +08:00
|
|
|
alert("Password has been changed.");
|
2017-09-17 12:18:03 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#settings-dialog").dialog('close');
|
2017-09-13 10:23:57 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
alert(result.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: () => alert("Error occurred during changing password.")
|
|
|
|
});
|
2017-09-11 11:10:32 +08:00
|
|
|
|
2017-09-13 11:04:17 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#encryption-timeout-form").submit(() => {
|
|
|
|
const encryptionTimeout = $("#encryption-timeout-in-seconds").val();
|
2017-09-13 11:04:17 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'settings',
|
2017-09-13 11:04:17 +08:00
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({
|
|
|
|
name: 'encryption_session_timeout',
|
|
|
|
value: encryptionTimeout
|
|
|
|
}),
|
|
|
|
contentType: "application/json",
|
2017-10-10 06:53:11 +08:00
|
|
|
success: () => {
|
2017-09-13 11:04:17 +08:00
|
|
|
alert("Encryption timeout has been changed.");
|
2017-09-23 22:59:36 +08:00
|
|
|
|
|
|
|
globalEncryptionSessionTimeout = encryptionTimeout;
|
2017-09-13 11:04:17 +08:00
|
|
|
},
|
|
|
|
error: () => alert("Error occurred during changing encryption timeout.")
|
|
|
|
});
|
|
|
|
|
2017-09-25 08:50:14 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#history-snapshot-time-interval-form").submit(() => {
|
|
|
|
const historySnapshotTimeInterval = $("#history-snapshot-time-interval-in-seconds").val();
|
2017-09-25 08:50:14 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'settings',
|
2017-09-25 08:50:14 +08:00
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({
|
|
|
|
name: 'history_snapshot_time_interval',
|
|
|
|
value: historySnapshotTimeInterval
|
|
|
|
}),
|
|
|
|
contentType: "application/json",
|
2017-10-10 06:53:11 +08:00
|
|
|
success: () => {
|
2017-09-25 08:50:14 +08:00
|
|
|
alert("History snapshot time interval has been changed.");
|
|
|
|
},
|
|
|
|
error: () => alert("Error occurred during changing history snapshot time interval.")
|
|
|
|
});
|
|
|
|
|
2017-09-11 11:10:32 +08:00
|
|
|
return false;
|
|
|
|
});
|