Skip to content

Commit

Permalink
Improve code style based on scrutinizer ci (bigbluebutton#337)
Browse files Browse the repository at this point in the history
* <fixed settingsJs and sortJs>

* <Fixed searchJs, renameJs and renameJs>

* <Fixed renameJs>
  • Loading branch information
jiama843 authored and jfederico committed Dec 21, 2018
1 parent 8cdbf1d commit e3389c8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
53 changes: 26 additions & 27 deletions app/assets/javascripts/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,8 @@ $(document).on('turbolinks:load', function(){

if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){

// Elements that can be renamed
var room_title = $('#room-title');
var room_blocks = $('#room_block_container').find('a');
var recording_rows = $('#recording-table').find('tr');

// Configure renaming for room header
configure_room_header(room_title);

// Configure renaming for room blocks
room_blocks.each(function(){
var room_block = $(this)
configure_room_block(room_block)
});

// Configure renaming for recording rows
recording_rows.each(function(){
var recording_title = $(this).find('#recording-title');
configure_recording_row(recording_title);
});

// Set a room block rename event
function configure_room_block(room_block){
var configure_room_block = function(room_block){
if(!room_block.is('#home_room_block')){

// Register a click event on each room_block rename dropdown
Expand All @@ -50,7 +30,6 @@ $(document).on('turbolinks:load', function(){
room_block.find('#room-name-editable-input').on('focusout', function(){
submit_rename_request(room_block.find('.card'));
$(window).off('mousedown keydown');
return;
});

room_block.click(function(linkEvent) { linkEvent.preventDefault(); });
Expand All @@ -67,7 +46,7 @@ $(document).on('turbolinks:load', function(){
}

// Set a room header rename event
function configure_room_header(room_title){
var configure_room_header = function(room_title){

function register_room_title_event(e){
// Remove current window events
Expand Down Expand Up @@ -101,7 +80,7 @@ $(document).on('turbolinks:load', function(){
}

// Set a recording row rename event
function configure_recording_row(recording_title){
var configure_recording_row = function(recording_title){

function register_recording_title_event(e){
// Remove current window events
Expand Down Expand Up @@ -134,7 +113,7 @@ $(document).on('turbolinks:load', function(){

// Register window event to submit new name
// upon click or upon pressing the enter key
function register_window_event(element, textfield_id, edit_button_id, edit_button_data){
var register_window_event = function(element, textfield_id, edit_button_id, edit_button_data){
$(window).on('mousedown keydown', function(clickEvent){

// Return if the text is clicked
Expand Down Expand Up @@ -162,7 +141,7 @@ $(document).on('turbolinks:load', function(){
}

// Apply ajax request depending on the element that triggered the event
function submit_rename_request(element){
var submit_rename_request = function(element){
if(element.data('room-uid')){
submit_update_request({
setting: "rename_block",
Expand All @@ -186,13 +165,33 @@ $(document).on('turbolinks:load', function(){
}

// Helper for submitting ajax requests
function submit_update_request(data){
var submit_update_request = function(data){
// Send ajax request for update
$.ajax({
url: window.location.pathname,
type: "PATCH",
data: data,
});
}

// Elements that can be renamed
var room_title = $('#room-title');
var room_blocks = $('#room_block_container').find('a');
var recording_rows = $('#recording-table').find('tr');

// Configure renaming for room header
configure_room_header(room_title);

// Configure renaming for room blocks
room_blocks.each(function(){
var room_block = $(this)
configure_room_block(room_block)
});

// Configure renaming for recording rows
recording_rows.each(function(){
var recording_title = $(this).find('#recording-title');
configure_recording_row(recording_title);
});
}
});
1 change: 0 additions & 1 deletion app/assets/javascripts/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ $(document).on('turbolinks:load', function(){

// Only run on room pages.
if (controller == "rooms" && action == "show"){
var invite_url;
var copy = $('#copy');

// Handle copy button.
Expand Down
10 changes: 5 additions & 5 deletions app/assets/javascripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ $(document).on('turbolinks:load', function(){
var action = $("body").data('action');

if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){
search_input = $('#search_bar');
var search_input = $('#search_bar');

search_input.bind("keyup", function(event){
search_input.bind("keyup", function(){

// Retrieve the current search query
search_query = search_input.find(".form-control").val();
var search_query = search_input.find(".form-control").val();

//Search for recordings and display them based on name match
var recordings_found = 0;

recordings = $('#recording-table').find('tr');
var recordings = $('#recording-table').find('tr');

recordings.each(function(){
if($(this).find('text').text().toLowerCase().includes(search_query.toLowerCase())){
Expand All @@ -42,7 +42,7 @@ $(document).on('turbolinks:load', function(){
});

// Show "No recordings match your search" if no recordings found
if(recordings_found == 0){
if(recordings_found === 0){
$('#no_recordings_found').show();
}
else{
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $(document).on('turbolinks:load', function(){

// Only run on the settings page.
if ((controller == "users" && action == "edit") || (controller == "users" && action == "update")){
settingsButtons = $('.setting-btn');
settingsViews = $('.setting-view');
var settingsButtons = $('.setting-btn');
var settingsViews = $('.setting-view');

settingsButtons.each(function(i, btn) {
if(!$(btn).hasClass("active")){ $(settingsViews[i]).hide(); }
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $(document).on('turbolinks:load', function(){

// Based on the header (Name, Length or Users) clicked,
// Modify the ui for the tables
function set_active_header(active_header){
var set_active_header = function(active_header){
$('th').each(function(){
if($(this).data("header") == active_header){
configure_order($(this));
Expand All @@ -47,7 +47,7 @@ $(document).on('turbolinks:load', function(){

// Based on the header (Name, Length or Users) clicked,
// Modify the ui for the tables
function configure_order(header_elem){
var configure_order = function(header_elem){
if(header_elem.data('order') === 'asc'){ // asc
header_elem.text(header_elem.data("header") + " ↓");
header_elem.data('order', 'desc');
Expand All @@ -64,7 +64,7 @@ $(document).on('turbolinks:load', function(){

// Given a label and an order, sort recordings by order
// under a given label
function sort_by(label, order){
var sort_by = function(label, order){
var recording_list_tbody = $('.table-responsive').find('tbody');
if(label === "Name"){
sort_recordings(recording_list_tbody, order, "#recording-title");
Expand All @@ -78,10 +78,10 @@ $(document).on('turbolinks:load', function(){
}

// Generalized function for sorting recordings
function sort_recordings(recording_list_tbody, order, recording_id){
var sort_recordings = function(recording_list_tbody, order, recording_id){
recording_list_tbody.find('tr').sort(function(a, b){
a_val = $.trim($(a).find(recording_id).text());
b_val = $.trim($(b).find(recording_id).text());
var a_val = $.trim($(a).find(recording_id).text());
var b_val = $.trim($(b).find(recording_id).text());

if(order === "asc"){
return a_val.localeCompare(b_val);
Expand Down

0 comments on commit e3389c8

Please sign in to comment.