Commit 5d57c5c8 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Appel à confirm pour éviter le bug du popAjax

parent a34b5518
Loading
Loading
Loading
Loading
Loading
+62 −4
Changes for public/js/pop-ajax.js: 62 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -300,7 +300,63 @@ $(function () {
});


// Recours à l'utilisation du popConform standard
function popConfirm(element, options)
{
    if (typeof options == 'function') {
        options = {
            confirm: options
        };
    }

    if (!options) {
        options = {};
    }
    if (!options.title) {
        options.title = element.dataset.title;
    }
    if (!options.title) {
        options.title = "Demande de confirmation";
    }

    if (!options.content) {
        options.content = element.dataset.content;
    }
    if (!options.content) {
        options.content = "Confirmez-vous cette action ?";
    }

    if (!options.confirm) {
        options.confirm = () => {
        };
    }
    if (!options.url) {
        options.url = element.href;
    }
    if (!options.url) {
        options.url = element.dataset.url;
    }

    if (options.url) {
        goFunc = () => {
            unicaenVue.axios.get(options.url).then(response => {
                options.confirm(response, element);
            });
        };
    } else {
        goFunc = () => {
            options.confirm(element);
        };
    }

    if (confirm(options.content)){
        goFunc();
    }
}


// ancien popConform sauvegardé
function popConfirmOld(element, options)
{
    var popConfirm = bootstrap.Popover.getInstance(element);
    if (!popConfirm) {
@@ -328,7 +384,8 @@ function popConfirm(element, options)
        }

        if (!options.confirm) {
            options.confirm = function () {};
            options.confirm = () => {
            };
        }
        if (!options.url) {
            options.url = element.href;
@@ -338,15 +395,15 @@ function popConfirm(element, options)
        }

        if (options.url) {
            goFunc = function () {
            goFunc = () => {
                unicaenVue.axios.get(options.url).then(response => {
                    options.confirm(response, element);
                });
            };
        } else {
            goFunc = function () {
            goFunc = () => {
                options.confirm(element);
            }
            };
        }

        let popoptions = {
@@ -366,6 +423,7 @@ function popConfirm(element, options)

            goButton.addEventListener('click', () => {
                popConfirm.hide();
                $("#" + popDivId).remove();
                goFunc();
            });