123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- OCA = OCA || {};
- (function() {
-
- var WizardView = function() {};
- WizardView.prototype = {
-
- STATUS_ERROR: 0,
-
- STATUS_INCOMPLETE: 1,
-
- STATUS_SUCCESS: 2,
-
- STATUS_UNTESTED: 3,
-
- init: function () {
- this.tabs = {};
- this.tabs.server = new OCA.LDAP.Wizard.WizardTabElementary();
- this.$settings = $('#ldapSettings');
- this.$saveSpinners = $('.ldap_saving');
- this.saveProcesses = 0;
- _.bindAll(this, 'onTabChange', 'onTestButtonClick');
- },
-
- initControls: function() {
- var view = this;
- $('.ldap_action_continue').click(function(event) {
- event.preventDefault();
- view._controlContinue(view);
- });
- $('.ldap_action_back').click(function(event) {
- event.preventDefault();
- view._controlBack(view);
- });
- $('.ldap_action_test_connection').click(this.onTestButtonClick);
- },
-
- registerTab: function(tabView, index) {
- if( _.isUndefined(this.tabs[index])
- && tabView instanceof OCA.LDAP.Wizard.WizardTabGeneric
- ) {
- this.tabs[index] = tabView;
- this.tabs[index].setModel(this.configModel);
- return true;
- }
- return false;
- },
-
- basicStatusCheck: function(view) {
- var host = view.configModel.configuration.ldap_host;
- var port = view.configModel.configuration.ldap_port;
- var base = view.configModel.configuration.ldap_base;
- var agent = view.configModel.configuration.ldap_dn;
- var pwd = view.configModel.configuration.ldap_agent_password;
- if(((host && port && base) || (host && base && host.indexOf('ldapi://') > -1 ))
- && ((!agent && !pwd) || (agent && pwd))) {
- view.enableTabs();
- } else {
- view.disableTabs();
- }
- },
-
- functionalityCheck: function() {
-
-
- var host = this.configModel.configuration.ldap_host;
- var port = this.configModel.configuration.ldap_port;
- var base = this.configModel.configuration.ldap_base;
- var userFilter = this.configModel.configuration.ldap_userlist_filter;
- var loginFilter = this.configModel.configuration.ldap_login_filter;
- if((host && port && base && userFilter && loginFilter) ||
- (host && base && host.indexOf('ldapi://') > -1 && userFilter && loginFilter)) {
- this.configModel.requestConfigurationTest();
- } else {
- this._updateStatusIndicator(this.STATUS_INCOMPLETE);
- }
- },
-
- considerFunctionalityCheck: function(changeSet) {
- var testTriggers = [
- 'ldap_host', 'ldap_port', 'ldap_dn', 'ldap_agent_password',
- 'ldap_base', 'ldap_userlist_filter', 'ldap_login_filter'
- ];
- for(var key in changeSet) {
- if($.inArray(key, testTriggers) >= 0) {
- this.functionalityCheck();
- return;
- }
- }
- },
-
- onSetRequested: function(view) {
- view.saveProcesses += 1;
- if(view.saveProcesses === 1) {
- view.showSaveSpinner();
- }
- },
-
- onSetRequestDone: function(view, result) {
- if(view.saveProcesses > 0) {
- view.saveProcesses -= 1;
- if(view.saveProcesses === 0) {
- view.hideSaveSpinner();
- }
- }
- view.basicStatusCheck(view);
- var param = {};
- param[result.key] = 1;
- view.considerFunctionalityCheck(param);
- },
-
- onDetectionTestCompleted: function(view, payload) {
- if(payload.feature === 'TestBaseDN') {
- if(payload.data.status === 'success') {
- var objectsFound = parseInt(payload.data.changes.ldap_test_base, 10);
- if(objectsFound > 0) {
- view._updateStatusIndicator(view.STATUS_SUCCESS);
- return;
- }
- }
- view._updateStatusIndicator(view.STATUS_ERROR);
- OC.Notification.showTemporary(t('user_ldap', 'The Base DN appears to be wrong'));
- }
- },
-
- onTestCompleted: function(view, result) {
- if(result.isSuccess) {
- view.configModel.requestWizard('ldap_test_base');
- } else {
- view._updateStatusIndicator(view.STATUS_ERROR);
- }
- },
-
- onConfigLoaded: function(view) {
- view._updateStatusIndicator(view.STATUS_UNTESTED);
- view.basicStatusCheck(view);
- view.functionalityCheck();
- },
-
- onTabChange: function(event, ui) {
- if(this.saveProcesses > 0) {
- return false;
- }
- var newTabID = ui.newTab[0].id;
- if(newTabID === '#ldapWizard1') {
- newTabID = 'server';
- }
- var oldTabID = ui.oldTab[0].id;
- if(oldTabID === '#ldapWizard1') {
- oldTabID = 'server';
- }
- if(!_.isUndefined(this.tabs[newTabID])) {
- this.tabs[newTabID].isActive = true;
- this.tabs[newTabID].onActivate();
- } else {
- console.warn('Unreferenced activated tab ' + newTabID);
- }
- if(!_.isUndefined(this.tabs[oldTabID])) {
- this.tabs[oldTabID].isActive = false;
- } else {
- console.warn('Unreferenced left tab ' + oldTabID);
- }
- if(!_.isUndefined(this.tabs[newTabID])) {
- this._controlUpdate(this.tabs[newTabID].tabIndex);
- }
- },
-
- onConfigUpdated: function(view, changeSet) {
- view.basicStatusCheck(view);
- view.considerFunctionalityCheck(changeSet);
- },
-
- onTestButtonClick: function() {
- this.configModel.requestWizard('ldap_action_test_connection', {ldap_serverconfig_chooser: this.configModel.configID});
- },
-
- setModel: function(configModel) {
-
- this.configModel = configModel;
- for(var i in this.tabs) {
- this.tabs[i].setModel(configModel);
- }
-
-
-
-
- this.configModel.on('configLoaded', this.onConfigLoaded, this);
- this.configModel.on('configUpdated', this.onConfigUpdated, this);
- this.configModel.on('setRequested', this.onSetRequested, this);
- this.configModel.on('setCompleted', this.onSetRequestDone, this);
- this.configModel.on('configurationTested', this.onTestCompleted, this);
- this.configModel.on('receivedLdapFeature', this.onDetectionTestCompleted, this);
- },
-
- enableTabs: function() {
-
- if(this.saveProcesses === 0) {
- $('.ldap_action_continue').removeAttr('disabled');
- $('.ldap_action_back').removeAttr('disabled');
- this.$settings.tabs('option', 'disabled', []);
- }
- },
-
- disableTabs: function() {
- $('.ldap_action_continue').attr('disabled', 'disabled');
- $('.ldap_action_back').attr('disabled', 'disabled');
- this.$settings.tabs('option', 'disabled', [1, 2, 3, 4, 5]);
- },
-
- showSaveSpinner: function() {
- this.$saveSpinners.removeClass('hidden');
- $('#ldap *').addClass('save-cursor');
- },
-
- hideSaveSpinner: function() {
- this.$saveSpinners.addClass('hidden');
- $('#ldap *').removeClass('save-cursor');
- },
-
- _requestConfig: function(configID) {
- this.configModel.load(configID);
- },
-
- render: function () {
- $('#ldapAdvancedAccordion').accordion({ heightStyle: 'content', animate: 'easeInOutCirc'});
- this.$settings.tabs({});
- $('#ldapSettings button:not(.icon-default-style):not(.ui-multiselect)').button();
- $('#ldapSettings').tabs({ beforeActivate: this.onTabChange });
- this.initControls();
- this.disableTabs();
- this._requestConfig(this.tabs.server.getConfigID());
- },
-
- _updateStatusIndicator: function(state) {
- var $indicator = $('.ldap_config_state_indicator');
- var $indicatorLight = $('.ldap_config_state_indicator_sign');
- switch(state) {
- case this.STATUS_UNTESTED:
- $indicator.text(t('user_ldap',
- 'Testing configuration…'
- ));
- $indicator.addClass('ldap_grey');
- $indicatorLight.removeClass('error');
- $indicatorLight.removeClass('success');
- break;
- case this.STATUS_ERROR:
- $indicator.text(t('user_ldap',
- 'Configuration incorrect'
- ));
- $indicator.removeClass('ldap_grey');
- $indicatorLight.addClass('error');
- $indicatorLight.removeClass('success');
- break;
- case this.STATUS_INCOMPLETE:
- $indicator.text(t('user_ldap',
- 'Configuration incomplete'
- ));
- $indicator.removeClass('ldap_grey');
- $indicatorLight.removeClass('error');
- $indicatorLight.removeClass('success');
- break;
- case this.STATUS_SUCCESS:
- $indicator.text(t('user_ldap', 'Configuration OK'));
- $indicator.addClass('ldap_grey');
- $indicatorLight.removeClass('error');
- $indicatorLight.addClass('success');
- if(!this.tabs.server.isActive) {
- this.configModel.set('ldap_configuration_active', 1);
- }
- break;
- }
- },
-
- _controlBack: function(view) {
- var curTabIndex = view.$settings.tabs('option', 'active');
- if(curTabIndex == 0) {
- return;
- }
- view.$settings.tabs('option', 'active', curTabIndex - 1);
- view._controlUpdate(curTabIndex - 1);
- },
-
- _controlContinue: function(view) {
- var curTabIndex = view.$settings.tabs('option', 'active');
- if(curTabIndex == 3) {
- return;
- }
- view.$settings.tabs('option', 'active', 1 + curTabIndex);
- view._controlUpdate(curTabIndex + 1);
- },
-
- _controlUpdate: function(nextTabIndex) {
- if(nextTabIndex == 0) {
- $('.ldap_action_back').addClass('invisible');
- $('.ldap_action_continue').removeClass('invisible');
- } else
- if(nextTabIndex == 1) {
- $('.ldap_action_back').removeClass('invisible');
- $('.ldap_action_continue').removeClass('invisible');
- } else
- if(nextTabIndex == 2) {
- $('.ldap_action_continue').removeClass('invisible');
- $('.ldap_action_back').removeClass('invisible');
- } else
- if(nextTabIndex == 3) {
- $('.ldap_action_back').removeClass('invisible');
- $('.ldap_action_continue').addClass('invisible');
- }
- }
- };
- OCA.LDAP.Wizard.WizardView = WizardView;
- })();
|