From 0cc67d030dd5fc8b5a853dfd4d8d8ea6a7c85806 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 14 Jan 2017 05:31:59 +0100 Subject: added date controller diff --git a/www/js/todo.js b/www/js/todo.js index 88b8aa4..5636be5 100644 --- a/www/js/todo.js +++ b/www/js/todo.js @@ -42,10 +42,9 @@ rh.ShowList = function(d) { rh.ShowList.prototype.fetch = function() { var self = this; + this.current_week = get_rd_week(this.current.valueOf()); - var d = this.current - var dstr = d.getFullYear() + '-' + Number(d.getMonth() + 1).pad(2) + '-' + Number(d.getDate()).pad(2); - $.getJSON( "/rh-bin/schedules.json?DAYS=1&START=" + dstr, function(data) { + $.getJSON( "/rh-bin/schedules.json?DAYS=1&START=" + format_date_iso(this.current), function(data) { if(data.status == "OK") { self.shows = []; $(data.shows).each(function(index, showdata) { @@ -57,6 +56,18 @@ rh.ShowList.prototype.fetch = function() { }); }; +rh.ShowList.prototype.prev = function() { + this.current = new Date(this.current.valueOf() - 24*3600*1000); + history.replaceState(null, null, '/todo/' + format_date_iso(this.current)); + this.fetch(); +}; + +rh.ShowList.prototype.next = function() { + this.current = new Date(this.current.valueOf() + 24*3600*1000); + history.replaceState(null, null, '/todo/' + format_date_iso(this.current)); + this.fetch(); +}; + rh.Show = function(show) { this.id = show.id; this.title = show.title; @@ -139,6 +150,27 @@ rh.ShowView.prototype.render = function() { /***************** controller *****************/ function todo_init() { - shows = new rh.ShowList(); + var url = parseLocationHref(); + var d = new Date(); + if(url.path.length > 1) { + tmp = new Date(url.path[1]); + if((Object.prototype.toString.call(tmp) === '[object Date]') || (tmp.toString() !== 'Invalid Date')) { + d = tmp; + } + } + history.pushState(null, null, '/todo/' + format_date_iso(d)); + + shows = new rh.ShowList(d); showListView = new rh.ShowListView(shows); + + $('#btn-earlier').click(todo_prev); + $('#btn-later').click(todo_next); +} + +function todo_prev() { + shows.prev(); +} + +function todo_next() { + shows.next(); } diff --git a/www/js/utils.js b/www/js/utils.js index ad64c17..ae2ad0a 100644 --- a/www/js/utils.js +++ b/www/js/utils.js @@ -54,6 +54,16 @@ monthname[11] = 'Dezember'; var monthname_short = new Array('Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'); +function format_date_iso(d) { + if(Object.prototype.toString.call(d) !== '[object Date]') { + return '-'; + } + if (d.toString() === 'Invalid Date') { + return '-'; + } + return d.getFullYear() + '-' + Number(d.getMonth() + 1).pad(2) + '-' + Number(d.getDate()).pad(2); +} + function format_date(d) { if(Object.prototype.toString.call(d) !== '[object Date]') { return '-'; diff --git a/www/styles/todo.css b/www/styles/todo.css index 6062a88..0ca11fa 100644 --- a/www/styles/todo.css +++ b/www/styles/todo.css @@ -35,19 +35,24 @@ body { margin-bottom: 0.5em; } -#header span.date { - font-size: 1.2em; - font-weight: bold; - padding-right: 0.3em; +#control { + float: left; + margin-right: 1em; } #header span.week { font-size: 0.6em; position: relative; - bottom: 0.3em; + bottom: 0.35em; padding-bottom: .15em; } +#header span.date { + font-size: 1.2em; + font-weight: bold; + padding-left: 0.3em; +} + #shows div.show { padding: 0.2em 0; diff --git a/www/todo.html b/www/todo.html index 0b7cdf5..0f582c1 100644 --- a/www/todo.html +++ b/www/todo.html @@ -16,11 +16,15 @@
-- cgit v0.10.2