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
|
2014-04-02 23:48:35 +04:00
|
|
|
* @param jQuery input element that works as the user text input field
|
2014-04-03 00:00:25 +04:00
|
|
|
* @param object the UserList object
|
2014-04-02 23:48:35 +04:00
|
|
|
*/
|
2014-04-15 02:13:23 +04:00
|
|
|
function UserManagementFilter(filterInput, userList, groupList) {
|
2014-04-02 23:48:35 +04:00
|
|
|
this.filterInput = filterInput;
|
|
|
|
this.userList = userList;
|
2014-04-15 02:13:23 +04:00
|
|
|
this.groupList = groupList;
|
2014-04-02 23:48:35 +04:00
|
|
|
this.thread = undefined;
|
2014-04-03 20:46:16 +04:00
|
|
|
this.oldval = this.filterInput.val();
|
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
|
|
|
|
*/
|
2014-04-02 23:48:35 +04:00
|
|
|
UserManagementFilter.prototype.init = function() {
|
2014-04-16 21:41:09 +04:00
|
|
|
var umf = this;
|
2014-04-03 20:46:16 +04:00
|
|
|
this.filterInput.keyup(function(e) {
|
2014-04-16 21:41:09 +04:00
|
|
|
//we want to react on any printable letter, plus on modifying stuff like
|
2014-04-03 20:46:16 +04:00
|
|
|
//Backspace and Delete. extended https://stackoverflow.com/a/12467610
|
|
|
|
var valid =
|
|
|
|
e.keyCode === 0 || e.keyCode === 8 || // like ö or ж; backspace
|
|
|
|
e.keyCode === 9 || e.keyCode === 46 || // tab; delete
|
|
|
|
e.keyCode === 32 || // space
|
|
|
|
(e.keyCode > 47 && e.keyCode < 58) || // number keys
|
|
|
|
(e.keyCode > 64 && e.keyCode < 91) || // letter keys
|
|
|
|
(e.keyCode > 95 && e.keyCode < 112) || // numpad keys
|
|
|
|
(e.keyCode > 185 && e.keyCode < 193) || // ;=,-./` (in order)
|
|
|
|
(e.keyCode > 218 && e.keyCode < 223); // [\]' (in order)
|
|
|
|
|
|
|
|
//besides the keys, the value must have been changed compared to last
|
|
|
|
//time
|
|
|
|
if(valid && umf.oldVal !== umf.getPattern()) {
|
|
|
|
clearTimeout(umf.thread);
|
|
|
|
umf.thread = setTimeout(
|
|
|
|
function() {
|
|
|
|
umf.run();
|
|
|
|
},
|
|
|
|
300
|
|
|
|
);
|
|
|
|
}
|
|
|
|
umf.oldVal = umf.getPattern();
|
2014-04-02 23:48:35 +04:00
|
|
|
});
|
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
|
|
|
|
*/
|
2014-04-02 23:48:35 +04:00
|
|
|
UserManagementFilter.prototype.run = function() {
|
|
|
|
this.userList.empty();
|
2014-04-17 23:40:28 +04:00
|
|
|
this.userList.update(GroupList.getCurrentGID());
|
2014-04-15 02:13:23 +04:00
|
|
|
this.groupList.empty();
|
|
|
|
this.groupList.update();
|
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 returns the filter String
|
|
|
|
* @returns string
|
|
|
|
*/
|
2014-04-02 23:48:35 +04:00
|
|
|
UserManagementFilter.prototype.getPattern = function() {
|
|
|
|
return this.filterInput.val();
|
2014-04-16 21:41:09 +04:00
|
|
|
};
|