<commit_before>/**
 * Autocomplete handler for institution specialization selector
 * 
 * @author allejochrisvelarde
 */

var InstitutionSpecialization = {
        
    _processing: 'Processing...',
    
    specializationsListContainer: null,
        
    setSpecializationsListContainerElement: function (_element) {
        this.specializationsListContainer = _element;
        
        return this;
    },
        
    removeTreatment: function(_linkElement, _container) {
        if (_linkElement.hasClass('disabled')) {
            return false;
        }
        _href = _linkElement.attr('href');
        _html = _linkElement.html();
        _linkElement.html('Processing...').addClass('disabled');
        
        $.ajax({
            url: _href,
            type: 'POST',
            success: function(response) {
                _linkElement.parents('tr').remove();
            },
            error: function(response) {
                console.log(response);
            }
        });
        
        return false;
    },
    
    showAddTreatmentsForm: function(_linkElement) {
        _linkElement = $(_linkElement);
        _modal = $(_linkElement.attr('data-target'));
        _modal.modal('show');
        _modal.find('.ajax_loader').show();
        $.ajax({
           url: _linkElement.attr('href'),
           type: 'GET',
           dataType: 'json',
           success: function(response) {
               _modal.find('.ajax_loader').hide();
               _modal.find('div.ajax_content_container').html(response.html);
               _modal.find('button.submit_button').attr('disabled', false);
           },
           error: function(response) {
               _modal.find('.ajax_loader').hide();
               _modal.find('ajax_content_container').html('Failed loading treatments.');
               console.log(response);
           }
        });
    },
    
    submitAddTreatmentsForm: function(_buttonElement) {
        _el = $(_buttonElement);
        _modal = _el.parents('div.add_treatments_modal');
        _form = _modal.find('form.add_treatments_form');
        _html = _el.html();
        _el.html(this._processing).attr('disabled', true);
        $.ajax({
            url: _form.attr('action'),
            data: _form.serialize(),
            type: 'POST',
            dataType: 'json',
            success: function (response) {
                _modal.find('div.ajax_content_container').html('');
                _modal.find('.ajax_loader').hide();
                
                // replace the treatments list
                _modal.parents('div.specializations_block').find('.institution_specialization_treatments_container').html(response.html);
                _modal.modal('hide');
            },<commit_msg>Fixes #142<commit_after>/**
 * Autocomplete handler for institution specialization selector
 * 
 * @author allejochrisvelarde
 */

var InstitutionSpecialization = {
        
    _processing: 'Processing...',
    
    specializationsListContainer: null,
        
    setSpecializationsListContainerElement: function (_element) {
        this.specializationsListContainer = _element;
        
        return this;
    },
        
    removeTreatment: function(_linkElement, _container) {
        if (_linkElement.hasClass('disabled')) {
            return false;
        }
        _href = _linkElement.attr('href');
        _html = _linkElement.html();
        _linkElement.html('Processing...').addClass('disabled');
        
        $.ajax({
            url: _href,
            type: 'POST',
            success: function(response) {
                _linkElement.parents('tr').remove();
            },
            error: function(response) {
                console.log(response);
            }
        });
        
        return false;
    },
    
    showAddTreatmentsForm: function(_linkElement) {
        _linkElement = $(_linkElement);
        _modal = $(_linkElement.attr('data-target'));
        _modal.modal('show');
        _modal.find('.ajax_loader').show();
        $('.ajax_content_container').hide();
        $.ajax({
           url: _linkElement.attr('href'),
           type: 'GET',
           dataType: 'json',
           success: function(response) {
               _modal.find('.ajax_loader').hide();
               $('.ajax_content_container').show();
               _modal.find('div.ajax_content_container').html(response.html);
               _modal.find('button.submit_button').attr('disabled', false);
           },
           error: function(response) {
               _modal.find('.ajax_loader').hide();
               _modal.find('ajax_content_container').html('Failed loading treatments.');
               console.log(response);
           }
        });
    },
    
    submitAddTreatmentsForm: function(_buttonElement) {
        _el = $(_buttonElement);
        _modal = _el.parents('div.add_treatments_modal');
        _form = _modal.find('form.add_treatments_form');
        _html = _el.html();
        _el.html(this._processing).attr('disabled', true);
        $.ajax({
            url: _form.attr('action'),
            data: _form.serialize(),
            type: 'POST',
            dataType: 'json',
            success: function (response) {
                _modal.find('div.ajax_content_container').html('');
                _modal.find('.ajax_loader').hide();
                
                // replace the treatments list
                _modal.parents('div.specializations_block').find('.institution_specialization_treatments_container').html(response.html);
                _modal.modal('hide');
            },
{'fraction_non_alphanumeric': 0.13320256776034237, 'fraction_numerical': 0.0005349500713266762, 'mean_word_length': 1.9017071908949819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7593685', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1427, 'n_words': 217}