summaryrefslogtreecommitdiffstats
path: root/settings/js/users/filter.js
blob: 339d6ad5ec7ffe0ac3a506897ebd61a190768488 (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
/**
 * 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.
 */

/**
 * @brief this object takes care of the filter functionality on the user
 * management page
 * @param {UserList} userList the UserList object
 * @param {GroupList} groupList the GroupList object
 */
function UserManagementFilter (userList, groupList) {
	this.userList = userList;
	this.groupList = groupList;
	this.oldFilter = '';

	this.init();
}

/**
 * @brief sets up when the filter action shall be triggered
 */
UserManagementFilter.prototype.init = function () {
	OC.Plugins.register('OCA.Search', this);
};

/**
 * @brief the filter action needs to be done, here the accurate steps are being
 * taken care of
 */
UserManagementFilter.prototype.run = _.debounce(function (filter) {
		if (filter === this.oldFilter) {
			return;
		}
		this.oldFilter = filter;
		this.userList.filter = filter;
		this.userList.empty();
		this.userList.update(GroupList.getCurrentGID());
		if (this.groupList.filterGroups) {
			// user counts are being updated nevertheless
			this.groupList.empty();
		}
		this.groupList.update();
	},
	300
);

/**
 * @brief returns the filter String
 * @returns string
 */
UserManagementFilter.prototype.getPattern = function () {
	var input = this.filterInput.val(),
		html = $('html'),
		isIE8or9 = html.hasClass('lte9');
	// FIXME - TODO - once support for IE8 and IE9 is dropped
	if (isIE8or9 && input == this.filterInput.attr('placeholder')) {
		input = '';
	}
	return input;
};

/**
 * @brief adds reset functionality to an HTML element
 * @param jQuery the jQuery representation of that element
 */
UserManagementFilter.prototype.addResetButton = function (button) {
	var umf = this;
	button.click(function () {
		umf.filterInput.val('');
		umf.run();
	});
};

UserManagementFilter.prototype.attach = function (search) {
	search.setFilter('settings', this.run.bind(this));
};