summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-17 19:07:27 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-17 19:07:43 (GMT)
commite3d491b0f97dae84336d5b3c60ceb7206af20c92 (patch)
tree3e28445c24232c85e058050ea7e41bad84901686 /www/js
parent0a4460d48706e36ca17217d0cdfa6da116299e19 (diff)
added websocket base clock
Diffstat (limited to 'www/js')
-rw-r--r--www/js/shows.js15
-rw-r--r--www/js/utils.js40
2 files changed, 50 insertions, 5 deletions
diff --git a/www/js/shows.js b/www/js/shows.js
index 8ebea41..eddb80f 100644
--- a/www/js/shows.js
+++ b/www/js/shows.js
@@ -24,6 +24,7 @@ var shows_list = [];
var shows_current;
var shows_group_carts = {};
var shows_log_carts = [];
+var shows_clock;
function shows_deleteCart(cart) {
@@ -320,9 +321,11 @@ function shows_updateList(data, status, req) {
shows_showSelected();
}
-function shows_drawCurrentWeek() {
- var weekspan = $('#current-week').removeClass().addClass('label');
- switch(get_rd_week()) {
+function shows_drawClock(date, time, week) {
+ $('#shows-clock span.clock-date').text(date);
+ $('#shows-clock span.clock-time').text(time);
+ var weekspan = $('#shows-clock span.current-week').removeClass().addClass('current-week').addClass('label');
+ switch(week) {
case 1:
weekspan.addClass('label-info').text('Woche 1');
break;
@@ -345,12 +348,16 @@ function shows_init() {
shows_list = [];
data = { LOGIN_NAME: auth_username, PASSWORD: auth_token };
$.post("/rh-bin/listdropboxes.cgi", data, shows_updateList, "xml")
- shows_drawCurrentWeek();
+ shows_drawClock('Do, 1.1.1970', '00:00:00', 0);
+ shows_clock = new Clock(shows_drawClock);
+ shows_clock.start();
}
function shows_cleanup() {
sessionStorage.removeItem("shows_currentid");
delete shows_currentid;
+ shows_clock.stop();
+ delete shows_clock;
shows_list = [];
shows_group_carts = {};
shows_log_carts = [];
diff --git a/www/js/utils.js b/www/js/utils.js
index 8436672..fbcf709 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -116,6 +116,44 @@ function get_rd_week() {
//
var today = new Date();
var sEpoch = ((+today) / 1000) + get_tz_offset(today);
- var week = Math.floor((((sEpoch + 259200)/604800) + 2) % 4) + 1
+ var week = Math.floor((((sEpoch + 259200)/604800) + 2) % 4) + 1;
return week;
}
+
+function Clock(draw_callback) {
+ this.draw_callback = draw_callback;
+ this.daynames = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
+
+ this.last_update = { timestamp: 0, tz_offset: 3600, week: 3 };
+ this.clock_offset = 0;
+
+ this.redraw = function() {
+ var rdtime_ms = (+new Date()) + (this.last_update.tz_offset * 1000) + this.clock_offset;
+
+ var rdtime = new Date(rdtime_ms);
+ var date_str = this.daynames[rdtime.getUTCDay()] + ', ';
+ date_str += rdtime.getUTCDate() + '.' + (rdtime.getUTCMonth() + 1) + '.' + rdtime.getUTCFullYear();
+
+ var time_str = (rdtime.getUTCHours() > 9 ? ' ' : ' 0') + rdtime.getUTCHours();
+ time_str += (rdtime.getUTCMinutes() > 9 ? ':' : ':0') + rdtime.getUTCMinutes();
+ time_str += (rdtime.getUTCSeconds() > 9 ? ':' : ':0') + rdtime.getUTCSeconds();
+
+ this.draw_callback(date_str, time_str, this.last_update.week);
+ }
+
+ this.update = function(event) {
+ var update = JSON.parse(event.data);
+ this.last_update = update;
+ this.clock_offset = (update.timestamp*1000) - (+new Date()) ;
+ }
+
+ this.start = function() {
+ this.sock = new WebSocket("wss://import.helsinki.at/time");
+ this.sock.onmessage = this.update.bind(this);
+ this.interval = setInterval(this.redraw.bind(this), 500);
+ }
+ this.stop = function() {
+ clearInterval(this.interval)
+ delete this.interval
+ }
+}