Commit 6b969d82 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

- Correction bug suite migr. BS5 sur le form des affectations

- amélioration sélection des catégories de privilèges
- suppression de droits.js, éclaté avec les widgets placés là où ils sont utilisés
parent b55c7ad8
Loading
Loading
Loading
Loading
+4 −3
Changes for module/Application/src/Form/Droits/AffectationForm.php: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ class AffectationForm extends AbstractForm
                'label'         => 'Structure',
                'value_options' => Util::collectionAsOptions($structures),
            ],
            'attributes' => [
                'class'            => 'selectpicker',
                'data-live-search' => true,
            ],
        ]);

        $this->add([
@@ -128,9 +132,6 @@ class AffectationForm extends AbstractForm
}





class AffectationFormHydrator implements HydratorInterface
{
    use StructureServiceAwareTrait;
+45 −0
Changes for module/Application/view/application/droits/affectation-edition.phtml: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,3 +16,48 @@ echo $this->formRow($form->get('submit'));
echo $this->formHidden($form->get('id'));

echo $this->form()->closeTag();

?>
<script type="application/javascript">

    $.widget("ose.affectationForm", {

        onUtilisateurChange: function (item)
        {
            this.getElementStructure().val(item.structure);
        },

        updateStructureVisibility: function ()
        {
            var roleMustHaveStructure = $.inArray(parseInt(this.getElementRole().val()), this.getRolesMustHaveStructure()) > -1;

            if (roleMustHaveStructure) {
                this.getElementStructure().parents('.mb-2').show();
            } else {
                this.getElementStructure().parents('.mb-2').hide();
            }
        },



        _create: function ()
        {
            var that = this;
            this.getElementRole().on('change', function () { that.updateStructureVisibility() });
            this.getElementUtilisateur().on("change", function (e, item) { that.onUtilisateurChange(item); });
            this.updateStructureVisibility();
        },



        //@formatter:off
        getRolesMustHaveStructure   : function () { return this.element.data('roles-must-have-structure'); },
        getElementUtilisateur         : function () { return this.element.find('input[name="utilisateur\\[id\\]"]'); },
        getElementRole              : function () { return this.element.find('select[name="role"]'); },
        getElementStructure         : function () { return this.element.find('select[name="structure"]'); }
        //@formatter:on
    });

    WidgetInitializer.add('affectation-form', 'affectationForm');

</script>
+137 −1
Changes for module/Application/view/application/droits/privileges.phtml: 137 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
    <tbody>
    <tr>
        <th class="categorie" colspan="<?= 2 + count($roles); ?>">
            <select class="categorie form-select" data-live-search="true" data-width="auto">
            <select class="categorie selectpicker" data-live-search="true" data-width="100%">
                <option value="">Veuillez choisir une catégorie de privilèges ...</option>
                <?php foreach ($privileges as $cat): ?>
                    <option value="<?= $cat['categorie']->getCode() ?>"><?= $cat['categorie'] ?></option>
@@ -46,3 +46,139 @@
    <?php endforeach; ?>
    </tbody>
</table>

<script type="application/javascript">

    /**
     * @constructor
     * @this {DroitsTbl}
     * @param {string} id
     * @returns {DroitsTbl}
     */
    $.widget("ose.droitsTbl", {

        modifier: function (td, action)
        {
            var that = this;
            td.html("<div class=\"loading\">&nbsp;</div>");
            td.load(unicaenVue.url('droits/privileges/modifier'), {
                role: td.data("role"),
                privilege: td.data("privilege"),
                action: action
            }, function ()
            {
                that.initModifierClick(td); // pour reconnecter l'action du lien...
            });

        },


        showHideCategorie: function (categorie)
        {
            this.element.find('tr.categorie[data-categorie="' + categorie + '"]').each(function () {

                if ($(this).is(':visible')) {
                    $(this).hide();
                } else {
                    $(this).show();
                }
            });
        },



        showCategorie: function (categorie)
        {
            console.log(categorie);
            this.element.find('tr.categorie[data-categorie!="' + categorie + '"]').hide();
            this.element.find('tr.categorie[data-categorie="' + categorie + '"]').show();
        },


        hideRole: function (roleId)
        {
            this.element.find('th.role[data-role="' + roleId + '"]').hide();
            this.element.find('td.role[data-role="' + roleId + '"]').hide();

            var rolesCount = this.element.find('th.role:visible').length;
            if (rolesCount > 0) {
                this.element.find('th.roles').attr('colspan', rolesCount).show();
            } else {
                this.element.find('th.roles').hide();
            }

            this.updateFirsts();
        },



        updateFirsts: function ()
        {
            this.element.find('th.role.first').removeClass('first');

            this.element.find('th.role:visible:first').addClass('first');
        },



        initModifierClick: function (td)
        {
            var that = this;
            td.find("a").on("click", function ()
            {
                that.modifier(td, $(this).data("action"));
            });
        },



        /**
         * Initialisation
         *
         * @returns {undefined}
         */
        _create: function ()
        {
            var that = this;
            this.element.find("td.modifier").each(function ()
            {
                that.initModifierClick($(this));
            });

            this.element.find('a.categorie').click(function ()
            {
                that.showHideCategorie($(this).data('categorie'));
            });

            this.element.find('th.role a').click(function ()
            {
                var roleId = $(this).parents('.role').data('role');
                that.hideRole(roleId);
            });

            this.element.find('select.categorie').change(function () {
                that.showCategorie($(this).val());
            });

            this.element.find('.modifier').on('mouseover mouseout', function ()
            {

                var id = $(this).data('role');
                var selector = 'role';

                that.element.find('.selected').removeClass('selected');

                $(this).prevAll().addBack()
                .add($(this).parent().prevAll()
                .children(':nth-child(' + ($(this).index() + 1) + '):not(.categorie)')).toggleClass('selected');

                that.element.find('th.' + selector + '[data-' + selector + '="' + id + '"] div').toggleClass('selected');
            });

            this.updateFirsts();
        }
    });

    WidgetInitializer.add('droits-tbl', 'droitsTbl');

</script>
 No newline at end of file
+0 −7
Changes for public/js/app.js: 0 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -100,13 +100,6 @@ $(function ()
        //     WidgetInitializer.includeJs(unicaenVue.url('js/chargens.js'));
    });

    /* Droits */
    WidgetInitializer.add('droits-tbl', 'droitsTbl', function () {
        WidgetInitializer.includeJs(unicaenVue.url('js/droits.js'));
    });
    WidgetInitializer.add('affectation-form', 'affectationForm', function () {
        WidgetInitializer.includeJs(unicaenVue.url('js/droits.js'));
    });

    // installation de tooltip Bootstrap sur les icônes d'information (i)
    $(".info-icon").tooltip();

public/js/droits.js

deleted100755 → 0
+0 −175
Changes for public/js/droits.js: 0 added lines, 175 removed lines.
Original line number Diff line number Diff line
/**
 * @constructor
 * @this {DroitsTbl}
 * @param {string} id
 * @returns {DroitsTbl}
 */
$.widget("ose.droitsTbl", {

    modifier: function (td, action)
    {
        var that = this;
        td.html("<div class=\"loading\">&nbsp;</div>");
        td.load(unicaenVue.url('droits/privileges/modifier'), {
            role: td.data("role"),
            privilege: td.data("privilege"),
            action: action
        }, function ()
        {
            that.initModifierClick(td); // pour reconnecter l'action du lien...
        });

    },


    showHideCategorie: function (categorie)
    {
        this.element.find('tr.categorie[data-categorie="' + categorie + '"]').each(function () {

            if ($(this).is(':visible')) {
                $(this).hide();
            } else {
                $(this).show();
            }
        });
    },



    showCategorie: function (categorie)
    {
        console.log(categorie);
        this.element.find('tr.categorie[data-categorie!="' + categorie + '"]').hide();
        this.element.find('tr.categorie[data-categorie="' + categorie + '"]').show();
    },


    hideRole: function (roleId)
    {
        this.element.find('th.role[data-role="' + roleId + '"]').hide();
        this.element.find('td.role[data-role="' + roleId + '"]').hide();

        var rolesCount = this.element.find('th.role:visible').length;
        if (rolesCount > 0) {
            this.element.find('th.roles').attr('colspan', rolesCount).show();
        } else {
            this.element.find('th.roles').hide();
        }

        this.updateFirsts();
    },



    updateFirsts: function ()
    {
        this.element.find('th.role.first').removeClass('first');

        this.element.find('th.role:visible:first').addClass('first');
    },



    initModifierClick: function (td)
    {
        var that = this;
        td.find("a").on("click", function ()
        {
            that.modifier(td, $(this).data("action"));
        });
    },



    /**
     * Initialisation
     *
     * @returns {undefined}
     */
    _create: function ()
    {
        var that = this;
        this.element.find("td.modifier").each(function ()
        {
            that.initModifierClick($(this));
        });

        this.element.find('a.categorie').click(function ()
        {
            that.showHideCategorie($(this).data('categorie'));
        });

        this.element.find('th.role a').click(function ()
        {
            var roleId = $(this).parents('.role').data('role');
            that.hideRole(roleId);
        });

        this.element.find('select.categorie').change(function () {
            that.showCategorie($(this).val());
        });

        this.element.find('.modifier').on('mouseover mouseout', function ()
        {

            var id = $(this).data('role');
            var selector = 'role';

            that.element.find('.selected').removeClass('selected');

            $(this).prevAll().addBack()
                .add($(this).parent().prevAll()
                    .children(':nth-child(' + ($(this).index() + 1) + '):not(.categorie)')).toggleClass('selected');

            that.element.find('th.' + selector + '[data-' + selector + '="' + id + '"] div').toggleClass('selected');
        });

        this.updateFirsts();
    }
});





/**
 *
 * @constructor
 */
$.widget("ose.affectationForm", {

    onUtilisateurChange: function (item)
    {
        this.getElementStructure().val(item.structure);
    },

    updateStructureVisibility: function ()
    {
        var roleMustHaveStructure = $.inArray(parseInt(this.getElementRole().val()), this.getRolesMustHaveStructure()) > -1;

        if (roleMustHaveStructure) {
            this.getElementStructure().parents('.form-group').show();
        } else {
            this.getElementStructure().parents('.form-group').hide();
        }
    },



    _create: function ()
    {
        var that = this;
        this.getElementRole().on('change', function () { that.updateStructureVisibility() });
        this.getElementUtilisateur().on("change", function (e, item) { that.onUtilisateurChange(item); });
        this.updateStructureVisibility();
    },



    //@formatter:off
    getRolesMustHaveStructure   : function () { return this.element.data('roles-must-have-structure'); },
    getElementUtilisateur         : function () { return this.element.find('input[name="utilisateur\\[id\\]"]'); },
    getElementRole              : function () { return this.element.find('select[name="role"]'); },
    getElementStructure         : function () { return this.element.find('select[name="structure"]'); }
    //@formatter:on
});