Commit 8d3b8825 authored by tguillon's avatar tguillon
Browse files

Correction + Factorisation: affichage des champs

parent 2bd5c347
......@@ -826,7 +826,7 @@ class FichesController extends AppController
$id
]);
$files = $this->Fichier->find('all', [
$filesSave = $this->Fichier->find('all', [
'conditions' => [
'fiche_id' => $id
]
......@@ -836,7 +836,7 @@ class FichesController extends AppController
$responsables = $this->_responsables();
$this->set(compact('soustraitance', 'valeurs', 'champs', 'id', 'files', 'responsables'));
$this->set(compact('soustraitance', 'valeurs', 'champs', 'id', 'filesSave', 'responsables'));
}
/**
......
......@@ -614,6 +614,10 @@ class FormulairesController extends AppController {
$champs = $this->Champ->find('all', [
'conditions' => [
'formulaires_id' => $id
],
'order' => [
'colonne ASC',
'ligne ASC'
]
]);
......
......@@ -673,13 +673,6 @@ $(document).ready(function () {
$('.ui-selected').find('.contentCheckbox').html(jQuery(objet));
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/height[^;]+;?/g, '');
});
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/width[^;]+;?/g, '');
});
} else if ($(this).hasClass('radioForm')) {
$.each(options, function (index, value) {
objet = objet + '<div class="radio"><input type="radio" name="' + nom + '" value="' + value + '">' + value + '</div>';
......@@ -687,13 +680,6 @@ $(document).ready(function () {
$('.ui-selected').find('.contentRadio').html(jQuery(objet));
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/height[^;]+;?/g, '');
});
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/width[^;]+;?/g, '');
});
} else if ($(this).hasClass('deroulantForm')) {
$.each(options, function (index, value) {
objet = objet + '<option name="' + nom + '" value="' + value +'">'+ value +'</option>';
......@@ -701,28 +687,21 @@ $(document).ready(function () {
$('.ui-selected').find('.contentDeroulant').html(jQuery(objet));
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/height[^;]+;?/g, '');
});
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/width[^;]+;?/g, '');
});
} else if ($(this).hasClass('multiSelectForm')) {
$.each(options, function (index, value) {
objet = objet + '<option name="' + nom + '" value="' + value +'">'+ value +'</option>';
});
$('.ui-selected').find('.contentMultiSelect').html(jQuery(objet));
}
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/height[^;]+;?/g, '');
});
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/height[^;]+;?/g, '');
});
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/width[^;]+;?/g, '');
});
}
$('.ui-selected').attr('style', function (i, style) {
return style.replace(/width[^;]+;?/g, '');
});
if ($(this).hasClass('obligForm')) {
if ($(this).prop('checked')) {
......
<!-- Onglet Annexe(s) -->
<div id="annexe" class="tab-pane">
<br/>
<!-- Texte Ajouter une pièce jointe -->
<h4>
<?php echo __d('fiche', 'fiche.textAjouterPieceJointe'); ?>
</h4>
<br/>
<!-- Texte format fichier accepté -->
<div class="alert alert-warning" role="alert">
<?php echo __d('fiche', 'fiche.textTypeFichierAccepter'); ?>
</div>
<?php
$i = $this->Html->tag(
'i',
'<!---->',
['class' => 'fa fa-cloud-upload fa-4x text-primary']
);
$p = $this->Html->tag(
'p',
('Glissez-déposez vos fichiers ici')
);
echo $this->Html->tag(
'div',
$i.$p,
['class' => 'dropbox']
);
?>
<br/>
if ($this->request->params['action'] != 'show') {
?>
<!-- Texte Ajouter une pièce jointe -->
<h4>
<?php echo __d('fiche', 'fiche.textAjouterPieceJointe'); ?>
</h4>
<br/>
<!-- Texte format fichier accepté -->
<div class="alert alert-warning" role="alert">
<?php echo __d('fiche', 'fiche.textTypeFichierAccepter'); ?>
</div>
<table class="table" id="render">
<tbody>
<?php
if (!empty($files)) {
foreach ($files as $key => $file) {
?>
<tr id="rowFiche<?php echo $key; ?>">
$i = $this->Html->tag(
'i',
'<!---->',
['class' => 'fa fa-cloud-upload fa-4x text-primary']
);
$p = $this->Html->tag(
'p',
('Glissez-déposez vos fichiers ici')
);
echo $this->Html->tag(
'div',
$i . $p,
['class' => 'dropbox']
);
?>
<td class="col-md-1">
<i class="fa fa-file-text-o fa-lg"><!----></i>
</td>
<br/>
<td class="col-md-9 tdleft">
<?php echo $file ?>
</td>
<table class="table" id="render">
<tbody>
<?php
if (!empty($files)) {
foreach ($files as $key => $file) {
?>
<tr id="rowFiche<?php echo $key; ?>">
<td class="col-md-2">
<button type="button" class="btn btn-warning" onclick="deleteFile('<?php echo $file ?>','<?php echo $key ?>')">
<i class="fa fa-times-circle"><!----></i>
Annuler
</button>
</td>
<td class="col-md-1">
<i class="fa fa-file-text-o fa-lg"><!----></i>
</td>
</tr>
<?php
<td class="col-md-9 tdleft">
<?php echo $file ?>
</td>
<td class="col-md-2">
<button type="button" class="btn btn-warning"
onclick="deleteFile('<?php echo $file ?>','<?php echo $key ?>')">
<i class="fa fa-times-circle"><!----></i>
Annuler
</button>
</td>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
?>
</tbody>
</table>
<?php
}
?>
<?php
if (!empty($filesSave)) {
if (empty($filesSave)) {
?>
<div class="col-md-12 top30">
<h4>
<?php echo __d('fiche', 'fiche.textInfoAucunePieceJointe'); ?>
</h4>
</div>
<?php
} else {
?>
<div class="col-md-12 top30">
<h4>
......@@ -95,12 +110,17 @@
'title' => 'Télécharger le fichier',
'escapeTitle' => false
]);
?>
<button type="button" class="btn btn-default-danger btn-sm my-tooltip left5 btn-del-file" onclick="deleteFileSave('<?php echo $val['Fichier']['id'] ?>','<?php echo $val['Fichier']['url'] ?>')">
<i class="fa fa-trash fa-lg"><!----></i>
</button>
if ($this->request->params['action'] != 'show') {
?>
<button type="button"
class="btn btn-default-danger btn-sm my-tooltip left5 btn-del-file"
onclick="deleteFileSave('<?php echo $val['Fichier']['id'] ?>','<?php echo $val['Fichier']['url'] ?>')">
<i class="fa fa-trash fa-lg"><!----></i>
</button>
<?php
}
?>
</td>
</tr>
<?php
......@@ -120,39 +140,39 @@
$(document).ready(function () {
$.fn.extend({
logEvents: function() {
logEvents: function () {
return this.each(function () {
$(this).onAny(function(event) {
$(this).onAny(function (event) {
console.log(event.target, event.type);
});
});
}
});
$.fn.onAny = function(cb){
for(var k in this[0])
if(k.search('on') === 0)
this.on(k.slice(2), function(e){
$.fn.onAny = function (cb) {
for (var k in this[0])
if (k.search('on') === 0)
this.on(k.slice(2), function (e) {
// Probably there's a better way to call a callback function with right context, $.proxy() ?
cb.apply(this,[e]);
cb.apply(this, [e]);
});
return this;
};
$('.dropbox').onAny(function(event) {
$('.dropbox').onAny(function (event) {
event.preventDefault();
$(this).removeClass('dragover');
});
$('.dropbox').on('dragover', function() {
$('.dropbox').on('dragover', function () {
$(this).addClass('dragover');
});
$('.dropbox').on('dragout, dragleave, dragexit', function() {
$('.dropbox').on('dragout, dragleave, dragexit', function () {
$(this).removeClass('dragover');
});
$('.dropbox').on('drop', function(event) {
$('.dropbox').on('drop', function (event) {
var formData = new FormData(),
files = [];
......@@ -166,22 +186,22 @@
data: formData,
processData: false,
contentType: false,
success: function(data) {
try{
success: function (data) {
try {
var content = JSON.parse(data);
for (var key in content) {
var tr = $('<tr id="rowFiche'+key+'"><\/tr>')
var tr = $('<tr id="rowFiche' + key + '"><\/tr>')
.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-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-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>')
$('#render').find('tbody').append(tr);
}
}catch(e){
} catch (e) {
alert("error");
return;
}
},
error: function() {
error: function () {
alert('error');
}
});
......@@ -189,34 +209,34 @@
});
function deleteFile(file, key){
function deleteFile(file, key) {
$.ajax({
url: '/fiches/deleteFile',
method: 'POST',
data: {filename :file},
success: function() {
var row = document.getElementById("rowFiche"+key);
data: {filename: file},
success: function () {
var row = document.getElementById("rowFiche" + key);
row.parentNode.removeChild(row);
},
error: function() {
error: function () {
alert('Erreur lors de la suppression du fichier');
}
});
}
function deleteFileSave(idFile, urlFile){
function deleteFileSave(idFile, urlFile) {
$.ajax({
url: '/fiches/deleteRecordingFile',
method: 'POST',
data: {
idFile : idFile,
urlFile : urlFile
idFile: idFile,
urlFile: urlFile
},
success: function() {
var row = document.getElementById("rowFichier"+idFile);
success: function () {
var row = document.getElementById("rowFichier" + idFile);
row.parentNode.removeChild(row);
},
error: function() {
error: function () {
alert('Erreur lors de la suppression du fichier');
}
});
......
......@@ -4,208 +4,206 @@ $line = 1;
?>
<!-- Onglet Formulaire -->
<div id="info_formulaire" class="tab-pane">
<br/>
<!-- Champs du formulaire -->
<div class="row">
<div class="col-md-6">
<?php
$incrementation_id = 0;
foreach ($champs as $value) {
if ($value['Champ']['colonne'] > $col) {
?>
</div>
<div class="col-md-6">
<?php
$line = 1;
$col++;
}
<br/>
<!-- Champs du formulaire -->
<div class="row">
<div class="col-md-6">
<?php
$incrementation_id = 0;
foreach ($champs as $value) {
if ($value['Champ']['colonne'] > $col) {
?>
</div>
<div class="col-md-6">
<?php
$line = 1;
$col++;
}
if ($value['Champ']['ligne'] > $line) {
for ($i = $line; $i < $value['Champ']['ligne']; $i++) {
?>
<div class="row row35"></div>
<?php
}
$line = $value['Champ']['ligne'];
if ($value['Champ']['ligne'] > $line) {
for ($i = $line; $i < $value['Champ']['ligne']; $i++) {
?>
<div class="row row35"></div>
<?php
}
$line = $value['Champ']['ligne'];
}
$options = json_decode($value['Champ']['details'], true);
$options = json_decode($value['Champ']['details'], true);
?>
?>
<!-- <div class="row row35">-->
<!-- <div class="col-md-12">-->
<div class="users form">
<div class="col-md-12">
<?php
switch ($value['Champ']['type']) {
// Petit champ texte
case 'input':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
break;
// Grand champ texte
case 'textarea':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'type' => 'textarea',
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
break;
// Champ date
case 'date':
echo $this->WebcilForm->input($options['name'], [
'id' => 'datetimepicker' . $incrementation_id,
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
$incrementation_id++;
break;
// Titre de catégorie
case 'title':
?>
<div class="col-md-12 text-center">
<h1>
<?php echo $options['content']; ?>
</h1>
<div class="users form">
<div class="col-md-12">
<?php
switch ($value['Champ']['type']) {
// Petit champ texte
case 'input':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
break;
// Grand champ texte
case 'textarea':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'type' => 'textarea',
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
break;
// Champ date
case 'date':
echo $this->WebcilForm->input($options['name'], [
'id' => 'datetimepicker' . $incrementation_id,
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
$incrementation_id++;
break;
// Titre de catégorie
case 'title':
?>
<div class="col-md-12 text-center">
<h1>
<?php echo $options['content']; ?>
</h1>
</div>
<?php
break;
// Label
case 'texte':
echo '<div class="form-group">'
. '<h5>' . $options['content'] . '</h5>'
. '</div>';
break;
// Champ d'information
case 'help':
?>
<div class="col-md-12 alert alert-info text-center">
<div class="col-md-12">
<i class="fa fa-fw fa-info-circle fa-2x"><!----></i>
</div>
<div class="col-md-12">
<?php echo $options['content']; ?>
</div>
<?php
break;
// Label
case 'texte':
echo '<div class="form-group">'
. '<h5>' . $options['content'] . '</h5>'
. '</div>';
break;
// Champ d'information
case 'help':
?>
<div class="col-md-12 alert alert-info text-center">
<div class="col-md-12">
<i class="fa fa-fw fa-info-circle fa-2x"><!----></i>
</div>
<div class="col-md-12">
<?php echo $options['content']; ?>
</div>
</div>
<?php
break;
// Cases à cocher
case 'checkboxes':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],
'class' => 'col-md-4'
],
'multiple' => 'checkbox',
'class' => 'checkbox',
'options' => $options['options'],
'div' => "input select"
]);
break;
// Menu déroulant
case 'deroulant':
echo $this->WebcilForm->input($options['name'], [
'id' => $options['name'],
'label' => [
'text' => $options['label'],