forked from DGNum/gestioCOF
force close working
This commit is contained in:
parent
5694e4b9bc
commit
8e7b9e2fd3
7 changed files with 112 additions and 48 deletions
|
@ -1,7 +1,8 @@
|
|||
function kfet_open(init_date, init_satus) {
|
||||
function kfet_open(init_date, init_satus, init_force_close, force_close_url, force_open_url) {
|
||||
// VARIABLES
|
||||
var kfet_open_bullet = $('#kfet-open');
|
||||
var open_status = $('#open_status');
|
||||
var force_close_button = $('#force_close_button');
|
||||
// bullet
|
||||
var open_color = "#73C252";
|
||||
var closed_color = "#B42B26";
|
||||
|
@ -13,16 +14,25 @@ function kfet_open(init_date, init_satus) {
|
|||
|
||||
var kfet_open_date = init_date;
|
||||
var kfet_open = init_status;
|
||||
var force_close = init_force_close;
|
||||
|
||||
// EVENT
|
||||
force_close_button.click(function() {
|
||||
if (force_close) {
|
||||
$.get(force_open_url, function(data) {});
|
||||
} else {
|
||||
$.get(force_close_url, function(data) {});
|
||||
}
|
||||
});
|
||||
|
||||
// INITIALISAITION
|
||||
update_open_bullet();
|
||||
update_open_status();
|
||||
update_open();
|
||||
update_force_button();
|
||||
|
||||
// On recherge toute les 30sec
|
||||
// (dans le cas où le statut deviendrait inconn)
|
||||
setInterval(function() {
|
||||
update_open_bullet();
|
||||
update_open_status();
|
||||
update_open();
|
||||
}, 30 * 1000); // 60 * 1000 milsec
|
||||
|
||||
// FONCTIONS
|
||||
|
@ -39,31 +49,42 @@ function kfet_open(init_date, init_satus) {
|
|||
|
||||
return tmp;
|
||||
}
|
||||
function update_open_bullet() {
|
||||
function do_kfet_close() {
|
||||
kfet_open_bullet.css({'background-color': closed_color});
|
||||
open_status.parent().css({'background-color': closed_color_status});
|
||||
open_status.html("FERMÉE");
|
||||
}
|
||||
function do_kfet_open() {
|
||||
kfet_open_bullet.css({'background-color': open_color});
|
||||
open_status.parent().css({'background-color': open_color_status});
|
||||
open_status.html("OUVERTE");
|
||||
}
|
||||
function do_kfet_unknown() {
|
||||
kfet_open_bullet.css({'background-color': unknown_color});
|
||||
open_status.parent().css({'background-color': unknown_color_status});
|
||||
open_status.html("?????");
|
||||
}
|
||||
function update_open() {
|
||||
nb_min = nb_min_diff();
|
||||
console.log("BULLET | K-Fêt ouverte : " + kfet_open);
|
||||
console.log("K-Fêt ouverte : " + (kfet_open&&(!force_close)));
|
||||
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
|
||||
if (nb_min > 15) {
|
||||
kfet_open_bullet.css({'background-color': unknown_color});
|
||||
} else if (kfet_open){
|
||||
kfet_open_bullet.css({'background-color': open_color});
|
||||
if (force_close) {
|
||||
do_kfet_close();
|
||||
} else {
|
||||
kfet_open_bullet.css({'background-color': closed_color});
|
||||
if (nb_min > 15) {
|
||||
do_kfet_unknown();
|
||||
} else if (kfet_open){
|
||||
do_kfet_open();
|
||||
} else {
|
||||
do_kfet_close();
|
||||
}
|
||||
}
|
||||
}
|
||||
function update_open_status() {
|
||||
nb_min = nb_min_diff();
|
||||
console.log("STATUS | K-Fêt ouverte : " + kfet_open);
|
||||
console.log(nb_min + " minute(s) depuis la dernière mise à jour");
|
||||
if (nb_min > 15) {
|
||||
open_status.parent().css({'background-color': unknown_color});
|
||||
open_status.html("?????");
|
||||
} else if (kfet_open){
|
||||
open_status.parent().css({'background-color': open_color});
|
||||
open_status.html("OUVERTE");
|
||||
function update_force_button() {
|
||||
if (force_close) {
|
||||
force_close_button.html('Réouvrir la K-Fêt');
|
||||
} else {
|
||||
open_status.parent().css({'background-color': closed_color});
|
||||
open_status.html("FERMÉE");
|
||||
force_close_button.html('Fermer manuellement');
|
||||
}
|
||||
}
|
||||
// SYNCHRONIZATION
|
||||
|
@ -76,12 +97,21 @@ function kfet_open(init_date, init_satus) {
|
|||
|
||||
socket.onmessage = function(e) {
|
||||
var data = $.extend({}, websocket_msg_default, JSON.parse(e.data));
|
||||
console.log("Message reçu de la part de la porte.");
|
||||
|
||||
kfet_open_date = new Date(data['kfet_open_date']);
|
||||
kfet_open = data['kfet_open'];
|
||||
if (data['door_action']) {
|
||||
console.log("* Message reçu de la part de la porte.");
|
||||
|
||||
update_open_bullet();
|
||||
update_open_status();
|
||||
kfet_open_date = new Date(data['door_action']['kfet_open_date']);
|
||||
kfet_open = data['door_action']['kfet_open'];
|
||||
|
||||
update_open();
|
||||
}
|
||||
if (data['force_action']) {
|
||||
force_close = data['force_action']['force_close'];
|
||||
console.log("* Message reçu de la part d'un-e utilisat-rice-eur. Close = " + force_close);
|
||||
|
||||
update_open();
|
||||
update_force_button();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue