<commit_before>;
(function ($, window, undefined) {

    var debug = false;

    /**
     Class Colonnes
     **/
    $.Colonnes = function ()
    {
        this.element = $('#colonnes_dr');
        this.element_saisies = $('#col_saisies');
        this.element_saisies_container = $('#col_saisies_cont');
        this.element_colonne_intitules = $('#colonne_intitules');
        this.colonnes = new Array();
        this.groupes_rows = new GroupesRows(this);
        this.event_valider = function () {}
        this.event_focus = function () {}
        this.event_unfocus = function () {}
        this.event_enabled = function () {}
        this.event_disabled = function () {}
        this.event_valider_champ_modification = function () {}
        this.event_colonne_init = function () {}
        this.event_edition_on = function () {}
        this.event_edition_off = function () {}

        this.init = function () {
            this.colonnes = new Array();

            var colonne_intitule = new ColonneIntitule(this, this.element_colonne_intitules);
            colonne_intitule.init();
            this.colonnes.push(colonne_intitule);

            var object = this;
            var colonnes = this.colonnes;
            this.element_saisies.find('.col_recolte').each(function (i)
            {
                var colonne = new ColonneProduit(object, $(this));
                colonne.init();
                colonnes.push(colonne);
            });

            this.groupes_rows.init();

            this.update();
        }

        this.add = function (html) {
            this.element_saisies_container.append(html);
            var colonne = new ColonneProduit(this, this.element_saisies.find('.col_recolte').last());
            colonne.init();
            this.colonnes.push(colonne);
            this.update();
            colonne.unActive();
            if (colonne.isActive()) {
                colonne.active();
            }
            colonne.focus();
            colonne.focusChampDefault();

            return colonne;
        }

        this.findByHash = function (hash) {
            for (key in this.colonnes) {
                if (this.colonnes[key].element.attr('data-hash') == hash) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.getActive = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isActive()) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.hasActive = function () {

            return this.getActive() !== false;
        }

        this.getFocus = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isFocus()) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.hasFocus = function () {

            return this.getFocus() !== false;
        }

        this.unFocus = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isFocus()) {
                    this.colonnes[key].unFocus();
                }
            }
        }

        this.unActive = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isActive()) {
                    this.colonnes[key].unActive();
                }
            }
        }

        this.updateScroll = function ()
        {
            if (this.hasActive())
            {
                this.element_saisies.scrollTo(this.getActive().element, 200);
            } else if (this.hasFocus())
            {
                this.element_saisies.scrollTo(this.getFocus().element, 200);
            } else
            {
                this.element_saisies.scrollTo({top: 0, left: 0}, 200);
            }
        };

        this.enabled = function () {
            for (key in this.colonnes) {
                this.colonnes[key].enabled();
            }
        }

        this.disabled = function () {
            for (key in this.colonnes) {
                this.colonnes[key].disabled();
            }
        }

        this.update = function () {
            this._updateLargeur();
            this._updateHauteur();
            this.groupes_rows.update();
        }

        this._updateLargeur = function () {
            var largeur = 0;
            var cols = this.element_colonne_intitules.add(this.element_saisies_container);

            for (key in this.colonnes) {
                if (this.colonnes[key].getClass() == "ColonneProduit") {
                    largeur += this.colonnes[key].element.outerWidth(true);
                }
            }
            this.element_saisies_container.width(largeur);
        }

        this._updateHauteur = function () {
            var cols = this.element_colonne_intitules.add(this.element_saisies_container);

            cols.find('.head').hauteurEgale();
        }
    }

    /**
     Class ColonneIntitule
     **/
    function ColonneIntitule(colonnes, element)
    {
        this.colonnes = colonnes;
        this.element = element;
        this.groupes = new Groupes(this);

        this.init = function () {
            if (debug) {
                console.log('init colonne intitule');
                console.log(this.element);
            }

            this.groupes.init();
        }

        this.isActive = function () {

            return false;
        }

        this.isFocus = function () {

            return false;
        }

        this.enabled = function () {

            return false;
        }

        this.disabled = function () {

            return false;
        }

        this.getClass = function () {

            return 'ColonneIntitule';
        }
    }

    /**
     Class ColonneProduit
     **/
    function ColonneProduit(colonnes, element)
    {

        this.colonnes = colonnes;
        this.element = element;
        this.groupes = new Groupes(this);
        this.boutons_etapes = $('#btn_etape_dr a');

        this.init = function () {
            if (debug) {
                console.log('init colonne produit');
                console.log(this.element);
            }

            this._initBoutons();
            this._initClavier();
            this.groupes.init();
            this.colonnes.event_colonne_init(this);
            this.calculer();
        }

        this.isActive = function () {

            return this.element.hasClass('col_active');
        }

        this.active = function () {
            if (this.isActive()) {
                return;
            }

            if (debug) {
                console.log('colonne active');
                console.log(this.element);
            }

            this.colonnes.unActive();
            this.focus();
            this.element.addClass('col_active');
            this.element.addClass('active');
            this.element.find('.col_btn').removeClass('invisible');
            this.colonnes.disabled();

            // On désactive les boutons et champs autour de la colonne
            this.desactiveElements();
        }

        this.unActive = function () {
            if (debug) {
                console.log('colonne unactive');
                console.log(this.element);
            }

            this.element.removeClass('col_active');
            this.element.removeClass('active');
            this.element.find('.col_btn').addClass('invisible');
            this.colonnes.enabled();

            // On réactive les boutons et champs autour de la colonne
            this.reactiveElements();
        }

        this.desactiveBoutons = function (e)
        {
            e.preventDefault();
        }

        this.desactiveElements = function () {

            this.colonnes.event_edition_on();
        }

        this.reactiveElements = function () {

            this.colonnes.event_edition_off();
        }

        this.enabled = function () {
            if (debug) {
                console.log('colonne enabled');
                console.log(this.element);
            }

            this.element.removeClass('col_inactive');
            this.element.removeClass('inactive');
            this.groupes.enabled();
            this.element.find('a').removeAttr('disabled');

            this.colonnes.event_enabled(this);
        }

        this.disabled = function () {
            if (this.isActive()) {
                return;
            }

            this.element.addClass('col_inactive');
            this.element.addClass('inactive');
            this.groupes.disabled();
            this.element.find('a').attr('disabled', 'disabled');

            this.colonnes.event_disabled(this);
        }

        this.focus = function () {
            if (this.isFocus()) {
                return;
            }

            if (debug) {
                console.log('colonne focus');
                console.log(this.element);
            }

            this.colonnes.unFocus();
            this.element.addClass('col_focus');
            this.element.removeClass('panel-success');
            this.element.addClass('panel-primary');
            this.colonnes.updateScroll();

            this.colonnes.event_focus(this);
        }

        this.focusChampDefault = function () {
            var tabIndex = this.element.attr('data-input-focus');
            var field = this.element.find('input[tabindex=' + tabIndex + ']');
            field.focus();
        }

        this.focusChamp = function (fieldId) {
          var field = this.element.find('input#' + fieldId);
          console.log(fieldId)
          field.focus();
        }

        this.unFocus = function () {
            this.element.removeClass('col_focus');
            if (this.element.hasClass('col_edited')) {
                this.element.addClass('panel-success');
            }
            this.element.removeClass('panel-primary');

            this.colonnes.event_unfocus();
        }

        this.isFocus = function () {

            return this.element.hasClass('col_focus');
        }

        this.isShow = function () {
            return this.element.is(':visible');
        }

        this.hide = function () {
            if (!this.isActive()) {
                this.unActive();
                if (this.getNext()) {
                    this.getNext().focus();
                    this.getNext().focusChampDefault();
                }
                this.element.hide();
                return true;
            }
            return false;
        }

        this.show = function () {
            this.unActive();
            return this.element.show();
            return true;
        }

        this.reinit = function () {
            if (!this.isActive()) {
                return;
            }

            if (debug) {
                console.log('colonne reinit');
                console.log(this.element);
            }

            this.groupes.reinit();
            this.unActive();
        }

        this.valider = function (nextfocus,fieldFocus) {
            if (!this.isActive()) {
                var object = this;
                object.colonnes.event_valider(object, nextfocus,fieldFocus);
                return;
            }

            if (debug) {
                console.log('colonne valider');
                console.log(this.element);
            }

            this.calculer();
            this.saving();

            var object = this;

            var form = this.element.find('form');

            $.post(form.attr('action'), form.serializeArray(), function (data)
            {
                object.unSaving();

                if (!data.success) {
                    alert("Le formulaire n'a pas été sauvegardé car il comporte des erreurs");

                    return;
                }

                object.groupes.valider();
                object.unActive();

                object.colonnes.event_valider(object, nextfocus,fieldFocus);

            }, 'json');
        }

        this.saving = function () {
            this.element.addClass('col_envoi');
        }

        this.unSaving = function () {
            this.element.removeClass('col_envoi');
        }

        this.calculer = function () {
            if (debug) {
                console.log('colonne calculer');
                console.log(this.element);
            }
            this.groupes.calculer();
        }

        this.totalRecolte = function () {

            return this.groupes.totalRecolte();
        }

        this.totalDontRevendique = function () {
            return this.groupes.totalDontRevendique();
        }

        this.getNext = function () {
            var find = false;
            for (key in this.colonnes.colonnes) {
                if (find) {
                    return this.colonnes.colonnes[key];
                }
                if ((this.colonnes.colonnes[key] instanceof ColonneProduit && this.colonnes.colonnes[key].getHash() == this.getHash())
                        && this.colonnes.colonnes[key].isShow()) {
                    find = true;
                }
            }

            return null;
        }

        this.gePrevious = function () {
            var last = false;

            for (key in this.colonnes.colonnes) {

                if ((this.colonnes.colonnes[key] instanceof ColonneProduit && this.colonnes.colonnes[key].getHash() == this.getHash())
                        && this.colonnes.colonnes[key].isShow()) {
                    return last;
                }
                if (this.colonnes.colonnes[key] instanceof ColonneProduit) {
                    last = this.colonnes.colonnes[key];
                }
            }

            return null;
        }

        this.getHash = function () {

            return this.element.attr('data-hash');
        }

        this.getClass = function () {

            return 'ColonneProduit';
        }

        this._initBoutons = function () {
            var object = this;

            this.element.find('.col_btn button.btn_reinitialiser').click(function () {
                object.reinit();
                return false;
            });

            this.element.find('.col_btn button.btn_valider').click(function () {
                object.valider();
                return false;
            });
        }

        this._initClavier = function () {
            var object = this;

            this.element.keydown(function (e)
            {
                if (e.keyCode == 27)
                {
                    var hasModal = false;
                    $(".modal").each(function () {
                        if ($(this).hasClass('in')) {
                            $("#" + $(this).attr('id')).modal('hide');
                            hasModal = true;
                        }
                    });
                    if (!hasModal) {
                        object.reinit();
                    }
                    e.preventDefault();
                }
            });

        }
    }

    /**
     Class GroupesRows
     **/
    function GroupesRows(colonnes)
    {
        this.colonnes = colonnes;
        this.groupes_rows = new Array();

        this.init = function () {
            var object = this;
            colonnes.element_colonne_intitules.find('.groupe').each(function () {<commit_msg>suppression du raccourcis clavier echap qui annule une colonne<commit_after>;
(function ($, window, undefined) {

    var debug = false;

    /**
     Class Colonnes
     **/
    $.Colonnes = function ()
    {
        this.element = $('#colonnes_dr');
        this.element_saisies = $('#col_saisies');
        this.element_saisies_container = $('#col_saisies_cont');
        this.element_colonne_intitules = $('#colonne_intitules');
        this.colonnes = new Array();
        this.groupes_rows = new GroupesRows(this);
        this.event_valider = function () {}
        this.event_focus = function () {}
        this.event_unfocus = function () {}
        this.event_enabled = function () {}
        this.event_disabled = function () {}
        this.event_valider_champ_modification = function () {}
        this.event_colonne_init = function () {}
        this.event_edition_on = function () {}
        this.event_edition_off = function () {}

        this.init = function () {
            this.colonnes = new Array();

            var colonne_intitule = new ColonneIntitule(this, this.element_colonne_intitules);
            colonne_intitule.init();
            this.colonnes.push(colonne_intitule);

            var object = this;
            var colonnes = this.colonnes;
            this.element_saisies.find('.col_recolte').each(function (i)
            {
                var colonne = new ColonneProduit(object, $(this));
                colonne.init();
                colonnes.push(colonne);
            });

            this.groupes_rows.init();

            this.update();
        }

        this.add = function (html) {
            this.element_saisies_container.append(html);
            var colonne = new ColonneProduit(this, this.element_saisies.find('.col_recolte').last());
            colonne.init();
            this.colonnes.push(colonne);
            this.update();
            colonne.unActive();
            if (colonne.isActive()) {
                colonne.active();
            }
            colonne.focus();
            colonne.focusChampDefault();

            return colonne;
        }

        this.findByHash = function (hash) {
            for (key in this.colonnes) {
                if (this.colonnes[key].element.attr('data-hash') == hash) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.getActive = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isActive()) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.hasActive = function () {

            return this.getActive() !== false;
        }

        this.getFocus = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isFocus()) {

                    return this.colonnes[key];
                }
            }

            return false;
        }

        this.hasFocus = function () {

            return this.getFocus() !== false;
        }

        this.unFocus = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isFocus()) {
                    this.colonnes[key].unFocus();
                }
            }
        }

        this.unActive = function () {
            for (key in this.colonnes) {
                if (this.colonnes[key].isActive()) {
                    this.colonnes[key].unActive();
                }
            }
        }

        this.updateScroll = function ()
        {
            if (this.hasActive())
            {
                this.element_saisies.scrollTo(this.getActive().element, 200);
            } else if (this.hasFocus())
            {
                this.element_saisies.scrollTo(this.getFocus().element, 200);
            } else
            {
                this.element_saisies.scrollTo({top: 0, left: 0}, 200);
            }
        };

        this.enabled = function () {
            for (key in this.colonnes) {
                this.colonnes[key].enabled();
            }
        }

        this.disabled = function () {
            for (key in this.colonnes) {
                this.colonnes[key].disabled();
            }
        }

        this.update = function () {
            this._updateLargeur();
            this._updateHauteur();
            this.groupes_rows.update();
        }

        this._updateLargeur = function () {
            var largeur = 0;
            var cols = this.element_colonne_intitules.add(this.element_saisies_container);

            for (key in this.colonnes) {
                if (this.colonnes[key].getClass() == "ColonneProduit") {
                    largeur += this.colonnes[key].element.outerWidth(true);
                }
            }
            this.element_saisies_container.width(largeur);
        }

        this._updateHauteur = function () {
            var cols = this.element_colonne_intitules.add(this.element_saisies_container);

            cols.find('.head').hauteurEgale();
        }
    }

    /**
     Class ColonneIntitule
     **/
    function ColonneIntitule(colonnes, element)
    {
        this.colonnes = colonnes;
        this.element = element;
        this.groupes = new Groupes(this);

        this.init = function () {
            if (debug) {
                console.log('init colonne intitule');
                console.log(this.element);
            }

            this.groupes.init();
        }

        this.isActive = function () {

            return false;
        }

        this.isFocus = function () {

            return false;
        }

        this.enabled = function () {

            return false;
        }

        this.disabled = function () {

            return false;
        }

        this.getClass = function () {

            return 'ColonneIntitule';
        }
    }

    /**
     Class ColonneProduit
     **/
    function ColonneProduit(colonnes, element)
    {

        this.colonnes = colonnes;
        this.element = element;
        this.groupes = new Groupes(this);
        this.boutons_etapes = $('#btn_etape_dr a');

        this.init = function () {
            if (debug) {
                console.log('init colonne produit');
                console.log(this.element);
            }

            this._initBoutons();
            this._initClavier();
            this.groupes.init();
            this.colonnes.event_colonne_init(this);
            this.calculer();
        }

        this.isActive = function () {

            return this.element.hasClass('col_active');
        }

        this.active = function () {
            if (this.isActive()) {
                return;
            }

            if (debug) {
                console.log('colonne active');
                console.log(this.element);
            }

            this.colonnes.unActive();
            this.focus();
            this.element.addClass('col_active');
            this.element.addClass('active');
            this.element.find('.col_btn').removeClass('invisible');
            this.colonnes.disabled();

            // On désactive les boutons et champs autour de la colonne
            this.desactiveElements();
        }

        this.unActive = function () {
            if (debug) {
                console.log('colonne unactive');
                console.log(this.element);
            }

            this.element.removeClass('col_active');
            this.element.removeClass('active');
            this.element.find('.col_btn').addClass('invisible');
            this.colonnes.enabled();

            // On réactive les boutons et champs autour de la colonne
            this.reactiveElements();
        }

        this.desactiveBoutons = function (e)
        {
            e.preventDefault();
        }

        this.desactiveElements = function () {

            this.colonnes.event_edition_on();
        }

        this.reactiveElements = function () {

            this.colonnes.event_edition_off();
        }

        this.enabled = function () {
            if (debug) {
                console.log('colonne enabled');
                console.log(this.element);
            }

            this.element.removeClass('col_inactive');
            this.element.removeClass('inactive');
            this.groupes.enabled();
            this.element.find('a').removeAttr('disabled');

            this.colonnes.event_enabled(this);
        }

        this.disabled = function () {
            if (this.isActive()) {
                return;
            }

            this.element.addClass('col_inactive');
            this.element.addClass('inactive');
            this.groupes.disabled();
            this.element.find('a').attr('disabled', 'disabled');

            this.colonnes.event_disabled(this);
        }

        this.focus = function () {
            if (this.isFocus()) {
                return;
            }

            if (debug) {
                console.log('colonne focus');
                console.log(this.element);
            }

            this.colonnes.unFocus();
            this.element.addClass('col_focus');
            this.element.removeClass('panel-success');
            this.element.addClass('panel-primary');
            this.colonnes.updateScroll();

            this.colonnes.event_focus(this);
        }

        this.focusChampDefault = function () {
            var tabIndex = this.element.attr('data-input-focus');
            var field = this.element.find('input[tabindex=' + tabIndex + ']');
            field.focus();
        }

        this.focusChamp = function (fieldId) {
          var field = this.element.find('input#' + fieldId);
          console.log(fieldId)
          field.focus();
        }

        this.unFocus = function () {
            this.element.removeClass('col_focus');
            if (this.element.hasClass('col_edited')) {
                this.element.addClass('panel-success');
            }
            this.element.removeClass('panel-primary');

            this.colonnes.event_unfocus();
        }

        this.isFocus = function () {

            return this.element.hasClass('col_focus');
        }

        this.isShow = function () {
            return this.element.is(':visible');
        }

        this.hide = function () {
            if (!this.isActive()) {
                this.unActive();
                if (this.getNext()) {
                    this.getNext().focus();
                    this.getNext().focusChampDefault();
                }
                this.element.hide();
                return true;
            }
            return false;
        }

        this.show = function () {
            this.unActive();
            return this.element.show();
            return true;
        }

        this.reinit = function () {
            if (!this.isActive()) {
                return;
            }

            if (debug) {
                console.log('colonne reinit');
                console.log(this.element);
            }

            this.groupes.reinit();
            this.unActive();
        }

        this.valider = function (nextfocus,fieldFocus) {
            if (!this.isActive()) {
                var object = this;
                object.colonnes.event_valider(object, nextfocus,fieldFocus);
                return;
            }

            if (debug) {
                console.log('colonne valider');
                console.log(this.element);
            }

            this.calculer();
            this.saving();

            var object = this;

            var form = this.element.find('form');

            $.post(form.attr('action'), form.serializeArray(), function (data)
            {
                object.unSaving();

                if (!data.success) {
                    alert("Le formulaire n'a pas été sauvegardé car il comporte des erreurs");

                    return;
                }

                object.groupes.valider();
                object.unActive();

                object.colonnes.event_valider(object, nextfocus,fieldFocus);

            }, 'json');
        }

        this.saving = function () {
            this.element.addClass('col_envoi');
        }

        this.unSaving = function () {
            this.element.removeClass('col_envoi');
        }

        this.calculer = function () {
            if (debug) {
                console.log('colonne calculer');
                console.log(this.element);
            }
            this.groupes.calculer();
        }

        this.totalRecolte = function () {

            return this.groupes.totalRecolte();
        }

        this.totalDontRevendique = function () {
            return this.groupes.totalDontRevendique();
        }

        this.getNext = function () {
            var find = false;
            for (key in this.colonnes.colonnes) {
                if (find) {
                    return this.colonnes.colonnes[key];
                }
                if ((this.colonnes.colonnes[key] instanceof ColonneProduit && this.colonnes.colonnes[key].getHash() == this.getHash())
                        && this.colonnes.colonnes[key].isShow()) {
                    find = true;
                }
            }

            return null;
        }

        this.gePrevious = function () {
            var last = false;

            for (key in this.colonnes.colonnes) {

                if ((this.colonnes.colonnes[key] instanceof ColonneProduit && this.colonnes.colonnes[key].getHash() == this.getHash())
                        && this.colonnes.colonnes[key].isShow()) {
                    return last;
                }
                if (this.colonnes.colonnes[key] instanceof ColonneProduit) {
                    last = this.colonnes.colonnes[key];
                }
            }

            return null;
        }

        this.getHash = function () {

            return this.element.attr('data-hash');
        }

        this.getClass = function () {

            return 'ColonneProduit';
        }

        this._initBoutons = function () {
            var object = this;

            this.element.find('.col_btn button.btn_reinitialiser').click(function () {
                object.reinit();
                return false;
            });

            this.element.find('.col_btn button.btn_valider').click(function () {
                object.valider();
                return false;
            });
        }

        this._initClavier = function () {
            var object = this;

            this.element.keydown(function (e)
            {
                if (e.keyCode == 27)
                {
                    $(".modal").each(function () {
                        if ($(this).hasClass('in')) {
                            $("#" + $(this).attr('id')).modal('hide');
                        }
                    });
                    e.preventDefault();
                }
            });

        }
    }

    /**
     Class GroupesRows
     **/
    function GroupesRows(colonnes)
    {
        this.colonnes = colonnes;
        this.groupes_rows = new Array();

        this.init = function () {
            var object = this;
            colonnes.element_colonne_intitules.find('.groupe').each(function () {
{'fraction_non_alphanumeric': 0.12056622193296453, 'fraction_numerical': 0.0009111617312072893, 'mean_word_length': 1.3189707214005433, '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': '5688237', 'n_tokens_mistral': 8364, 'n_tokens_neox': 7934, 'n_words': 1276}