'use strict';

var insertToken = function () {

    $('form').each(function() {

        var tokenInput = document.createElement('input');

        tokenInput.type = 'hidden';
        tokenInput.name = '_csrf';
        tokenInput.value = $('meta[name=csrf-token]').attr('content');

        if ($(this).find('input[name="_csrf"]').length) {
            $(this).find('input[name="_csrf"]').replaceWith(tokenInput);
        }

        $(this).prepend(tokenInput);

    });

};

linz.addLoadEvent(function () {

    insertToken();

    // Update whenever a new form is loaded
    $('#linzModal, #groupActionModal, #recordActionModal, #exportModal, #documentsModal').on('show.bs.modal', function () {
        insertToken();
    });

});

'use strict';

var insertToken = function () {

    $('form').each(function() {

        var tokenInput = document.createElement('input');

        tokenInput.type = 'hidden';
        tokenInput.name = '_csrf';
        tokenInput.value = $('meta[name=csrf-token]').attr('content');

        if ($(this).find('input[name="_csrf"]').length) {
            $(this).find('input[name="_csrf"]').replaceWith(tokenInput);
        }

        $(this).prepend(tokenInput);

    });

};

linz.addLoadEvent(function () {

    insertToken();

    // Update whenever a new form is loaded
    $('#linzModal, #groupActionModal, #recordActionModal, #exportModal, #documentsModal').on({
        'show.bs.modal': insertToken,
        'shown.bs.modal': insertToken
    });

});

use all modal methods