forked from External/greenlight
		
	Improve code style based on scrutinizer ci (#337)
* <fixed settingsJs and sortJs> * <Fixed searchJs, renameJs and renameJs> * <Fixed renameJs>
This commit is contained in:
		@@ -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
 | 
			
		||||
@@ -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(); });
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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",
 | 
			
		||||
@@ -186,7 +165,7 @@ $(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,
 | 
			
		||||
@@ -194,5 +173,25 @@ $(document).on('turbolinks:load', function(){
 | 
			
		||||
        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);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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())){
 | 
			
		||||
@@ -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{
 | 
			
		||||
 
 | 
			
		||||
@@ -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(); }
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
@@ -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');
 | 
			
		||||
@@ -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");
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user