summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/js/experiencedAdmin.js
blob: fac8dd6470f712ab9c70e493d034d982fdcddf3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * Copyright (c) 2014, Arthur Schiwon <blizzz@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

/* global LdapWizard */

/**
 * controls behaviour depend on whether the admin is experienced in LDAP or not.
 *
 * @class
 * @param {object} wizard the LDAP Wizard object
 * @param {boolean} initialState whether the admin is experienced or not
 */
function ExperiencedAdmin(wizard, initialState) {
	this.wizard = wizard;
	this._isExperienced = initialState;
	if(this._isExperienced) {
		this.hideEntryCounters();
	}
}


/**
 * toggles whether the admin is an experienced one or not
 *
 * @param {boolean} whether the admin is experienced or not
 */
ExperiencedAdmin.prototype.setExperienced = function(isExperienced) {
	this._isExperienced = isExperienced;
	if(this._isExperienced) {
		this.enableRawMode();
		this.hideEntryCounters();
	} else {
		this.showEntryCounters();
	}
};

/**
* answers whether the admin is an experienced one or not
*
* @return {boolean} whether the admin is experienced or not
*/
ExperiencedAdmin.prototype.isExperienced = function() {
	return this._isExperienced;
};

/**
 * switches all LDAP filters from Assisted to Raw mode.
 */
ExperiencedAdmin.prototype.enableRawMode = function() {
	var containers = {
		'toggleRawGroupFilter': '#rawGroupFilterContainer',
		'toggleRawLoginFilter': '#rawLoginFilterContainer',
		'toggleRawUserFilter' : '#rawUserFilterContainer'
	};

	for(var method in containers) {
		if($(containers[method]).hasClass('invisible')) {
			this.wizard[method]();
		}
	}
};

ExperiencedAdmin.prototype.updateUserTab = function(mode) {
	this._updateTab(mode, $('#ldap_user_count'));
};

ExperiencedAdmin.prototype.updateGroupTab = function(mode) {
	this._updateTab(mode, $('#ldap_group_count'));
};

ExperiencedAdmin.prototype._updateTab = function(mode, $countEl) {
	if(mode === LdapWizard.filterModeAssisted) {
		$countEl.removeClass('hidden');
	} else if(!this._isExperienced) {
		$countEl.removeClass('hidden');
	} else {
		$countEl.addClass('hidden');
	}
};

/**
 * hide user and group counters, they will be displayed on demand only
 */
ExperiencedAdmin.prototype.hideEntryCounters = function() {
	$('#ldap_user_count').addClass('hidden');
	$('#ldap_group_count').addClass('hidden');
	$('.ldapGetEntryCount').removeClass('hidden');
};

/**
* shows user and group counters, they will be displayed on demand only
*/
ExperiencedAdmin.prototype.showEntryCounters = function() {
	$('#ldap_user_count').removeClass('hidden');
	$('#ldap_group_count').removeClass('hidden');
	$('.ldapGetEntryCount').addClass('hidden');
};