diff --git a/openlp/plugins/remotes/html/index.html b/openlp/plugins/remotes/html/index.html index 17033dbc8..bb3352f1f 100644 --- a/openlp/plugins/remotes/html/index.html +++ b/openlp/plugins/remotes/html/index.html @@ -66,7 +66,7 @@ - Show Alert + Show Alert diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index a20ec7a9b..0745db61c 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -149,21 +149,38 @@ window.OpenLP = { }, nextItem: function (event) { $.getJSON("/api/service/next"); + return false; }, previousItem: function (event) { $.getJSON("/api/service/previous"); + return false; }, nextSlide: function (event) { $.getJSON("/api/controller/live/next"); + return false; }, previousSlide: function (event) { $.getJSON("/api/controller/live/previous"); + return false; }, blankDisplay: function (event) { $.getJSON("/api/display/hide"); + return false; }, unblankDisplay: function (event) { $.getJSON("/api/display/show"); + return false; + }, + showAlert: function (event) { + var text = JSON.stringify({"request": {"text": $("#alert-text").val()}}); + $.getJSON( + "/api/alert", + {"data": text}, + function () { + $("#alert-text").val(""); + } + ); + return false; } } // Service Manager @@ -180,6 +197,8 @@ $("#controller-next").live("click", OpenLP.nextSlide); $("#controller-previous").live("click", OpenLP.previousSlide); $("#controller-blank").live("click", OpenLP.blankDisplay); $("#controller-unblank").live("click", OpenLP.unblankDisplay); +// Alerts +$("#alert-submit").live("click", OpenLP.showAlert); // Poll the server twice a second to get any updates. setInterval("OpenLP.pollServer();", 500); OpenLP.pollServer(); diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 5d7ee37da..8b9d4076b 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -50,6 +50,12 @@ the remotes. ``/api/display/{hide|show}`` Blank or unblank the screen. +``/api/alert`` + Sends an alert message to the alerts plugin. This method expects a + JSON-encoded dict like this:: + + {"request": {"text": ""}} + ``/api/controller/{live|preview}/{action}`` Perform ``{action}`` on the live or preview controller. Valid actions are: @@ -244,7 +250,8 @@ class HttpConnection(object): (r'^/api/poll$', self.poll), (r'^/api/controller/(live|preview)/(.*)$', self.controller), (r'^/api/service/(.*)$', self.service), - (r'^/api/display/(hide|show)$', self.display) + (r'^/api/display/(hide|show)$', self.display), + (r'^/api/alert$', self.alert) ] QtCore.QObject.connect(self.socket, QtCore.SIGNAL(u'readyRead()'), self.ready_read) @@ -294,16 +301,6 @@ class HttpConnection(object): break if response: self.send_response(response) - """ - if hasattr(response, u'mimetype'): - self.send_200_ok(response.mimetype) - else: - self.send_200_ok() - if hasattr(response, u'content'): - self.socket.write(response.content) - elif isinstance(response, basestring): - self.socket.write(response) - """ else: self.send_response(HttpResponse(code='404 Not Found')) self.close() @@ -375,6 +372,15 @@ class HttpConnection(object): return HttpResponse(json.dumps({u'results': {u'success': True}}), {u'Content-Type': u'application/json'}) + def alert(self): + """ + Send an alert. + """ + text = json.loads(self.url_params[u'data'][0])[u'request'][u'text'] + Receiver.send_message(u'alerts_text', [text]) + return HttpResponse(json.dumps({u'results': {u'success': True}}), + {u'Content-Type': u'application/json'}) + def controller(self, type, action): """ Perform an action on the slide controller.