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>
<input type="text" name="alert-text" id="alert-text" value="" />
</div>
<a href="#" data-role="button">Show Alert</a>
<a href="#" id="alert-submit" data-role="button">Show Alert</a>
</div>
</div>
</body>

View File

@ -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();

View File

@ -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": "<your alert 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.