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
|
|
|
// Fixes turbolinks issue with bootstrap select |
25
|
|
|
$(window).trigger('load.bs.select.data-api'); |
26
|
|
|
|
27
|
|
|
var copy = $('#copy'); |
28
|
|
|
|
29
|
|
|
// Handle copy button. |
30
|
|
|
copy.on('click', function(){ |
31
|
|
|
var inviteURL = $('#invite-url'); |
32
|
|
|
inviteURL.select(); |
33
|
|
|
|
34
|
|
|
var success = document.execCommand("copy"); |
35
|
|
|
if (success) { |
36
|
|
|
inviteURL.blur(); |
37
|
|
|
copy.addClass('btn-success'); |
38
|
|
|
copy.html("<i class='fas fa-check'></i>" + getLocalizedString("copied")) |
39
|
|
|
setTimeout(function(){ |
40
|
|
|
copy.removeClass('btn-success'); |
41
|
|
|
copy.html("<i class='fas fa-copy'></i>" + getLocalizedString("copy")) |
42
|
|
|
}, 2000) |
43
|
|
|
} |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
// Forces the wrapper to take the entire screen height if the user can't create rooms |
47
|
|
|
if ($("#cant-create-room-wrapper").length){ |
48
|
|
|
$(".wrapper").css('height', '100%').css('height', '-=130px'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Display and update all fields related to creating a room in the createRoomModal |
52
|
|
|
$("#create-room-block").click(function(){ |
53
|
|
|
showCreateRoom(this) |
54
|
|
|
}) |
55
|
|
|
|
56
|
|
|
// Display and update all fields related to creating a room in the createRoomModal |
57
|
|
|
$(".update-room").click(function(){ |
58
|
|
|
showUpdateRoom(this) |
59
|
|
|
}) |
60
|
|
|
|
61
|
|
|
$(".delete-room").click(function() { |
62
|
|
|
showDeleteRoom(this) |
63
|
|
|
}) |
64
|
|
|
|
65
|
|
|
$(".share-room").click(function() { |
66
|
|
|
// Update the path of save button |
67
|
|
|
$("#save-access").attr("data-path", $(this).data("path")) |
68
|
|
|
|
69
|
|
|
// Get list of users shared with and display them |
70
|
|
|
displaySharedUsers($(this).data("users-path")) |
71
|
|
|
}) |
72
|
|
|
|
73
|
|
|
$("#shareRoomModal").on("show.bs.modal", function() { |
74
|
|
|
$(".selectpicker").selectpicker('val','') |
75
|
|
|
}) |
76
|
|
|
|
77
|
|
|
$(".remove-share-room").click(function() { |
78
|
|
|
$("#remove-shared-confirm").parent().attr("action", $(this).data("path")) |
79
|
|
|
}) |
80
|
|
|
|
81
|
|
|
// User selects an option from the Room Access dropdown |
82
|
|
|
$(".bootstrap-select").on("changed.bs.select", function(){ |
83
|
|
|
// Get the uid of the selected user |
84
|
|
|
let uid = $(".selectpicker").selectpicker('val') |
85
|
|
|
|
86
|
|
|
// If the value was changed to blank, ignore it |
87
|
|
|
if (uid == "") return |
|
|
|
|
88
|
|
|
|
89
|
|
|
let currentListItems = $("#user-list li").toArray().map(user => $(user).data("uid")) |
90
|
|
|
|
91
|
|
|
// Check to make sure that the user is not already there |
92
|
|
|
if (!currentListItems.includes(uid)) { |
93
|
|
|
// Create the faded list item and display it |
94
|
|
|
let option = $("option[value='" + uid + "']") |
95
|
|
|
|
96
|
|
|
let listItem = document.createElement("li") |
97
|
|
|
listItem.setAttribute('class', 'list-group-item text-left not-saved add-access'); |
98
|
|
|
listItem.setAttribute("data-uid", uid) |
99
|
|
|
|
100
|
|
|
let spanItem = "<span class='avatar float-left mr-2'>" + option.text().charAt(0) + "</span> <span class='shared-user'>" + option.text() + " <span class='text-muted'>" + option.data("subtext") + "</span></span>" + "<span class='text-primary float-right shared-user cursor-pointer' onclick='removeSharedUser(this)'><i class='fas fa-times'></i></span>" |
101
|
|
|
|
102
|
|
|
listItem.innerHTML = spanItem |
103
|
|
|
|
104
|
|
|
$("#user-list").append(listItem) |
105
|
|
|
} |
106
|
|
|
}) |
107
|
|
|
} |
108
|
|
|
}); |
109
|
|
|
|
110
|
|
|
function showCreateRoom(target) { |
111
|
|
|
var modal = $(target) |
|
|
|
|
112
|
|
|
$("#create-room-name").val("") |
113
|
|
|
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder")) |
114
|
|
|
$("#room_access_code").val(null) |
115
|
|
|
|
116
|
|
|
$("#createRoomModal form").attr("action", $("body").data('relative-root')) |
117
|
|
|
$("#room_mute_on_join").prop("checked", false) |
118
|
|
|
$("#room_require_moderator_approval").prop("checked", false) |
119
|
|
|
$("#room_anyone_can_start").prop("checked", false) |
120
|
|
|
$("#room_all_join_moderator").prop("checked", false) |
121
|
|
|
|
122
|
|
|
//show all elements & their children with a create-only class |
123
|
|
|
$(".create-only").each(function() { |
124
|
|
|
$(this).show() |
125
|
|
|
if($(this).children().length > 0) { $(this).children().show() } |
126
|
|
|
}) |
127
|
|
|
|
128
|
|
|
//hide all elements & their children with a update-only class |
129
|
|
|
$(".update-only").each(function() { |
130
|
|
|
$(this).attr('style',"display:none !important") |
131
|
|
|
if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") } |
132
|
|
|
}) |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function showUpdateRoom(target) { |
136
|
|
|
var modal = $(target) |
137
|
|
|
var room_block_uid = modal.closest("#room-block").data("room-uid") |
138
|
|
|
$("#create-room-name").val(modal.closest("tbody").find("#room-name h4").text()) |
139
|
|
|
$("#createRoomModal form").attr("action", room_block_uid + "/update_settings") |
140
|
|
|
|
141
|
|
|
//show all elements & their children with a update-only class |
142
|
|
|
$(".update-only").each(function() { |
143
|
|
|
$(this).show() |
144
|
|
|
if($(this).children().length > 0) { $(this).children().show() } |
145
|
|
|
}) |
146
|
|
|
|
147
|
|
|
//hide all elements & their children with a create-only class |
148
|
|
|
$(".create-only").each(function() { |
149
|
|
|
$(this).attr('style',"display:none !important") |
150
|
|
|
if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") } |
151
|
|
|
}) |
152
|
|
|
|
153
|
|
|
updateCurrentSettings(modal.closest("#room-block").data("room-settings")) |
154
|
|
|
|
155
|
|
|
var accessCode = modal.closest("#room-block").data("room-access-code") |
156
|
|
|
|
157
|
|
|
if(accessCode){ |
158
|
|
|
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode) |
159
|
|
|
$("#room_access_code").val(accessCode) |
160
|
|
|
} else { |
161
|
|
|
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder")) |
162
|
|
|
$("#room_access_code").val(null) |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
function showDeleteRoom(target) { |
167
|
|
|
$("#delete-header").text(getLocalizedString("modal.delete_room.confirm").replace("%{room}", $(target).data("name"))) |
168
|
|
|
$("#delete-confirm").parent().attr("action", $(target).data("path")) |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
//Update the createRoomModal to show the correct current settings |
172
|
|
|
function updateCurrentSettings(settings){ |
173
|
|
|
//set checkbox |
174
|
|
|
$("#room_mute_on_join").prop("checked", settings.muteOnStart) |
175
|
|
|
$("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval) |
176
|
|
|
$("#room_anyone_can_start").prop("checked", settings.anyoneCanStart) |
177
|
|
|
$("#room_all_join_moderator").prop("checked", settings.joinModerator) |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
function generateAccessCode(){ |
181
|
|
|
const accessCodeLength = 6 |
182
|
|
|
var validCharacters = "0123456789" |
183
|
|
|
var accessCode = "" |
184
|
|
|
|
185
|
|
|
for( var i = 0; i < accessCodeLength; i++){ |
186
|
|
|
accessCode += validCharacters.charAt(Math.floor(Math.random() * validCharacters.length)); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode) |
190
|
|
|
$("#room_access_code").val(accessCode) |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
function ResetAccessCode(){ |
194
|
|
|
$("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder")) |
195
|
|
|
$("#room_access_code").val(null) |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
function saveAccessChanges() { |
199
|
|
|
let listItemsToAdd = $("#user-list li").toArray().map(user => $(user).data("uid")) |
200
|
|
|
|
201
|
|
|
$.post($("#save-access").data("path"), {add: listItemsToAdd}) |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// Get list of users shared with and display them |
205
|
|
|
function displaySharedUsers(path) { |
206
|
|
|
$.get(path, function(users) { |
207
|
|
|
// Create list element and add to user list |
208
|
|
|
var user_list_html = "" |
209
|
|
|
|
210
|
|
|
users.forEach(function(user) { |
211
|
|
|
user_list_html += "<li class='list-group-item text-left' data-uid='" + user.uid + "'>" |
212
|
|
|
|
213
|
|
|
if (user.image) { |
214
|
|
|
user_list_html += "<img id='user-image' class='avatar float-left mr-2' src='" + user.image + "'></img>" |
215
|
|
|
} else { |
216
|
|
|
user_list_html += "<span class='avatar float-left mr-2'>" + user.name.charAt(0) + "</span>" |
217
|
|
|
} |
218
|
|
|
user_list_html += "<span class='shared-user'>" + user.name + "<span class='text-muted ml-1'>" + user.email + "</span></span>" |
219
|
|
|
user_list_html += "<span class='text-primary float-right shared-user cursor-pointer' onclick='removeSharedUser(this)'><i class='fas fa-times'></i></span>" |
220
|
|
|
user_list_html += "</li>" |
221
|
|
|
}) |
222
|
|
|
|
223
|
|
|
$("#user-list").html(user_list_html) |
224
|
|
|
}); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
// Removes the user from the list of shared users |
228
|
|
|
function removeSharedUser(target) { |
229
|
|
|
let parentLI = target.closest("li") |
230
|
|
|
|
231
|
|
|
parentLI.parentNode.removeChild(parentLI) |
232
|
|
|
} |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.