Commit c59c0e4f authored by Mat's avatar Mat
Browse files

le date range slider dans une fonction, on lui passe les date debut et fin

parent 1b49b26f
......@@ -54,8 +54,6 @@
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formLettre.startedAt) }}
......@@ -76,6 +74,9 @@
</div>
</div>
<div id="dateRuleSlider" class="mb-4"></div>
{# TODO résoudre ptit bug d'affichage du slider #}
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formLettre.status) }}
......
......@@ -48,7 +48,6 @@
<div class="clearfix"></div>
</div>
<div id="dateRuleSlider" class="mb-4"></div>
</section>
{% endblock %}
......@@ -131,6 +130,10 @@
{% include '@Potage/LettreInfos/ajaxDisplay.js' %}
console.log('hop:');
console.log(new Date(2018, 5, 1));
</script>
{% endblock %}
......@@ -165,12 +165,16 @@ function editBlocLettre()
function(request) {
let json = JSON.parse(request.responseText);
formTitle.textContent = "Modifier l'lettre " + json.reference;
formTitle.textContent = "Modifier la lettre " + json.reference;
form.querySelector('#lettre_groupe').value = json.groupe.id;
form.querySelector('#lettre_offre').value = json.offre.id;
form.querySelector('#lettre_subject').value = json.subject;
form.querySelector('#lettre_startedAt').value = formatDateISO(json.started_at);
form.querySelector('#lettre_endedAt').value = formatDateISO(json.ended_at);
console.log('ajax get read_one:');
displayDateRangeSlider(json.started_at, json.ended_at);
form.querySelector('#lettre_status').value = json.status;
submitURL = Routing.generate('api_lettre_update', {'id': id_lettre});
});
......@@ -205,84 +209,89 @@ form.addEventListener('submit', function(e)
*
*/
function displayDateRangeSlider(minDate, maxDate)
{
let months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
let dows = ['di', 'lu', 'ma', 'me', 'je', 've', 'sa'];
let firstDay = 1; //lundi
console.log(new Date(minDate).getDate());
let months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
let dows = ['di', 'lu', 'ma', 'me', 'je', 've', 'sa'];
let firstDay = 1; //lundi
$("#dateRuleSlider").dateRangeSlider({
bounds: {
min: new Date(2018, 5, 1),
max: new Date(2018, 8, 20)
},
defaultValues: {
min: new Date(2018, 5, 29),
max: new Date(2018, 6, 6)
},
arrows: true,
step:{
days: 1
},
formatter: function(valeur){
let dow = dows[valeur.getDay()],
days = valeur.getDate(),
month = valeur.getMonth() + 1,
year = valeur.getFullYear();
return dow + " " + formatNumber(days, 2) + "/" + formatNumber(month, 2);
},
scales: [{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
return new Date(next.setMonth(value.getMonth() + 1));
let minD = new Date(minDate);
let maxD = new Date(maxDate);
$("#dateRuleSlider").dateRangeSlider({
bounds: {
min: new Date(2018, 5, 1),
max: new Date(2018, 8, 1)
},
label: function(value){
return months[value.getMonth()] + " " + value.getFullYear();
}
},
{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
if (value.getDay() === firstDay) {
return new Date(next.setDate(value.getDate() + 7));
} else {
function firstJump(i, d) {
let c = 0;
while (i !== d) {
if (i === 6) { i = 0; } else { i++; }
c++;
}
return c;
}
let jump = firstJump(value.getDay(), firstDay);
return new Date(next.setDate(value.getDate() + jump));
defaultValues: {
min: new Date(minD.getFullYear(), minD.getMonth(), minD.getDate()),
max: new Date(maxD.getFullYear(), maxD.getMonth(), maxD.getDate())
},
arrows: true,
step:{
days: 1
},
formatter: function(valeur){
let dow = dows[valeur.getDay()],
days = valeur.getDate(),
month = valeur.getMonth() + 1,
year = valeur.getFullYear();
return dow + " " + formatNumber(days, 2) + "/" + formatNumber(month, 2);
},
scales: [{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
return new Date(next.setMonth(value.getMonth() + 1));
},
label: function(value){
return months[value.getMonth()] + " " + value.getFullYear();
}
},
label: function() { return null; },
format: function(tickContainer, tickStart, tickEnd){
if (tickStart.getDate() === 1) {
tickContainer.addClass("no-tick");
{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
if (value.getDay() === firstDay) {
return new Date(next.setDate(value.getDate() + 7));
} else {
function firstJump(i, d) {
let c = 0;
while (i !== d) {
if (i === 6) { i = 0; } else { i++; }
c++;
}
return c;
}
let jump = firstJump(value.getDay(), firstDay);
return new Date(next.setDate(value.getDate() + jump));
}
},
label: function() { return null; },
format: function(tickContainer, tickStart, tickEnd){
if (tickStart.getDate() === 1) {
tickContainer.addClass("no-tick");
}
}
}
},
{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
return new Date(next.setDate(value.getDate() + 1));
},
label: function() { return null; },
format: function(tickContainer, tickStart, tickEnd){
if (tickStart.getDay() === firstDay || tickStart.getDate() === 1) {
tickContainer.addClass("no-tick");
{
first: function(value){ return value; },
end: function(value) {return value; },
next: function(value){
let next = new Date(value);
return new Date(next.setDate(value.getDate() + 1));
},
label: function() { return null; },
format: function(tickContainer, tickStart, tickEnd){
if (tickStart.getDay() === firstDay || tickStart.getDate() === 1) {
tickContainer.addClass("no-tick");
}
}
}
}]
});
}]
});
}
Supports Markdown
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