summaryrefslogtreecommitdiff
path: root/www/js/shows.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/shows.js')
-rw-r--r--www/js/shows.js76
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('&nbsp;' + errorString));
+ var reason = $('<span>').addClass('label').addClass('label-danger').text(responseCode).after($('<b>').text('&nbsp;' + errorString));
var dismiss_button = '<button class="btn btn-info btn-xs">' +
'<span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;Ok</button>';