summaryrefslogtreecommitdiffstats
path: root/settings/js/admin.js
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-12-19 23:13:35 +0100
committerMichael Weimann <mail@michael-weimann.eu>2019-01-14 00:08:24 +0100
commit813ff430f159fdc8aade236048f4a8ff18ac3b2e (patch)
treebb8fe0773a03ed43dba3c9cdecbb3343251fdb1a /settings/js/admin.js
parent6993faaf67b6e822f7b03bd972fe42c9b4dd1d5d (diff)
downloadnextcloud-server-813ff430f159fdc8aade236048f4a8ff18ac3b2e.tar.gz
nextcloud-server-813ff430f159fdc8aade236048f4a8ff18ac3b2e.zip
Implement storing and loading the server info
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'settings/js/admin.js')
-rw-r--r--settings/js/admin.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/settings/js/admin.js b/settings/js/admin.js
index b93c55a8a9c..1c9b5460eab 100644
--- a/settings/js/admin.js
+++ b/settings/js/admin.js
@@ -313,4 +313,107 @@ $(document).ready(function(){
if (document.getElementById('security-warning') !== null) {
setupChecks();
}
+
+ // server info
+
+ var serverInfoForm = $('#server-info-form');
+ var serverInfoWorkingTimeoutHandle;
+ var serverInfoSubmitButton = $('#server-info-submit-button');
+
+ /**
+ * Sets the server info submit button state to default.
+ */
+ function setServerInfoButtonDefault() {
+ serverInfoSubmitButton.removeClass('button-success');
+ serverInfoSubmitButton.removeClass('button-error');
+ serverInfoSubmitButton.removeClass('button-working');
+ }
+
+ /**
+ * Sets the server info submit button state to working.
+ */
+ function setServerInfoButtonWorking() {
+ serverInfoSubmitButton.removeClass('button-success');
+ serverInfoSubmitButton.removeClass('button-error');
+ serverInfoSubmitButton.addClass('button-working');
+ }
+
+ /**
+ * Sets the server info submit button state to success.
+ */
+ function setServerInfoButtonSuccess() {
+ serverInfoSubmitButton.removeClass('button-error');
+ serverInfoSubmitButton.removeClass('button-working');
+ serverInfoSubmitButton.addClass('button-success');
+ }
+
+ /**
+ * Sets the server info submit button state to error.
+ */
+ function setServerInfoButtonError() {
+ serverInfoSubmitButton.removeClass('button-success');
+ serverInfoSubmitButton.removeClass('button-working');
+ serverInfoSubmitButton.addClass('button-error');
+ }
+
+ /**
+ * Clears the server info working timeout, if present.
+ */
+ function clearServerInfoWorkingTimeout() {
+ if (serverInfoWorkingTimeoutHandle) {
+ clearTimeout(serverInfoWorkingTimeoutHandle);
+ serverInfoWorkingTimeoutHandle = undefined;
+ }
+ }
+
+ /**
+ * Unlocks the server info form, e.g. removing readonly from inputs.
+ */
+ function unlockForm() {
+ serverInfoForm.find('input, select').prop('readonly', false);
+ serverInfoSubmitButton.prop('disabled', false);
+ }
+
+ /**
+ * Resets the submit button state one of the form elements is changed.
+ */
+ serverInfoForm.find('input, select').on('keyup change', function() {
+ setServerInfoButtonDefault();
+ });
+
+ /**
+ * Handles the server info form submit.
+ */
+ serverInfoForm.on('submit', function(event) {
+ event.stopImmediatePropagation();
+ event.preventDefault();
+
+ serverInfoForm.find('input, select').prop('readonly', true);
+ serverInfoSubmitButton.prop('disabled', true);
+
+ clearServerInfoWorkingTimeout();
+
+ // start show spinner only if request takes longer than one second
+ serverInfoWorkingTimeoutHandle = setTimeout(function() {
+ setServerInfoButtonWorking();
+ }, 1000);
+
+ $.ajax({
+ url: OC.generateUrl('/settings/serverinfo'),
+ type: 'POST',
+ data: serverInfoForm.serialize(),
+ success: function() {
+ clearServerInfoWorkingTimeout();
+ setServerInfoButtonSuccess();
+ unlockForm();
+ serverInfoSubmitButton.blur();
+ },
+ error: function() {
+ clearServerInfoWorkingTimeout();
+ setServerInfoButtonError();
+ unlockForm();
+ serverInfoSubmitButton.blur();
+ }
+ });
+ });
});