Merge branch 'Aufinal/open_password' into 'master'

Fix : fermeture manuelle de la K-Fêt avec mot de passe

Closes #183

See merge request klub-dev-ens/gestioCOF!460
This commit is contained in:
Martin Pepin 2020-09-15 20:22:05 +02:00
commit 569ce0ba25

View file

@ -2,7 +2,7 @@ var OpenWS = new KfetWebsocket({
relative_url: "open/"
});
var OpenKfet = function(force_close_url, admin) {
var OpenKfet = function (force_close_url, admin) {
this.force_close_url = force_close_url;
this.admin = admin;
@ -11,11 +11,11 @@ var OpenKfet = function(force_close_url, admin) {
status_text: $('.kfetopen .status-text'),
force_close_btn: $('.kfetopen .force-close-btn'),
warning: $('.kfetopen .warning')
},
}
this.dom.force_close_btn.click( () => this.toggle_force_close() );
setInterval( () => this.refresh(), this.refresh_interval * 1000);
OpenWS.add_handler( data => this.refresh(data) );
this.dom.force_close_btn.click(() => this.toggle_force_close());
setInterval(() => this.refresh(), this.refresh_interval * 1000);
OpenWS.add_handler(data => this.refresh(data));
};
@ -53,7 +53,7 @@ OpenKfet.prototype = {
return this.last_update && moment().diff(this.last_update, 'minute') <= this.time_unknown;
},
refresh: function(data) {
refresh: function (data) {
if (data) {
$.extend(this, data);
this.last_update = moment();
@ -63,7 +63,7 @@ OpenKfet.prototype = {
this.refresh_dom();
},
refresh_dom: function() {
refresh_dom: function () {
let status = this.status;
this.clear_class();
@ -83,31 +83,31 @@ OpenKfet.prototype = {
}
},
toggle_force_close: function(password) {
toggle_force_close: function (password) {
$.post({
context: this,
url: this.force_close_url,
data: {force_close: !this.force_close},
data: { force_close: !this.force_close },
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password !== undefined)
$xhr.setRequestHeader("KFetPassword", password);
}
})
.fail(function($xhr) {
}).fail(function ($xhr) {
switch ($xhr.status) {
case 403:
requestAuth({'errors': {}}, this.toggle_force_close);
requestAuth({ 'errors': {} }, (password) => this.toggle_force_close(password));
break;
}
});
},
clear_class: function() {
clear_class: function () {
let re = new RegExp('(^|\\s)' + this.class_prefix + '\\S+', 'g');
$(this.target).attr('class', (i, c) => c ? c.replace(re, '') : '');
},
add_class: function(status) {
add_class: function (status) {
$(this.target).addClass(this.class_prefix + status);
}
};