From 51d783ca6e2d8341531b12224c7e2f51fe70fdfe Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 13 Jan 2015 18:36:16 +0100 Subject: JS cleanup --- apps/user_ldap/js/experiencedAdmin.js | 5 ++--- apps/user_ldap/js/ldapFilter.js | 19 ++++++------------ apps/user_ldap/js/settings.js | 36 +++++++++++++++++------------------ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/apps/user_ldap/js/experiencedAdmin.js b/apps/user_ldap/js/experiencedAdmin.js index 8d138eecc41..f9820c56c92 100644 --- a/apps/user_ldap/js/experiencedAdmin.js +++ b/apps/user_ldap/js/experiencedAdmin.js @@ -25,12 +25,11 @@ function ExperiencedAdmin(wizard, initialState) { /** * toggles whether the admin is an experienced one or not * - * @param {boolean} whether the admin is experienced or not + * @param {boolean} isExperienced whether the admin is experienced or not */ ExperiencedAdmin.prototype.setExperienced = function(isExperienced) { this._isExperienced = isExperienced; - if(this._isExperienced) { - this.enableRawMode(); + if(this._isExperienced) { this.enableRawMode(); this.hideEntryCounters(); } else { this.showEntryCounters(); diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js index 0f7d240adac..c77995e0dee 100644 --- a/apps/user_ldap/js/ldapFilter.js +++ b/apps/user_ldap/js/ldapFilter.js @@ -69,14 +69,6 @@ LdapFilter.prototype.compose = function(updateCount) { ); }; -/** - * this function is triggered after attribute detectors have completed in - * LdapWizard - */ -LdapFilter.prototype.afterDetectorsRan = function() { - this.updateCount(); -}; - /** * this function is triggered after LDAP filters have been composed successfully * @param {object} result returned by the ajax call @@ -99,11 +91,13 @@ LdapFilter.prototype.determineMode = function() { function(result) { var property = 'ldap' + filter.target + 'FilterMode'; filter.mode = parseInt(result.changes[property], 10); - if(filter.mode === LdapWizard.filterModeRaw && - $('#raw'+filter.target+'FilterContainer').hasClass('invisible')) { + var rawContainerIsInvisible = + $('#raw'+filter.target+'FilterContainer').hasClass('invisible'); + if(filter.mode === LdapWizard.filterModeRaw + && rawContainerIsInvisible) { LdapWizard['toggleRaw'+filter.target+'Filter'](); - } else if(filter.mode === LdapWizard.filterModeAssisted && - !$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) { + } else if(filter.mode === LdapWizard.filterModeAssisted + && !rawContainerIsInvisible) { LdapWizard['toggleRaw'+filter.target+'Filter'](); } else { console.log('LDAP Wizard determineMode: returned mode was »' + @@ -167,7 +161,6 @@ LdapFilter.prototype.findFeatures = function() { /** * this function is triggered before user and group counts are executed * resolving the passed status variable will fire up counting - * @param {object} status an instance of $.Deferred */ LdapFilter.prototype.beforeUpdateCount = function() { var status = $.Deferred(); diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 6db210fe435..3372613b941 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -207,7 +207,7 @@ var LdapWizard = { }, basicStatusCheck: function() { - //criterias to continue from the first tab + //criteria to continue from the first tab // - host, port, user filter, agent dn, password, base dn var host = $('#ldap_host').val(); var port = $('#ldap_port').val(); @@ -224,7 +224,7 @@ var LdapWizard = { blacklistAdd: function(id) { - obj = $('#'+id); + var obj = $('#' + id); if(!(obj[0].hasOwnProperty('multiple') && obj[0]['multiple'] === true)) { //no need to blacklist multiselect LdapWizard.saveBlacklist[id] = true; @@ -242,14 +242,14 @@ var LdapWizard = { }, checkBaseDN: function() { - host = $('#ldap_host').val(); - port = $('#ldap_port').val(); - user = $('#ldap_dn').val(); - pass = $('#ldap_agent_password').val(); + var host = $('#ldap_host').val(); + var port = $('#ldap_port').val(); + var user = $('#ldap_dn').val(); + var pass = $('#ldap_agent_password').val(); //FIXME: determine base dn with anonymous access if(host && port && user && pass) { - param = 'action=guessBaseDN'+ + var param = 'action=guessBaseDN'+ '&ldap_serverconfig_chooser='+ encodeURIComponent($('#ldap_serverconfig_chooser').val()); @@ -276,11 +276,11 @@ var LdapWizard = { }, checkPort: function() { - host = $('#ldap_host').val(); - port = $('#ldap_port').val(); + var host = $('#ldap_host').val(); + var port = $('#ldap_port').val(); if(host && !port) { - param = 'action=guessPortAndTLS'+ + var param = 'action=guessPortAndTLS'+ '&ldap_serverconfig_chooser='+ encodeURIComponent($('#ldap_serverconfig_chooser').val()); @@ -307,7 +307,7 @@ var LdapWizard = { }, controlBack: function() { - curTabIndex = $('#ldapSettings').tabs('option', 'active'); + var curTabIndex = $('#ldapSettings').tabs('option', 'active'); if(curTabIndex == 0) { return; } @@ -316,7 +316,7 @@ var LdapWizard = { }, controlContinue: function() { - curTabIndex = $('#ldapSettings').tabs('option', 'active'); + var curTabIndex = $('#ldapSettings').tabs('option', 'active'); if(curTabIndex == 3) { return; } @@ -529,7 +529,7 @@ var LdapWizard = { if(type !== 'User' && type !== 'Group') { return false; } - param = 'action=determine'+encodeURIComponent(type)+'ObjectClasses'+ + var param = 'action=determine'+encodeURIComponent(type)+'ObjectClasses'+ '&ldap_serverconfig_chooser='+ encodeURIComponent($('#ldap_serverconfig_chooser').val()); @@ -571,11 +571,11 @@ var LdapWizard = { functionalityCheck: function() { //criteria to enable the connection: // - host, port, basedn, user filter, login filter - host = $('#ldap_host').val(); - port = $('#ldap_port').val(); - base = $('#ldap_base').val(); - userfilter = $('#ldap_userlist_filter').val(); - loginfilter = $('#ldap_login_filter').val(); + var host = $('#ldap_host').val(); + var port = $('#ldap_port').val(); + var base = $('#ldap_base').val(); + var userfilter = $('#ldap_userlist_filter').val(); + var loginfilter = $('#ldap_login_filter').val(); //FIXME: activates a manually deactivated configuration. if(host && port && base && userfilter && loginfilter) { -- cgit v1.2.3 From 672bc287154f63cc742812cc76f22869036e20c7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 14 Jan 2015 15:15:55 +0100 Subject: allow to read again objectclasses and groups under certain conditions --- apps/user_ldap/js/ldapFilter.js | 11 ++++++++++- apps/user_ldap/js/settings.js | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js index c77995e0dee..c546e942d07 100644 --- a/apps/user_ldap/js/ldapFilter.js +++ b/apps/user_ldap/js/ldapFilter.js @@ -19,6 +19,8 @@ function LdapFilter(target, determineModeCallback) { LdapFilter.prototype.activate = function() { if(this.activated) { + // might be necessary, if configuration changes happened. + this.findFeatures(); return; } this.activated = true; @@ -136,8 +138,15 @@ LdapFilter.prototype.unlock = function() { } }; +/** + * resets this.foundFeatures so that LDAP queries can be fired again to retrieve + * objectClasses, groups, etc. + */ +LdapFilter.prototype.reAllowFeatureLookup = function () { + this.foundFeatures = false; +}; + LdapFilter.prototype.findFeatures = function() { - //TODO: reset this.foundFeatures when any base DN changes if(!this.foundFeatures && !this.locked && this.mode === LdapWizard.filterModeAssisted) { this.foundFeatures = true; var objcEl, avgrEl; diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 3372613b941..2a8fedf5dde 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -149,6 +149,7 @@ var LdapWizard = { loginFilter: false, groupFilter: false, ajaxRequests: {}, + lastTestSuccessful: true, ajax: function(param, fnOnSuccess, fnOnError, reqID) { if(!_.isUndefined(reqID)) { @@ -619,6 +620,7 @@ var LdapWizard = { LdapWizard.detectorsRunInXPMode = 0; LdapWizard.instantiateFilters(); LdapWizard.admin.setExperienced($('#ldap_experienced_admin').is(':checked')); + LdapWizard.lastTestSuccessful = true; LdapWizard.basicStatusCheck(); LdapWizard.functionalityCheck(); LdapWizard.isConfigurationActiveControlLocked = false; @@ -760,7 +762,19 @@ var LdapWizard = { } }, - processChanges: function(triggerObj) { + /** + * allows UserFilter, LoginFilter and GroupFilter to lookup objectClasses + * and similar again. This should be called after essential changes, e.g. + * Host or BaseDN changes, or positive functionality check + * + */ + allowFilterFeatureSearch: function () { + LdapWizard.userFilter.reAllowFeatureLookup(); + LdapWizard.loginFilter.reAllowFeatureLookup(); + LdapWizard.groupFilter.reAllowFeatureLookup(); + }, + + processChanges: function (triggerObj) { LdapWizard.hideInfoBox(); if(triggerObj.id === 'ldap_host' @@ -771,6 +785,7 @@ var LdapWizard = { if($('#ldap_port').val()) { //if Port is already set, check BaseDN LdapWizard.checkBaseDN(); + LdapWizard.allowFilterFeatureSearch(); } } @@ -1002,6 +1017,10 @@ var LdapWizard = { $('.ldap_config_state_indicator').addClass('ldap_grey'); $('.ldap_config_state_indicator_sign').removeClass('error'); $('.ldap_config_state_indicator_sign').addClass('success'); + if(!LdapWizard.lastTestSuccessful) { + LdapWizard.lastTestSuccessful = true; + LdapWizard.allowFilterFeatureSearch(); + } }, //onError function(result) { @@ -1011,6 +1030,7 @@ var LdapWizard = { $('.ldap_config_state_indicator').removeClass('ldap_grey'); $('.ldap_config_state_indicator_sign').addClass('error'); $('.ldap_config_state_indicator_sign').removeClass('success'); + LdapWizard.lastTestSuccessful = false; } ); } else { -- cgit v1.2.3 From 3d94aa8953a0d79da2c934b59edd60254e24f5ea Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 14 Jan 2015 17:31:20 +0100 Subject: update user or group count only, when the multiselect is closed --- apps/user_ldap/js/settings.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 2a8fedf5dde..b1abb0994ba 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -819,15 +819,33 @@ var LdapWizard = { LdapWizard._save(inputObj, val); }, + /** + * updates user or group count on multiSelect close. Resets the event + * function subsequently. + * + * @param {LdapFilter} filter + * @param {Object} $multiSelectObj + */ + onMultiSelectClose: function(filter, $multiSelectObj) { + filter.updateCount(); + $multiSelectObj.multiselect({close: function(){}}); + }, + saveMultiSelect: function(originalObj, resultObj) { - values = ''; - for(i = 0; i < resultObj.length; i++) { + var values = ''; + for(var i = 0; i < resultObj.length; i++) { values = values + "\n" + resultObj[i].value; } LdapWizard._save($('#'+originalObj)[0], $.trim(values)); + var $multiSelectObj = $('#'+originalObj); + var updateCount = !$multiSelectObj.multiselect("isOpen"); + var applyUpdateOnCloseToFilter; if(originalObj === 'ldap_userfilter_objectclass' || originalObj === 'ldap_userfilter_groups') { - LdapWizard.userFilter.compose(true); + LdapWizard.userFilter.compose(updateCount); + if(!updateCount) { + applyUpdateOnCloseToFilter = LdapWizard.userFilter; + } //when user filter is changed afterwards, login filter needs to //be adjusted, too if(!LdapWizard.loginFilter) { @@ -838,7 +856,19 @@ var LdapWizard = { LdapWizard.loginFilter.compose(); } else if(originalObj === 'ldap_groupfilter_objectclass' || originalObj === 'ldap_groupfilter_groups') { - LdapWizard.groupFilter.compose(true); + LdapWizard.groupFilter.compose(updateCount); + if(!updateCount) { + applyUpdateOnCloseToFilter = LdapWizard.groupFilter; + } + } + + if(applyUpdateOnCloseToFilter instanceof LdapFilter) { + $multiSelectObj.multiselect({ + close: function () { + LdapWizard.onMultiSelectClose( + applyUpdateOnCloseToFilter, $multiSelectObj); + } + }); } }, -- cgit v1.2.3 From 56ba07aa5cc52cd8a937aa6fb514a82b82385568 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 15 Jan 2015 12:25:36 +0100 Subject: coding style --- apps/user_ldap/js/experiencedAdmin.js | 3 ++- apps/user_ldap/js/ldapFilter.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/user_ldap/js/experiencedAdmin.js b/apps/user_ldap/js/experiencedAdmin.js index f9820c56c92..7dc5a4e503d 100644 --- a/apps/user_ldap/js/experiencedAdmin.js +++ b/apps/user_ldap/js/experiencedAdmin.js @@ -29,7 +29,8 @@ function ExperiencedAdmin(wizard, initialState) { */ ExperiencedAdmin.prototype.setExperienced = function(isExperienced) { this._isExperienced = isExperienced; - if(this._isExperienced) { this.enableRawMode(); + if(this._isExperienced) { + this.enableRawMode(); this.hideEntryCounters(); } else { this.showEntryCounters(); diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js index c546e942d07..dc65858217d 100644 --- a/apps/user_ldap/js/ldapFilter.js +++ b/apps/user_ldap/js/ldapFilter.js @@ -95,11 +95,13 @@ LdapFilter.prototype.determineMode = function() { filter.mode = parseInt(result.changes[property], 10); var rawContainerIsInvisible = $('#raw'+filter.target+'FilterContainer').hasClass('invisible'); - if(filter.mode === LdapWizard.filterModeRaw - && rawContainerIsInvisible) { + if ( filter.mode === LdapWizard.filterModeRaw + && rawContainerIsInvisible + ) { LdapWizard['toggleRaw'+filter.target+'Filter'](); - } else if(filter.mode === LdapWizard.filterModeAssisted - && !rawContainerIsInvisible) { + } else if ( filter.mode === LdapWizard.filterModeAssisted + && !rawContainerIsInvisible + ) { LdapWizard['toggleRaw'+filter.target+'Filter'](); } else { console.log('LDAP Wizard determineMode: returned mode was »' + -- cgit v1.2.3