Added filter for user role (#540)

This commit is contained in:
farhatahmad
2019-05-22 13:39:34 -04:00
committed by Jesus Federico
parent eac8290001
commit 996518eea7
9 changed files with 165 additions and 36 deletions

View File

@ -31,8 +31,21 @@ $(document).on('turbolinks:load', function(){
$("#delete-confirm").parent().attr("action", url)
})
/* COLOR SELECTORS */
//clear the role filter if user clicks on the x
$(".clear-role").click(function(data) {
search = new URL(location.href).searchParams.get('search')
url = window.location.pathname + "?page=1"
if (search) {
url += "&search=" + search
}
window.location.replace(url);
})
/* COLOR SELECTORS */
$('#colorinput-regular').ColorPicker({
onBeforeShow: function () {
var colour = rgb2hex($("#colorinput-regular").css("background-color"))
@ -93,6 +106,19 @@ function changeBrandingImage(path) {
$.post(path, {url: url})
}
// Filters by role
function filterRole(role) {
search = new URL(location.href).searchParams.get('search')
url = window.location.pathname + "?page=1" + "&role=" + role
if (search) {
url += "&search=" + search
}
window.location.replace(url);
}
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
@ -100,3 +126,4 @@ function rgb2hex(rgb) {
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

View File

@ -77,10 +77,19 @@ function searchPage() {
var controller = $("body").data('controller');
var action = $("body").data('action');
// Check if the user filtered by role
role = new URL(location.href).searchParams.get('role')
url = window.location.pathname + "?page=1&search=" + search
if (role) {
url += "&role=" + role
}
if(controller === "rooms" && action === "show"){
window.location.replace(window.location.pathname + "?page=1&search=" + search + "#recordings-table");
window.location.replace(url + "#recordings-table");
} else{
window.location.replace(window.location.pathname + "?page=1&search=" + search);
window.location.replace(url);
}
}
@ -90,9 +99,17 @@ function clearSearch() {
var controller = $("body").data('controller');
var action = $("body").data('action');
role = new URL(location.href).searchParams.get('role')
url = window.location.pathname + "?page=1"
if (role) {
url += "&role=" + role
}
if(controller === "rooms" && action === "show"){
window.location.replace(window.location.pathname + "?page=1" + "#recordings-table");
window.location.replace(url + "#recordings-table");
} else{
window.location.replace(window.location.pathname + "?page=1");
window.location.replace(url);
}
}