From a8ac4bdf79b65239c6aeef4e6d0d642bedefc9c3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 30 Jan 2013 02:30:24 +0100 Subject: [PATCH] LDAP: Always preset configuration prefix when no configuratin is stored or all remaining ones are deleted --- apps/user_ldap/js/settings.js | 60 +++++++++++++++++++++-------------- apps/user_ldap/settings.php | 3 ++ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 7d0a85248f3..d1b1b715a57 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -1,5 +1,9 @@ var LdapConfiguration = { refreshConfig: function() { + if($('#ldap_serverconfig_chooser option').length < 2) { + LdapConfiguration.addConfiguration(true); + return; + } $.post( OC.filePath('user_ldap','ajax','getConfiguration.php'), $('#ldap_serverconfig_chooser').serialize(), @@ -64,6 +68,37 @@ var LdapConfiguration = { } } ); + }, + + addConfiguration: function(doNotAsk) { + $.post( + OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'), + function (result) { + if(result.status == 'success') { + if(doNotAsk) { + LdapConfiguration.resetDefaults(); + } else { + OC.dialogs.confirm( + t('user_ldap', 'Take over settings from recent server configuration?'), + t('user_ldap', 'Keep settings?'), + function(keep) { + if(!keep) { + LdapConfiguration.resetDefaults(); + } + } + ); + } + $('#ldap_serverconfig_chooser option:selected').removeAttr('selected'); + var html = ''; + $('#ldap_serverconfig_chooser option:last').before(html); + } else { + OC.dialogs.alert( + result.message, + t('user_ldap', 'Cannot add server configuration') + ); + } + } + ); } } @@ -123,30 +158,7 @@ $(document).ready(function() { $('#ldap_serverconfig_chooser').change(function(event) { value = $('#ldap_serverconfig_chooser option:selected:first').attr('value'); if(value == 'NEW') { - $.post( - OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'), - function (result) { - if(result.status == 'success') { - OC.dialogs.confirm( - t('user_ldap', 'Take over settings from recent server configuration?'), - t('user_ldap', 'Keep settings?'), - function(keep) { - if(!keep) { - LdapConfiguration.resetDefaults(); - } - } - ); - $('#ldap_serverconfig_chooser option:selected').removeAttr('selected'); - var html = ''; - $('#ldap_serverconfig_chooser option:last').before(html); - } else { - OC.dialogs.alert( - result.message, - t('user_ldap', 'Cannot add server configuration') - ); - } - } - ); + LdapConfiguration.addConfiguration(false); } else { LdapConfiguration.refreshConfig(); } diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 5b679683f27..d5d2f648b38 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -49,6 +49,9 @@ foreach($prefixes as $prefix) { $scoHtml .= ''; $sel = ''; } +if(count($prefixes) == 0) { + $scoHtml .= ''; +} $tmpl->assign('serverConfigurationOptions', $scoHtml, false); // assign default values -- 2.39.5