diff --git a/public/js/waip.js b/public/js/waip.js index 933c5de..4de332a 100644 --- a/public/js/waip.js +++ b/public/js/waip.js @@ -113,6 +113,44 @@ function resetActivTimer(e) { do_on_Active(); }; +/* ############################ */ +/* ####### Progressbar ####### */ +/* ############################ */ + +var counter_ID = 0; + +function start_counter(zeitstempel, ablaufzeit) { + // Split timestamp into [ Y, M, D, h, m, s ] + var t1 = zeitstempel.split(/[- :]/), + t2 = ablaufzeit.split(/[- :]/); + + var start = new Date(t1[0], t1[1]-1, t1[2], t1[3], t1[4], t1[5]), + end = new Date(t2[0], t2[1]-1, t2[2], t2[3], t2[4], t2[5]); + + clearInterval(counter_ID); + counter_ID = setInterval(function(){ do_progressbar(start, end); }, 1000); +}; + +function do_progressbar(start, end) { + today = new Date(); + // restliche Zeit ermitteln + var current_progress = Math.round(100 / (end.getTime() - start.getTime()) * (end.getTime() - today.getTime())); + + var diff = Math.abs(end - today); + var minutesDifference = Math.floor(diff/1000/60); + diff -= minutesDifference*1000*60; + var secondsDifference = Math.floor(diff/1000); + if (secondsDifference <= 9) { + secondsDifference = '0' + secondsDifference; + }; + var minutes = minutesDifference + ':' + secondsDifference; + // Progressbar anpassen + $("#hilfsfrist") + .css("width", current_progress + "%") + .attr("aria-valuenow", current_progress) + .text(minutes + " min"); +}; + /* ########################### */ /* ######### LEAFLET ######### */ /* ########################### */ @@ -318,6 +356,10 @@ socket.on('io.neuerEinsatz', function(data) { icon: redIcon }).addTo(map); map.setView(new L.LatLng(data.wgs84_x, data.wgs84_y), 14); + // Hilfsfrist setzen + start_counter(data.zeitstempel, data.ablaufzeit); + //var intervalid; + //createInterval(countdown, intervalid, data.zeitstempel, data.ablaufzeit, 1000); // Uhr ausblenden $("#waipclock").addClass("d-none"); $("#waiptableau").removeClass("d-none"); @@ -380,3 +422,9 @@ setInterval(set_clock, 1000); /* ########################### */ /* ######## SONSTIGES ######## */ /* ########################### */ + +$('#rueckmeldung a').on('click', function (e) { + $('#waipModalTitle').html('Rückmeldung'); + $('#waipModalBody').html('Ich melde mich als: BUTTON(EK, MA, AGT, FK)'); + $('#waipModal').modal('show'); +})