Issues (40)

app/assets/javascripts/search.js (2 issues)

1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
$(document).on('turbolinks:load', function(){
18
  var controller = $("body").data('controller');
19
  var action = $("body").data('action');
20
21
  if ((controller == "admins" && action == "index") || 
22
      (controller == "rooms" && action == "show") || 
23
      (controller == "rooms" && action == "update") ||
24
      (controller == "rooms" && action == "join") || 
25
      (controller == "users" && action == "recordings") ||
26
      (controller == "admins" && action == "server_recordings") ||
27
      (controller == "admins" && action == "server_rooms")) {
28
    // Submit search if the user hits enter
29
    $("#search-input").keypress(function(key) {
30
      if (key.which == 13) {
31
        searchPage()
32
      }
33
    })
34
35
    // Add listeners for sort
36
    $("th[data-order]").click(function(data){
37
      var header_elem = $(data.target)
38
39
      if(header_elem.data('order') === 'asc'){ // asc
40
        header_elem.data('order', 'desc');
41
      }
42
      else if(header_elem.data('order') === 'desc'){ // desc
43
        header_elem.data('order', 'none');
44
      }
45
      else{ // none
46
        header_elem.data('order', 'asc');
47
      }
48
49
      var search = $("#search-input").val();
50
51
      var url = window.location.pathname + "?page=1&search=" + search + "&column=" + header_elem.data("header") +
52
       "&direction=" + header_elem.data('order')
53
54
      window.location.replace(addRecordingTable(url))
55
    })
56
57
    if(controller === "rooms" && action === "show"){
58
      $(".page-item > a").each(function(){
59
        if(!$(this).attr('href').endsWith("#")){
60
          $(this).attr('href', $(this).attr('href') + "#recordings-table")
61
        }
62
      })
63
    }
64
  }
65
})
66
67
// Searches the user table for the given string
68
function searchPage() {
69
  var search = $("#search-input").val();
70
71
  // Check if the user filtered by role
72
  var role = new URL(location.href).searchParams.get('role')
73
  var tab = new URL(location.href).searchParams.get('tab')
74
75
  var url = window.location.pathname + "?page=1&search=" + search
76
77
  if (role) { url += "&role=" + role } 
78
  if (tab) { url += "&tab=" + tab } 
79
80
  window.location.replace(addRecordingTable(url));
81
}
82
83
// Clears the search bar
84
function clearSearch() {
85
  var role = new URL(location.href).searchParams.get('role')
86
  var tab = new URL(location.href).searchParams.get('tab')
87
88
  var url = window.location.pathname + "?page=1"
89
90
  if (role) { url += "&role=" + role } 
91
  if (tab) { url += "&tab=" + tab } 
92
  
93
  window.location.replace(addRecordingTable(url));
94
95
  var search_params = new URLSearchParams(window.location.search)
0 ignored issues
show
The variable URLSearchParams seems to be never declared. If this is a global, consider adding a /** global: URLSearchParams */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
The variable search_params seems to be never used. Consider removing it.
Loading history...
96
}
97
98
function addRecordingTable(url) {
99
  if($("body").data('controller') === "rooms" && $("body").data('action') === "show") { 
100
    url += "#recordings-table"
101
  }
102
  return url
103
}
104