{% extends 'base.html.twig' %}
{% block title %}LouvreBible, gestion des contenus{% endblock %}
{% block content %}
<a title="Nouvel article" class="btn btn-primary" href="{{ path('insert_article_global') }}">Nouvel Article</a>
<div id="toolbar-ujuo">
<div class="form-inline" role="form">
<h4 style="color:purple;">Articles un jour une oeuvre</h4>
</div>
</div>
<table id="articles-ujuo-table" name="articles-ujuo-table" class="w-100 table-striped clickable-row"
data-url="{{ path('articles_un_jour_une_oeuvre_list_json') }}"
data-show-export="true"
data-export-types="['excel','csv']"
data-smart-display="true"
data-pagination="true"
data-page-list="[10, 25, 50, 100, 500, 1000, 5000]"
data-page-size="20"
data-show-pagination-switch="true"
data-show-toggle="false"
data-id-field="id"
data-cache="false"
data-show-refresh="true"
data-show-columns="false"
data-search="true"
data-filter-control="false"
data-toolbar="#toolbar-ujuo"
>
<thead>
<tr>
<th data-field="id" data-sortable="true" data-visible="true">#</th>
<th data-field="status" data-sortable="true" data-visible="true">Statut</th>
<th data-field="title" data-sortable="true" data-visible="true">Titre de l'article</th>
<th data-field="last_update" data-formatter="dateFormatHour" data-sortable="false" data-visible="true" >MAJ</th>
<th data-field="to_show" data-sortable="true" data-visible="true" >En avant (MM-JJ)</th>
<th data-field="bible_book_name_verse" data-sortable="true" data-visible="true" >Livre</th>
<th data-field="operate" data-formatter="operateFormatter" data-sortable="true">Actions</th>
</tr>
</thead>
</table>
<div id="toolbar-lbi">
<div class="form-inline" role="form">
<h4 style="color:purple;">Articles la Bible illustrée</h4>
</div>
</div>
<table id="articles-lbi-table" name="articles-lbi-table" class="w-100 table-striped clickable-row"
data-url="{{ path('articles_lbi_list_json') }}"
data-show-export="true"
data-export-types="['excel','csv']"
data-smart-display="true"
data-pagination="true"
data-page-list="[10, 25, 50, 100, 500, 1000, 5000]"
data-page-size="20"
data-show-pagination-switch="true"
data-show-toggle="false"
data-id-field="id"
data-cache="false"
data-show-refresh="true"
data-show-columns="false"
data-search="true"
data-filter-control="false"
data-toolbar="#toolbar-lbi"
>
<thead>
<tr>
<th data-field="id" data-sortable="true" data-visible="true">#</th>
<th data-field="status" data-sortable="true" data-visible="true">Statut</th>
<th data-field="title" data-sortable="true" data-visible="true">Titre de l'article</th>
<th data-field="last_update" data-formatter="dateFormatHour" data-sortable="false" data-visible="true" >MAJ</th>
<th data-field="to_show" data-sortable="true" data-visible="true" >En avant (MM-JJ)</th>
<th data-field="bible_book_name_verse" data-sortable="true" data-visible="true" >Livre</th>
<th data-field="operate" data-formatter="operateFormatter" data-sortable="true">Actions</th>
</tr>
</thead>
</table>
<div id="toolbar-only">
<div class="form-inline" role="form">
<h4 style="color:purple;">Autres articles du site</h4>
</div>
</div>
<table id="articles-only-table" name="articles-only-table" class="w-100 table-striped clickable-row"
data-url="{{ path('articles_list_json') }}"
data-show-export="true"
data-export-types="['excel','csv']"
data-smart-display="true"
data-pagination="true"
data-page-list="[10, 25, 50, 100, 500, 1000, 5000]"
data-page-size="20"
data-show-pagination-switch="true"
data-show-toggle="false"
data-id-field="id"
data-cache="false"
data-show-refresh="true"
data-show-columns="false"
data-search="true"
data-filter-control="false"
data-toolbar="#toolbar-only"
>
<thead>
<tr>
<th data-field="id" data-sortable="true" data-visible="true">#</th>
<th data-field="status" data-sortable="true" data-visible="true">Statut</th>
<th data-field="title" data-sortable="true" data-visible="true">Titre de l'article</th>
<th data-field="last_update" data-formatter="dateFormatHour" data-sortable="false" data-visible="true" >MAJ</th>
<th data-field="to_show" data-sortable="true" data-visible="true" >En avant (MM-JJ)</th>
<th data-field="operate" data-formatter="operateFormatter" data-sortable="true">Actions</th>
</tr>
</thead>
</table>
<div class="modal" id="deleteArticleModal" tabindex="-1" aria-labelledby="deleteArticleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteArticleModalLabel">Suppression de l'article</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<label for="articleDelId">Êtes-vous certain de supprimer l'article no:</label>
<p id="articleDelId">#</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Fermer</button>
<button id="submitButton" type="button" class="btn btn-danger" value="" >Valider</button>
</div>
</div>
</div>
</div>
<script>
$('#titlenav').html('Gestion des articles');
//<i class="fas fa-exclamation"></i>
function operateFormatter(value, row, index) {
var actions = '';
console.log('value : '+ value); console.log('index : '+ index); console.log('row.id : '+row.id);
var articleEditUrl = "{{ path('edit_article_global') }}/"+row.id;
console.log('articleEditUrl: '+articleEditUrl);
var articleCopyUrl = "{{ path('insert_article_global') }}/"+row.id;
console.log('articleCopyUrl: '+articleCopyUrl);
actions +="<a title='Modifier' class='btn btn-warning edit_item mx-2' href="+articleEditUrl+"><i class='far fa-file-alt fa-2x'></i></a>";
actions +="<a title='Dupliquer' class='btn btn-outline-info mx-2' href="+articleCopyUrl+"><i class='far fa-copy fa-2x'></i></a>";
actions +="<button type='button' title='Supprimer' class='btn btn-danger mx-2' data-toggle='modal' data-target='#deleteArticleModal' data-whatever="+row.id+"><i class='fas fa-trash fa-2x'></i></button>";
return [ actions ].join('');
}
// CALLBACKS
$('#deleteArticleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var recipient = button.data('whatever'); // Extract info from data-* attributes
console.log('data-whatever : '+ recipient);
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content.
var modal = $(this);
modal.find('.modal-body p').text(recipient);
modal.find('.modal-footer #submitButton').val(recipient);
});
$( "#submitButton" ).on( "click", function() {
console.log("submitButton val is :" + $( this ).val() );
// RETRIEVE
var id_article = $( this ).val();
// CREATE JSON
var donnees = JSON.stringify({
"id_article":id_article
});
console.log(donnees);
// SEND REQUEST
$.ajax({
type:'POST',
url:'{{ path("delete_article_global") }}',
data:{'parametres':donnees},
dataType:'json',
success: function(data){
if ( (data['retour']=="O") || (data['retour']=="N") ){
/*if(confirm(data['message']+". Voulez vous recharger la page ?") ){
location.reload();
}
else{ }*/
$('#articles-ujuo-table').bootstrapTable('refresh');
$('#articles-lbi-table').bootstrapTable('refresh');
$('#articles-only-table').bootstrapTable('refresh');
$('#deleteArticleModal').modal('hide');
}
},
error: function(request, status, error){
alert("Erreur interne");
console.log("Appel AJAX : "+error);
}
});
});
</script>
{% endblock %}
{% block document_ready %}
$('#articles-only-table').bootstrapTable();
$('#articles-only-table').on('dbl-click-row.bs.table', function (row, element, field) {
$('#articles-only-table tbody tr').removeClass("selected");
field.addClass("selected");
var params = "{{ path('edit_article_global') }}/"+element.id;
$(location).attr('href', params);
});
$('#articles-ujuo-table').bootstrapTable();
$('#articles-ujuo-table').on('dbl-click-row.bs.table', function (row, element, field) {
$('#articles-ujuo-table tbody tr').removeClass("selected");
field.addClass("selected");
var params = "{{ path('edit_article_global') }}/"+element.id;
$(location).attr('href', params);
});
$('#articles-lbi-table').bootstrapTable();
$('#articles-lbi-table').on('dbl-click-row.bs.table', function (row, element, field) {
$('#articles-lbi-table tbody tr').removeClass("selected");
field.addClass("selected");
var params = "{{ path('edit_article_global') }}/"+element.id;
$(location).attr('href', params);
});
{% endblock %}