{{define "Mass"}}
<script>
    // Список ссылок на материалы
    let m = ["Contract", "Schedule"];

    document.addEventListener("DOMContentLoaded", function(){
        VKKOWork.XHR.POST(function(result) {

            let Materials = document.querySelector(".main-article");

            if (Materials && "Materials" in result && result != null) {
                let articles = ''; 
                for (let m of result.Materials) {
                    articles  += '<article class="main-article">';
                        
                        {{if eq .IsAdmin true}} 
                            articles += '<div class="material-tool-group"><div class="edit-material-button tool-button" data-category="материал" data-link="'+m.Link+'"><i class="fas fa-pencil-alt"></i></div>';
                        if (m.Active) {
                            articles += '<div class="delete-material-button tool-button" data-active="true" data-link="'+m.Link+'"><i class="fas fa-times"></i></div></div>';
                        } else {
                            articles += '<div class="delete-material-button tool-button" data-active="false" data-link="'+m.Link+'"><i class="fas fa-redo-alt"></i></div></div><div style="margin: 20px;color: red;text-align: center;">Материал удалён</div>';
                        }
                        {{end}}

                        articles += '<h1>' + m.Caption + '</h1>' + m.Content + '</article>';
                }
                Materials.outerHTML = articles;

                VKKO.MaterialEditor.initButton();
            }

        }, "/get-materials", {List: m});
    });

</script>
{{end}}

