diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index a6a4a9c2..c2d7f1ff 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -12,6 +12,12 @@ input[type=number]::-webkit-outer-spin-button { background:#fff; } +@keyframes colorchange { + 0% { background: yellow; } + 50% { background: #660066; } + 100% { background: yellow; } +} + /* * Top row */ @@ -163,6 +169,24 @@ input[type=number]::-webkit-outer-spin-button { right:0; } +#addcost { + position:absolute; + bottom:0; + left:0; + + height:32px; + line-height:32px; + padding:0 10px; + + background:#c8102e; + color:#fff; + + font-weight:bold; + + animation: blink 1.5s steps(1) infinite; +} +@keyframes blink { 50% { visibility: hidden; } } + /* * Second part */ diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index dac7ee61..2d7a1238 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -126,14 +126,30 @@ $(document).ready(function() { } }); - var subvention_cof = 25; - function amountToUKF(amount, is_cof=false) { - if (is_cof) - return Math.round(amount * (1+subvention_cof/100) * 10); - return Math.round(amount * 10); + var coef_cof = is_cof ? 1 + settings['subvention_cof'] / 100 : 1; + return Math.round(amount * coef_cof * 10); } + // Retrieve settings + + var settings = {} + + function resetSettings() { + $.ajax({ + dataType: "json", + url : "{% url 'kfet.kpsul.get_settings' %}", + method : "POST", + }) + .done(function(data) { + settings['addcost_for'] = data['addcost_for']; + settings['addcost_amount'] = parseFloat(data['addcost_amount']); + settings['subvention_cof'] = parseFloat(data['subvention_cof']); + displayAddcost(); + }); + } + + // ----- // Account data management // ----- @@ -665,7 +681,7 @@ $(document).ready(function() { article_data = articlesList[i]; var reduc_divisor = 1; if (account_data['is_cof']) - reduc_divisor = 1 + subvention_cof / 100; + reduc_divisor = 1 + settings['subvention_cof'] / 100; return - article_data[3] * nb / reduc_divisor; } @@ -1027,6 +1043,20 @@ $(document).ready(function() { // Addcost // ----- + var addcost_default_html = '
Majoration vers de
'; + + function displayAddcost() { + checkout_container.find('#addcost').remove(); + $('body').css('animation', 'none'); + if (settings['addcost_for'] && settings['addcost_amount']) { + var addcost_html = $(addcost_default_html); + addcost_html + .find('.addcost_for').text(settings['addcost_for']).end() + .find('.addcost_amount').text(settings['addcost_amount'].toFixed(2)).end(); + checkout_container.prepend(addcost_html); + $('body').css('animation', 'colorchange 3s infinite'); + } + } function sendAddcost(trigramme, amount, password='') { var data = { trigramme: trigramme, @@ -1043,9 +1073,6 @@ $(document).ready(function() { $xhr.setRequestHeader("KFetPassword", password); }, }) - .done(function(data) { - location.reload(); - }) .fail(function($xhr) { var data = $xhr.responseJSON; switch ($xhr.status) { @@ -1160,6 +1187,11 @@ $(document).ready(function() { articles_container.find('[data-article='+article['id']+'] .stock') .text(article['stock']); } + if (data['addcost']) { + settings['addcost_for'] = data['addcost']['for']; + settings['addcost_amount'] = parseFloat(data['addcost']['amount']); + displayAddcost(); + } } // ----- @@ -1181,6 +1213,7 @@ $(document).ready(function() { resetCheckout(); resetArticles(); resetHistory(); + resetSettings(); getArticles(); getHistory(); } diff --git a/kfet/urls.py b/kfet/urls.py index c62684c4..1ce9b7a7 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -121,6 +121,8 @@ urlpatterns = [ name = 'kfet.kpsul.articles_data'), url('^k-psul/update_addcost$', views.kpsul_update_addcost, name = 'kfet.kpsul.update_addcost'), + url('^k-psul/get_settings$', views.kpsul_get_settings, + name = 'kfet.kpsul.get_settings'), # ----- # Settings urls diff --git a/kfet/views.py b/kfet/views.py index 2ae22ccb..4702f614 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -479,8 +479,19 @@ def kpsul(request): data['checkout_form'] = KPsulCheckoutForm() operation_formset = KPsulOperationFormSet(queryset=Operation.objects.none()) data['operation_formset'] = operation_formset + addcost_for = Settings.ADDCOST_FOR() return render(request, 'kfet/kpsul.html', data) +@permission_required('kfet.is_team') +def kpsul_get_settings(request): + addcost_for = Settings.ADDCOST_FOR() + data = { + 'subvention_cof': Settings.SUBVENTION_COF(), + 'addcost_for' : addcost_for and addcost_for.trigramme or '', + 'addcost_amount': Settings.ADDCOST_AMOUNT(), + } + return JsonResponse(data) + @permission_required('kfet.is_team') def kpsul_account_data(request): trigramme = request.POST.get('trigramme', '')