WIP: Aureplop/kpsul js refactor #501
6 changed files with 38 additions and 44 deletions
|
@ -908,15 +908,15 @@ class Formatter {
|
|||
var prefix_prop = options.prefix_prop !== undefined ? options.prefix_prop : '.';
|
||||
var prefix_attr = options.prefix_attr !== undefined ? options.prefix_attr : '';
|
||||
|
||||
for (var i in props) {
|
||||
var selector = prefix_prop + props[i];
|
||||
var html = options.empty_props ? '' : this.get_prop(object, props[i]);
|
||||
for (let prop of props) {
|
||||
var selector = prefix_prop + prop;
|
||||
var html = options.empty_props ? '' : this.get_prop(object, prop);
|
||||
$container.find( selector ).html( html );
|
||||
}
|
||||
|
||||
for (var i in attrs) {
|
||||
var name = prefix_attr + attrs[i];
|
||||
var value = options.empty_attrs ? '' : this.get_attr(object, attrs[i]);
|
||||
for (let attr of attrs) {
|
||||
var name = prefix_attr + attr;
|
||||
var value = options.empty_attrs ? '' : this.get_attr(object, attr);
|
||||
$container.attr( name, value );
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,21 @@ String.prototype.isValidTri = function() {
|
|||
}
|
||||
|
||||
|
||||
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() {
|
||||
$(window).scroll(function() {
|
||||
if ($(window).width() >= 768 && $(this).scrollTop() > 72.6) {
|
||||
|
|
|
@ -51,15 +51,15 @@ class AccountManager {
|
|||
if (this.is_empty()) {
|
||||
var trigramme = this.selection.get();
|
||||
if (trigramme.isValidTri()) {
|
||||
var url_base = "{% url 'kfet.account.create' %}";
|
||||
var url_base = Urls['kfet.account.create']();
|
||||
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>';
|
||||
} else { /* trigramme input is empty or invalid */
|
||||
buttons += '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>';
|
||||
}
|
||||
} else { /* an account is loaded */
|
||||
var url = Urls['kfet.account.update'](encodeURIComponent(this.account.trigramme));
|
||||
buttons += '<a href="'+url+'" class="btn btn-primary" target="_blank" title="Modifier ce compte"><span class="glyphicon glyphicon-cog"></span></a>';
|
||||
var url = this.account.url_object;
|
||||
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);
|
||||
|
@ -188,13 +188,14 @@ class AccountSearch {
|
|||
var that = this;
|
||||
|
||||
this._$input.yourlabsAutocomplete({
|
||||
url: '{% url "kfet.account.search.autocomplete" %}',
|
||||
url: Urls['kfet.account.search.autocomplete'](),
|
||||
minimumCharacters: 2,
|
||||
id: 'search_autocomplete',
|
||||
choiceSelector: '.choice',
|
||||
placeholder: "Chercher un utilisateur K-Fêt",
|
||||
container: that._$results_container,
|
||||
box: that._$results_container,
|
||||
fixPosition: function() {},
|
||||
});
|
||||
|
||||
return this;
|
||||
|
@ -344,11 +345,10 @@ class CheckoutSelection {
|
|||
|
||||
this._init_events();
|
||||
|
||||
this.choices = [
|
||||
for (option of this._$input.find('option'))
|
||||
if ($(option).attr('value') != '')
|
||||
parseInt($(option).attr('value'))
|
||||
];
|
||||
this.choices = this._$input.find('option[value!=""]').toArray()
|
||||
.map(function(opt) {
|
||||
return parseInt($(opt).attr('value'));
|
||||
});
|
||||
}
|
||||
|
||||
_init_events() {
|
||||
|
|
|
@ -170,27 +170,6 @@
|
|||
{% csrf_token %}
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function functionCheck(v) {
|
||||
if (typeof v === 'function')
|
||||
return v;
|
||||
return function(){};
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
'use strict';
|
||||
// -----
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
{% block extra_head %}
|
||||
<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="{% url 'js_reverse' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}Nouveaux transferts{% endblock %}
|
||||
|
@ -51,14 +52,12 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
function getAccountData(trigramme, callback = function() {}) {
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url : "{% url 'kfet.account.read.json' %}",
|
||||
method : "POST",
|
||||
data : { trigramme: trigramme },
|
||||
success : callback,
|
||||
});
|
||||
function getAccountData(trigramme, callback) {
|
||||
callback = callback || $.noop;
|
||||
$.getJSON(Urls['kfet.account.read'](trigramme), {
|
||||
'format': 'json',
|
||||
})
|
||||
.done(callback);
|
||||
}
|
||||
|
||||
function updateAccountData(trigramme, $input) {
|
||||
|
|
|
@ -858,6 +858,7 @@ def kpsul_checkout_data(request, pk):
|
|||
last_statement,
|
||||
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``
|
||||
last_statement_data['at'] = last_statement.at
|
||||
data['laststatement'] = last_statement_data
|
||||
|
|
Loading…
Reference in a new issue