<commit_before>$(document).ready(function() {    
   
  //////////////////////////////
  //
  // Create Unit Assessment
  //
  //////////////////////////////


  $(document).on('click', '#create_map_assessment', function(e) {

    // var userId = $('#user-id').val();
    var mapId = $('#map-id').val();
    var actionUrl = $(this).attr('action-url');

    if( mapId == undefined || actionUrl == undefined) return false;

    // console.log("Adding assessment to Map: " + mapId + " owned by " + userId + " via path " + actionUrl);

    $.ajax({
        data: { 
            'map_id' : mapId
        },
        type: 'POST',
        url: actionUrl,
        dataType: 'html',
        success: function (response) {
            $('#maps_list_map_assessments').html(response);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            pushFlash({message:"Error adding a Map Assessment", state: 'error', fadeOut: 5000});
        }
    });

    e.stopPropagation();
  });

  //////////////////////////////
  //
  // Remove Unit Assessment to Map
  //
  //////////////////////////////


  $(document)
  .on('ajax:error', ".maps_map_assessments_destroy", function(event, data, status, xhr) {
    pushFlash({message:"Error deleting Map Assessment", state: 'error', fadeOut: 5000});
  })
  .on('ajax:success', ".maps_map_assessments_destroy", function(event, data, status, xhr) {
    $('#maps_list_map_assessments').html(data);
  });

  $(document)
  .on('ajax:error', ".maps_map_assessments_show_resources", function(event, data, status, xhr) {
    pushFlash({message:"Error fetching Map Assessment resources", state: 'error', fadeOut: 5000});
  })
  .on('ajax:success', ".maps_map_assessments_show_resources", function(event, data, status, xhr) {
    $('#filter_map_resources_modal').html(data);        
  });









  //////////////////////////////
  //
  // Filter Standards 
  //
  //////////////////////////////

  var timer;
  $(document).on('keyup input', '#filter_standards_search', function() {
    var form = $(this);
    // Prevents ajax request till N milliseconds 
    timer && clearTimeout(timer);
    timer = setTimeout(function(){ 
        form.submit();
    }, 500);
  });

  // Needed for browser compatibility 
  $(document).on('change', '#filter_standards_form', function() {
    $(this).submit();
  });

  $(document)
  .on('ajax:error', "#filter_standards_form", function(event, data, status, xhr) {
    pushFlash({message:"<%= I18n.t('resources.filter_failure') %>", state: 'success', fadeOut: 5000});
  })
  .on('ajax:success', "#filter_standards_form", function(event, data, status, xhr) {
    // Update the resources table
    $("#standards_table").html(data);  
  });



  //////////////////////////////
  //
  // Adding/Removing Map Standards
  //
  //////////////////////////////


  $(document).on('click', '#standards_list .standard-selected', function(e) {


    var standardId = $(this).attr('standard-id');
    var mapId = $('#map-id').val();
    if(standardId == undefined || mapId == undefined) return false;

    console.log("Removing Standard from Map: " + standardId + " From Map: " + mapId);

    var requestURL = '/ajax/maps/'+mapId+'/map_standards/'+standardId+'/destroy';

    $.ajax({
      url: requestURL,
      dataType: 'html'
    }).done(function(data) {
      console.log("Removed Standard from Map: " + standardId + " From Map: " + mapId);
      $('#map_standards_list').html(data);
    });   

    $(this).attr('class','standard-default');

    e.stopPropagation();
  });

  $(document).on('click', '#standards_list .standard-default', function(e) {
  
    var standardId = $(this).attr('standard-id');
    var mapId = $('#map-id').val();
    if(standardId == undefined || mapId == undefined) return false;

    console.log("Adding Standard from Map: " + standardId + " From Map: " + mapId);

    var requestURL = '/ajax/maps/'+mapId+'/map_standards/'+standardId+'/new';

    $.ajax({
      url: requestURL,
      dataType: 'html'
    }).done(function(data) {
      console.log("Added Standard from Map: " + standardId + " From Map: " + mapId);
      $('#map_standards_list').html(data);
    });   

    // Mark all children standards as selected
    $(this).find('.standard-default').each(function() {
        $(this).attr('class','standard-selected');
    });

    $(this).attr('class','standard-selected');

    e.stopPropagation();
  });



});<commit_msg>revised js in maps<commit_after>$(document).ready(function() {    
   
  //////////////////////////////
  //
  // Create Unit Assessment
  //
  //////////////////////////////

  $(document).on('click', '#create_map_assessment', function(e) {

    var mapId = $('#map-id').val();
    var actionUrl = $(this).attr('action-url');

    if( mapId == undefined || actionUrl == undefined) return false;

    $.ajax({
      data: { 'map_id' : mapId },
      type: 'POST',
      url: actionUrl,
      dataType: 'html',
      success: function (response) {
        $('#maps_list_map_assessments').html(response);
      },
      error: function (xhr, ajaxOptions, thrownError) {
        pushFlash({message:"Error adding a Map Assessment", state: 'error', fadeOut: 5000});
      }
    });

    e.stopPropagation();
  });

  //////////////////////////////
  //
  // Remove Unit Assessment to Map
  //
  //////////////////////////////

  $(document)
  .on('ajax:error', ".maps_map_assessments_destroy", function(event, data, status, xhr) {
    pushFlash({message:"Error deleting Map Assessment", state: 'error', fadeOut: 5000});
  })
  .on('ajax:success', ".maps_map_assessments_destroy", function(event, data, status, xhr) {
    $('#maps_list_map_assessments').html(data);
  });

  $(document)
  .on('ajax:error', ".maps_map_assessments_show_resources", function(event, data, status, xhr) {
    pushFlash({message:"Error fetching Map Assessment resources", state: 'error', fadeOut: 5000});
  })
  .on('ajax:success', ".maps_map_assessments_show_resources", function(event, data, status, xhr) {
    $('#filter_map_resources_modal').html(data);        
  });

  //////////////////////////////
  //
  // Filter Standards 
  //
  //////////////////////////////

  var timer;
  $(document).on('keyup input', '#filter_standards_search', function() {
    var form = $(this);
    // Prevents ajax request till N milliseconds 
    timer && clearTimeout(timer);
    timer = setTimeout(function(){ 
      form.submit();
    }, 500);
  });

  $(document).on('change', '#filter_standards_form', function() {
    $(this).submit();
  });

  $(document)
  .on('ajax:error', "#filter_standards_form", function(event, data, status, xhr) {
    pushFlash({message:"<%= I18n.t('resources.filter_failure') %>", state: 'success', fadeOut: 5000});
  })
  .on('ajax:success', "#filter_standards_form", function(event, data, status, xhr) {
    // Update the resources table
    $("#standards_table").html(data);  
  });

  //////////////////////////////
  //
  // Adding/Removing Map Standards
  //
  //////////////////////////////

  $(document).on('click', '#standards_list .standard-selected', function(e) {

    var standardId = $(this).attr('standard-id');
    var mapId = $('#map-id').val();
    var element = $(this);
    var actionUrl = '/ajax/maps/'+mapId+'/map_standards/'+standardId+'/destroy';
    if(standardId == undefined || mapId == undefined) return false;

    $.ajax({
      url: actionUrl,
      dataType: 'html',
      success: function (response) {
        $('#map_standards_list').html(response);
        element.attr('class','standard-default');
      },
      error: function (xhr, ajaxOptions, thrownError) {
        pushFlash({message:"Error adding a Map Assessment", state: 'error', fadeOut: 5000});
      }
    });

    e.stopPropagation();
  });

  $(document).on('click', '#standards_list .standard-default', function(e) {
  
    var standardId = $(this).attr('standard-id');
    var mapId = $('#map-id').val();
    var element = $(this);
    var actionUrl = '/ajax/maps/'+mapId+'/map_standards/'+standardId+'/new';
    if(standardId == undefined || mapId == undefined) return false;

    $.ajax({
      url: actionUrl,
      dataType: 'html',
      success: function (response) {
        $('#map_standards_list').html(response);

        // Mark all children standards as selected
        element.find('.standard-default').each(function() {
            element.attr('class','standard-selected');
        });

        element.attr('class','standard-selected');
      },
      error: function (xhr, ajaxOptions, thrownError) {
        pushFlash({message:"Error adding a Map Assessment", state: 'error', fadeOut: 5000});
      }
    }); 

    e.stopPropagation();

  });

});
{'fraction_non_alphanumeric': 0.22914989071666858, 'fraction_numerical': 0.005751754285056942, 'mean_word_length': 2.535583570557137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5430162', 'n_tokens_mistral': 2687, 'n_tokens_neox': 2549, 'n_words': 525}