diff options
author | Peter Grassberger <petertheone@gmail.com> | 2016-06-27 23:08:15 (GMT) |
---|---|---|
committer | Peter Grassberger <petertheone@gmail.com> | 2016-06-27 23:08:15 (GMT) |
commit | d5d29c8889a9dc655044a1cf0926c1ac892b6696 (patch) | |
tree | a73ddad8bad0cf275e11886dac20e19bb6935522 /www/js/shows.js | |
parent | dd5cd12cafa71f5d757642aec25c65dcceb3d02c (diff) | |
parent | 03af1fed48370ddc4772709207f064c16191f5c1 (diff) |
Merge branch 'master' of ssh://git@git.helsinki.at:2342/rhwebimport.git
Diffstat (limited to 'www/js/shows.js')
-rw-r--r-- | www/js/shows.js | 76 |
1 files changed, 55 insertions, 21 deletions
diff --git a/www/js/shows.js b/www/js/shows.js index 8fcba8b..233a5c3 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) { @@ -87,22 +96,34 @@ Rdxport.ShowListView.prototype.updateSelector = function() { var $showSelector = $('#show-selector'); $showSelector.off(); - $('option', $showSelector).remove(); + $('li', $showSelector).remove(); - $(this.model.groups).each(function(index, show) { - var name = show.title + ' (' + show.rhythm + ', ' + weekday[show.dayofweek] + ', ' + show.starttime + ', ' + show.length + ' Min.)'; - $showSelector.append($('<option>').attr('value', show.id).text(name)); + $(this.model.groups).sort(function(a, b) { + if(a.title.toLowerCase() == b.title.toLowerCase()) { + return b.rhythm - a.rhythm; + } + return a.title.toLowerCase() >= b.title.toLowerCase() + }).each(function(index, show) { + var name = show.id + ' | <strong>' + show.title + '</strong> (' + show.rhythm + ', ' + weekday[show.dayofweek] + ', ' + show.starttime + ', ' + show.length + ' Min.)'; + var link = $('<a>').attr('href', '#').html(name).click(function() { + self.setCurrentShowId(show.id); + self.getCurrentShowView().model.fetchCarts(); + }); + $showSelector.append($('<li>').append(link)); }); - - if (this.currentShowId === null) { - this.setCurrentShowId(this.model.groups[0].id); + if($showSelector.children().length == 0) { + $showSelector.append($('<li>').append($('<a>').text('Keine Sendung gefunden!'))); } - $('option[value="' + this.currentShowId + '"]', $showSelector).attr('selected', 'selected'); - $showSelector.on('change', function() { - self.setCurrentShowId($('option:selected', $showSelector).attr('value')); - self.getCurrentShowView().model.fetchCarts(); - }); + // 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); + } + } this.getCurrentShowView().model.fetchCarts(); }; @@ -189,10 +210,23 @@ Rdxport.ShowView = function(model) { Rdxport.ShowView.prototype.render = function() { $('#show-title').text(this.model.title); $('#show-dow').text(weekday[this.model.dayofweek]); - $('#show-rhythm').text(this.model.rhythm); $('#show-starttime').text(this.model.starttime); $('#show-length').text(this.model.length + ' Min.'); + for(var w = 0; w < 4; w++) { + if(this.model.rhythm.charAt(w) == '1') { + var s = $('#show-rhythm-w' + (w+1)).attr('class', 'label') + switch(w+1) { + case 1: s.addClass('label-info'); break; + case 2: s.addClass('label-warning'); break; + case 3: s.addClass('label-success'); break; + case 4: s.addClass('label-danger'); break; + } + } else { + $('#show-rhythm-w' + (w+1)).attr('class', 'label label-disabled') + } + } + var $tableBody = $('#app-shows table tbody'); $('tr', $tableBody).remove(); @@ -249,7 +283,7 @@ Rdxport.ShowView.prototype.uploadError = function(upload, file, msg, xhr, acknow //var msg = $(xmlDoc); //var responseCode = msg.find('ResponseCode').text(); //var errorString = msg.find('ErrorString').text(); - var reason = $('<span>').addClass('label').addClass('label-danger').text(responseCode).after($('<b>').html(' ' + errorString)); + var reason = $('<span>').addClass('label').addClass('label-danger').text(responseCode).after($('<b>').text(' ' + errorString)); var dismiss_button = '<button class="btn btn-info btn-xs">' + '<span class="glyphicon glyphicon-remove"></span> Ok</button>'; |