// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-ui/effect.all

//= require_tree ./global
//= require close_messages

function page_before() {
    $('#offset').val(parseInt($('#offset').val()) - parseInt($('#amount').val()));
    $('#pagination').submit();
}

function page_after() {
    $('#offset').val(parseInt($('#offset').val()) + parseInt($('#amount').val()));
    $('#pagination').submit();
}

$(document).on('change', '.prevent-submit', function() {
    let has_selected_file = $(this).filter(function(){
        return $.trim(this.value) != ''
    }).length  > 0 ;

    let submitButton = $(this).closest('form').find('input[type=submit]');

    if (has_selected_file) {
        submitButton.prop('disabled', false);
        submitButton.addClass('ready');
    } else {
        submitButton.prop('disabled', true);
        submitButton.removeClass('ready');
    }
});

// $(function() {
//   $('[data-remote][data-replace]')
//     .data('type', 'html')
//     .live('ajax:success', function(event, data) {
//       var $this = $(this);
//       $($this.data('replace')).html(data);
//       $this.trigger('ajax:replaced');
//     });
// });
