diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-01-09 15:06:41 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2017-01-09 15:06:41 +0300 |
commit | 3239c861e880a246084ce1da9ad4efefd43e4b37 (patch) | |
tree | 184b976bba3d2f5af67da2402b3dd8fe437b42cd /js/admin.js | |
parent | e97077409d256abcad29e293c0e30a6772ea1cab (diff) |
Make the JS work with sudo mode
Previously the JS reloaded the page or gave the user no indication that a password confirmation was required. Thus not saving the changes.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'js/admin.js')
-rw-r--r-- | js/admin.js | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/js/admin.js b/js/admin.js index a3814c95..0e2b9322 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,8 +1,42 @@ -function setSAMLConfigValue(category, setting, value) { - OC.msg.startSaving('#user-saml-save-indicator'); - OC.AppConfig.setValue('user_saml', category+'-'+setting, value); - OC.msg.finishedSaving('#user-saml-save-indicator', {status: 'success', data: {message: t('user_saml', 'Saved')}}); -} +(function(OCA) { + OCA.User_SAML = OCA.User_SAML || {}; + + /** + * @namespace OCA.User_SAML.Admin + */ + OCA.User_SAML.Admin = { + chooseEnv: function() { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.chooseEnv, this)); + return; + } + + OC.AppConfig.setValue('user_saml', 'type', 'environment-variable'); + location.reload(); + }, + + chooseSaml: function() { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.chooseSaml, this)); + return; + } + + OC.AppConfig.setValue('user_saml', 'type', 'saml'); + location.reload(); + }, + + setSamlConfigValue: function(category, setting, value) { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.setSamlConfigValue, this, category, setting, value)); + return; + } + + OC.msg.startSaving('#user-saml-save-indicator'); + OC.AppConfig.setValue('user_saml', category+'-'+setting, value); + OC.msg.finishedSaving('#user-saml-save-indicator', {status: 'success', data: {message: t('user_saml', 'Saved')}}); + } + } +})(OCA); $(function() { // Hide depending on the setup state @@ -21,13 +55,11 @@ $(function() { $('#user-saml-choose-saml').click(function(e) { e.preventDefault(); - OC.AppConfig.setValue('user_saml', 'type', 'saml'); - location.reload(); + OCA.User_SAML.Admin.chooseSaml(); }); $('#user-saml-choose-env').click(function(e) { e.preventDefault(); - OC.AppConfig.setValue('user_saml', 'type', 'environment-variable'); - location.reload(); + OCA.User_SAML.Admin.chooseEnv(); }); // Enable tabs @@ -37,11 +69,11 @@ $(function() { var el = $(this); $.when(el.focusout()).then(function() { var key = $(this).attr('name'); - setSAMLConfigValue('sp', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('sp', key, $(this).val()); }); if (e.keyCode === 13) { var key = $(this).attr('name'); - setSAMLConfigValue('sp', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('sp', key, $(this).val()); } }); @@ -49,11 +81,11 @@ $(function() { var el = $(this); $.when(el.focusout()).then(function() { var key = $(this).attr('name'); - setSAMLConfigValue('idp', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('idp', key, $(this).val()); }); if (e.keyCode === 13) { var key = $(this).attr('name'); - setSAMLConfigValue('idp', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('idp', key, $(this).val()); } }); @@ -61,11 +93,11 @@ $(function() { var el = $(this); $.when(el.focusout()).then(function() { var key = $(this).attr('name'); - setSAMLConfigValue('general', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('general', key, $(this).val()); }); if (e.keyCode === 13) { var key = $(this).attr('name'); - setSAMLConfigValue('general', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('general', key, $(this).val()); } }); @@ -78,7 +110,7 @@ $(function() { } else { $(this).val("0"); } - setSAMLConfigValue('general', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('general', key, $(this).val()); }); }); @@ -91,7 +123,7 @@ $(function() { } else { $(this).val("0"); } - setSAMLConfigValue('security', key, $(this).val()); + OCA.User_SAML.Admin.setSamlConfigValue('security', key, $(this).val()); }); }); |