From 5c05a9327ce77a488d0c08eb571c23f68a62a0c2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 30 Jun 2017 11:30:43 +0200 Subject: [PATCH] add save button for setting LDAP Agent DN and Password Signed-off-by: Arthur Schiwon --- .../js/wizard/wizardTabElementary.js | 14 ++++++-- apps/user_ldap/js/wizard/wizardTabGeneric.js | 35 ++++++++++++++++++- .../templates/part.wizard-server.php | 3 ++ 3 files changed, 48 insertions(+), 4 deletions(-) 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/templates/part.wizard-server.php b/apps/user_ldap/templates/part.wizard-server.php index fdb2dcb4ba..ff027d54c0 100644 --- a/apps/user_ldap/templates/part.wizard-server.php +++ b/apps/user_ldap/templates/part.wizard-server.php @@ -61,6 +61,9 @@ placeholder="t('Password'));?>" autocomplete="off" title="t('For anonymous access, leave DN and Password empty.'));?>" /> +