diff --git a/apps/user_ldap/css/settings.css b/apps/user_ldap/css/settings.css index 129064ff8b..54d0e2dbb0 100644 --- a/apps/user_ldap/css/settings.css +++ b/apps/user_ldap/css/settings.css @@ -209,11 +209,6 @@ select[multiple=multiple] + button { color: #777; } -.outoftheway { - position: absolute; - left: -2000px; -} - #ldapSettings { background-color: white; padding: 0; diff --git a/apps/user_ldap/js/wizard/wizardTabElementary.js b/apps/user_ldap/js/wizard/wizardTabElementary.js index c8cb308952..7ce1009565 100644 --- a/apps/user_ldap/js/wizard/wizardTabElementary.js +++ b/apps/user_ldap/js/wizard/wizardTabElementary.js @@ -43,11 +43,15 @@ OCA = OCA || {}; }, ldap_dn: { $element: $('#ldap_dn'), - setMethod: 'setAgentDN' + setMethod: 'setAgentDN', + preventAutoSave: true, + $saveButton: $('.ldapSaveAgentCredentials') }, ldap_agent_password: { $element: $('#ldap_agent_password'), - setMethod: 'setAgentPwd' + setMethod: 'setAgentPwd', + preventAutoSave: true, + $saveButton: $('.ldapSaveAgentCredentials') }, ldap_base: { $element: $('#ldap_base'), @@ -65,7 +69,11 @@ OCA = OCA || {}; } }; this.setManagedItems(items); - _.bindAll(this, 'onPortButtonClick', 'onBaseDNButtonClick', 'onBaseDNTestButtonClick'); + _.bindAll(this, + 'onPortButtonClick', + 'onBaseDNButtonClick', + 'onBaseDNTestButtonClick' + ); this.managedItems.ldap_port.$relatedElements.click(this.onPortButtonClick); this.managedItems.ldap_base.$detectButton.click(this.onBaseDNButtonClick); this.managedItems.ldap_base.$testButton.click(this.onBaseDNTestButtonClick); diff --git a/apps/user_ldap/js/wizard/wizardTabGeneric.js b/apps/user_ldap/js/wizard/wizardTabGeneric.js index 98e26d303b..57ac375e32 100644 --- a/apps/user_ldap/js/wizard/wizardTabGeneric.js +++ b/apps/user_ldap/js/wizard/wizardTabGeneric.js @@ -53,6 +53,7 @@ OCA = OCA || {}; setManagedItems: function(managedItems) { this.managedItems = managedItems; this._enableAutoSave(); + this._enableSaveButton(); }, /** @@ -319,7 +320,10 @@ OCA = OCA || {}; for(var id in this.managedItems) { if(_.isUndefined(this.managedItems[id].$element) - || _.isUndefined(this.managedItems[id].setMethod)) { + || _.isUndefined(this.managedItems[id].setMethod) + || (!_.isUndefined(this.managedItems[id].preventAutoSave) + && this.managedItems[id].preventAutoSave === true) + ) { continue; } var $element = this.managedItems[id].$element; @@ -331,6 +335,35 @@ OCA = OCA || {}; } }, + /** + * set's up save-button behavior (essentially used for agent dn and pwd) + * + * @private + */ + _enableSaveButton: function() { + var view = this; + + // TODO: this is not nice, because it fires one request per change + // in the scenario this happens twice, causes detectors to run + // duplicated etc. To have this work properly, the wizard endpoint + // must accept setting multiple changes. Instead of messing around + // with old ajax/wizard.php use this opportunity and create a + // Controller + for(var id in this.managedItems) { + if(_.isUndefined(this.managedItems[id].$element) + || _.isUndefined(this.managedItems[id].$saveButton) + ) { + continue; + } + (function (item) { + item.$saveButton.click(function(event) { + event.preventDefault(); + view._requestSave(item.$element); + }); + })(this.managedItems[id]); + } + }, + /** * initializes a multiSelect element * diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index bf8a9095a6..d971f2ffef 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -37,9 +37,13 @@ namespace OCA\User_LDAP; * @property int ldapPagingSize holds an integer */ class Configuration { - protected $configPrefix = null; protected $configRead = false; + /** + * @var string[] pre-filled with one reference key so that at least one entry is written on save request and + * the config ID is registered + */ + protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; //settings protected $config = array( @@ -187,7 +191,9 @@ class Configuration { $this->$setMethod($key, $val); if(is_array($applied)) { $applied[] = $inputKey; + // storing key as index avoids duplication, and as value for simplicity } + $this->unsavedChanges[$key] = $key; } return null; } @@ -240,11 +246,12 @@ class Configuration { } /** - * saves the current Configuration in the database + * saves the current config changes in the database */ public function saveConfiguration() { $cta = array_flip($this->getConfigTranslationArray()); - foreach($this->config as $key => $value) { + foreach($this->unsavedChanges as $key) { + $value = $this->config[$key]; switch ($key) { case 'ldapAgentPassword': $value = base64_encode($value); @@ -275,6 +282,7 @@ class Configuration { } $this->saveValue($cta[$key], $value); } + $this->unsavedChanges = []; } /** diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 0f10874bc2..79d66189c2 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -150,7 +150,7 @@ class Connection extends LDAPUtility { $this->configuration->$name = $value; $after = $this->configuration->$name; if($before !== $after) { - if ($this->configID !== '') { + if ($this->configID !== '' && $this->configID !== null) { $this->configuration->saveConfiguration(); } $this->validateConfiguration(); diff --git a/apps/user_ldap/templates/part.wizard-server.php b/apps/user_ldap/templates/part.wizard-server.php index f4f2abe0f9..9803fb3cd3 100644 --- a/apps/user_ldap/templates/part.wizard-server.php +++ b/apps/user_ldap/templates/part.wizard-server.php @@ -1,10 +1,3 @@ -
- - - -
-

+ +