Skip to content

Commit

Permalink
fix bootstrap date picker event catching. Locale is still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed Dec 25, 2024
1 parent 7352efd commit 7f5bbe8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 64 deletions.
2 changes: 2 additions & 0 deletions crm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def company_pivotable(request, company_id=None):
startDate = datetime.now() - timedelta(365) # Default to 1 year. It is often enough.
if endDate:
endDate = datetime.strptime(endDate, dateFormat)
else:
endDate = datetime.today()
except ValueError:
pass

Expand Down
45 changes: 27 additions & 18 deletions templates/billing/pre_billing.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,42 @@ <h4>{{ mission.lead }} ({{ mission.lead.deal_id }})</h4>
{% include "core/_datepicker.html" %}

<script type="text/javascript">
// set dates on widgets with template value
// set dates on widgets with template value
{% if start_date %}
$("#startDate").datepicker("setDate", new Date("{{ start_date|date:"Y-m-d" }}"));
{% endif %}
{% if end_date %}
$("#endDate").datepicker("setDate", new Date("{{ end_date|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("changeDate", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (fromDate > toDate || fromDate.getTime() == toDate.getTime()) {
toDate = new Date(toDate.setMonth(toDate.getMonth()+1));
}
if (!isNaN(fromDate.getTime())) {
param += yyyymm(fromDate) + '/';
}
if (!isNaN(toDate.getTime())) {
param += yyyymm(toDate);
}
window.location.href = window.location.href.replace(/\?.*/, '').replace(/\d{6}\/?/g, '') + param;
});

$(document).ready(function() {
$(".pydici-tooltip").tooltip();

// set dates on widgets with template value
{% if start_date %}
$("#startDate").datepicker("setDate", new Date("{{ start_date|date:"Y-m-d" }}"));
{% endif %}
{% if end_date %}
$("#endDate").datepicker("setDate", new Date("{{ end_date|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("change", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (fromDate > toDate || fromDate.getTime() == toDate.getTime()) {
toDate = new Date(toDate.setMonth(toDate.getMonth()+1));
}
if (!isNaN(fromDate.getTime())) {
param += yyyymm(fromDate) + '/';
}
if (!isNaN(toDate.getTime())) {
param += yyyymm(toDate);
}
window.location.href = window.location.href.replace(/\?.*/, '').replace(/\d{6}\/?/g, '') + param;
});

});
</script>
{% endblock %}
6 changes: 3 additions & 3 deletions templates/core/pydici.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha512-mSYUmp1HYZDFaVKK//63EcZq4iFWFjxSL+Z3T/aCt4IO9Cejm03q3NKKYN6pFQzY0SBOr8h+eCIAZHPXcpZaNw==" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/css/bootstrap-datepicker.min.css" integrity="sha512-34s5cpvaNG3BknEWSuOncX28vz97bRI59UnVtEEpFX536A7BtZSJHsDyFoCl8S7Dt2TPzcrCEoHBGeM4SUBDBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="{{ MEDIA_URL }}tables2/css/screen.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" type="text/css" media="screen" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/select2-bootstrap-5-theme.min.css" type="text/css" media="screen" rel="stylesheet">
Expand All @@ -43,9 +43,9 @@

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha512-T/tUfKSV1bihCnd+MxKD0Hm1uBBroVYBOYSk1knyvQ9VyZJpc/ALb4P0r6ubwVPSGB2GvjeoMAJJImBG12TiaQ==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js" integrity="sha512-LsnSViqQyaXpD4mBBdRYeP6sRwJiJveh2ZIbW41EBrNmKxgr/LFZIiWT6yr+nycvhvauz8c2nYMhrP80YhG7Cw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{% if LANGUAGE_CODE == "fr-fr" %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/locales/bootstrap-datepicker.fr.min.js" integrity="sha512-fx3aztaUjb4NyoD+Tso5g7R1l29bU3jnnTfNRKBiY9fdQOHzVhKJ10wEAgQ1zM/WXCzB9bnVryHD1M40775Tsw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.fr.min.js" integrity="sha512-fx3aztaUjb4NyoD+Tso5g7R1l29bU3jnnTfNRKBiY9fdQOHzVhKJ10wEAgQ1zM/WXCzB9bnVryHD1M40775Tsw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{% endif %}

<script src="https://cdn.datatables.net/v/bs5/jszip-3.10.1/dt-2.1.8/b-3.1.2/b-colvis-3.1.2/b-html5-3.1.2/date-1.5.4/fh-4.0.1/r-3.0.3/sp-2.3.3/datatables.min.js"></script>
Expand Down
41 changes: 21 additions & 20 deletions templates/crm/company_pivotable.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,30 @@ <h2 class="mt-2">{% trans "Pivot table for company " %} {{ company }}</h2>
}

