summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrh-bin/cutevergreen.cgi116
-rw-r--r--www/js/jingles.js49
-rw-r--r--www/js/rdxport.rh.js15
-rw-r--r--www/js/router.js1
4 files changed, 147 insertions, 34 deletions
diff --git a/rh-bin/cutevergreen.cgi b/rh-bin/cutevergreen.cgi
new file mode 100755
index 0000000..f6be224
--- /dev/null
+++ b/rh-bin/cutevergreen.cgi
@@ -0,0 +1,116 @@
+#!/usr/bin/perl
+#
+# rhwebimport
+#
+# Copyright (C) 2014-2016 Christian Pointner <equinox@helsinki.at>
+# Copyright (C) 2015-2016 Peter Grassberger <petertheone@gmail.com>
+#
+# This file is part of rhwebimport.
+#
+# rhwebimport is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# rhwebimport is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with rhwebimport. If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use CGI;
+use POSIX;
+use XML::Quote;
+use RHRD::rddb;
+
+my $status = 'ERROR';
+my $errorstring = 'unknown';
+my $responsecode = 500;
+
+my $q = CGI->new;
+my $username = $q->param('LOGIN_NAME');
+my $token = $q->param('PASSWORD');
+my $cmd = $q->request_method();
+my $cart = $q->param('CART_NUMBER');
+my $cut = $q->param('CUT_NUMBER');
+my $value = $q->param('VALUE');
+
+
+sub is_authorized
+{
+ my ($ctx, $username, $cart) = @_;
+
+ RHRD::rddb::is_group_member($ctx, $username);
+
+ my ($groupname, undef, undef) = RHRD::rddb::get_cart_group($ctx, $cart);
+ my ($cnt, undef, undef) = RHRD::rddb::is_group_member($ctx, $groupname, $username);
+ unless(defined $cnt) {
+ return 0;
+ }
+ return (($cnt) ? 1 : 0);
+}
+
+if(!defined $username) {
+ $responsecode = 400;
+ $errorstring = "mandatory field LOGIN_NAME is missing";
+} elsif(!defined $token) {
+ $responsecode = 400;
+ $errorstring = "mandatory field PASSWORD is missing";
+} elsif(!defined $cart) {
+ $responsecode = 400;
+ $errorstring = "mandatory field CART_NUMBER is missing";
+} elsif($cart < RHRD::rddb::RD_MIN_CART || $cart > RHRD::rddb::RD_MAX_CART) {
+ $responsecode = 400;
+ $errorstring = "CART_NUMBER is out of range";
+} elsif(!defined $cut) {
+ $responsecode = 400;
+ $errorstring = "mandatory field CUT_NUMBER is missing";
+} elsif($cut < RHRD::rddb::RD_MIN_CUT || $cut > RHRD::rddb::RD_MAX_CUT) {
+ $responsecode = 400;
+ $errorstring = "CUT_NUMBER is out of range";
+} elsif(!defined $value) {
+ $responsecode = 400;
+ $errorstring = "mandatory field VALUE is missing";
+} else {
+ (my $ctx, $status, $errorstring) = RHRD::rddb::init();
+ if(defined $ctx) {
+ my ($authenticated, undef, undef) = RHRD::rddb::check_token($ctx, $username, $token);
+ my ($authorized, undef, undef) = is_authorized($ctx, $username, $cart);
+ if($authenticated == 1 && $authorized == 1) {
+ if($cmd eq "POST") {
+ my ($result, $status, $error) = RHRD::rddb::set_cut_evergreen($ctx, $cart, $cut, $value);
+ if(!defined $result) {
+ $responsecode = 500;
+ $errorstring = $status . ": " . $error;
+ } else {
+ $responsecode = 200;
+ $errorstring = "OK"
+ }
+ }
+ else {
+ $responsecode = 405;
+ $errorstring = "request method '$cmd' is unknown";
+ }
+ } elsif($authenticated == 0) {
+ $responsecode = 401;
+ } elsif($authorized == 0) {
+ $responsecode = 403;
+ $errorstring = "user '" . $username . "' is not allowed to access the cart/cut";
+ } else {
+ $responsecode = 500;
+ }
+ RHRD::rddb::destroy($ctx);
+ }
+}
+
+print "Content-type: application/xml; charset=UTF-8\n";
+print "Status: $responsecode\n\n";
+
+print "<RDWebResult>\n";
+print " <ResponseCode>" . xml_quote($responsecode) . "</ResponseCode>\n";
+print " <ErrorString>" . xml_quote($errorstring) . "</ErrorString>\n";
+print "</RDWebResult>\n";
diff --git a/www/js/jingles.js b/www/js/jingles.js
index 2a269cd..6b66ea4 100644
--- a/www/js/jingles.js
+++ b/www/js/jingles.js
@@ -76,8 +76,7 @@ Rdxport.JingleGroup.prototype.constructor = Rdxport.JingleGroup;
Rdxport.JingleGroupView = function(model) {
this.model = model;
- this.mainCartView = null;
- this.deactivateCartView = null;
+ this.cartView = null;
this.$el = null;
@@ -88,11 +87,8 @@ Rdxport.JingleGroupView = function(model) {
importer.syncUploads('jingles', self, function() {
$('table > tbody', self.$el).empty();
- self.model.mainCart = self.model.carts[0];
- self.mainCartView = new Rdxport.JingleCartView(self.model.mainCart, self, true);
-
- self.model.deactivateCart = self.model.carts[1];
- self.deactivateCartView = new Rdxport.JingleCartView(self.model.deactivateCart, self, false);
+ self.model.cart = self.model.carts[0];
+ self.cartView = new Rdxport.JingleCartView(self.model.cart, self);
});
});
@@ -180,10 +176,9 @@ Rdxport.JingleGroupView.uploadError = function(upload) {
$cut.replaceWith($errorRow);
};
-Rdxport.JingleCartView = function(model, groupView, active) {
+Rdxport.JingleCartView = function(model, groupView) {
this.model = model;
this.groupView = groupView;
- this.active = active;
this.cutViews = [];
@@ -196,8 +191,6 @@ Rdxport.JingleCartView = function(model, groupView, active) {
return 1;
return -1;
}).each(function(index, cut) {
- cut.active = self.active;
-
var cutView = new Rdxport.JingleCutView(cut);
self.cutViews.push(cutView);
@@ -243,16 +236,12 @@ Rdxport.JingleCutView.prototype.render = function() {
var status = $('<span class="label"></span>');
var moveButton = $('<button class="btn btn-info btn-xs"><span class="glyphicon glyphicon-transfer"></span>&nbsp;&nbsp;Verschieben</button>');
var activateButton;
- if (this.model.active) {
+ if (!this.model.isEvergreen) {
activateButton = $('<button class="btn btn-warning btn-xs"><span class="glyphicon glyphicon-ban-circle"></span>&nbsp;&nbsp;Deaktivieren</button>');
- if (!this.model.isEvergreen) {
- status.addClass('label-success').html('<span class="glyphicon glyphicon-star"></span>');
- } else {
- status.addClass('label-info').html('<span class="glyphicon glyphicon-star-empty"></span>');
- }
+ status.addClass('label-success').html('<span class="glyphicon glyphicon-star"></span>');
} else {
activateButton = $('<button class="btn btn-success btn-xs"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;Aktivieren</button>');
- status.addClass('label-warning').html('<span class="glyphicon glyphicon-ban-circle"></span>');
+ status.addClass('label-default').html('<span class="glyphicon glyphicon-star-empty"></span>');
}
var deleteButton = $('<button class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span>&nbsp;&nbsp;Löschen</button>');
@@ -268,7 +257,7 @@ Rdxport.JingleCutView.prototype.render = function() {
self.move();
});
activateButton.on('click', function() {
- self.toggleActive();
+ self.toggleEvergreen();
});
deleteButton.on('click', function() {
self.delete();
@@ -325,14 +314,8 @@ Rdxport.JingleCutView.prototype.move = function() {
// todo: make this work for multiple groups
if (jingleGroupListView.model.groups.length === 2) {
$(jingleGroupListView.model.groups).each(function(index, group) {
- if (self.model.active) {
- if (self.model.cartNumber !== group.mainCart.number) {
- destinationCart = group.mainCart;
- }
- } else {
- if (self.model.cartNumber !== group.deactivateCart.number) {
- destinationCart = group.deactivateCart;
- }
+ if (self.model.cartNumber !== group.cart.number) {
+ destinationCart = group.cart;
}
});
} else {
@@ -346,16 +329,14 @@ Rdxport.JingleCutView.prototype.move = function() {
});
};
-Rdxport.JingleCutView.prototype.toggleActive = function() {
+Rdxport.JingleCutView.prototype.toggleEvergreen = function() {
this.$el.find('td:first').html(this.$spinner);
- var destinationCart = this.model.cartNumber;
- if (this.model.active) {
- destinationCart++;
- } else {
- destinationCart--;
+ var newvalue = 1;
+ if(this.model.isEvergreen) {
+ newvalue = 0;
}
var self = this;
- rdxport.moveCut(this.model.cartNumber, this.model.number, destinationCart, function() {
+ rdxport.setCutEvergreen(this.model.cartNumber, this.model.number, newvalue, function() {
self.model.cart.group.fetchCarts();
});
};
diff --git a/www/js/rdxport.rh.js b/www/js/rdxport.rh.js
index b5b58c9..868deeb 100644
--- a/www/js/rdxport.rh.js
+++ b/www/js/rdxport.rh.js
@@ -38,6 +38,10 @@ Rdxport.Rdxport.prototype.setListDropboxesEndpoint = function(listDropboxesEndpo
this.listDropboxesEndpoint = listDropboxesEndpoint;
};
+Rdxport.Rdxport.prototype.setCutEvergreenEndpoint = function(cutEvergreenEndpoint) {
+ this.cutEvergreenEndpoint = cutEvergreenEndpoint;
+};
+
Rdxport.Rdxport.prototype.setMusicgridEndpoint = function(musicgridEndpoint) {
this.musicgridEndpoint = musicgridEndpoint;
};
@@ -97,6 +101,17 @@ Rdxport.Rdxport.prototype.addAndEditCart = function(groupName, type, cartNumber,
return $.post(this.endpoint, options, success, 'xml');
};
+Rdxport.Rdxport.prototype.setCutEvergreen = function(cartNumber, cutNumber, value, success) {
+ var command = {
+ LOGIN_NAME: this.username,
+ PASSWORD: this.token,
+ CART_NUMBER: cartNumber,
+ CUT_NUMBER: cutNumber,
+ VALUE: value
+ };
+ return $.post(this.cutEvergreenEndpoint, command, success, "xml");
+};
+
Rdxport.Rdxport.prototype.getMusicgrid = function(success) {
var command = {
LOGIN_NAME: this.username,
diff --git a/www/js/router.js b/www/js/router.js
index 9e11383..cbd453c 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -66,6 +66,7 @@ Rdxport.Router.prototype.route = function(page, subpage) {
if (!rdxport) {
rdxport = new Rdxport.Rdxport(this.auth.username, this.auth.token, '/rd-bin/rdxport.cgi');
rdxport.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi');
+ rdxport.setCutEvergreenEndpoint('/rh-bin/cutevergreen.cgi');
rdxport.setMusicgridEndpoint('/rh-bin/musicgrid.cgi');
}