123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642 |
- OCA = OCA || {};
- (function() {
-
- var WizardTabGeneric = OCA.LDAP.Wizard.WizardObject.subClass({
- isActive: false,
-
- multiSelectPluginClass: 'multiSelectPlugin',
-
- bjQuiButtonClass: 'ui-button',
-
- isToggling: false,
-
- init: function(tabIndex, tabID) {
- this.tabIndex = tabIndex;
- this.tabID = tabID;
- this.spinner = $('.ldapSpinner').first().clone().removeClass('hidden');
- _.bindAll(this, '_toggleRawFilterMode', '_toggleRawFilterModeConfirmation');
- },
-
- setManagedItems: function(managedItems) {
- this.managedItems = managedItems;
- this._enableAutoSave();
- this._enableSaveButton();
- },
-
- setModel: function(configModel) {
- this.configModel = configModel;
- this.parsedFilterMode = this.configModel.FILTER_MODE_ASSISTED;
- this.configModel.on('detectionStarted', this.onDetectionStarted, this);
- this.configModel.on('detectionCompleted', this.onDetectionCompleted, this);
- this.configModel.on('serverError', this.onServerError, this);
- this.configModel.on('setCompleted', this.onItemSaved, this);
- this.configModel.on('configUpdated', this.onConfigLoaded, this);
- },
-
- overrideErrorMessage: function(message, key) {
- if(message === 'LDAP authentication method rejected'
- && !this.configModel.configuration.ldap_dn)
- {
- message = t('user_ldap', 'Anonymous bind is not allowed. Please provide a User DN and Password.');
- } else if (message === 'LDAP Operations error'
- && !this.configModel.configuration.ldap_dn
- && !this.configModel.configuration.ldap_agent_password)
- {
- message = t('user_ldap', 'LDAP Operations error. Anonymous bind might not be allowed.');
- }
- return message;
- },
-
- onActivate: function() {
- if(!_.isUndefined(this.filterModeKey)
- && this.configModel.configuration.ldap_experienced_admin === '1') {
- this.setFilterMode(this.configModel.FILTER_MODE_RAW);
- }
- },
-
- onConfigLoaded: function(view, configuration) {
- for(var key in view.managedItems){
- if(!_.isUndefined(configuration[key])) {
- var value = configuration[key];
- var methodName = view.managedItems[key].setMethod;
- if(!_.isUndefined(view[methodName])) {
- view[methodName](value);
- }
- }
- }
- },
-
- onItemSaved: function(view, result) {
- if(!_.isUndefined(view.managedItems[result.key])) {
- var methodName = view.managedItems[result.key].setMethod;
- view[methodName](result.value);
- if(!result.isSuccess) {
- OC.Notification.showTemporary(t('user_ldap', 'Saving failed. Please make sure the database is in Operation. Reload before continuing.'));
- console.warn(result.errorMessage);
- }
- }
- },
-
- onServerError: function(view, payload) {
- if ( !_.isUndefined(view.managedItems[payload.relatedKey])) {
- var message = view.overrideErrorMessage(payload.message, payload.relatedKey);
- if(message) {
- OC.Notification.showTemporary(message);
- }
- }
- },
-
- onDetectionStarted: function(view, key) {
- if(!_.isUndefined(view.managedItems[key])) {
- view.disableElement(view.managedItems[key].$element);
- if(!_.isUndefined(view.managedItems[key].$relatedElements)){
- view.disableElement(view.managedItems[key].$relatedElements);
- }
- view.attachSpinner(view.managedItems[key].$element.attr('id'));
- }
- },
-
- onDetectionCompleted: function(view, key) {
- if(!_.isUndefined(view.managedItems[key])) {
- view.enableElement(view.managedItems[key].$element);
- if(!_.isUndefined(view.managedItems[key].$relatedElements)){
- view.enableElement(view.managedItems[key].$relatedElements);
- }
- view.removeSpinner(view.managedItems[key].$element.attr('id'));
- }
- },
-
- setElementValue: function($element, value) {
-
- if ($element.is('input[type=checkbox]')) {
- this._setCheckBox($element, value);
- return;
- }
-
- if ($element.is('textarea') && $.isArray(value)) {
- value = value.join("\n");
- } else if($element.hasClass(this.multiSelectPluginClass)) {
- if(!_.isArray(value)) {
- value = value.split("\n");
- }
- }
- if ($element.is('span')) {
- $element.text(value);
- } else {
- $element.val(value);
- }
- },
-
- equipMultiSelect: function($element, options) {
- if($element.find('option').length === 0) {
- $element.empty();
- for (var i in options) {
- var name = options[i];
- $element.append($('<option>').val(name).text(name).attr('title', name));
- }
- }
- if(!$element.hasClass('ldapGroupList')) {
- $element.multiselect('refresh');
- this.enableElement($element);
- }
- },
-
- enableElement: function($element) {
- var isMS = $element.is('select[multiple]');
- var hasOptions = isMS ? ($element.find('option').length > 0) : false;
- if($element.hasClass(this.multiSelectPluginClass) && hasOptions) {
- $element.multiselect("enable");
- } else if ($element.hasClass(this.bjQuiButtonClass)) {
- $element.button("enable");
- }
- else if(!isMS || (isMS && hasOptions)) {
- $element.prop('disabled', false);
- }
- },
-
- disableElement: function($element) {
- if($element.hasClass(this.multiSelectPluginClass)) {
- $element.multiselect("disable");
- } else if ($element.hasClass(this.bjQuiButtonClass)) {
- $element.button("disable");
- } else {
- $element.prop('disabled', 'disabled');
- }
- },
-
- attachSpinner: function(elementID) {
- if($('#' + elementID + ' + .ldapSpinner').length == 0) {
- var spinner = this.spinner.clone();
- var $element = $('#' + elementID);
- $(spinner).insertAfter($element);
-
- if ($element.is('select[multiple]')) {
- $('#' + elementID + " + img + button").css('display', 'none');
- }
- }
- },
-
- removeSpinner: function(elementID) {
- $('#' + elementID+' + .ldapSpinner').remove();
-
- $('#' + elementID + " + button").css('display', 'inline');
- },
-
- isExperiencedMode: function() {
- return parseInt(this.configModel.configuration.ldap_experienced_admin, 10) === 1;
- },
-
- _enableAutoSave: function() {
- var view = this;
- for(var id in this.managedItems) {
- if(_.isUndefined(this.managedItems[id].$element)
- || _.isUndefined(this.managedItems[id].setMethod)
- || (!_.isUndefined(this.managedItems[id].preventAutoSave)
- && this.managedItems[id].preventAutoSave === true)
- ) {
- continue;
- }
- var $element = this.managedItems[id].$element;
- if (!$element.is('select[multiple]')) {
- $element.change(function() {
- view._requestSave($(this));
- });
- }
- }
- },
-
- _enableSaveButton: function() {
- var view = this;
-
-
-
-
-
-
- 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);
- item.$saveButton.removeClass('primary');
- });
- item.$element.change(function () {
- item.$saveButton.addClass('primary');
- });
- })(this.managedItems[id]);
- }
- },
-
- _initMultiSelect: function($element, caption) {
- var view = this;
- $element.multiselect({
- header: false,
- selectedList: 9,
- noneSelectedText: caption,
- classes: this.multiSelectPluginClass,
- close: function() {
- view._requestSave($element);
- }
- });
- },
-
-
- _requestSave: function($element) {
- var value = '';
- if($element.is('input[type=checkbox]')
- && !$element.is(':checked')) {
- value = 0;
- } else if ($element.is('select[multiple]')) {
- var entries = $element.multiselect("getChecked");
- for(var i = 0; i < entries.length; i++) {
- value = value + "\n" + entries[i].value;
- }
- value = $.trim(value);
- } else {
- value = $element.val();
- }
- this.configModel.set($element.attr('id'), value);
- },
-
- _setCheckBox: function($element, value) {
- if(parseInt(value, 10) === 1) {
- $element.prop('checked', 'checked');
- } else {
- $element.removeAttr('checked');
- }
- },
-
- considerFeatureRequests: function() {},
-
- requestCompileFilter: function() {
- this.configModel.requestWizard(this.filterName);
- },
-
- setFilterModeOnce: function(mode) {
- this.isToggling = false;
- if(!this.filterModeInitialized) {
- this.filterModeInitialized = true;
- this.setFilterMode(mode);
- }
- },
-
- setFilterMode: function(mode) {
- if(parseInt(mode, 10) === this.configModel.FILTER_MODE_ASSISTED) {
- this.parsedFilterMode = this.configModel.FILTER_MODE_ASSISTED;
- this.considerFeatureRequests();
- this._setFilterModeAssisted();
- if(this.isActive) {
-
-
- this.requestCompileFilter();
- }
- } else {
- this._setFilterModeRaw();
- this.parsedFilterMode = this.configModel.FILTER_MODE_RAW;
- }
- },
-
- _setFilterModeAssisted: function() {
- var view = this;
- this.$filterModeRawContainer.addClass('invisible');
- var filter = this.$filterModeRawContainer.find('.ldapFilterInputElement').val();
- this.$filterModeRawContainer.siblings('.ldapReadOnlyFilterContainer').find('.ldapFilterReadOnlyElement').text(filter);
- this.$filterModeRawContainer.siblings('.ldapReadOnlyFilterContainer').removeClass('hidden');
- $.each(this.filterModeDisableableElements, function(i, $element) {
- view.enableElement($element);
- });
- if(!_.isUndefined(this.filterModeStateElement)) {
- if (this.filterModeStateElement.status === 'enabled') {
- this.enableElement(this.filterModeStateElement.$element);
- } else {
- this.filterModeStateElement.status = 'disabled';
- }
- }
- },
-
- _setFilterModeRaw: function() {
- var view = this;
- this.$filterModeRawContainer.removeClass('invisible');
- this.$filterModeRawContainer.siblings('.ldapReadOnlyFilterContainer').addClass('hidden');
- $.each(this.filterModeDisableableElements, function (i, $element) {
- view.disableElement($element);
- });
- if(!_.isUndefined(this.filterModeStateElement)) {
- if(this.filterModeStateElement.$element.multiselect().attr('disabled') === 'disabled') {
- this.filterModeStateElement.status = 'disabled';
- } else {
- this.filterModeStateElement.status = 'enabled';
- }
- }
- if(!_.isUndefined(this.filterModeStateElement)) {
- this.disableElement(this.filterModeStateElement.$element);
- }
- },
-
-
- _toggleRawFilterModeConfirmation: function(toggleFnc) {
- if( !this.isExperiencedMode()
- || this.parsedFilterMode === this.configModel.FILTER_MODE_ASSISTED
- ) {
- toggleFnc(true);
- } else {
- OC.dialogs.confirm(
- t('user_ldap', 'Switching the mode will enable automatic LDAP queries. Depending on your LDAP size they may take a while. Do you still want to switch the mode?'),
- t('user_ldap', 'Mode switch'),
- toggleFnc
- );
- }
- },
-
- _toggleRawFilterMode: function() {
- var view = this;
- this._toggleRawFilterModeConfirmation(function(isConfirmed) {
- if(!isConfirmed) {
- return;
- }
-
- var mode;
- if (view.parsedFilterMode === view.configModel.FILTER_MODE_ASSISTED) {
- mode = view.configModel.FILTER_MODE_RAW;
- } else {
- mode = view.configModel.FILTER_MODE_ASSISTED;
- }
- view.setFilterMode(mode);
-
- var saveInfo = {
- val: function () {
- return mode;
- },
- attr: function () {
- return view.filterModeKey;
- },
- is: function () {
- return false;
- }
- };
- view._requestSave(saveInfo);
- });
- },
-
-
- _initFilterModeSwitcher: function(
- $switcher,
- $filterModeRawContainer,
- filterModeDisableableElements,
- filterModeKey,
- filterModeStateElement
- ) {
- this.$filterModeRawContainer = $filterModeRawContainer;
- this.filterModeDisableableElements = filterModeDisableableElements;
- this.filterModeStateElement = filterModeStateElement;
- this.filterModeKey = filterModeKey;
- var view = this;
- $switcher.click(function() {
- if(view.isToggling) {
- return;
- }
- view.isToggling = true;
- view._toggleRawFilterMode();
- });
- },
- });
- OCA.LDAP.Wizard.WizardTabGeneric = WizardTabGeneric;
- })();
|