Remove useless kpsul.html code

This commit is contained in:
Ludovic Stephan 2019-12-25 20:12:03 +01:00
parent 17d96f1775
commit f901ea9396

View file

@ -10,6 +10,7 @@
<script type="text/javascript" src="{% static 'kfet/vendor/underscore-min.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/vendor/underscore-min.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/vendor/backbone-min.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/vendor/backbone-min.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/account.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/js/account.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/kpsul.js' %}"></script>
{% endblock %} {% endblock %}
{% block title %}K-Psul{% endblock %} {% block title %}K-Psul{% endblock %}
@ -213,124 +214,8 @@ $(document).ready(function() {
// Account data management // Account data management
// ----- // -----
// Initializing var account_manager = new AccountManager();
var account = new Account()
var account_container = $('#account');
var triInput = $('#id_trigramme'); var triInput = $('#id_trigramme');
var account_data = {};
var account_data_default = {
'id' : 0,
'name' : '',
'email': '',
'is_cof' : '',
'promo' : '',
'balance': '',
'trigramme' : '',
'is_frozen' : false,
'departement': '',
'nickname' : '',
};
// Search for an account
function searchAccount() {
var content = '<input type="text" name="q" id="search_autocomplete" spellcheck="false" autofocus><div id="account_results"></div>' ;
$.dialog({
title: 'Recherche de compte',
content: content,
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
onOpen: function() {
var that=this ;
$('input#search_autocomplete').yourlabsAutocomplete({
url: '{% url "kfet.account.search.autocomplete" %}',
minimumCharacters: 2,
id: 'search_autocomplete',
choiceSelector: '.choice',
placeholder: "Chercher un utilisateur K-Fêt",
box: $("#account_results"),
fixPosition: function() {},
});
$('input#search_autocomplete').bind(
'selectChoice',
function(e, choice, autocomplete) {
autocomplete.hide() ;
triInput.val(choice.find('.trigramme').text()) ;
triInput.trigger('input') ;
that.close() ;
});
}
});
}
account_container.on('click', '.search', function () {
searchAccount() ;
}) ;
account_container.on('keydown', function(e) {
if (e.which == 70 && e.ctrlKey) {
// Ctrl + F : universal search shortcut
searchAccount() ;
e.preventDefault() ;
}
});
// Clear data
function resetAccountData() {
account_data = account_data_default;
$('#id_on_acc').val(0);
account.reset();
account.view().reset()
}
function resetAccount() {
triInput.val('');
resetAccountData();
}
// Store data
function storeAccountData() {
account_data = account.toJSON();
$('#id_on_acc').val(account.id);
account.render();
}
// Retrieve via ajax
function retrieveAccountData(tri) {
account.set({'trigramme': tri});
account.fetch({
'success': function() {
storeAccountData();
articleSelect.focus();
updateBasketAmount();
updateBasketRel();
},
'error': function() {
resetAccountData();
},
})
}
// Event listener
triInput.on('input', function() {
var tri = triInput.val().toUpperCase();
// Checking if tri is valid to avoid sending requests
if (isValidTrigramme(tri)) {
retrieveAccountData(tri);
} else {
resetAccountData();
}
});
triInput.on('keydown', function(e) {
if (e.keyCode == 40) {
// Arrow Down - Shorcut to LIQ
triInput.val('LIQ');
triInput.trigger('input');
}
});
// ----- // -----
@ -416,7 +301,7 @@ $(document).ready(function() {
// Event listener // Event listener
checkoutInput.on('change', function() { checkoutInput.on('change', function() {
retrieveCheckoutData(checkoutInput.val()); retrieveCheckoutData(checkoutInput.val());
if (account_data['trigramme']) { if (account_manager.data['trigramme']) {
articleSelect.focus().select(); articleSelect.focus().select();
} else { } else {
triInput.focus().select(); triInput.focus().select();
@ -752,11 +637,11 @@ $(document).ready(function() {
var amount_euro = - article_data[3] * nb ; var amount_euro = - article_data[3] * nb ;
if (settings['addcost_for'] if (settings['addcost_for']
&& settings['addcost_amount'] && settings['addcost_amount']
&& account_data['trigramme'] != settings['addcost_for'] && account_manager.data['trigramme'] != settings['addcost_for']
&& article_data[5]) && article_data[5])
amount_euro -= settings['addcost_amount'] * nb; amount_euro -= settings['addcost_amount'] * nb;
var reduc_divisor = 1; var reduc_divisor = 1;
if (account_data['is_cof'] && article_data[6]) if (account_manager.data['is_cof'] && article_data[6])
reduc_divisor = 1 + settings['subvention_cof'] / 100; reduc_divisor = 1 + settings['subvention_cof'] / 100;
return (amount_euro / reduc_divisor).toFixed(2); return (amount_euro / reduc_divisor).toFixed(2);
} }
@ -779,7 +664,7 @@ $(document).ready(function() {
.attr('data-opeindex', index) .attr('data-opeindex', index)
.find('.number').text('('+nb+'/'+article_data[4]+')').end() .find('.number').text('('+nb+'/'+article_data[4]+')').end()
.find('.name').text(article_data[0]).end() .find('.name').text(article_data[0]).end()
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'], false)); .find('.amount').text(amountToUKF(amount_euro, account_manager.data['is_cof'], false));
basket_container.prepend(article_basket_html); basket_container.prepend(article_basket_html);
if (is_low_stock(id, nb)) if (is_low_stock(id, nb))
article_basket_html.find('.lowstock') article_basket_html.find('.lowstock')
@ -805,7 +690,7 @@ $(document).ready(function() {
.attr('data-opeindex', index) .attr('data-opeindex', index)
.find('.number').text(amount+"€").end() .find('.number').text(amount+"€").end()
.find('.name').text('Charge').end() .find('.name').text('Charge').end()
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false)); .find('.amount').text(amountToUKF(amount, account_manager.data['is_cof'], false));
basket_container.prepend(deposit_basket_html); basket_container.prepend(deposit_basket_html);
updateBasketRel(); updateBasketRel();
} }
@ -818,7 +703,7 @@ $(document).ready(function() {
.attr('data-opeindex', index) .attr('data-opeindex', index)
.find('.number').text(amount+"€").end() .find('.number').text(amount+"€").end()
.find('.name').text('Édition').end() .find('.name').text('Édition').end()
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false)); .find('.amount').text(amountToUKF(amount, account_manager.data['is_cof'], false));
basket_container.prepend(deposit_basket_html); basket_container.prepend(deposit_basket_html);
updateBasketRel(); updateBasketRel();
} }
@ -831,7 +716,7 @@ $(document).ready(function() {
.attr('data-opeindex', index) .attr('data-opeindex', index)
.find('.number').text(amount+"€").end() .find('.number').text(amount+"€").end()
.find('.name').text('Retrait').end() .find('.name').text('Retrait').end()
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false)); .find('.amount').text(amountToUKF(amount, account_manager.data['is_cof'], false));
basket_container.prepend(withdraw_basket_html); basket_container.prepend(withdraw_basket_html);
updateBasketRel(); updateBasketRel();
} }
@ -887,7 +772,7 @@ $(document).ready(function() {
var amount = $(this).find('#id_form-'+opeindex+'-amount'); var amount = $(this).find('#id_form-'+opeindex+'-amount');
if (!deleted && type == "purchase") if (!deleted && type == "purchase")
amount.val(amountEuroPurchase(article_id, article_nb)); amount.val(amountEuroPurchase(article_id, article_nb));
basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_data['is_cof'], false)); basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_manager.data['is_cof'], false));
}); });
} }
@ -895,7 +780,7 @@ $(document).ready(function() {
function updateBasketRel() { function updateBasketRel() {
var basketrel_html = ''; var basketrel_html = '';
if (account_data['trigramme'] == 'LIQ' && !isBasketEmpty()) { if (account_manager.data['trigramme'] == 'LIQ' && !isBasketEmpty()) {
var amount = - getAmountBasket(); var amount = - getAmountBasket();
basketrel_html += '<div>Total: '+amount.toFixed(2)+' €</div>'; basketrel_html += '<div>Total: '+amount.toFixed(2)+' €</div>';
if (amount < 5) if (amount < 5)
@ -904,11 +789,11 @@ $(document).ready(function() {
basketrel_html += '<div>Sur 10€: '+ (10-amount).toFixed(2) +' €</div>'; basketrel_html += '<div>Sur 10€: '+ (10-amount).toFixed(2) +' €</div>';
if (amount < 20) if (amount < 20)
basketrel_html += '<div>Sur 20€: '+ (20-amount).toFixed(2) +' €</div>'; basketrel_html += '<div>Sur 20€: '+ (20-amount).toFixed(2) +' €</div>';
} else if (account_data['trigramme'] != '' && !isBasketEmpty()) { } else if (account_manager.data['trigramme'] != '' && !isBasketEmpty()) {
var amount = getAmountBasket(); var amount = getAmountBasket();
var amountUKF = amountToUKF(amount, account_data['is_cof'], false); var amountUKF = amountToUKF(amount, account_manager.data['is_cof'], false);
var newBalance = account_data['balance'] + amount; var newBalance = account_manager.data['balance'] + amount;
var newBalanceUKF = amountToUKF(newBalance, account_data['is_cof'], true); var newBalanceUKF = amountToUKF(newBalance, account_manager.data['is_cof'], true);
basketrel_html += '<div>Total: '+amountUKF+'</div>'; basketrel_html += '<div>Total: '+amountUKF+'</div>';
basketrel_html += '<div>Nouveau solde: '+newBalanceUKF+'</div>'; basketrel_html += '<div>Nouveau solde: '+newBalanceUKF+'</div>';
if (newBalance < 0) if (newBalance < 0)
@ -929,7 +814,7 @@ $(document).ready(function() {
var nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val(); var nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val();
var nb_after = parseInt(nb_before) + parseInt(nb); var nb_after = parseInt(nb_before) + parseInt(nb);
var amountEuro_after = amountEuroPurchase(id, nb_after); var amountEuro_after = amountEuroPurchase(id, nb_after);
var amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); var amountUKF_after = amountToUKF(amountEuro_after, account_manager.data['is_cof']);
if (type == 'purchase') { if (type == 'purchase') {
if (nb_after == 0) { if (nb_after == 0) {
@ -1151,7 +1036,7 @@ $(document).ready(function() {
function updatePreviousOp() { function updatePreviousOp() {
var previousop_html = ''; var previousop_html = '';
var trigramme = account_data['trigramme']; var trigramme = account_manager.data['trigramme'];
previousop_html += '<div class="trigramme">Trigramme : '+trigramme+'</div>'; previousop_html += '<div class="trigramme">Trigramme : '+trigramme+'</div>';
previousop_html += basketrel_container.html(); previousop_html += basketrel_container.html();
previousop_container.html(previousop_html); previousop_container.html(previousop_html);
@ -1293,7 +1178,7 @@ $(document).ready(function() {
// Reset functions // Reset functions
function coolReset(give_tri_focus=true) { function coolReset(give_tri_focus=true) {
resetAccount(); account_manager.reset(true);
resetBasket(); resetBasket();
resetComment(); resetComment();
resetSelectable(); resetSelectable();
@ -1348,7 +1233,7 @@ $(document).ready(function() {
case 113: case 113:
if (e.shiftKey) { if (e.shiftKey) {
// Shift+F2 - Account reset // Shift+F2 - Account reset
resetAccount(); account_manager.reset(true);
triInput.focus(); triInput.focus();
} else { } else {
// F2 - Basket reset // F2 - Basket reset
@ -1380,6 +1265,9 @@ $(document).ready(function() {
} }
}); });
// On exporte les fonctions nécessaires dans `window`
window.updateBasketAmount = updateBasketAmount;
window.updateBasketRel = updateBasketRel;
// ----- // -----
// Initiliazing all // Initiliazing all
// ----- // -----