summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
Diffstat (limited to 'www')
-rw-r--r--www/js/todo.js40
1 files changed, 32 insertions, 8 deletions
diff --git a/www/js/todo.js b/www/js/todo.js
index 37eb292..23768b7 100644
--- a/www/js/todo.js
+++ b/www/js/todo.js
@@ -38,14 +38,19 @@ rh.ShowList = function(d) {
this.current = d;
}
this.current_week = get_rd_week(this.current.valueOf());
+ this.request_sent = false;
};
rh.ShowList.prototype.fetch = function() {
var self = this;
this.current_week = get_rd_week(this.current.valueOf());
+ this.request_sent = true;
+ self.$this.trigger('update-hdr');
$.getJSON( "/rh-bin/schedules.json?DAYS=1&START=" + format_date_iso(this.current), function(data) {
if(data.status == "OK") {
+ history.replaceState(null, null, '/todo/' + format_date_iso(self.current));
+ self.last_succeeded = self.current;
self.shows = [];
$(data.shows).each(function(index, showdata) {
var show = new rh.Show(showdata);
@@ -53,19 +58,30 @@ rh.ShowList.prototype.fetch = function() {
});
self.$this.trigger('update');
}
+ }).fail(function() {
+ if((Object.prototype.toString.call(self.last_succeeded) === '[object Date]') &&
+ (self.last_succeeded.toString() !== 'Invalid Date')) {
+ self.current = self.last_succeeded;
+ self.current_week = get_rd_week(self.current.valueOf());
+ self.$this.trigger('update');
+ }
+ }).always(function() {
+ self.request_sent = false;
});
};
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();
+ if(!this.request_sent) {
+ this.current = new Date(this.current.valueOf() - 24*3600*1000);
+ 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();
+ if(!this.request_sent) {
+ this.current = new Date(this.current.valueOf() + 24*3600*1000);
+ this.fetch();
+ }
};
rh.Show = function(show) {
@@ -87,13 +103,16 @@ rh.ShowListView = function(model) {
this.showViews = [];
var self = this;
+ $(this.model).on('update-hdr', function() {
+ self.render_hdr();
+ });
$(this.model).on('update', function() {
self.render();
});
this.model.fetch();
};
-rh.ShowListView.prototype.render = function() {
+rh.ShowListView.prototype.render_hdr = function() {
var hdr = $('#header');
$('span.date', hdr).text(format_date(this.model.current));
var weekspan = $('span.week', hdr).removeClass().addClass('week').addClass('label');
@@ -117,7 +136,12 @@ rh.ShowListView.prototype.render = function() {
var list = $('#shows');
$('div.show', list).remove();
this.showViews = [];
+};
+rh.ShowListView.prototype.render = function() {
+ this.render_hdr();
+
+ var list = $('#shows');
for (var i = 0; i < this.model.shows.length; i++) {
var showView = new rh.ShowView(this.model.shows[i], this);
this.showViews.push(showView);
@@ -154,7 +178,7 @@ function todo_init() {
var d = new Date();
if(url.path.length > 1) {
var tmp = new Date(url.path[1]);
- if((Object.prototype.toString.call(tmp) === '[object Date]') || (tmp.toString() !== 'Invalid Date')) {
+ if((Object.prototype.toString.call(tmp) === '[object Date]') && (tmp.toString() !== 'Invalid Date')) {
d = tmp;
}
}