This commit is contained in:
Ludovic Stephan 2020-07-26 21:40:28 +02:00
parent f901ea9396
commit a984d1fd6f
3 changed files with 9 additions and 9 deletions

View file

@ -17,7 +17,8 @@ var Account = Backbone.Model.extend({
}, },
reset: function () { reset: function () {
// On n'utilise pas .clear() car on ne veut pas clear le trigramme // Réinitialise les attributs du modèle à leurs défaults, sauf le trigramme qui est bind à l'input.
// On n'utilise pas .clear() car on ne veut pas clear le trigramme.
this.set(this.defaults) this.set(this.defaults)
}, },
@ -30,7 +31,7 @@ var Account = Backbone.Model.extend({
}, },
view: function () { view: function () {
if (!this.is_valid()) { if (!this.is_empty_account()) {
view_class = EmptyAccountView view_class = EmptyAccountView
} else if (this.get("trigramme") == 'LIQ') { } else if (this.get("trigramme") == 'LIQ') {
view_class = LIQView view_class = LIQView
@ -44,7 +45,7 @@ var Account = Backbone.Model.extend({
this.view().render(); this.view().render();
}, },
is_valid: function () { is_empty_account: function () {
return (this.id != 0) return (this.id != 0)
}, },
}) })
@ -132,7 +133,7 @@ var EmptyAccountView = AccountView.extend({
le compte est invalide */ le compte est invalide */
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>';
trigramme = this.model.get("trigramme") trigramme = this.model.get("trigramme")
if (trigramme.is_valid_tri()) { 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"]();
var url = `${url_base}?trigramme=${trigramme}`; var url = `${url_base}?trigramme=${trigramme}`;

View file

@ -6,7 +6,7 @@ String.prototype.format_trigramme = function () {
return this.toUpperCase().substr(0, 3) return this.toUpperCase().substr(0, 3)
} }
String.prototype.is_valid_tri = function () { String.prototype.is_valid_trigramme = function () {
var pattern = /^[^a-z]{3}$/; var pattern = /^[^a-z]{3}$/;
return pattern.test(this); return pattern.test(this);
} }

View file

@ -27,8 +27,7 @@ class AccountManager {
// Raccourci LIQ // Raccourci LIQ
this._$input.on("keydown", function (e) { this._$input.on("keydown", function (e) {
// keycode 40: Down Arrow if (e.key == "ArrowDown") {
if (e.keyCode == 40) {
that.set("LIQ") that.set("LIQ")
} }
}) })
@ -39,7 +38,7 @@ class AccountManager {
}); });
this._$container.on('keydown', function (e) { this._$container.on('keydown', function (e) {
if (e.which == 70 && e.ctrlKey) { if (e.key == "f" && e.ctrlKey) {
// Ctrl + F : universal search shortcut // Ctrl + F : universal search shortcut
that.search.open(); that.search.open();
e.preventDefault(); e.preventDefault();
@ -55,7 +54,7 @@ class AccountManager {
update() { update() {
var trigramme = this._$input.val().format_trigramme(); var trigramme = this._$input.val().format_trigramme();
this.account.set({ "trigramme": trigramme }) this.account.set({ "trigramme": trigramme })
if (trigramme.is_valid_tri()) { if (trigramme.is_valid_trigramme()) {
this.account.fetch({ this.account.fetch({
"success": this._on_success.bind(this), "success": this._on_success.bind(this),
"error": this.reset.bind(this, false), "error": this.reset.bind(this, false),