GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( ec4722...b2f2e7 )
by Jesus
04:24 queued 10s
created

room.js ➔ showCreateRoom   D

Complexity

Conditions 13

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
c 0
b 0
f 0
dl 0
loc 23
rs 4.2
eloc 15

How to fix   Complexity   

Complexity

Complex classes like room.js ➔ showCreateRoom often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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
// Room specific js for copy button and email link.
18
$(document).on('turbolinks:load', function(){
19
  var controller = $("body").data('controller');
20
  var action = $("body").data('action');
21
22
  // Only run on room pages.
23
  if (controller == "rooms" && action == "show"){
24
    var copy = $('#copy');
25
26
    // Handle copy button.
27
    copy.on('click', function(){
28
      var inviteURL = $('#invite-url');
29
      inviteURL.select();
30
31
      var success = document.execCommand("copy");
32
      if (success) {
33
        inviteURL.blur();
34
        copy.addClass('btn-success');
35
        copy.html("<i class='fas fa-check'></i>" + getLocalizedString("copied"))
36
        setTimeout(function(){
37
          copy.removeClass('btn-success');
38
          copy.html("<i class='fas fa-copy'></i>" + getLocalizedString("copy"))
39
        }, 2000)
40
      }
41
    });
42
43
    // Forces the wrapper to take the entire screen height if the user can't create rooms
44
    if ($("#cant-create-room-wrapper").length){
45
      $(".wrapper").css('height', '100%').css('height', '-=130px');
46
    }
47
48
    // Display and update all fields related to creating a room in the createRoomModal
49
    $("#create-room-block").click(function(){
50
      showCreateRoom()
51
    })
52
53
    // Display and update all fields related to creating a room in the createRoomModal
54
    $(".update-room").click(function(){
55
      showUpdateRoom()
56
    })
57
  }
58
});
59
60
function showCreateRoom() {
61
  $("#create-room-name").val("")
62
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
63
  $("#room_access_code").val(null)
64
65
  $("#createRoomModal form").attr("action", $("body").data('relative-root'))
66
  $("#room_mute_on_join").prop("checked", false)
67
  $("#room_require_moderator_approval").prop("checked", false)
68
  $("#room_anyone_can_start").prop("checked", false)
69
  $("#room_all_join_moderator").prop("checked", false)
70
71
  //show all elements & their children with a create-only class
72
  $(".create-only").each(function() {
73
    $(this).show()
74
    if($(this).children().length > 0) { $(this).children().show() }
75
  })
76
77
  //hide all elements & their children with a update-only class
78
  $(".update-only").each(function() {
79
    $(this).attr('style',"display:none !important")
80
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
81
  })
82
}
83
84
function showUpdateRoom() {
85
  var room_block_uid = $(this).closest("#room-block").data("room-uid")
86
  $("#create-room-name").val($(this).closest("tbody").find("#room-name h4").text())
87
  $("#createRoomModal form").attr("action", room_block_uid + "/update_settings")
88
89
  //show all elements & their children with a update-only class
90
  $(".update-only").each(function() {
91
    $(this).show()
92
    if($(this).children().length > 0) { $(this).children().show() }
93
  })
94
95
  //hide all elements & their children with a create-only class
96
  $(".create-only").each(function() {
97
    $(this).attr('style',"display:none !important")
98
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
99
  })
100
101
  updateCurrentSettings($(this).closest("#room-block").data("room-settings"))
102
  
103
  var accessCode = $(this).closest("#room-block").data("room-access-code")
104
105
  if(accessCode){
106
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
107
    $("#room_access_code").val(accessCode)
108
  } else {
109
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
110
    $("#room_access_code").val(null)
111
  }
112
}
113
114
//Update the createRoomModal to show the correct current settings
115
function updateCurrentSettings(settings){
116
  //set checkbox
117
  $("#room_mute_on_join").prop("checked", settings.muteOnStart)
118
  $("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval)
119
  $("#room_anyone_can_start").prop("checked", settings.anyoneCanStart)
120
  $("#room_all_join_moderator").prop("checked", settings.joinModerator)
121
}
122
123
function generateAccessCode(){
124
  const accessCodeLength = 6
125
  var validCharacters = "0123456789"
126
  var accessCode = ""
127
128
  for( var i = 0; i < accessCodeLength; i++){
129
    accessCode += validCharacters.charAt(Math.floor(Math.random() * validCharacters.length));
130
  }
131
132
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
133
  $("#room_access_code").val(accessCode)
134
}
135
136
function ResetAccessCode(){
137
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
138
  $("#room_access_code").val(null)
139
}
140