Commit 96a01db2 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Correction : suppression article dans la faq avec les annexes

Correction : suppression alert
parent 3137594b
...@@ -430,12 +430,26 @@ class ArticlesController extends AppController { ...@@ -430,12 +430,26 @@ class ArticlesController extends AppController {
$success = true; $success = true;
$this->Article->begin(); $this->Article->begin();
$files = $this->Fichierarticle->find('all', [
'conditions' => [
'article_id' => $id
],
'fields' => [
'url'
]
]);
$success = $success && false !== $this->Article->deleteAll([ $success = $success && false !== $this->Article->deleteAll([
'id' => $id 'Article.id' => $id
]); ]);
if ($success == true) { if ($success == true) {
$this->Article->commit(); $this->Article->commit();
foreach ($files as $file) {
$this->_deleteFileDisk($file['Fichierarticle']['url']);
}
$this->Session->setFlash(__d('article', 'article.flashsuccessSuppressionArticleEntite'), 'flashsuccess'); $this->Session->setFlash(__d('article', 'article.flashsuccessSuppressionArticleEntite'), 'flashsuccess');
} else { } else {
$this->Article->rollback(); $this->Article->rollback();
......
...@@ -42,8 +42,6 @@ class Article extends AppModel { ...@@ -42,8 +42,6 @@ class Article extends AppModel {
] ]
]; ];
public $hasOne = 'Fichier';
/** /**
* hasMany associations * hasMany associations
* *
......
...@@ -247,8 +247,8 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -247,8 +247,8 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
}); });
$.fn.onAny = function(cb){ $.fn.onAny = function(cb){
for(var k in this[0]) for (let k in this[0])
if(k.search('on') === 0) if (k.search('on') === 0)
this.on(k.slice(2), function(e){ this.on(k.slice(2), function(e){
// Probably there's a better way to call a callback function with right context, $.proxy() ? // Probably there's a better way to call a callback function with right context, $.proxy() ?
cb.apply(this,[e]); cb.apply(this,[e]);
...@@ -270,10 +270,10 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -270,10 +270,10 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
}); });
$('.dropbox').on('drop', function(event) { $('.dropbox').on('drop', function(event) {
var formData = new FormData(), let formData = new FormData(),
files = []; files = [];
for (var key in event.originalEvent.dataTransfer.files) { for (let key in event.originalEvent.dataTransfer.files) {
formData.append('fichiers[]', event.originalEvent.dataTransfer.files[key]); formData.append('fichiers[]', event.originalEvent.dataTransfer.files[key]);
} }
...@@ -285,20 +285,19 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -285,20 +285,19 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
contentType: false, contentType: false,
success: function(data) { success: function(data) {
try{ try{
var content = JSON.parse(data); let content = JSON.parse(data);
for (var key in content) { for (let key in content) {
if (content[key].status === "success") { if (content[key].status === "success") {
var tr = $('<tr id="rowArticle' + key + '"></tr>') let tr = $('<tr id="rowArticle' + key + '"></tr>')
.append('<td class="col-md-1"><i class="fa fa-file-text-o fa-lg"><!----></i></td>') .append('<td class="col-md-1"><i class="fa fa-file-text-o fa-lg"><!----></i></td>')
.append('<td class="col-md-9 tdleft">' + content[key].filename + '</td>') .append('<td class="col-md-9 tdleft">' + content[key].filename + '</td>')
.append('<td class=\"col-md-2\"><button type="button" class="btn btn-warning" onclick=\"deleteFile(\'' + content[key].filename + '\',\'' + key + '\')\"><i class="fa fa-times-circle"><!----></i> Annuler</button></td>') .append('<td class=\"col-md-2\"><button type="button" class="btn btn-warning" onclick=\"deleteFile(\'' + content[key].filename + '\',\'' + key + '\')\"><i class="fa fa-times-circle"><!----></i> Annuler</button></td>')
$('#render').find('tbody').append(tr); $('#render').find('tbody').append(tr);
} else { } else {
alert('totot');
$('#errorExtentionAnnexe').modal('show'); $('#errorExtentionAnnexe').modal('show');
} }
} }
}catch(e){ } catch(e){
alert("error"); alert("error");
return; return;
} }
...@@ -311,7 +310,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -311,7 +310,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
// Mise en évidence des onglets ayant des erreurs. // Mise en évidence des onglets ayant des erreurs.
$("div.form-group .error-message").closest("div.tab-pane").each(function(idx, pane) { $("div.form-group .error-message").closest("div.tab-pane").each(function(idx, pane) {
var a = $( "a[href='#"+$(pane).attr('id')+"']" ); let a = $( "a[href='#"+$(pane).attr('id')+"']" );
$(a).closest("li").addClass("form-error"); $(a).closest("li").addClass("form-error");
$(a).append("<span class='fa fa-exclamation-circle fa-danger' aria-hidden='true'><!----></span>"); $(a).append("<span class='fa fa-exclamation-circle fa-danger' aria-hidden='true'><!----></span>");
}); });
...@@ -326,7 +325,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -326,7 +325,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
method: 'POST', method: 'POST',
data: {filename: file}, data: {filename: file},
success: function () { success: function () {
var row = document.getElementById("rowArticle" + key); let row = document.getElementById("rowArticle" + key);
row.parentNode.removeChild(row); row.parentNode.removeChild(row);
}, },
error: function () { error: function () {
...@@ -348,7 +347,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [ ...@@ -348,7 +347,7 @@ echo $this->element('Fiches/modal/modalErrorExtentionAnnexe', [
urlFile: urlFile urlFile: urlFile
}, },
success: function () { success: function () {
var row = document.getElementById("rowArticle" + idFile); let row = document.getElementById("rowArticle" + idFile);
row.parentNode.removeChild(row); row.parentNode.removeChild(row);
}, },
error: function () { error: function () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment