From c09725d1a62830d69daf8d286638e0d334394f78 Mon Sep 17 00:00:00 2001
From: PeterTheOne <petertheone@gmail.com>
Date: Fri, 29 Jan 2016 14:34:18 +0100
Subject: fix login and logout


diff --git a/www/js/apps.js b/www/js/apps.js
index 6bdf3d6..ef904f2 100644
--- a/www/js/apps.js
+++ b/www/js/apps.js
@@ -97,6 +97,7 @@ function apps_init() {
   apps_current = locationHrefValue();
 
   if(auth_token && auth_username) {
+    // todo: do this at a central place
     rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi');
     rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi');
     rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi');
@@ -106,6 +107,11 @@ function apps_init() {
 
   $(window).on('popstate', function(event) {
     if(auth_token && auth_username) {
+      // todo: do this at a central place
+      rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi');
+      rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi');
+      rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi');
+
       apps_select(locationHrefValue());
     }
   });
diff --git a/www/js/auth.js b/www/js/auth.js
index f830a0a..9bc83a8 100644
--- a/www/js/auth.js
+++ b/www/js/auth.js
@@ -38,6 +38,11 @@ function auth_loginSuccess(data) {
      sessionStorage.setItem("auth_fullname", auth_fullname);
      sessionStorage.setItem("auth_token", auth_token);
 
+     // todo: do this at a central place
+     rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi');
+     rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi');
+     rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi');
+
      apps_select(apps_current);
 
      $('#username-field').html(auth_fullname + ' (' + auth_username + ')');
diff --git a/www/js/jingles.js b/www/js/jingles.js
index d80dd95..fbc0807 100644
--- a/www/js/jingles.js
+++ b/www/js/jingles.js
@@ -58,6 +58,14 @@ var JingleGroupListView = function(model) {
   this.model.fetch('jingle');
 };
 
+JingleGroupListView.prototype.destroy = function() {
+  var self = this;
+  $(this.jingleGroupViews).each(function(index, groupView) {
+    groupView.destroy();
+  });
+  this.jingleGroupViews = [];
+};
+
 var JingleGroup = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title) {
   if (arguments.length = 1) {
     Rivendell.Group.call(this, groupName);
diff --git a/www/js/musicgrid.js b/www/js/musicgrid.js
index d95fb1e..bd219ff 100644
--- a/www/js/musicgrid.js
+++ b/www/js/musicgrid.js
@@ -38,7 +38,9 @@ function musicgrid_init() {
 function musicgrid_cleanup() {
   musicpoolModal = null;
 
-  musicgridView.clean();
+  if (musicgridView) {
+    musicgridView.clean();
+  }
   musicgridView = null;
 }
 
diff --git a/www/js/rivendell.js b/www/js/rivendell.js
index 4a40ce0..6e5d099 100644
--- a/www/js/rivendell.js
+++ b/www/js/rivendell.js
@@ -357,12 +357,6 @@ Rivendell.GroupList = function(rivendell) {
   this.groups = [];
 };
 
-Rivendell.GroupList.prototype.destroy = function() {
-  $(this.groups).each(function(index, group) {
-    group.destroy();
-  });
-};
-
 Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, trimlevel) {
   this.xml = null;
 
-- 
cgit v0.10.2