summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/todo.js40
-rw-r--r--www/js/utils.js10
2 files changed, 46 insertions, 4 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 '-';