nextcloud/apps/user_ldap/js/wizard/wizardTabElementary.js

346 lines
9.7 KiB
JavaScript
Raw Normal View History

LDAP Wizard Overhaul wizard refactor reimplement save spinners and cursor implement Port detector introduced detector queue, added base dn detector disable input fields when detectors are running introduce spinners for fields that are being updated by detector cache jq element objects consolidate processing of detector results in generic / abstract base class display notification if a detector discovered a problem don't run base dn detector if a base is configured reset detector queue on configuration switch implement functionality check and update of status indicator document ConfigModel jsdoc for controller and main view more documentation implement the user filter tab view so far the multiselects get initialized (not filled yet) and the mode can be switched. mode is also restored. reintroduce filter switch confirmation in admin XP mode new detector for user object classes. so we also load user object classes if necessary and are able to save and show the setting. multiselect trigger save actions now on close only show spinners automatically, when a detector is running 20k limit for object classes preselection test adjust wordings, fix grammar add group (for users tab) detector also includes wording fixes error presentation moved from detectors to view, where it belongs add info label to users page missing wording changes show effective LDAP filter in Assisted Mode add user filter detector implement count button for users and limit all count actions to 1001 for performance reasons make port field a bit bigger. not perfect though. do not detect port automatically implement login filter tab view only load features in assisted mode and don't enable assisted fields while in raw mode add tooltips on login filter checkbox options for better understanding permanently show filter on login tab and also compile login filter in assisted mode test/verify button on login attributes tab, with backend changes. only run wizard requests if your an active tab. also run compile filter requests when switching to assisted mode underline toggle filter links to stress that they are clickable unity user and group tab functionality in common abstract class, add group filter tab view. only detectors and template adjustments left to have group tab implementation complete add object class and group detector for groups as well as filter composer show ldap filter permanently on groups tab introduce input element that can deal better with many groups, will be used with > 40 fix disabling complex group chooser while detection is running hide complex group chooser on config switch fix few more issues with complex chooser make complex group chooser available on Users tab as well detect base dn improvements/changes: - do not look for Base DN automatically, offer a button instead - fix for alternative way to detect a base dn (if agent dn is not given) - do not trigger filter composers on config switch Changes with configuration chooser controls - "New" was removed out of the configuration list - and split into buttons "add" and "copy" - delete button is also now an icon add test button for Base DN reimplement advanced tab. The save button is gone. reimplement expert tab remove unused methods implement mail attribute detector implement user display name attribute detection implement member group association detector replace text input with textarea for raw filter input finish functionality check auto-enable good configurations, as it was before cleanup move save confirmation handling to base class, reduces code duplication enable tabs only if no running save processes are left. move onConfigLoaded to base class, avoids code duplication simplify, save LOCs Test Configuration button to be dealt with in main view as it is a cross-tab element require detectorQueue in constructor cleanup put bootstrap into a function and thus make it testable get rid of old stuff
2015-03-03 13:56:03 +03:00
/**
* Copyright (c) 2015, Arthur Schiwon <blizzz@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OCA = OCA || {};
(function() {
/**
* @classdesc This class represents the view belonging to the server tab
* in the LDAP wizard.
*/
var WizardTabElementary = OCA.LDAP.Wizard.WizardTabGeneric.subClass({
/**
* initializes the instance. Always call it after initialization.
*
* @param tabIndex
* @param tabID
*/
init: function (tabIndex, tabID) {
this._super(tabIndex, tabID);
this.isActive = true;
this.configChooserID = '#ldap_serverconfig_chooser';
var items = {
ldap_host: {
$element: $('#ldap_host'),
setMethod: 'setHost'
},
ldap_port: {
$element: $('#ldap_port'),
setMethod: 'setPort',
$relatedElements: $('.ldapDetectPort')
},
ldap_dn: {
$element: $('#ldap_dn'),
setMethod: 'setAgentDN'
},
ldap_agent_password: {
$element: $('#ldap_agent_password'),
setMethod: 'setAgentPwd'
},
ldap_base: {
$element: $('#ldap_base'),
setMethod: 'setBase',
$relatedElements: $('.ldapDetectBase, .ldapTestBase'),
$detectButton: $('.ldapDetectBase'),
$testButton: $('.ldapTestBase')
},
ldap_base_test: {
$element: $('#ldap_base')
},
ldap_experienced_admin: {
$element: $('#ldap_experienced_admin'),
setMethod: 'setExperiencedAdmin'
}
};
this.setManagedItems(items);
_.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);
},
/**
* Sets the config model for this view and subscribes to some events.
* Also binds the config chooser to the model
*
* @param {OCA.LDAP.Wizard.ConfigModel} configModel
*/
setModel: function(configModel) {
this._super(configModel);
this.configModel.on('configLoaded', this.onConfigSwitch, this);
this.configModel.on('newConfiguration', this.onNewConfiguration, this);
this.configModel.on('deleteConfiguration', this.onDeleteConfiguration, this);
this.configModel.on('receivedLdapFeature', this.onTestResultReceived, this);
this._enableConfigChooser();
this._enableConfigButtons();
},
/**
* returns the currently selected configuration ID
*
* @returns {string}
*/
getConfigID: function() {
return $(this.configChooserID).val();
},
/**
* updates the host configuration text field
*
* @param {string} host
*/
setHost: function(host) {
this.setElementValue(this.managedItems.ldap_host.$element, host);
if(host) {
this.enableElement(this.managedItems.ldap_port.$relatedElements);
} else {
this.disableElement(this.managedItems.ldap_port.$relatedElements);
}
},
/**
* updates the port configuration text field
*
* @param {string} port
*/
setPort: function(port) {
this.setElementValue(this.managedItems.ldap_port.$element, port);
},
/**
* updates the user (agent) DN text field
*
* @param {string} agentDN
*/
setAgentDN: function(agentDN) {
this.setElementValue(this.managedItems.ldap_dn.$element, agentDN);
},
/**
* updates the user (agent) password field
*
* @param {string} agentPwd
*/
setAgentPwd: function(agentPwd) {
this.setElementValue(
this.managedItems.ldap_agent_password.$element, agentPwd
);
},
/**
* updates the base DN text area
*
* @param {string} bases
*/
setBase: function(bases) {
this.setElementValue(this.managedItems.ldap_base.$element, bases);
if(!bases) {
this.disableElement(this.managedItems.ldap_base.$testButton);
} else {
this.enableElement(this.managedItems.ldap_base.$testButton);
}
},
/**
* updates the experienced admin check box
*
* @param {string} xpAdminMode contains an int
*/
setExperiencedAdmin: function(xpAdminMode) {
this.setElementValue(
this.managedItems.ldap_experienced_admin.$element, xpAdminMode
);
},
/**
* @inheritdoc
*/
overrideErrorMessage: function(message, key) {
switch(key) {
case 'ldap_port':
if (message === 'Invalid credentials') {
return t('user_ldap', 'Please check the credentials, they seem to be wrong.');
} else {
return t('user_ldap', 'Please specify the port, it could not be auto-detected.');
}
break;
case 'ldap_base':
if( message === 'Server is unwilling to perform'
|| message === 'Could not connect to LDAP'
) {
return t('user_ldap', 'Base DN could not be auto-detected, please revise credentials, host and port.');
}
return t('user_ldap', 'Could not detect Base DN, please enter it manually.');
break;
}
return message;
},
/**
* resets the view when a configuration switch happened.
*
* @param {WizardTabElementary} view
* @param {Object} configuration
*/
onConfigSwitch: function(view, configuration) {
view.disableElement(view.managedItems.ldap_port.$relatedElements);
view.onConfigLoaded(view, configuration);
},
/**
* updates the configuration chooser when a new configuration was added
* which also means it is being switched to. The configuration fields
* are updated on a different step.
*
* @param {WizardTabElementary} view
* @param {Object} result
*/
onNewConfiguration: function(view, result) {
if(result.isSuccess === true) {
$(view.configChooserID + ' option:selected').removeAttr('selected');
var html = '<option value="'+result.configPrefix+'" selected="selected">'+t('user_ldap','{nthServer}. Server', {nthServer: $(view.configChooserID + ' option').length})+'</option>';
$(view.configChooserID + ' option:last').before(html);
}
},
/**
* updates the configuration chooser upon the deletion of a
* configuration and, if necessary, loads an existing one.
*
* @param view
* @param result
*/
onDeleteConfiguration: function(view, result) {
if(result.isSuccess === true) {
if(view.getConfigID() === result.configPrefix) {
// if the deleted value is still the selected one (99% of
// the cases), remove it from the list and load the topmost
$(view.configChooserID + ' option:selected').remove();
$(view.configChooserID + ' option:first').select();
if($(view.configChooserID + ' option').length < 2) {
view.configModel.newConfig(false);
} else {
view.configModel.load(view.getConfigID());
}
} else {
// otherwise just remove the entry
$(view.configChooserID + ' option[value=' + result.configPrefix + ']').remove();
}
} else {
OC.Notification.showTemporary(result.errorMessage);
}
},
/**
* Base DN test results will arrive here
*
* @param {WizardTabElementary} view
* @param {FeaturePayload} payload
*/
onTestResultReceived: function(view, payload) {
if(payload.feature === 'TestBaseDN') {
var message;
if(payload.data.status === 'success') {
var objectsFound = parseInt(payload.data.changes.ldap_test_base, 10);
if(objectsFound < 1) {
message = t('user_ldap', 'No object found in the given Base DN. Please revise.');
} else if(objectsFound > 1000) {
message = t('user_ldap', 'More then 1.000 directory entries available.');
} else {
message = t('user_ldap', objectsFound + ' entries available within the provided Base DN');
}
} else {
message = t('user_ldap', 'An error occurred. Please check the Base DN, as well as connection settings and credentials.');
if(payload.data.message) {
console.warn(payload.data.message);
}
}
OC.Notification.showTemporary(message);
}
},
/**
* request to count the users with the current filter
*
* @param {Event} event
*/
onPortButtonClick: function(event) {
event.preventDefault();
this.configModel.requestWizard('ldap_port');
},
/**
* request to count the users with the current filter
*
* @param {Event} event
*/
onBaseDNButtonClick: function(event) {
event.preventDefault();
this.configModel.requestWizard('ldap_base');
},
/**
* request to count the users with the current filter
*
* @param {Event} event
*/
onBaseDNTestButtonClick: function(event) {
event.preventDefault();
this.configModel.requestWizard('ldap_test_base');
},
/**
* registers the change event on the configuration chooser and makes
* the model load a newly selected configuration
*
* @private
*/
_enableConfigChooser: function() {
var view = this;
$(this.configChooserID).change(function(){
var value = $(view.configChooserID + ' option:selected:first').attr('value');
view.configModel.load(value);
});
},
/**
* adds actions to the action buttons for configuration management
*
* @private
*/
_enableConfigButtons: function() {
var view = this;
$('#ldap_action_delete_configuration').click(function(event) {
event.preventDefault();
OC.dialogs.confirm(
t('user_ldap', 'Do you really want to delete the current Server Configuration?'),
t('user_ldap', 'Confirm Deletion'),
function(doDelete) {
if(doDelete) {
view.configModel.deleteConfig(view.getConfigID());
}
},
false
);
});
$('#ldap_action_add_configuration').click(function(event) {
event.preventDefault();
view.configModel.newConfig(false);
});
$('#ldap_action_copy_configuration').click(function(event) {
event.preventDefault();
view.configModel.newConfig(true);
});
}
});
OCA.LDAP.Wizard.WizardTabElementary = WizardTabElementary;
})();