// set dates on widgets with template value
{% if startDate %}
$("#startDate").datepicker("setDate", new Date("{{ startDate|date:"Y-m-d" }}"));
{% endif %}
{% if endDate %}
$("#endDate").datepicker("setDate", new Date("{{ endDate|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("changeDate", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (!isNaN(fromDate.getTime())) {
param += "start=" + yyyymmdd(fromDate);
}
if (!isNaN(toDate.getTime())) {
param += "&end=" + yyyymmdd(toDate);
}
$('#tab-reporting').load("{% url 'crm:company_pivotable' company.id %}?"+param);
$(document).ready(function() {
{% if startDate %}
$("#startDate").datepicker("setDate", new Date("{{ startDate|date:"Y-m-d" }}"));
{% endif %}
{% if endDate %}
$("#endDate").datepicker("setDate", new Date("{{ endDate|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("change", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (!isNaN(fromDate.getTime())) {
param += "start=" + yyyymmdd(fromDate);
}
if (!isNaN(toDate.getTime())) {
param += "&end=" + yyyymmdd(toDate);
}
$('#tab-reporting').load("{% url 'crm:company_pivotable' company.id %}?"+param);
});
});



// default
done_by_client();
</script>
Expand Down
45 changes: 22 additions & 23 deletions templates/leads/lead_pivotable.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,30 @@ <h2 class="mt-2">{% trans "Pivot table for lead " %} {{ lead }}</h2>
var cols = ["{% trans 'mission name' %}"];;
drawPivot(data, rows, cols, "Stacked Bar Chart", '{% trans "Sum" %}', ['{% trans "done (days)" %}']);
}

// set dates on widgets with template value
{% if startDate %}
$("#startDate").datepicker("setDate", new Date("{{ startDate|date:"Y-m-d" }}"));
{% endif %}
{% if endDate %}
$("#endDate").datepicker("setDate", new Date("{{ endDate|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("changeDate", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (fromDate !== null && !isNaN(fromDate.getTime())) {
param += "start=" + yyyymmdd(fromDate);
}
if (toDate !== null && !isNaN(toDate.getTime())) {
param += "&end=" + yyyymmdd(toDate);
}
$('#tab-reporting').load("{% url 'leads:lead_pivotable' lead.id %}?"+param);
$(document).ready(function() {
// set dates on widgets with template value
{% if startDate %}
$("#startDate").datepicker("setDate", new Date("{{ startDate|date:"Y-m-d" }}"));
{% endif %}
{% if endDate %}
$("#endDate").datepicker("setDate", new Date("{{ endDate|date:"Y-m-d" }}"));
{% endif %}

// reload data with choosen timeframe
$('.datepicker').datepicker().on("change", function(e) {
var param = "";
var fromDate = $("#startDate").datepicker("getDate");
var toDate = $("#endDate").datepicker("getDate");
if (fromDate !== null && !isNaN(fromDate.getTime())) {
param += "start=" + yyyymmdd(fromDate);
}
if (toDate !== null && !isNaN(toDate.getTime())) {
param += "&end=" + yyyymmdd(toDate);
}
$('#tab-reporting').load("{% url 'leads:lead_pivotable' lead.id %}?"+param);
});
});



// default
mission_by_date();
</script>
Expand Down

0 comments on commit 7f5bbe8

Please sign in to comment.