Point d'entrée unique pour le JS de K-Psul #740

Open
lstephan wants to merge 5 commits from Aufinal/es6-js into master
8 changed files with 41 additions and 16 deletions

1
kfet/static/kfet/js/kpsul.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,28 @@
# Compilation des fichiers .js de K-Psul en une version minifiée
LIBS = libs/underscore.js libs/backbone.js
MODELS = $(wildcard models/**.js)
MANAGERS = $(wildcard managers/**.js)
ENTRYPOINT = kpsul.js
CONCAT_FILE = kpsul.src.js
TARGET = ../../js/kpsul.min.js
FLAGS =
build: concat minify clean
# For dev use : we don't minify
dev: concat cp clean
concat:
@cat $(LIBS) $(MODELS) $(MANAGERS) $(ENTRYPOINT) > $(CONCAT_FILE)
cp:
@cp $(CONCAT_FILE) $(TARGET)
minify:
terser $(CONCAT_FILE) -o $(TARGET) $(FLAGS)
clean:
@rm $(CONCAT_FILE)

View file

@ -0,0 +1,3 @@
$(function () {
self.account_manager = new AccountManager();
})

View file

@ -141,7 +141,7 @@ class AccountSearch {
var choice_text = choice.text().trim(); var choice_text = choice.text().trim();
var trigramme_regex = /\((.{3})\)$/; var trigramme_regex = /\((.{3})\)$/;
// le match est de la forme [<global match>, <group match>] // le match est de la forme [<global match>, <group match>]
trigramme = choice_text.match(trigramme_regex)[1] var trigramme = choice_text.match(trigramme_regex)[1]
this.manager.set(trigramme); this.manager.set(trigramme);
this.close(); this.close();
} }
@ -151,4 +151,4 @@ class AccountSearch {
this._$dialog.close(); this._$dialog.close();
} }
} }
} }

View file

@ -31,6 +31,7 @@ var Account = Backbone.Model.extend({
}, },
view: function () { view: function () {
var view_class;
if (this.is_empty_account()) { if (this.is_empty_account()) {
view_class = EmptyAccountView view_class = EmptyAccountView
} else if (this.get("trigramme") == 'LIQ') { } else if (this.get("trigramme") == 'LIQ') {
@ -61,7 +62,7 @@ var AccountView = Backbone.View.extend({
get: function (property) { get: function (property) {
/* If the function this.get_<property> is defined, /* If the function this.get_<property> is defined,
we call it ; else we call this.model.<property>. */ we call it ; else we call this.model.<property>. */
getter_name = `get_${property}`; var getter_name = `get_${property}`;
if (_.functions(this).includes(getter_name)) if (_.functions(this).includes(getter_name))
return this[getter_name]() return this[getter_name]()
else else
@ -131,8 +132,8 @@ var EmptyAccountView = AccountView.extend({
/* Léger changement de fonctionnement : /* Léger changement de fonctionnement :
on affiche *toujours* le bouton de recherche si on affiche *toujours* le bouton de recherche si
le compte est invalide */ le compte est invalide */
buttons = '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>'; var buttons = '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>';
trigramme = this.model.get("trigramme") var trigramme = this.model.get("trigramme")
if (trigramme.is_valid_trigramme()) { if (trigramme.is_valid_trigramme()) {
trigramme = encodeURIComponent(trigramme); trigramme = encodeURIComponent(trigramme);
var url_base = django_urls["kfet.account.create"](); var url_base = django_urls["kfet.account.create"]();
@ -142,4 +143,4 @@ var EmptyAccountView = AccountView.extend({
return buttons return buttons
} }
}) })

View file

@ -7,10 +7,7 @@
<script type="text/javascript" src="{% static 'kfet/vendor/moment/moment-timezone-with-data-2012-2022.min.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/vendor/moment/moment-timezone-with-data-2012-2022.min.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/history.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/js/history.js' %}"></script>
<script type="text/javascript" src="{% url 'js_reverse' %}" ></script> <script type="text/javascript" src="{% url 'js_reverse' %}" ></script>
<script type="text/javascript" src="{% static 'kfet/vendor/underscore-min.js' %}"></script> <script type="text/javascript" src="{% static 'kfet/js/kpsul.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/kpsul.js' %}"></script>
{% endblock %} {% endblock %}
{% block title %}K-Psul{% endblock %} {% block title %}K-Psul{% endblock %}
@ -209,12 +206,7 @@ $(document).ready(function() {
}); });
} }
// -----
// Account data management
// -----
var account_manager = new AccountManager();
var triInput = $('#id_trigramme'); var triInput = $('#id_trigramme');