nextcloud/settings/js/users/filter.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-04-02 23:48:35 +04:00
/**
* 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.
*/
/**
2014-04-16 21:41:09 +04:00
* @brief this object takes care of the filter functionality on the user
2014-04-03 00:00:25 +04:00
* management page
* @param {UserList} userList the UserList object
* @param {GroupList} groupList the GroupList object
2014-04-02 23:48:35 +04:00
*/
function UserManagementFilter (userList, groupList) {
2014-04-02 23:48:35 +04:00
this.userList = userList;
2014-04-15 02:13:23 +04:00
this.groupList = groupList;
this.oldFilter = '';
2014-04-02 23:48:35 +04:00
this.init();
}
2014-04-03 00:00:25 +04:00
/**
* @brief sets up when the filter action shall be triggered
*/
UserManagementFilter.prototype.init = function () {
OC.Plugins.register('OCA.Search', this);
2014-04-16 21:41:09 +04:00
};
2014-04-02 23:48:35 +04:00
2014-04-03 00:00:25 +04:00
/**
* @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
);
2014-04-02 23:48:35 +04:00
2014-04-03 00:00:25 +04:00
/**
* @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;
2014-04-16 21:41:09 +04:00
};
2014-04-18 00:14:04 +04:00
/**
* @brief adds reset functionality to an HTML element
* @param jQuery the jQuery representation of that element
*/
UserManagementFilter.prototype.addResetButton = function (button) {
2014-04-18 00:14:04 +04:00
var umf = this;
button.click(function () {
2014-04-18 00:14:04 +04:00
umf.filterInput.val('');
umf.run();
});
};
UserManagementFilter.prototype.attach = function (search) {
search.setFilter('settings', this.run.bind(this));
};