diff options
author | Christian Pointner <equinox@helsinki.at> | 2017-01-14 04:31:59 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2017-01-14 04:31:59 (GMT) |
commit | 0cc67d030dd5fc8b5a853dfd4d8d8ea6a7c85806 (patch) | |
tree | 9fb1a518a070874cbaea75ecf1cfabdb9e213e5b | |
parent | deaa31e2269b4f13ddf777a4c05a57dc26d7bba1 (diff) |
added date controller
-rw-r--r-- | www/js/todo.js | 40 | ||||
-rw-r--r-- | www/js/utils.js | 10 | ||||
-rw-r--r-- | www/styles/todo.css | 15 | ||||
-rw-r--r-- | www/todo.html | 10 |
4 files changed, 63 insertions, 12 deletions
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 @@ <body> <div id="container"> <div id="header"> + <div id="control"> + <div class="btn-group" role="group"> + <button type="button" class="btn btn-default" id="btn-earlier"><span class="glyphicon glyphicon-minus"></span></button> + <button type="button" class="btn btn-default" id="btn-later"><span class="glyphicon glyphicon-plus"></span></button> + </div> + </div> <div> - <span class="date">--.--.----</span> <span class="week"></span> - </div> - <div id="control"> + <span class="date">--.--.----</span> </div> </div> |