diff options
Diffstat (limited to 'www/js/shows.js')
-rw-r--r-- | www/js/shows.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/www/js/shows.js b/www/js/shows.js index f0eb34e..bb8058d 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -26,9 +26,9 @@ var Rdxport = Rdxport || {}; var showListView = null; -function shows_init() { +function shows_init(subpage) { var showList = new Rdxport.GroupList(); - showListView = new Rdxport.ShowListView(showList); + showListView = new Rdxport.ShowListView(showList, subpage); drawClock('Do, 1.1.1970', '00:00:00', 0); clock_add_callback(drawClock); @@ -39,11 +39,13 @@ function shows_cleanup() { importer.cancelAllUploads(); } -Rdxport.ShowListView = function(model) { +Rdxport.ShowListView = function(model, subpage) { this.model = model; this.showViews = []; - this.currentShowId = sessionStorage.getItem('currentShowId'); + this.currentShowId = null; + + this.setCurrentShowId(subpage); var self = this; $(this.model).on('update', function() { @@ -57,6 +59,16 @@ Rdxport.ShowListView = function(model) { }; Rdxport.ShowListView.prototype.setCurrentShowId = function(currentShowId) { + if (!currentShowId) { + return; + } + if (this.currentShowId !== currentShowId) { + if (this.currentShowId) { + history.pushState(null, null, '/shows/' + currentShowId + '/'); + } else { + history.replaceState(null, null, '/shows/' + currentShowId + '/'); + } + } this.currentShowId = currentShowId; sessionStorage.setItem('currentShowId', this.currentShowId); }; @@ -68,9 +80,6 @@ Rdxport.ShowListView.prototype.getCurrentShowView = function() { if (this.showViews.length === 0) { return null; } - if (this.currentShowId === null) { - this.setCurrentShowId(this.model.groups[0].id); - } var self = this; var showViewFound = null; $(this.showViews).each(function(index, showView) { @@ -94,8 +103,14 @@ Rdxport.ShowListView.prototype.updateSelector = function() { $showSelector.append($('<option>').attr('value', show.id).text(name)); }); - if (this.currentShowId === null) { - this.setCurrentShowId(this.model.groups[0].id); + // todo: maybe integrate this into setCurrentShowId? + if (!this.currentShowId) { + var currentShowId = sessionStorage.getItem('currentShowId'); + if (currentShowId) { + this.setCurrentShowId(currentShowId); + } else { + this.setCurrentShowId(this.model.groups[0].id); + } } $('option[value="' + this.currentShowId + '"]', $showSelector).attr('selected', 'selected'); |