Complete date field on the all the screen that call framadatepicker.js
This commit is contained in:
parent
d6500a77d9
commit
f8611c09d6
@ -174,41 +174,7 @@
|
|||||||
|
|
||||||
// Title update on hours and buttons -/+ hours
|
// Title update on hours and buttons -/+ hours
|
||||||
|
|
||||||
var leftPad = function(text, pad) {
|
$(document).on('change', '.input-group.date input', function () {
|
||||||
return text ? pad.substring(0, pad.length - text.length) + text : text;
|
|
||||||
};
|
|
||||||
|
|
||||||
$(document).on('change', '#selected-days legend input', function () {
|
|
||||||
// Complete field if needed
|
|
||||||
var val = $(this).val();
|
|
||||||
var capture = /([0-9]+)(?:\/([0-9]+))?/.exec(val);
|
|
||||||
|
|
||||||
if (capture) {
|
|
||||||
var inputDay = leftPad(capture[1], "00"); // 5->05, 15->15
|
|
||||||
var inputMonth = leftPad(capture[2], "00"); // 3->03, 11->11
|
|
||||||
var inputDate = null;
|
|
||||||
var now = new Date();
|
|
||||||
|
|
||||||
if (inputMonth) {
|
|
||||||
inputDate = new Date(now.getFullYear() + '-' + inputMonth + '-' + inputDay);
|
|
||||||
|
|
||||||
// If new date is before now, add 1 year
|
|
||||||
if (inputDate < now) {
|
|
||||||
inputDate.setFullYear(now.getFullYear() + 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inputDate = new Date(now.getFullYear() + '-' + leftPad(""+(now.getMonth() + 1), "00") + '-' + inputDay);
|
|
||||||
|
|
||||||
// If new date is before now, add 1 month
|
|
||||||
if (inputDate < now) {
|
|
||||||
inputDate.setMonth(now.getMonth() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$(this).val(inputDate.toLocaleFormat("%d/%m/%Y"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define title on hours fields using the value of the new date
|
// Define title on hours fields using the value of the new date
|
||||||
$selected_days.find('.hours').each(function () {
|
$selected_days.find('.hours').each(function () {
|
||||||
$(this).attr('title', $(this).parents('fieldset').find('legend input').val() + ' - ' + $(this).attr('placeholder'));
|
$(this).attr('title', $(this).parents('fieldset').find('legend input').val() + ' - ' + $(this).attr('placeholder'));
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
|
$(document).ready(function() {
|
||||||
var init_datepicker = function() {
|
var init_datepicker = function () {
|
||||||
$('.input-group.date').datepicker({
|
$('.input-group.date').datepicker({
|
||||||
format: "dd/mm/yyyy",
|
format: "dd/mm/yyyy",
|
||||||
todayBtn: "linked",
|
todayBtn: "linked",
|
||||||
@ -24,17 +24,17 @@ var init_datepicker = function() {
|
|||||||
autoclose: true,
|
autoclose: true,
|
||||||
language: lang,
|
language: lang,
|
||||||
todayHighlight: true,
|
todayHighlight: true,
|
||||||
beforeShowDay: function (date){
|
beforeShowDay: function (date) {
|
||||||
var $selected_days = [];
|
var $selected_days = [];
|
||||||
$('#selected-days').find('input[id^="day"]').each(function() {
|
$('#selected-days').find('input[id^="day"]').each(function () {
|
||||||
if($(this).val()!='') {
|
if ($(this).val() != '') {
|
||||||
$selected_days.push($(this).val());
|
$selected_days.push($(this).val());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for(var i = 0; i < $selected_days.length; i++){
|
for (var i = 0; i < $selected_days.length; i++) {
|
||||||
var $selected_date = $selected_days[i].split('/');
|
var $selected_date = $selected_days[i].split('/');
|
||||||
|
|
||||||
if (date.getFullYear() == $selected_date[2] && (date.getMonth()+1) == $selected_date[1] && date.getDate() == $selected_date[0]){
|
if (date.getFullYear() == $selected_date[2] && (date.getMonth() + 1) == $selected_date[1] && date.getDate() == $selected_date[0]) {
|
||||||
return {
|
return {
|
||||||
classes: 'disabled selected'
|
classes: 'disabled selected'
|
||||||
};
|
};
|
||||||
@ -42,4 +42,44 @@ var init_datepicker = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Complete the date fields when use partialy fill it (eg: 15/01 could become 15/01/2016)
|
||||||
|
|
||||||
|
var leftPad = function(text, pad) {
|
||||||
|
return text ? pad.substring(0, pad.length - text.length) + text : text;
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).on('change', '.input-group.date input', function () {
|
||||||
|
// Complete field if needed
|
||||||
|
var val = $(this).val();
|
||||||
|
var capture = /([0-9]+)(?:\/([0-9]+))?/.exec(val);
|
||||||
|
|
||||||
|
if (capture) {
|
||||||
|
var inputDay = leftPad(capture[1], "00"); // 5->05, 15->15
|
||||||
|
var inputMonth = leftPad(capture[2], "00"); // 3->03, 11->11
|
||||||
|
var inputDate = null;
|
||||||
|
var now = new Date();
|
||||||
|
|
||||||
|
if (inputMonth) {
|
||||||
|
inputDate = new Date(now.getFullYear() + '-' + inputMonth + '-' + inputDay);
|
||||||
|
|
||||||
|
// If new date is before now, add 1 year
|
||||||
|
if (inputDate < now) {
|
||||||
|
inputDate.setFullYear(now.getFullYear() + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputDate = new Date(now.getFullYear() + '-' + leftPad("" + (now.getMonth() + 1), "00") + '-' + inputDay);
|
||||||
|
|
||||||
|
// If new date is before now, add 1 month
|
||||||
|
if (inputDate < now) {
|
||||||
|
inputDate.setMonth(now.getMonth() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(this).val(inputDate.toLocaleFormat("%d/%m/%Y"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user