Added in support for showing alerts.

This commit is contained in:
Raoul Snyman 2011-03-16 12:59:23 +02:00
parent df79ab09fa
commit 955933237c
3 changed files with 37 additions and 12 deletions

View File

@ -66,7 +66,7 @@
<label for="alert-text">Text:</label> <label for="alert-text">Text:</label>
<input type="text" name="alert-text" id="alert-text" value="" /> <input type="text" name="alert-text" id="alert-text" value="" />
</div> </div>
<a href="#" data-role="button">Show Alert</a> <a href="#" id="alert-submit" data-role="button">Show Alert</a>
</div> </div>
</div> </div>
</body> </body>

View File

@ -149,21 +149,38 @@ window.OpenLP = {
}, },
nextItem: function (event) { nextItem: function (event) {
$.getJSON("/api/service/next"); $.getJSON("/api/service/next");
return false;
}, },
previousItem: function (event) { previousItem: function (event) {
$.getJSON("/api/service/previous"); $.getJSON("/api/service/previous");
return false;
}, },
nextSlide: function (event) { nextSlide: function (event) {
$.getJSON("/api/controller/live/next"); $.getJSON("/api/controller/live/next");
return false;
}, },
previousSlide: function (event) { previousSlide: function (event) {
$.getJSON("/api/controller/live/previous"); $.getJSON("/api/controller/live/previous");
return false;
}, },
blankDisplay: function (event) { blankDisplay: function (event) {
$.getJSON("/api/display/hide"); $.getJSON("/api/display/hide");
return false;
}, },
unblankDisplay: function (event) { unblankDisplay: function (event) {
$.getJSON("/api/display/show"); $.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 // Service Manager
@ -180,6 +197,8 @@ $("#controller-next").live("click", OpenLP.nextSlide);
$("#controller-previous").live("click", OpenLP.previousSlide); $("#controller-previous").live("click", OpenLP.previousSlide);
$("#controller-blank").live("click", OpenLP.blankDisplay); $("#controller-blank").live("click", OpenLP.blankDisplay);
$("#controller-unblank").live("click", OpenLP.unblankDisplay); $("#controller-unblank").live("click", OpenLP.unblankDisplay);
// Alerts
$("#alert-submit").live("click", OpenLP.showAlert);
// Poll the server twice a second to get any updates. // Poll the server twice a second to get any updates.
setInterval("OpenLP.pollServer();", 500); setInterval("OpenLP.pollServer();", 500);
OpenLP.pollServer(); OpenLP.pollServer();

View File

@ -50,6 +50,12 @@ the remotes.
``/api/display/{hide|show}`` ``/api/display/{hide|show}``
Blank or unblank the screen. 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": "<your alert text>"}}
``/api/controller/{live|preview}/{action}`` ``/api/controller/{live|preview}/{action}``
Perform ``{action}`` on the live or preview controller. Valid actions Perform ``{action}`` on the live or preview controller. Valid actions
are: are:
@ -244,7 +250,8 @@ class HttpConnection(object):
(r'^/api/poll$', self.poll), (r'^/api/poll$', self.poll),
(r'^/api/controller/(live|preview)/(.*)$', self.controller), (r'^/api/controller/(live|preview)/(.*)$', self.controller),
(r'^/api/service/(.*)$', self.service), (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()'), QtCore.QObject.connect(self.socket, QtCore.SIGNAL(u'readyRead()'),
self.ready_read) self.ready_read)
@ -294,16 +301,6 @@ class HttpConnection(object):
break break
if response: if response:
self.send_response(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: else:
self.send_response(HttpResponse(code='404 Not Found')) self.send_response(HttpResponse(code='404 Not Found'))
self.close() self.close()
@ -375,6 +372,15 @@ class HttpConnection(object):
return HttpResponse(json.dumps({u'results': {u'success': True}}), return HttpResponse(json.dumps({u'results': {u'success': True}}),
{u'Content-Type': u'application/json'}) {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): def controller(self, type, action):
""" """
Perform an action on the slide controller. Perform an action on the slide controller.