2016-08-06 22:19:52 +02:00
{% extends 'kfet/base.html' %}
{% load staticfiles %}
{% block extra_head %}
2016-08-18 05:33:42 +02:00
< link rel = "stylesheet" style = "text/css" href = "{% static 'kfet/css/jquery-ui.min.css' %}" >
2016-08-17 00:46:31 +02:00
< link rel = "stylesheet" style = "text/css" href = "{% static 'kfet/css/kpsul_grid.css' %}" >
2016-08-14 19:59:36 +02:00
< script type = "text/javascript" src = "{% static 'kfet/js/js.cookie.js' %}" > < / script >
< script type = "text/javascript" src = "{% static 'kfet/js/reconnecting-websocket.js' %}" > < / script >
2016-08-18 05:33:42 +02:00
< script type = "text/javascript" src = "{% static 'kfet/js/jquery-ui.min.js' %}" > < / script >
2016-08-17 00:46:31 +02:00
< script type = "text/javascript" src = "{% static 'kfet/js/jquery-confirm.js' %}" > < / script >
2016-08-06 22:19:52 +02:00
{% endblock %}
{% block title %}K-Psul{% endblock %}
2016-08-12 10:03:39 +02:00
{% block content-header %}{% endblock %}
2016-08-06 22:19:52 +02:00
{% block content %}
{% csrf_token %}
< form id = "operationgroup_form" > {{ operationgroup_form }}< / form >
2016-08-16 03:36:14 +02:00
< div class = "row kpsul_top" >
< div class = "col-sm-8" >
< div class = "row" id = "account" >
< div class = "col-lg-3 col-xs-4" id = "account_form" >
{{ trigramme_form.trigramme }}
< / div >
< div class = "col-lg-9 col-xs-8" id = "account_data" >
< div id = "account-balance" class = "data_line" > < / div >
< div id = "account-name" class = "data_line" > < / div >
< div id = "account-nickname" class = "data_line" > < / div >
< div class = "data_line" >
< span id = "account-is_cof" > < / span >
< span id = "account-departement" > < / span >
< span id = "account-promo" > < / span >
< / div >
< div id = "account-email" class = "data_line" > < / div >
2016-08-19 02:56:45 +02:00
< div class = "buttons" >
< / div >
2016-08-16 03:36:14 +02:00
< / div >
< / div >
< / div >
< div class = "col-sm-4" id = "checkout" >
< div id = "checkout_form" >
{{ checkout_form.checkout }}
< / div >
< div id = "checkout_data" >
< div >
< b > En caisse:< / b > < span id = "checkout-balance" > < / span > €
< / div >
2016-08-21 16:45:25 +02:00
< div id = "last_statement" >
2016-08-16 03:36:14 +02:00
< / div >
2016-08-19 02:56:45 +02:00
< div class = "buttons" >
< / div >
2016-08-16 03:36:14 +02:00
< / div >
< / div >
2016-08-06 22:19:52 +02:00
< / div >
2016-08-16 03:36:14 +02:00
< div class = "row kpsul_middle" >
2016-08-17 00:46:31 +02:00
< div class = "col-sm-8 kpsul_middle_left_col" >
< div class = "kpsul_middle_left" >
< div class = "kpsul_middle_left_top" >
< div id = "special_operations" >
< button role = "button" class = "btn" id = "operation_deposit" > Charge< / button >
< button role = "button" class = "btn" id = "operation_withdraw" > Retrait< / button >
< / div >
< div id = "article_selection" >
< input type = "text" id = "article_autocomplete" >
< input type = "number" id = "article_number" step = "1" min = "1" >
< input type = "hidden" id = "article_id" value = "" >
< / div >
< div id = "articles_data" >
< table >
< tbody >
< / tbody >
< / table >
< / div >
2016-08-16 03:36:14 +02:00
< / div >
2016-08-17 00:46:31 +02:00
< div class = "row kpsul_middle_left_bottom" >
2016-08-19 01:44:56 +02:00
< div class = "col-sm-6" >
< div id = "basket" >
< table id = "basket_table" >
< / table >
< / div >
2016-08-17 00:46:31 +02:00
< / div >
2016-08-19 01:44:56 +02:00
< div class = "col-sm-6" >
< div id = "basket_rel" >
< / div >
2016-08-17 00:46:31 +02:00
< / div >
2016-08-16 03:36:14 +02:00
< / div >
< / div >
< / div >
2016-08-19 01:08:57 +02:00
< div class = "col-sm-4 kpsul_middle_right_col" >
2016-08-18 18:26:58 +02:00
< div id = "history" >
2016-08-17 00:46:31 +02:00
< / div >
2016-08-16 03:36:14 +02:00
< / div >
2016-08-06 22:19:52 +02:00
< / div >
2016-08-17 11:44:58 +02:00
< form id = "operation_formset" style = "display:none" >
2016-08-06 22:19:52 +02:00
{{ operation_formset.as_p }}
< / form >
2016-08-17 11:44:58 +02:00
< div style = "display:none;" id = "operation_empty_html" data-opeindex = "__prefix__" >
{{ operation_formset.empty_form }}
< / div >
2016-08-14 19:59:36 +02:00
2016-08-06 22:19:52 +02:00
< script type = "text/javascript" >
$(document).ready(function() {
// -----
// General
// -----
// Retrieving csrf token
var csrftoken = Cookies.get('csrftoken');
// Appending csrf token to ajax post requests
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) & & !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
2016-08-18 05:33:42 +02:00
function amountToUKF(amount, is_cof=false) {
2016-08-22 16:08:21 +02:00
var coef_cof = is_cof ? 1 + settings['subvention_cof'] / 100 : 1;
return Math.round(amount * coef_cof * 10);
2016-08-18 05:33:42 +02:00
}
2016-08-22 16:08:21 +02:00
// 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();
});
}
2016-08-06 22:19:52 +02:00
// -----
// Account data management
// -----
// Initializing
2016-08-19 02:56:45 +02:00
var account_container = $('#account');
2016-08-06 22:19:52 +02:00
var triInput = $('#id_trigramme')
var triPattern = /^[^a-z]{3}$/
var account_data = {}
2016-08-12 10:03:39 +02:00
var account_data_default = {
2016-08-19 02:56:45 +02:00
'id' : 0,
2016-08-12 10:03:39 +02:00
'name' : '',
'email': '',
2016-08-18 05:33:42 +02:00
'is_cof' : '',
2016-08-12 10:03:39 +02:00
'promo' : '',
'balance': '',
2016-08-16 03:36:14 +02:00
'trigramme' : '',
2016-08-13 10:07:35 +02:00
'is_frozen' : false,
2016-08-12 10:03:39 +02:00
'departement': '',
'nickname' : '',
}
2016-08-06 22:19:52 +02:00
// Display data
function displayAccountData() {
2016-08-18 05:33:42 +02:00
var balance = account_data['trigramme'] != 'LIQ' ? account_data['balance'] : '';
if (balance != '')
balance = amountToUKF(account_data['balance'], account_data['is_cof']);
2016-08-16 03:36:14 +02:00
for (var elem in account_data) {
2016-08-18 05:33:42 +02:00
if (elem == 'balance') {
$('#account-balance').text(balance);
} else {
$('#account-'+elem).text(account_data[elem]);
}
2016-08-16 03:36:14 +02:00
}
if (account_data['is_frozen']) {
$('#account').attr('data-balance', 'frozen');
} else if (account_data['balance'] >= 5 || account_data['trigramme'] == 'LIQ') {
$('#account').attr('data-balance', 'ok');
2016-08-19 01:08:57 +02:00
} else if (account_data['balance'] == '') {
$('#account').attr('data-balance', '');
2016-08-16 03:36:14 +02:00
} else if (account_data['balance'] >= 0) {
$('#account').attr('data-balance', 'low');
} else {
$('#account').attr('data-balance', 'neg');
2016-08-06 22:19:52 +02:00
}
2016-08-19 02:56:45 +02:00
var buttons = '';
if (account_data['id'] != 0) {
buttons += '< a href = "/k-fet/accounts/'+account_data['trigramme']+'" class = "btn btn-primary" target = "_blank" title = "Modifier" > < span class = "glyphicon glyphicon-cog" > < / span > < / a > ';
}
account_container.find('.buttons').html(buttons);
2016-08-06 22:19:52 +02:00
}
// Clear data
function resetAccountData() {
2016-08-12 10:03:39 +02:00
account_data = account_data_default;
2016-08-06 22:19:52 +02:00
$('#id_on_acc').val(0);
displayAccountData();
}
2016-08-18 05:33:42 +02:00
function resetAccount() {
resetAccountData();
triInput.val('');
}
2016-08-06 22:19:52 +02:00
// Store data
function storeAccountData(data) {
2016-08-16 03:36:14 +02:00
account_data = $.extend({}, account_data_default, data);
2016-08-18 16:38:44 +02:00
account_data['balance'] = parseFloat(account_data['balance']);
2016-08-19 03:07:21 +02:00
$('#id_on_acc').val(account_data['id']);
2016-08-06 22:19:52 +02:00
displayAccountData();
}
// Retrieve via ajax
function retrieveAccountData(tri) {
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.account_data' %}",
method : "POST",
data : { trigramme: tri },
})
2016-08-17 00:46:31 +02:00
.done(function(data) {
storeAccountData(data);
2016-08-18 16:38:44 +02:00
articleSelect.focus();
updateBasketAmount();
updateBasketRel();
2016-08-17 00:46:31 +02:00
})
.fail(function() { resetAccountData() });
2016-08-06 22:19:52 +02:00
}
// Event listener
triInput.on('input', function() {
2016-08-16 03:36:14 +02:00
var tri = triInput.val().toUpperCase();
2016-08-06 22:19:52 +02:00
// Checking if tri is valid to avoid sending requests
if (tri.match(triPattern)) {
retrieveAccountData(tri);
} else {
resetAccountData();
}
});
// -----
// Checkout data management
// -----
// Initializing
2016-08-19 02:56:45 +02:00
var checkout_container = $('#checkout');
2016-08-06 22:19:52 +02:00
var checkoutInput = $('#id_checkout_select');
var checkout_data = {}
2016-08-12 10:03:39 +02:00
var checkout_data_default = {
'id' : 0,
'name': '',
'balance' : '',
'valid_from': '',
'valid_to' : '',
'last_statement_balance': '',
'last_statement_at' : '',
'last_statement_by_trigramme' : '',
'last_statement_by_first_name': '',
'last_statement_by_last_name' : '' ,
}
2016-08-21 16:45:25 +02:00
var last_statement_container = $('#last_statement');
var last_statement_html_default = '< b > Dernier relevé: < / b > < br > < span id = "checkout-last_statement_balance" > < / span > € à < span id = "checkout-last_statement_at" > < / span > par < span id = "checkout-last_statement_by_trigramme" > < / span > ';
2016-08-06 22:19:52 +02:00
// Display data
function displayCheckoutData() {
2016-08-21 16:45:25 +02:00
if (checkout_data['last_statement_at']) {
last_statement_container.html(last_statement_html_default);
} else {
last_statement_container.html('');
}
2016-08-16 03:36:14 +02:00
for (var elem in checkout_data) {
$('#checkout-'+elem).text(checkout_data[elem]);
2016-08-06 22:19:52 +02:00
}
2016-08-19 02:56:45 +02:00
var buttons = '';
if (checkout_data['id'] !== 0) {
buttons += '< a class = "btn btn-primary" href = "/k-fet/checkouts/'+checkout_data['id']+'/statements/add" title = "Effectuer un relevé" target = "_blank" > < span class = "glyphicon glyphicon-euro" > < / span > < / a > ';
buttons += '< a class = "btn btn-primary" href = "/k-fet/checkouts/'+checkout_data['id']+'" title = "Modifier" target = "_blank" > < span class = "glyphicon glyphicon-cog" > < / span > < / a > ';
}
checkout_container.find('.buttons').html(buttons);
2016-08-06 22:19:52 +02:00
}
// Clear data
2016-08-18 05:33:42 +02:00
function resetCheckout() {
2016-08-12 10:03:39 +02:00
checkout_data = checkout_data_default;
2016-08-06 22:19:52 +02:00
$('#id_checkout').val(0);
2016-08-17 00:46:31 +02:00
checkoutInput.find('option:first').prop('selected', true);
2016-08-06 22:19:52 +02:00
displayCheckoutData();
}
// Store data
function storeCheckoutData(data) {
2016-08-16 03:36:14 +02:00
checkout_data = $.extend({}, checkout_data_default, data);
2016-08-12 10:03:39 +02:00
$('#id_checkout').val(checkout_data['id']);
2016-08-06 22:19:52 +02:00
displayCheckoutData();
}
// Retrieve data
function retrieveCheckoutData(id) {
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.checkout_data' %}",
method : "POST",
data : { 'pk': id },
})
.done(function(data) { storeCheckoutData(data) })
2016-08-18 05:33:42 +02:00
.fail(function() { resetCheckout() });
2016-08-06 22:19:52 +02:00
}
// Event listener
checkoutInput.on('change', function() {
retrieveCheckoutData(checkoutInput.val());
});
2016-08-19 06:20:37 +02:00
// -----
// Auth
// -----
function requestAuth(data, callback) {
2016-08-20 17:55:46 +02:00
var content = getErrorsHtml(data);
content += '< input type = "password" name = "password" autofocus > ',
2016-08-19 06:20:37 +02:00
$.confirm({
title: 'Authentification requise',
2016-08-20 17:55:46 +02:00
content: content,
2016-08-19 06:20:37 +02:00
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
keyboardEnabled: true,
confirm: function() {
var password = this.$content.find('input').val();
callback(password);
},
onOpen: function() {
var that = this
this.$content.find('input').on('keypress', function(e) {
if (e.keyCode == 13)
that.$confirmButton.click();
});
},
onClose: function() { this._lastFocused = articleSelect; }
});
}
2016-08-20 17:55:46 +02:00
// -----
// Errors ajax
// -----
function getErrorsHtml(data) {
var content = '';
if ('operation_group' in data['errors']) {
content += 'Général';
content += '< ul > ';
if (data['errors']['operation_group'].indexOf('on_acc') != -1)
content += '< li > Pas de compte sélectionné< / li > ';
if (data['errors']['operation_group'].indexOf('checkout') != -1)
content += '< li > Pas de caisse sélectionnée< / li > ';
content += '< / ul > ';
}
if ('missing_perms' in data['errors']) {
content += 'Permissions manquantes';
content += '< ul > ';
for (var i=0; i< data [ ' errors ' ] [ ' missing_perms ' ] . length ; i + + )
content += '< li > '+data['errors']['missing_perms'][i]+'< / li > ';
content += '< / ul > ';
}
if ('negative' in data['errors'])
content += '< a class = "btn btn-primary" href = "/k-fet/accounts/'+account_data['trigramme']+'/edit" target = "_blank" > Autorisation de négatif requise< / a > ';
2016-08-22 16:29:12 +02:00
if ('addcost' in data['errors']) {
content += '< ul > ';
if (data['errors']['addcost'].indexOf('__all__') != -1)
content += '< li > Compte invalide< / li > ';
if (data['errors']['addcost'].indexOf('amount') != -1)
content += '< li > Montant invalide< / li > ';
content += '< / ul > ';
}
2016-08-20 17:55:46 +02:00
return content;
}
function displayErrors(html) {
$.alert({
title: 'Erreurs',
content: html,
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
});
}
2016-08-06 22:19:52 +02:00
// -----
// Perform operations
// -----
var performButton = $('#perform_operations');
var operationGroup = $('#operationgroup_form');
var operations = $('#operation_formset');
2016-08-19 06:20:37 +02:00
function performOperations(password = '') {
2016-08-09 11:02:26 +02:00
var data = operationGroup.serialize() + '& ' + operations.serialize();
2016-08-06 22:19:52 +02:00
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.perform_operations' %}",
method : "POST",
data : data,
2016-08-19 06:20:37 +02:00
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')
$xhr.setRequestHeader("KFetPassword", password);
},
2016-08-06 22:19:52 +02:00
})
.done(function(data) {
2016-08-19 06:20:37 +02:00
coolReset();
2016-08-06 22:19:52 +02:00
})
2016-08-14 19:59:36 +02:00
.fail(function($xhr) {
2016-08-06 22:19:52 +02:00
var data = $xhr.responseJSON;
2016-08-19 06:20:37 +02:00
switch ($xhr.status) {
case 403:
requestAuth(data, performOperations);
break;
2016-08-20 17:55:46 +02:00
case 400:
displayErrors(getErrorsHtml(data));
break;
2016-08-19 06:20:37 +02:00
}
2016-08-06 22:19:52 +02:00
});
}
// Event listeners
performButton.on('click', function() {
performOperations();
});
2016-08-09 11:02:26 +02:00
2016-08-14 19:59:36 +02:00
// -----
2016-08-09 11:02:26 +02:00
// Cancel operations
2016-08-14 19:59:36 +02:00
// -----
2016-08-09 11:02:26 +02:00
var cancelButton = $('#cancel_operations');
var cancelForm = $('#cancel_form');
2016-08-19 06:20:37 +02:00
function cancelOperations(opes_array, password = '') {
2016-08-18 18:26:58 +02:00
var data = { 'operations' : opes_array }
2016-08-09 11:02:26 +02:00
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.cancel_operations' %}",
method : "POST",
data : data,
2016-08-19 06:20:37 +02:00
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')
$xhr.setRequestHeader("KFetPassword", password);
},
2016-08-09 11:02:26 +02:00
})
.done(function(data) {
2016-08-19 06:20:37 +02:00
coolReset();
2016-08-09 11:02:26 +02:00
})
2016-08-14 20:27:13 +02:00
.fail(function($xhr) {
2016-08-09 11:02:26 +02:00
var data = $xhr.responseJSON;
2016-08-19 06:20:37 +02:00
switch ($xhr.status) {
case 403:
requestAuth(data, function(password) {
cancelOperations(opes_array, password);
});
break;
2016-08-20 17:56:38 +02:00
case 400:
displayErrors(getErrorsHtml(data));
break;
2016-08-19 06:20:37 +02:00
}
2016-08-09 11:02:26 +02:00
});
}
// Event listeners
cancelButton.on('click', function() {
cancelOperations();
});
2016-08-14 19:59:36 +02:00
// -----
2016-08-14 23:37:05 +02:00
// Articles data
2016-08-14 19:59:36 +02:00
// -----
var articles_container = $('#articles_data tbody');
2016-08-17 00:46:31 +02:00
var article_category_default_html = '< tr class = "category" > < td colspan = "3" > < / td > < / tr > ';
var article_default_html = '< tr class = "article" > < td class = "name" > < / td > < td class = "price" > < / td > < td class = "stock" > < / td > < / tr > ';
2016-08-14 19:59:36 +02:00
function addArticle(article) {
2016-08-14 23:37:05 +02:00
var article_html = $(article_default_html);
2016-08-17 00:46:31 +02:00
article_html.attr('data-article', article['id']);
article_html.attr('data-category', article['category_id']);
2016-08-14 19:59:36 +02:00
for (var elem in article) {
2016-08-14 23:37:05 +02:00
article_html.find('.'+elem).text(article[elem])
2016-08-14 19:59:36 +02:00
}
2016-08-18 05:33:42 +02:00
article_html.find('.price').text(amountToUKF(article['price'], false));
2016-08-17 00:46:31 +02:00
var category_html = articles_container
.find('.category[data-category='+article['category_id']+']');
if (category_html.length == 0) {
category_html = $(article_category_default_html);
category_html.attr('data-category', article['category_id']);
category_html.find('td').text(article['category__name']);
var added = false;
articles_container.find('.category').each(function() {
if (article['category__name'].toLowerCase() < $(this).text().toLowerCase()) {
$(this).before(category_html);
added = true;
return false;
}
});
if (!added) articles_container.append(category_html);
}
var added = false;
articles_container
.find('.article[data-category='+article['category_id']+']').each(function() {
if (article['name'].toLowerCase < $('.name', this).text().toLowerCase()) {
$(this).before(article_html);
added = true;
return false;
}
});
if (!added) articles_container.find('[data-category='+article['category_id']+']').after(article_html);
2016-08-16 03:36:14 +02:00
// Pour l'autocomplétion
2016-08-17 00:46:31 +02:00
articlesList.push([article['name'],article['id'],article['category_id'],article['price']]);
2016-08-14 19:59:36 +02:00
}
2016-08-18 05:33:42 +02:00
function getArticles() {
2016-08-14 19:59:36 +02:00
$.ajax({
dataType: "json",
2016-08-14 23:37:05 +02:00
url : "{% url 'kfet.kpsul.articles_data' %}",
2016-08-14 19:59:36 +02:00
method : "GET",
})
.done(function(data) {
2016-08-14 23:37:05 +02:00
for (var i=0; i< data [ ' articles ' ] . length ; i + + ) {
addArticle(data['articles'][i]);
}
2016-08-14 19:59:36 +02:00
});
}
2016-08-18 05:33:42 +02:00
function resetArticles() {
articles_container.find('tr').remove();
articlesList = [];
}
2016-08-16 03:36:14 +02:00
// -----
// Article selection
// -----
var articleSelect = $('#article_autocomplete');
var articleId = $('#article_id');
var articleNb = $('#article_number');
2016-08-22 05:41:31 +02:00
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|120-123:F9-F12
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|120|121|122|123)$/;
2016-08-16 03:36:14 +02:00
var articlesList = [];
function deleteNonMatching(array, str) {
var dup = [];
var lower_str = str.toLowerCase();
for (var i=0; i< array.length ; i + + ) {
if (((array[i][0]).toLowerCase()).indexOf(lower_str) === 0)
dup.push(array[i])
}
return dup;
}
function callbackForPrefix(elt) {
return elt[0].toLowerCase();
}
function sharedPrefix(array) {
var dup = array.map(callbackForPrefix);
dup.sort(); // On trie l'array
// On récupère le préfixe du premier et du dernier élément
var first = dup[0], last = dup[array.length-1],
length = first.length, i = 0;
while (i < length & & first . charAt ( i ) = = = last . charAt ( i ) ) i + + ;
return first.substring(0, i);
}
2016-08-17 00:46:31 +02:00
function displayMatchedArticles(array) {
var categories_to_display = [];
for (var i=0; i< articlesList.length ; i + + ) {
if (array.indexOf(articlesList[i]) > -1) {
articles_container.find('[data-article='+articlesList[i][1]+']').show();
if (categories_to_display.indexOf(articlesList[i][2]) == -1)
categories_to_display.push(articlesList[i][2]);
} else {
articles_container.find('[data-article='+articlesList[i][1]+']').hide();
}
}
articles_container.find('.category').hide();
for (var i=0; i< categories_to_display.length ; i + + ) {
articles_container
.find('.category[data-category='+categories_to_display[i]+']')
.show();
}
}
function updateMatchedArticles(str, commit = true) {
var lower_str = str.toLowerCase();
var articlesMatch = deleteNonMatching(articlesList, lower_str);
if (articlesMatch.length == 1) {
articleId.val(0);
// 1 seul résultat, victoire
if (commit) {
articleId.val(articlesMatch[0][1]);
articleSelect.val(articlesMatch[0][0]);
displayMatchedArticles(articlesList);
return true;
}
displayMatchedArticles(articlesMatch);
} else if (articlesMatch.length > 1) {
articleId.val(0);
if (commit)
articleSelect.val(sharedPrefix(articlesMatch));
displayMatchedArticles(articlesMatch);
}
return false;
}
2016-08-16 03:36:14 +02:00
articleSelect.on('keypress', function(e) {
2016-08-17 00:46:31 +02:00
var text = articleSelect.val();
2016-08-16 03:36:14 +02:00
// Comportement normal pour ces touches
if (normalKeys.test(e.keyCode) || e.ctrlKey) {
2016-08-19 06:20:37 +02:00
if (text == '' & & e.keyCode == 13)
2016-08-17 11:44:58 +02:00
performOperations();
2016-08-16 03:36:14 +02:00
if (e.keyCode == 8)
2016-08-17 00:46:31 +02:00
updateMatchedArticles(text.substring(0,text.length-1), commit=false);
2016-08-16 03:36:14 +02:00
if (e.charCode == 97 & & e.ctrlKey) {
articleId.val(0);
articleSelect.val('');
}
return true;
} else if (e.charCode !== 0) {
2016-08-17 00:46:31 +02:00
if (updateMatchedArticles(text+e.key)) {
articleNb.val('1');
articleNb.focus().select();
2016-08-16 03:36:14 +02:00
}
2016-08-17 00:46:31 +02:00
return false;
2016-08-16 03:36:14 +02:00
}
return false;
});
2016-08-17 00:46:31 +02:00
function is_nb_ok(nb) {
return /^[0-9]+$/.test(nb) & & nb > 0 & & nb < = 24;
}
articleNb.on('keypress', function(e) {
if (e.keyCode == 13 & & is_nb_ok(articleNb.val()) & & articleId.val() > 0) {
2016-08-18 05:33:42 +02:00
addPurchase(articleId.val(), articleNb.val());
2016-08-17 00:46:31 +02:00
articleSelect.val('');
articleNb.val('');
articleSelect.focus();
displayMatchedArticles(articlesList);
return false;
}
if (normalKeys.test(e.keyCode) || arrowKeys.test(e.keyCode) || e.keyCode == 8 || e.ctrlKey) {
if (e.ctrlKey & & e.charCode == 97)
articleNb.val('');
return true;
}
var nb = articleNb.val()+e.key;
if (is_nb_ok(nb))
return true;
return false;
});
2016-08-18 05:33:42 +02:00
// -----
// Basket
// -----
var item_basket_default_html = '< tr > < td class = "amount" > < / td > < td class = "number" > < / td > < td class = "name" > < / td > < / tr > ';
var basket_container = $('#basket table');
var arrowKeys = /^(37|38|39|40)$/;
2016-08-18 16:38:44 +02:00
function amountEuroPurchase(id,nb) {
2016-08-18 05:33:42 +02:00
var i = 0;
while (i< articlesList.length & & id ! = articlesList [ i ] [ 1 ] ) i + + ;
article_data = articlesList[i];
var reduc_divisor = 1;
if (account_data['is_cof'])
2016-08-22 16:08:21 +02:00
reduc_divisor = 1 + settings['subvention_cof'] / 100;
2016-08-18 16:38:44 +02:00
return - article_data[3] * nb / reduc_divisor;
}
function addPurchase(id, nb) {
2016-08-18 18:26:58 +02:00
var amount_euro = amountEuroPurchase(id, nb).toFixed(2);
2016-08-18 05:33:42 +02:00
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
article_basket_html = $(item_basket_default_html);
article_basket_html
.attr('data-opeindex', index)
.find('.number').text(nb).end()
.find('.name').text(article_data[0]).end()
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof']));
basket_container.prepend(article_basket_html);
updateBasketRel();
}
function addDeposit(amount) {
var deposit_basket_html = $(item_basket_default_html);
2016-08-19 01:08:57 +02:00
var amount = parseFloat(amount).toFixed(2);
2016-08-18 05:33:42 +02:00
var index = addDepositToFormset(amount);
deposit_basket_html
.attr('data-opeindex', index)
2016-08-19 01:08:57 +02:00
.find('.number').text(amount+"€").end()
2016-08-18 05:33:42 +02:00
.find('.name').text('Charge').end()
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
basket_container.prepend(deposit_basket_html);
updateBasketRel();
}
function addWithdraw(amount) {
var withdraw_basket_html = $(item_basket_default_html);
2016-08-19 01:08:57 +02:00
var amount = (- parseFloat(amount)).toFixed(2);
2016-08-18 05:33:42 +02:00
var index = addWithdrawToFormset(amount);
withdraw_basket_html
.attr('data-opeindex', index)
2016-08-19 01:08:57 +02:00
.find('.number').text(amount+"€").end()
2016-08-18 05:33:42 +02:00
.find('.name').text('Retrait').end()
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
basket_container.prepend(withdraw_basket_html);
updateBasketRel();
}
basket_container.selectable({
filter: 'tr',
});
$(document).on('keypress', function (e) {
if (e.keyCode == 46) {
// DEL (Suppr)
basket_container.find('.ui-selected').each(function () {
deleteFromBasket($(this).data('opeindex'));
});
}
});
2016-08-18 16:38:44 +02:00
function isBasketEmpty() {
return !basket_container.find('[data-opeindex]').length;
}
2016-08-18 05:33:42 +02:00
function getAmountBasket() {
var total = 0;
formset_container.find('[data-opeindex]').each(function () {
var opeindex = $(this).attr('data-opeindex');
if (!$(this).find('#id_form-'+opeindex+'-DELETE').prop('checked'))
total += parseFloat($(this).find('#id_form-'+opeindex+'-amount').val());
});
return total;
}
2016-08-18 16:38:44 +02:00
function updateBasketAmount() {
formset_container.find('[data-opeindex]').each(function () {
var opeindex = $(this).attr('data-opeindex');
var deleted = $(this).find('#id_form-'+opeindex+'-DELETE').prop('checked');
var type = $(this).find('#id_form-'+opeindex+'-type').val();
var article_id = $(this).find('#id_form-'+opeindex+'-article').val();
var article_nb = $(this).find('#id_form-'+opeindex+'-article_nb').val();
var amount = $(this).find('#id_form-'+opeindex+'-amount');
if (!deleted & & type == "purchase")
amount.val(amountEuroPurchase(article_id, article_nb));
basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_data['is_cof']));
});
}
2016-08-18 05:33:42 +02:00
var basketrel_container = $('#basket_rel');
function updateBasketRel() {
2016-08-18 16:38:44 +02:00
var basketrel_html = '';
if (account_data['trigramme'] == 'LIQ' & & !isBasketEmpty()) {
var amount = - getAmountBasket();
basketrel_html += '< div > Total: '+amount.toFixed(2)+' €< / div > ';
if (amount < 5 )
basketrel_html += '< div > Sur 5€: '+ (5-amount).toFixed(2) +' €< / div > ';
if (amount < 10 )
basketrel_html += '< div > Sur 10€: '+ (10-amount).toFixed(2) +' €< / div > ';
if (amount < 20 )
basketrel_html += '< div > Sur 20€: '+ (20-amount).toFixed(2) +' €< / div > ';
} else if (account_data['trigramme'] != '' & & !isBasketEmpty()) {
var amount = getAmountBasket();
var amountUKF = amountToUKF(amount, account_data['is_cof']);
var newBalance = account_data['balance'] + amount;
var newBalanceUKF = amountToUKF(newBalance, account_data['is_cof']);
basketrel_html += '< div > Total: '+amountUKF+'< / div > ';
basketrel_html += '< div > Nouveau solde: '+newBalanceUKF+'< / div > ';
if (newBalance < 0 )
basketrel_html += '< div > Manque: '+ (-newBalance).toFixed(2) +' €< / div > ';
2016-08-18 05:33:42 +02:00
}
basketrel_container.html(basketrel_html);
2016-08-18 16:38:44 +02:00
}
2016-08-18 05:33:42 +02:00
function deleteFromBasket(opeindex) {
basket_container.find('[data-opeindex='+opeindex+']').remove();
deleteFromFormset(opeindex);
2016-08-18 16:38:44 +02:00
updateBasketRel();
2016-08-18 05:33:42 +02:00
}
2016-08-17 00:46:31 +02:00
function resetBasket() {
basket_container.find('tr').remove();
2016-08-17 11:56:42 +02:00
mngmt_total_forms = 1;
mngmt_total_forms_input.val(1);
formset_container.find('div').remove();
2016-08-18 05:33:42 +02:00
updateBasketRel();
articleId.val(0);
articleSelect.val('');
articleNb.val('');
displayMatchedArticles(articlesList);
2016-08-17 00:46:31 +02:00
}
// -----
2016-08-18 05:33:42 +02:00
// Ask deposit or withdraw
2016-08-17 00:46:31 +02:00
// -----
function askDeposit() {
$.confirm({
title: 'Montant de la charge',
content: '< input type = "number" step = "0.01" min = "0.01" on autofocus placeholder = "€" > ',
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
2016-08-18 05:33:42 +02:00
keyboardEnabled: true,
2016-08-17 00:46:31 +02:00
confirm: function() {
var amount = this.$content.find('input').val();
if (!$.isNumeric(amount) || amount < = 0)
return false;
addDeposit(amount);
},
onOpen: function() {
var that = this
this.$content.find('input').on('keypress', function(e) {
if (e.keyCode == 13)
that.$confirmButton.click();
});
},
onClose: function() { this._lastFocused = articleSelect; }
});
}
function askWithdraw() {
$.confirm({
title: 'Montant du retrait',
content: '< input type = "number" step = "0.01" min = "0.01" on autofocus placeholder = "€" > ',
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
2016-08-18 05:33:42 +02:00
keyboardEnabled: true,
2016-08-17 00:46:31 +02:00
confirm: function() {
var amount = this.$content.find('input').val();
if (!$.isNumeric(amount) || amount < = 0)
return false;
addWithdraw(amount);
},
onOpen: function() {
var that = this
this.$content.find('input').on('keypress', function(e) {
if (e.keyCode == 13)
that.$confirmButton.click();
});
},
onClose: function() { this._lastFocused = articleSelect; }
});
}
// Event
var depositButton = $('#operation_deposit');
var withdrawButton = $('#operation_withdraw');
depositButton.on('click', function() { askDeposit(); });
withdrawButton.on('click', function() { askWithdraw(); });
2016-08-17 11:44:58 +02:00
// -----
2016-08-18 05:33:42 +02:00
// Operation formset management
2016-08-17 11:44:58 +02:00
// -----
var operation_empty_html = $('#operation_empty_html')
.removeAttr('id')
.find('label').remove().end()
.find('#id_form-__prefix__-DELETE').css('display','none').end();
$('#id_form-0-DELETE').prop('checked',true);
var formset_container = $('#operation_formset');
var mngmt_total_forms_input = $('#id_form-TOTAL_FORMS');
var mngmt_total_forms = 1;
var prefix_regex = /__prefix__/;
2016-08-18 05:33:42 +02:00
function addOperationToFormset(type, amount, article='', article_nb='', is_checkout=1) {
2016-08-17 11:44:58 +02:00
var operation_html = operation_empty_html.clone();
var index = mngmt_total_forms;
2016-08-17 11:56:42 +02:00
operation_html.attr('data-opeindex', index);
2016-08-17 11:44:58 +02:00
operation_html
.find('#id_form-__prefix__-type').val(type).end()
2016-08-20 17:55:46 +02:00
.find('#id_form-__prefix__-amount').val((parseFloat(amount)).toFixed(2)).end()
2016-08-17 11:44:58 +02:00
.find('#id_form-__prefix__-article').val(article).end()
.find('#id_form-__prefix__-article_nb').val(article_nb).end()
.find('#id_form-__prefix__-is_checkout').val(is_checkout);
mngmt_total_forms_input.val(index+1);
mngmt_total_forms++;
operation_html.find(':input').each(function() {
var name = $(this).attr('name').replace(prefix_regex, index);
var id = 'id_' + name;
$(this).attr({'name': name, 'id': id});
});
formset_container.append(operation_html);
return index;
}
function addDepositToFormset(amount, is_checkout=1) {
2016-08-18 05:33:42 +02:00
return addOperationToFormset('deposit', amount, '', '', is_checkout);
2016-08-17 11:44:58 +02:00
}
function addWithdrawToFormset(amount, is_checkout=1) {
2016-08-18 05:33:42 +02:00
return addOperationToFormset('withdraw', amount, '', '', is_checkout);
}
function addPurchaseToFormset(article_id, article_nb, amount=0) {
return addOperationToFormset('purchase', amount, article_id, article_nb);
}
function deleteFromFormset(opeindex) {
formset_container.find('#id_form-'+opeindex+'-DELETE').prop('checked', true);
2016-08-17 11:44:58 +02:00
}
2016-08-14 19:59:36 +02:00
// -----
// History
// -----
2016-08-18 18:26:58 +02:00
var history_container = $('#history');
2016-08-20 17:18:41 +02:00
var history_operationgroup_html = '< div class = "opegroup" > < span class = "time" > < / span > < span class = "trigramme" > < / span > < span class = "amount" > < / span > < / div > ';
var history_operation_html = '< div class = "ope" > < span class = "amount" > < / span > < span class = "infos1" > < / span > < span class = "infos2" > < / span > < / div > ';
2016-08-19 01:08:57 +02:00
function getOpeHtml(ope, is_cof=false, trigramme='') {
var ope_html = $(history_operation_html);
var amount = parseFloat(ope['amount']);
var amountUKF = amountToUKF(amount, is_cof);
var infos1 = '', infos2 = '';
2016-08-14 19:59:36 +02:00
if (ope['type'] == 'deposit') {
2016-08-19 01:08:57 +02:00
infos1 = amount.toFixed(2)+'€';
infos2 = 'Charge';
2016-08-14 19:59:36 +02:00
} else if (ope['type'] == 'withdraw') {
2016-08-19 01:08:57 +02:00
infos1 = amount.toFixed(2)+'€';
infos2 = 'Retrait';
} else {
infos1 = ope['article_nb'];
infos2 = ope['article__name'];
}
if (trigramme == 'LIQ')
amountUKF = (- amount).toFixed(2) +"€";
ope_html
.attr('data-ope', ope['id'])
2016-08-20 17:18:41 +02:00
.find('.amount').text(amountUKF).end()
2016-08-19 01:08:57 +02:00
.find('.infos1').text(infos1).end()
.find('.infos2').text(infos2).end();
if (ope['canceled_at'])
ope_html.addClass('canceled');
return ope_html;
}
2016-08-20 17:18:41 +02:00
function getOpegroupHtml(opegroup) {
var opegroup_html = $(history_operationgroup_html);
2016-08-19 01:08:57 +02:00
var at = new Date(opegroup['at']);
var at_hours = (at.getHours() < 10 ? ' 0 ' : ' ' ) + at . getHours ( ) ;
var at_minutes = (at.getMinutes() < 10 ? ' 0 ' : ' ' ) + at . getMinutes ( ) ;
var at_seconds = (at.getSeconds() < 10 ? ' 0 ' : ' ' ) + at . getSeconds ( ) ;
var at_formated = at_hours+':'+at_minutes+':'+at_seconds;
var amount = parseFloat(opegroup['amount']);
var trigramme = opegroup['on_acc__trigramme'];
if (opegroup['on_acc__trigramme'] == 'LIQ') {
var amount = (- amount).toFixed(2) +'€';
2016-08-14 19:59:36 +02:00
} else {
2016-08-19 01:08:57 +02:00
var amount = amountToUKF(amount, opegroup['is_cof']);
2016-08-14 19:59:36 +02:00
}
2016-08-19 01:08:57 +02:00
2016-08-20 17:18:41 +02:00
opegroup_html
.attr('data-opegroup', opegroup['id'])
.find('.time').text(at_formated).end()
2016-08-19 01:08:57 +02:00
.find('.amount').text(amount).end()
.find('.trigramme').text(trigramme).end();
2016-08-20 17:18:41 +02:00
return opegroup_html;
2016-08-14 19:59:36 +02:00
}
function addOpeGroup(opegroup) {
2016-08-19 01:08:57 +02:00
checkOrCreateDay(opegroup['at']);
2016-08-20 17:18:41 +02:00
var $opegroup_html = getOpegroupHtml(opegroup);
history_container.find('.day').first().after($opegroup_html);
2016-08-14 19:59:36 +02:00
// Ajout des opérations de ce groupe
2016-08-20 17:18:41 +02:00
var $opegroup = history_container.find('[data-opegroup='+opegroup['id']+']');
2016-08-14 19:59:36 +02:00
for (var i=0; i < opegroup [ ' opes ' ] . length ; i + + ) {
2016-08-20 17:18:41 +02:00
var $ope = getOpeHtml(opegroup['opes'][i], opegroup['is_cof'], opegroup['on_acc__trigramme']);
$ope.attr('data-opegroup', opegroup['id']);
$opegroup.after($ope);
2016-08-14 19:59:36 +02:00
}
2016-08-19 01:08:57 +02:00
}
var history_day_default_html = '< div class = "day" > < / div > ';
var months = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
function checkOrCreateDay(at) {
var at = new Date(at);
var mostRecentDay = history_container.find('.day').first();
if (mostRecentDay.length == 0 || at.getMonth() != mostRecentDay.attr('data-month') || at.getDate() != mostRecentDay.attr('data-day')) {
var day_html = $(history_day_default_html);
day_html
.attr('data-month', at.getMonth())
.attr('data-day', at.getDate())
.text(at.getDate()+' '+months[at.getMonth()]);
history_container.prepend(day_html);
}
2016-08-14 19:59:36 +02:00
}
function getHistory() {
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.history' %}",
method : "GET",
})
.done(function(data) {
2016-08-14 23:37:05 +02:00
for (var opegroup_id in data) {
addOpeGroup(data[opegroup_id]);
2016-08-14 19:59:36 +02:00
}
});
}
2016-08-18 05:33:42 +02:00
function resetHistory() {
2016-08-19 01:51:03 +02:00
history_container.children().remove();
2016-08-18 05:33:42 +02:00
}
2016-08-22 05:41:31 +02:00
// -----
// Addcost
// -----
2016-08-22 16:08:21 +02:00
var addcost_default_html = '< div id = "addcost" > Majoration vers < span class = "addcost_for" > < / span > de < span class = "addcost_amount" > < / span > €< / div > ';
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');
}
}
2016-08-22 05:41:31 +02:00
function sendAddcost(trigramme, amount, password='') {
var data = {
trigramme: trigramme,
amount: amount,
}
$.ajax({
dataType: "json",
url : "{% url 'kfet.kpsul.update_addcost' %}",
method : "POST",
data : data,
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')
$xhr.setRequestHeader("KFetPassword", password);
},
})
.fail(function($xhr) {
var data = $xhr.responseJSON;
switch ($xhr.status) {
case 403:
requestAuth(data, function(password) {
sendAddcost(trigramme, amount, password);
});
break;
case 400:
2016-08-22 16:29:12 +02:00
askAddcost(getErrorsHtml(data));
2016-08-22 05:41:31 +02:00
break;
}
});
}
2016-08-22 16:29:12 +02:00
function askAddcost(errors = '') {
2016-08-22 05:41:31 +02:00
$.confirm({
title: 'Majoration',
2016-08-22 16:29:12 +02:00
content: errors + '< input type = "text" placeholder = "Trigramme" autocomplete = "off" name = "trigramme" spellcheck = "false" style = "text-transform:uppercase" autofocus > < input type = "number" step = "0.01" min = "0.01" placeholder = "€" name = "amount" > ',
2016-08-22 05:41:31 +02:00
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
keyboardEnabled: true,
confirm: function() {
var trigramme = this.$content.find('input[name=trigramme]').val().toUpperCase();
var amount = this.$content.find('input[name=amount]').val();
sendAddcost(trigramme, amount);
},
onOpen: function() {
var that = this
this.$content.find('input[name=amount]').on('keypress', function(e) {
if (e.keyCode == 13)
that.$confirmButton.click();
});
},
2016-08-22 16:29:12 +02:00
onClose: function() { this._lastFocused = triInput; }
2016-08-22 05:41:31 +02:00
});
}
2016-08-18 18:26:58 +02:00
// -----
// Cancel from history
// -----
history_container.selectable({
2016-08-20 17:18:41 +02:00
filter: 'div.opegroup, div.ope',
2016-08-18 18:26:58 +02:00
selected: function(e, ui) {
$(ui.selected).each(function() {
2016-08-20 17:18:41 +02:00
if ($(this).hasClass('opegroup'))
2016-08-20 21:22:24 +02:00
var opegroup = $(this).attr('data-opegroup');
$(this).siblings('.ope[data-opegroup='+opegroup+']').addClass('ui-selected');
2016-08-18 18:26:58 +02:00
});
},
});
2016-08-20 21:15:14 +02:00
$(document).on('keydown', function (e) {
2016-08-18 18:26:58 +02:00
if (e.keyCode == 46) {
// DEL (Suppr)
var opes_to_cancel = [];
history_container.find('.ope.ui-selected').each(function () {
opes_to_cancel.push($(this).attr('data-ope'));
});
cancelOperations(opes_to_cancel);
}
});
2016-08-14 19:59:36 +02:00
function cancelOpeGroup(opegroup) {
2016-08-14 23:37:05 +02:00
var opegroup_html = history_container.find('[data-opegroup='+opegroup['id']+']');
2016-08-19 01:08:57 +02:00
if (opegroup_html.find('.trigramme').text() == 'LIQ') {
var amount = (- parseFloat(opegroup['amount']).tofixed(2))+'€';
} else {
var amount = amountToUKF(opegroup['amount'], opegroup['on_acc__is_cof']);
}
opegroup_html.find('.amount').text(amount);
2016-08-14 19:59:36 +02:00
}
function cancelOpe(ope) {
2016-08-14 23:37:05 +02:00
var ope_html = history_container.find('[data-ope='+ope['id']+']');
2016-08-14 19:59:36 +02:00
ope_html.addClass('canceled');
}
// -----
// Synchronization
// -----
2016-08-16 03:36:14 +02:00
websocket_msg_default = {'opegroups':[],'opes':[],'checkouts':[],'articles':[]}
2016-08-14 19:59:36 +02:00
socket = new ReconnectingWebSocket("ws://" + window.location.host + "/k-fet/k-psul/");
socket.onmessage = function(e) {
2016-08-16 03:36:14 +02:00
data = $.extend({}, websocket_msg_default, JSON.parse(e.data));
2016-08-14 19:59:36 +02:00
for (var i=0; i< data [ ' opegroups ' ] . length ; i + + ) {
if (data['opegroups'][i]['add']) {
addOpeGroup(data['opegroups'][i]);
} else if (data['opegroups'][i]['cancellation']) {
cancelOpeGroup(data['opegroups'][i]);
}
}
for (var i=0; i< data [ ' opes ' ] . length ; i + + ) {
if (data['opes'][i]['cancellation']) {
cancelOpe(data['opes'][i]);
}
}
for (var i=0; i< data [ ' checkouts ' ] . length ; i + + ) {
if (checkout_data['id'] == data['checkouts'][i]['id']) {
checkout_data['balance'] = data['checkouts'][i]['balance'];
displayCheckoutData();
}
}
2016-08-14 23:37:05 +02:00
for (var i=0; i< data [ ' articles ' ] . length ; i + + ) {
article = data['articles'][i];
articles_container.find('[data-article='+article['id']+'] .stock')
.text(article['stock']);
}
2016-08-22 16:08:21 +02:00
if (data['addcost']) {
settings['addcost_for'] = data['addcost']['for'];
settings['addcost_amount'] = parseFloat(data['addcost']['amount']);
displayAddcost();
}
2016-08-14 19:59:36 +02:00
}
2016-08-17 00:46:31 +02:00
// -----
// General
// -----
// Reset functions
2016-08-17 11:51:44 +02:00
function coolReset(give_tri_focus=true) {
2016-08-18 05:33:42 +02:00
resetAccount();
2016-08-17 00:46:31 +02:00
resetBasket();
2016-08-19 01:08:57 +02:00
resetSelectable();
2016-08-17 11:51:44 +02:00
if (give_tri_focus)
triInput.focus();
2016-08-17 00:46:31 +02:00
}
2016-08-17 11:51:44 +02:00
function hardReset(give_tri_focus=true) {
coolReset(give_tri_focus);
2016-08-18 05:33:42 +02:00
resetCheckout();
resetArticles();
resetHistory();
2016-08-22 16:08:21 +02:00
resetSettings();
2016-08-18 05:33:42 +02:00
getArticles();
2016-08-17 00:46:31 +02:00
getHistory();
}
2016-08-19 01:08:57 +02:00
function resetSelectable() {
$('.ui-selected').removeClass('ui-selected');
}
2016-08-17 00:46:31 +02:00
// Shorcuts
2016-08-19 03:07:21 +02:00
$(document).on('keydown', function(e) {
2016-08-17 00:46:31 +02:00
switch (e.keyCode) {
case 112:
// F1 - Cool reset
coolReset();
return false;
case 113:
2016-08-18 05:33:42 +02:00
if (e.shiftKey) {
// Shift+F2 - Basket reset
resetBasket();
articleSelect.focus();
} else {
// F2 - Account reset
resetAccount();
triInput.focus();
}
2016-08-17 00:46:31 +02:00
return false;
case 114:
2016-08-18 05:33:42 +02:00
if (e.shiftKey) {
// Shift+F3 - Withdraw
askWithdraw();
articleSelect.focus();
} else {
// F3 - Withdraw
askDeposit();
articleSelect.focus();
}
2016-08-17 00:46:31 +02:00
return false;
2016-08-22 05:41:31 +02:00
case 120:
// F9 - Addcost
askAddcost();
return false;
2016-08-17 00:46:31 +02:00
case 121:
// F10 - Hard reset
hardReset();
return false;
}
});
2016-08-14 19:59:36 +02:00
// -----
// Initiliazing all
// -----
2016-08-17 00:46:31 +02:00
hardReset();
2016-08-14 19:59:36 +02:00
2016-08-06 22:19:52 +02:00
});
< / script >
{% endblock %}