WIP: Aureplop/kpsul js refactor #501

Draft
delobell wants to merge 215 commits from aureplop/kpsul_js_refactor into master
5 changed files with 38 additions and 23 deletions
Showing only changes of commit 0997d85083 - Show all commits

View file

@ -1255,15 +1255,15 @@ class Formatter {
var prefix_prop = options.prefix_prop !== undefined ? options.prefix_prop : '.'; var prefix_prop = options.prefix_prop !== undefined ? options.prefix_prop : '.';
var prefix_attr = options.prefix_attr !== undefined ? options.prefix_attr : ''; var prefix_attr = options.prefix_attr !== undefined ? options.prefix_attr : '';
for (var i in props) { for (let prop of props) {
var selector = prefix_prop + props[i]; var selector = prefix_prop + prop;
var html = options.empty_props ? '' : this.get_prop(object, props[i]); var html = options.empty_props ? '' : this.get_prop(object, prop);
$container.find( selector ).html( html ); $container.find( selector ).html( html );
} }
for (var i in attrs) { for (let attr of attrs) {
var name = prefix_attr + attrs[i]; var name = prefix_attr + attr;
var value = options.empty_attrs ? '' : this.get_attr(object, attrs[i]); var value = options.empty_attrs ? '' : this.get_attr(object, attr);
$container.attr( name, value ); $container.attr( name, value );
} }

View file

@ -55,6 +55,21 @@ function floatCheck(v) {
function intCheck(v) {
return Number.parseInt(v);
}
function floatCheck(v) {
if (typeof v === 'number')
return v;
return Number.parseFloat(v);
}
function booleanCheck(v) {
return v == true;
}
$(document).ready(function() { $(document).ready(function() {
$(window).scroll(function() { $(window).scroll(function() {
if ($(window).width() >= 768 && $(this).scrollTop() > 72.6) { if ($(window).width() >= 768 && $(this).scrollTop() > 72.6) {

View file

@ -52,15 +52,15 @@ class AccountManager {
if (this.is_empty()) { if (this.is_empty()) {
var trigramme = this.selection.get(); var trigramme = this.selection.get();
if (trigramme.isValidTri()) { if (trigramme.isValidTri()) {
var url_base = "{% url 'kfet.account.create' %}"; var url_base = Urls['kfet.account.create']();
var url = url_base + '?trigramme=' + encodeURIComponent(trigramme); var url = url_base + '?trigramme=' + encodeURIComponent(trigramme);
buttons += '<a href="'+url+'" class="btn btn-primary" target="_blank" title="Créer ce compte"><span class="glyphicon glyphicon-plus"></span></a>'; buttons += '<a href="'+url+'" class="btn btn-primary" target="_blank" title="Créer ce compte"><span class="glyphicon glyphicon-plus"></span></a>';
} else { /* trigramme input is empty or invalid */ } else { /* trigramme input is empty or invalid */
buttons += '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>'; buttons += '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>';
} }
} else { /* an account is loaded */ } else { /* an account is loaded */
var url = Urls['kfet.account.update'](encodeURIComponent(this.account.trigramme)); var url = this.account.url_object;
buttons += '<a href="'+url+'" class="btn btn-primary" target="_blank" title="Modifier ce compte"><span class="glyphicon glyphicon-cog"></span></a>'; buttons += '<a href="'+url+'" class="btn btn-primary" target="_blank" title="Détails du compte"><span class="glyphicon glyphicon-cog"></span></a>';
} }
this._$container.find('.buttons').html(buttons); this._$container.find('.buttons').html(buttons);
@ -189,13 +189,14 @@ class AccountSearch {
var that = this; var that = this;
this._$input.yourlabsAutocomplete({ this._$input.yourlabsAutocomplete({
url: '{% url "kfet.account.search.autocomplete" %}', url: Urls['kfet.account.search.autocomplete'](),
minimumCharacters: 2, minimumCharacters: 2,
id: 'search_autocomplete', id: 'search_autocomplete',
choiceSelector: '.choice', choiceSelector: '.choice',
placeholder: "Chercher un utilisateur K-Fêt", placeholder: "Chercher un utilisateur K-Fêt",
container: that._$results_container, container: that._$results_container,
box: that._$results_container, box: that._$results_container,
fixPosition: function() {},
}); });
return this; return this;
@ -345,11 +346,10 @@ class CheckoutSelection {
this._init_events(); this._init_events();
this.choices = [ this.choices = this._$input.find('option[value!=""]').toArray()
for (option of this._$input.find('option')) .map(function(opt) {
if ($(option).attr('value') != '') return parseInt($(opt).attr('value'));
parseInt($(option).attr('value')) });
];
} }
_init_events() { _init_events() {

View file

@ -4,6 +4,7 @@
{% block extra_head %} {% block extra_head %}
<link rel="stylesheet" type="text/css" href="{% static 'kfet/css/transfers_form.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'kfet/css/transfers_form.css' %}">
<script type="text/javascript" src="{% static 'kfet/js/js.cookie.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/js/js.cookie.js' %}"></script>
<script type="text/javascript" src="{% url 'js_reverse' %}"></script>
{% endblock %} {% endblock %}
{% block title %}Nouveaux transferts{% endblock %} {% block title %}Nouveaux transferts{% endblock %}
@ -51,14 +52,12 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
function getAccountData(trigramme, callback = function() {}) { function getAccountData(trigramme, callback) {
$.ajax({ callback = callback || $.noop;
dataType: "json", $.getJSON(Urls['kfet.account.read'](trigramme), {
url : "{% url 'kfet.account.read.json' %}", 'format': 'json',
method : "POST", })
data : { trigramme: trigramme }, .done(callback);
success : callback,
});
} }
function updateAccountData(trigramme, $input) { function updateAccountData(trigramme, $input) {

View file

@ -858,6 +858,7 @@ def kpsul_checkout_data(request, pk):
last_statement, last_statement,
fields=['id', 'at', 'balance_new', 'balance_old', 'by'] fields=['id', 'at', 'balance_new', 'balance_old', 'by']
) )
last_statement_data['by'] = str(last_statement.by)
# ``at`` is not editable, so skipped by ``model_to_dict`` # ``at`` is not editable, so skipped by ``model_to_dict``
last_statement_data['at'] = last_statement.at last_statement_data['at'] = last_statement.at
data['laststatement'] = last_statement_data data['laststatement'] = last_statement_data