From f306d3578d0ec18e34df3b7ed30e20fa71339bf6 Mon Sep 17 00:00:00 2001 From: PeterTheOne Date: Fri, 29 Jan 2016 15:06:18 +0100 Subject: move authLogin function to rivendel.rh.js, use more namespaces in jingles diff --git a/www/js/auth.js b/www/js/auth.js index 9bc83a8..c9fe52e 100644 --- a/www/js/auth.js +++ b/www/js/auth.js @@ -63,17 +63,6 @@ function auth_loginError(req, status, error) { $("#password").val(''); } -function auth_login() { - $.ajax("/rh-bin/authtoken.json", - { cache: false, - username: $("#username").val(), - password: $("#password").val(), - dataType: "json", - error: auth_loginError, - success: auth_loginSuccess - }); -} - function auth_logout() { auth_cleanup(); apps_cleanup(); @@ -97,18 +86,27 @@ function auth_init() { } else { $("#mainwindow").hide(); } - $("#loginform").submit(function(event) { auth_login(); event.preventDefault(); }); + $("#loginform").submit(function(event) { + event.preventDefault(); + + Rivendell.Rivendell.authLogin( + '/rh-bin/authtoken.json', + $("#username").val(), + $("#password").val(), + auth_loginSuccess + ).fail(auth_loginError); + }); } function auth_cleanup() { sessionStorage.removeItem("auth_username"); - auth_username = null; - $("#username").val('').focus(); - sessionStorage.removeItem("auth_fullname"); - auth_fullname = null; - sessionStorage.removeItem("auth_token"); + + auth_username = null; + auth_fullname = null; auth_token = null; + + $("#username").val('').focus(); $("#password").val(''); } diff --git a/www/js/jingles.js b/www/js/jingles.js index fbc0807..bd3b182 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -31,7 +31,7 @@ function jingles_init() { importer = new Rivendell.Importer(); var groupList = new Rivendell.GroupList(rivendell); - jingleGroupListView = new JingleGroupListView(groupList); + jingleGroupListView = new Rivendell.JingleGroupListView(groupList); } function jingles_cleanup() { @@ -42,7 +42,7 @@ function jingles_cleanup() { importer = null; } -var JingleGroupListView = function(model) { +Rivendell.JingleGroupListView = function(model) { this.model = model; this.jingleGroupViews = []; @@ -52,13 +52,13 @@ var JingleGroupListView = function(model) { var self = this; $(this.model).on('update', function() { $(self.model.groups).each(function(index, group) { - self.jingleGroupViews.push(new JingleGroupView(group)); + self.jingleGroupViews.push(new Rivendell.JingleGroupView(group)); }); }); this.model.fetch('jingle'); }; -JingleGroupListView.prototype.destroy = function() { +Rivendell.JingleGroupListView.prototype.destroy = function() { var self = this; $(this.jingleGroupViews).each(function(index, groupView) { groupView.destroy(); @@ -66,7 +66,7 @@ JingleGroupListView.prototype.destroy = function() { this.jingleGroupViews = []; }; -var JingleGroup = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title) { +Rivendell.JingleGroup = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title) { if (arguments.length = 1) { Rivendell.Group.call(this, groupName); this.title = $('jingle-title', this.xml).text(); @@ -75,10 +75,10 @@ var JingleGroup = function(groupName, description, lowcart, highcart, normlevel, this.title = title; } }; -JingleGroup.prototype = Object.create(Rivendell.Group.prototype); -JingleGroup.prototype.constructor = JingleGroup; +Rivendell.JingleGroup.prototype = Object.create(Rivendell.Group.prototype); +Rivendell.JingleGroup.prototype.constructor = Rivendell.JingleGroup; -var JingleGroupView = function(model) { +Rivendell.JingleGroupView = function(model) { this.model = model; this.mainCartView = null; @@ -93,16 +93,16 @@ var JingleGroupView = function(model) { $('table > tbody', self.$el).html(''); self.model.mainCart = self.model.carts[0]; - self.mainCartView = new JingleCartView(self.model.mainCart, self, true); + self.mainCartView = new Rivendell.JingleCartView(self.model.mainCart, self, true); self.model.deactivateCart = self.model.carts[1]; - self.deactivateCartView = new JingleCartView(self.model.deactivateCart, self, false); + self.deactivateCartView = new Rivendell.JingleCartView(self.model.deactivateCart, self, false); }); this.model.fetchCarts(); }; -JingleGroupView.prototype.render = function() { +Rivendell.JingleGroupView.prototype.render = function() { var self = this; this.$el = $('#hiddenTemplates .jingleGroupTemplate').clone().removeClass('jingleGroupTemplate'); @@ -116,11 +116,11 @@ JingleGroupView.prototype.render = function() { }); }; -JingleGroupView.prototype.destroy = function() { +Rivendell.JingleGroupView.prototype.destroy = function() { $('table > tbody', this.$el).html(''); }; -var JingleCartView = function(model, groupView, active) { +Rivendell.JingleCartView = function(model, groupView, active) { this.model = model; this.groupView = groupView; this.active = active; @@ -132,7 +132,7 @@ var JingleCartView = function(model, groupView, active) { $(this.model.cuts).each(function(index, cut) { cut.active = self.active; - var cutView = new JingleCutView(cut); + var cutView = new Rivendell.JingleCutView(cut); self.cutViews.push(cutView); $('table > tbody', self.groupView.$el).append(cutView.$el); @@ -140,7 +140,7 @@ var JingleCartView = function(model, groupView, active) { } }; -var JingleCutView = function(model) { +Rivendell.JingleCutView = function(model) { this.model = model; this.$el = null; @@ -148,7 +148,7 @@ var JingleCutView = function(model) { this.render(); }; -JingleCutView.prototype.render = function() { +Rivendell.JingleCutView.prototype.render = function() { var moveButton = $(''); var activateButton; if (this.model.active) { @@ -181,7 +181,7 @@ JingleCutView.prototype.render = function() { ); }; -JingleCutView.prototype.move = function() { +Rivendell.JingleCutView.prototype.move = function() { var self = this; var destinationCart = this.model.cartNumber; @@ -209,7 +209,7 @@ JingleCutView.prototype.move = function() { }); }; -JingleCutView.prototype.toggleActive = function() { +Rivendell.JingleCutView.prototype.toggleActive = function() { var destinationCart = this.model.cartNumber; if (this.model.active) { destinationCart++; @@ -222,7 +222,7 @@ JingleCutView.prototype.toggleActive = function() { }); }; -JingleCutView.prototype.removeSelf = function() { +Rivendell.JingleCutView.prototype.removeSelf = function() { var self = this; rivendell.removeCut(this.model.cartNumber, this.model.number, function() { self.model.cart.removeCut(this); diff --git a/www/js/musicpools.js b/www/js/musicpools.js index 00cffe3..1e9025f 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -108,7 +108,6 @@ Rivendell.MusicpoolsView.prototype.updateSelector = function() { this.getCurrentPoolView().render(); }; -// this and jinglegroup are basicly the same thing Rivendell.Musicpool = function(groupName, description, lowcart, highcart, normlevel, trimlevel, title, clock) { if (arguments.length === 1) { Rivendell.Group.call(this, groupName); diff --git a/www/js/rivendell.rh.js b/www/js/rivendell.rh.js index bc8252e..8e58d01 100644 --- a/www/js/rivendell.rh.js +++ b/www/js/rivendell.rh.js @@ -24,9 +24,20 @@ var Rivendell = Rivendell || {}; +Rivendell.Rivendell.authLogin = function(authEndpoint, username, password, success) { + return $.ajax(authEndpoint, { + username: username, + password: password, + success: success, + dataType: 'json', + cache: false + }); +}; + Rivendell.Rivendell.prototype.setListDropboxesEndpoint = function(listDropboxesEndpoint) { this.listDropboxesEndpoint = listDropboxesEndpoint; }; + Rivendell.Rivendell.prototype.setMusicgridEndpoint = function(musicgridEndpoint) { this.musicgridEndpoint = musicgridEndpoint; }; @@ -85,7 +96,7 @@ Rivendell.GroupList.prototype.fetch = function(type) { // todo break;*/ case 'jingle': - group = new JingleGroup(groupXml); + group = new Rivendell.JingleGroup(groupXml); break; case 'musicpool': group = new Rivendell.Musicpool(groupXml); -- cgit v0.10.2