diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-09-20 04:31:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-09-20 04:31:41 (GMT) |
commit | 06be1342eb1616dec595befb059e0d7049139bec (patch) | |
tree | 1634883a6626ccfc7008a7c08658b8504f1457c9 /index.html | |
parent | c807e3f3618861c06aa7f5c43b595e0881775a26 (diff) |
even more refactoring
Diffstat (limited to 'index.html')
-rw-r--r-- | index.html | 166 |
1 files changed, 100 insertions, 66 deletions
@@ -27,10 +27,6 @@ <script src="/javascript/twitter-bootstrap/js/bootstrap.min.js"></script> <script src="/javascript/twitter-bootstrap/js/bootstrap-alert.min.js"></script> <script type="text/javascript"> - var username = sessionStorage.getItem("username"); - var token = sessionStorage.getItem("token"); - var app = sessionStorage.getItem("app"); - alertbox = function() {} alertbox.warning = function (heading, message) { $('#alertbox').html('<div class="alert"><a class="close" data-dismiss="alert" href="#">×</a><h4 class="alert-heading">' + heading + '</h4>' + message + '</div>'); @@ -54,6 +50,7 @@ + var shows_currentid; var shows_list = []; var shows_current; @@ -108,27 +105,29 @@ sessionStorage.setItem("shows_currentid", shows_currentid); shows_current = $.grep(shows_list, function(elem) { return elem.id == shows_currentid; })[0]; - $('#show-title').text(shows_current.title); - $('#show-dow').text(weekday[shows_current.dow]); - $('#show-rhythm').text(shows_current.rhythm); - $('#show-starttime').text(shows_current.starttime); - $('#show-length').text(shows_current.length + ' Min.'); - - shows_log_carts = []; - data = { COMMAND: 22, LOGIN_NAME: username, PASSWORD: token, NAME: shows_current.log }; - lcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateLogCartList, "xml"); - - shows_group_carts = []; - data = { COMMAND: 6, LOGIN_NAME: username, PASSWORD: token, GROUP_NAME: shows_current.group.name, INCLUDE_CUTS: 1 }; - gcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateGroupCartList, "xml"); - - $.when(lcd, gcd).done( - function(lcres, gcres) { - if(lcres[1] == 'success' && gcres[1] == 'success') { - shows_udpateCartListing(); + if(shows_current) { + $('#show-title').text(shows_current.title); + $('#show-dow').text(weekday[shows_current.dow]); + $('#show-rhythm').text(shows_current.rhythm); + $('#show-starttime').text(shows_current.starttime); + $('#show-length').text(shows_current.length + ' Min.'); + + shows_log_carts = []; + data = { COMMAND: 22, LOGIN_NAME: auth_username, PASSWORD: auth_token, NAME: shows_current.log }; + lcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateLogCartList, "xml"); + + shows_group_carts = []; + data = { COMMAND: 6, LOGIN_NAME: auth_username, PASSWORD: auth_token, GROUP_NAME: shows_current.group.name, INCLUDE_CUTS: 1 }; + gcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateGroupCartList, "xml"); + + $.when(lcd, gcd).done( + function(lcres, gcres) { + if(lcres[1] == 'success' && gcres[1] == 'success') { + shows_udpateCartListing(); + } } - } - ); + ); + } } function shows_updateList(data, status, req) { @@ -170,16 +169,32 @@ function shows_init() { shows_currentid = sessionStorage.getItem("shows_currentid"); shows_list = []; - data = { LOGIN_NAME: username, PASSWORD: token }; + data = { LOGIN_NAME: auth_username, PASSWORD: auth_token }; $.post("/listdropboxes.cgi", data, shows_updateList, "xml") } function shows_cleanup() { sessionStorage.removeItem("shows_currentid"); delete shows_currentid; + shows_list = []; + shows_group_carts = []; + shows_log_carts = []; + } + + + + + function musicpools_init() { + } + + function musicpools_cleanup() { } + + + var apps_current; + function apps_select(app) { switch(app) { case "musicpools": @@ -187,51 +202,59 @@ $('#nav-btn-shows').removeClass('active'); $('#app-musicpools').show(); $('#nav-btn-musicpools').addClass('active'); + musicpools_init(); break; default: $('#app-shows').show(); $('#nav-btn-shows').addClass('active'); $('#app-musicpools').hide(); $('#nav-btn-musicpools').removeClass('active'); - app = 'shows'; + apps_current = 'shows'; shows_init(); } - sessionStorage.setItem("app", app); + sessionStorage.setItem("apps_current", apps_current); + } + + function apps_init() { + apps_current = sessionStorage.getItem("apps_current"); + apps_select(apps_current); } + function apps_cleanup() { + shows_cleanup(); + musicpools_cleanup(); + + sessionStorage.removeItem("apps_current"); + delete apps_current; + } + + + + var auth_username; + var auth_token; - function authSuccess(data) { + function auth_loginSuccess(data) { if (data.status == 'OK') { - username = data.username; - sessionStorage.setItem("username", username); + auth_username = data.username; + sessionStorage.setItem("auth_username", auth_username); - token = data.token; - sessionStorage.setItem("token", token); + auth_token = data.token; + sessionStorage.setItem("auth_token", auth_token); apps_select('shows'); - $('#username-field').html(username); + $('#username-field').html(auth_username); $('#loginbox').slideUp(); $('#mainwindow').fadeIn(); } else { alertbox.error("Fehler beim Login", data.errorstring); - - sessionStorage.removeItem("username"); - delete username; - $("#username").val('').focus(); - - sessionStorage.removeItem("token"); - delete token; - $("#password").val(''); - - sessionStorage.removeItem("app"); - delete app; + auth_cleanup(); } } - function authError(req, status, error) { + function auth_loginError(req, status, error) { message = req.status + ': ' + error; if(req.status == 401) { message = "Benutzer und/oder Passwort sind falsch!"; @@ -240,28 +263,22 @@ $("#password").val(''); } - function login() + function auth_login() { $.ajax("/authtoken.json", { cache: false, username: $("#username").val(), password: $("#password").val(), dataType: "json", - error: authError, - success: authSuccess + error: auth_loginError, + success: auth_loginSuccess }); } - function logout() + function auth_logout() { - sessionStorage.removeItem("username"); - delete username; - sessionStorage.removeItem("token"); - delete token; - sessionStorage.removeItem("app"); - delete app; - - shows_cleanup(); + auth_cleanup(); + apps_cleanup(); $(".alert").alert('close'); $("#username").val(''); @@ -270,6 +287,29 @@ $('#username-field').html(''); $('#loginbox').slideDown(); } + + function auth_init() { + auth_username = sessionStorage.getItem("auth_username"); + auth_token = sessionStorage.getItem("auth_token"); + + if(auth_token && auth_username) { + $("#loginbox").hide(); + $('#username-field').html(auth_username); + } else { + $("#mainwindow").hide(); + } + $("#loginform").submit(function(event) { auth_login(); event.preventDefault(); }); + } + + function auth_cleanup() { + sessionStorage.removeItem("auth_username"); + delete auth_username; + $("#username").val('').focus(); + + sessionStorage.removeItem("auth_token"); + delete auth_token; + $("#password").val(''); + } </script> </head> <body> @@ -308,7 +348,7 @@ </ul> <form id="logoutform" class="navbar-form pull-right"> <span class="navbar-text">angmeldet als <strong id="username-field">UNKNOWN</strong></span> - <button style="margin-top: 0;" type="button" class="btn btn-danger btn-small" onclick="logout()"> + <button style="margin-top: 0;" type="button" class="btn btn-danger btn-small" onclick="auth_logout()"> <i class="icon-off icon-white"></i> Abmelden </button> </form> @@ -416,14 +456,8 @@ </div> <script type="text/javascript"> - $("#loginform").submit(function(event) { login(); event.preventDefault(); }); - $('#username-field').html(username); - apps_select(app); - if(token && username) { - $("#loginbox").hide(); - } else { - $("#mainwindow").hide(); - } + auth_init(); + apps_init(); </script> </body> |