Here my solution
in Grocery_CRUD library, here the modifications in get_upload_file_input function:
/*
$input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'">
<span>'.$this->l('form_upload_a_file').'</span>
<input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'">
<input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" />
</span>';
*/
$input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'">
<span>'.$this->l('form_upload_a_file').'</span>
<input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'">
<input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" />
</span>';
before the return $input;
$input .= "<div id='pdfs'></div>"; //ajout
in my view, after js and css files
<script>
/* fonction de suppression pour d'un pdf */
function supprimerPdf(id) {
var part = (window.location.pathname).match(/\d+$/);
$.ajax({
type: "get",
url: "<?php echo base_url("index.php/participations/delete_pdfs/"); ?>" + id + "/" + part,
dataType: 'JSON',
success: function (data) {
$('#pdf_' + id).css({'color':'#aaaaaa', 'text-decoration':'line-through'});
$('#pdf_' + id + ' > .mm-delete').removeAttr('onclick').empty().next().next().removeAttr('onclick').empty();
},
error: function (a,b,c) {
console.log(a);
console.log(b);
console.log(c);
}
});
}
/* fonction la lecture d'un pdf */
function lirepdf(pdf) {
window.open(pdf);
}
</script>
at the end of view
<script>
window.onload = function () {
var id = (window.location.pathname).match(/\d+$/);
/* Affichage des pdfs */
function recherche_pdf(id) {
$.ajax({
type: "get",
url: "<?php echo base_url("index.php/participations/get_pdfs/"); ?>" + id[0],
dataType: 'JSON',
success: function (data) {
$('#pdfs').empty();
if (data != 'nopdf') {
for (var pdf in data) {
var name_pdf = data[pdf].substr(6);
$('#pdfs').append('<br/><span id="pdf_' + pdf + '"><span class="mm-delete" onClick="supprimerPdf(' + pdf + ')"><span class="text-danger glyphicon glyphicon-trash"></span></span> <span>' + name_pdf + '</span> <span onClick="lirepdf(\'<?php echo base_url('/assets/pdfs/'); ?>' + data[pdf] + '\')"><span class="text-info glyphicon glyphicon-eye-open"></span></span></span>');
};
}
},
error: function (a,b,c) {
console.log(a);
console.log(b);
console.log(c);
}
});
}
if (id != null) {
recherche_pdf(id);
}
$('#file_url_display_as_box').click(function () {
recherche_pdf(id);
});
}
</script>
The get_pdfs function returns an array $data[id_file] = $pdf_name.
this function calls a join table id_file / part_id (main table id)
and a table that lists the files.
in controller
$state = $crud->getState();
if ($state == 'delete_file')
{
die; // prevents the deletion of the pdf after its insertion ;O))
}