Moved Jonathan's JS over to jQuery

This commit is contained in:
Raoul Snyman 2010-05-27 21:40:44 +02:00
parent 4d9f429ae0
commit 2ddde15875
3 changed files with 145 additions and 50 deletions

View File

@ -1,10 +1,14 @@
<html>
<head>
<title>OpenLP Controller</title>
<script type='text/javascript'>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OpenLP Remote Controller</title>
<script type="text/javascript" src="/files/jquery.js"></script>
<script type='text/javascript'>
function send_event(eventname, data){
var req = new XMLHttpRequest();
function send_event(eventname, data) {
/*var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if(req.readyState==4)
response(eventname, req);
@ -12,13 +16,41 @@ function send_event(eventname, data){
var url = '';
if(eventname.substr(-8) == '_request')
url = 'request';
else
else
url = 'send';
url += '/' + eventname;
if(data!=null)
url += '?q=' + escape(data);
req.open('GET', url, true);
req.send();
req.send();*/
var url = "";
if (eventname.substr(-8) == "_request")
{
url = "request";
}
else
{
url = "send";
}
url += "/" + eventname;
var args = {};
if (data != null)
{
args.q = escape(data);
}
$.get(url, args, function (data, textStatus) {
if (textStatus != "success")
{
if (eventname == "remotes_poll_request")
{
send_event("remotes_poll_request");
}
}
else
{
new_response(eventname, data);
}
});
}
function failed_response(eventname, req){
switch(eventname){
@ -51,7 +83,7 @@ function response(eventname, req){
html += '</tr>';
}
html += '</table>';
document.getElementById('service').innerHTML = html;
document.getElementById('service').innerHTML = html;
break;
case 'slidecontroller_live_text_request':
var data = eval('(' + text + ')');
@ -67,7 +99,51 @@ function response(eventname, req){
html += '</td></tr>';
}
html += '</table>';
document.getElementById('currentitem').innerHTML = html;
document.getElementById('currentitem').innerHTML = html;
break;
case 'remotes_poll_request':
send_event("remotes_poll_request");
send_event("servicemanager_list_request");
send_event("slidecontroller_live_text_request");
break;
}
}
function new_response(eventname, text){
switch (eventname)
{
case 'servicemanager_list_request':
var data = eval('(' + text + ')');
var table = $("<table>");
for (row in data)
{
var trow = $("<tr>").click("send_event('servicemanager_set_item', '" + row + "')");
if (data[row]['selected'])
{
trow.attr("style", "font-weight: bold");
}
trow.append($("<td>").text(parseInt(row)+1));
trow.append($("<td>").text(data[row]['title']));
trow.append($("<td>").text(data[row]['plugin']));
trow.append($("<td>").text(data[row]['notes']));
table.append(trow);
}
$("#service").html(table);
break;
case 'slidecontroller_live_text_request':
var data = eval('(' + text + ')');
var html = '<table>';
for(row in data){
html += '<tr onclick="send_event('
html += "'slidecontroller_live_set', " + row + ')"';
if(data[row]['selected'])
html += ' style="font-weight: bold"';
html += '>';
html += '<td>' + data[row]['tag'] + '</td>';
html += '<td>' + data[row]['text'].replace(/\\n/g, '<br>');
html += '</td></tr>';
}
html += '</table>';
document.getElementById('currentitem').innerHTML = html;
break;
case 'remotes_poll_request':
send_event("remotes_poll_request");
@ -83,31 +159,31 @@ send_event("remotes_poll_request");
</head>
<body>
<h1>OpenLP Controller</h1>
<input type='button' value='<- Previous Slide'
<input type='button' value='<- Previous Slide'
onclick='send_event("slidecontroller_live_previous");' />
<input type='button' value='Next Slide ->'
<input type='button' value='Next Slide ->'
onclick='send_event("slidecontroller_live_next");' />
<br/>
<input type='button' value='<- Previous Item'
<input type='button' value='<- Previous Item'
onclick='send_event("servicemanager_previous_item");' />
<input type='button' value='Next Item ->'
<input type='button' value='Next Item ->'
onclick='send_event("servicemanager_next_item");' />
<br/>
<input type='button' value='Blank'
<input type='button' value='Blank'
onclick='send_event("slidecontroller_live_blank");' />
<input type='button' value='Unblank'
<input type='button' value='Unblank'
onclick='send_event("slidecontroller_live_unblank");' />
<br/>
<label>Alert text</label><input id='alert' type='text' />
<input type='button' value='Send'
onclick='send_event("alerts_text",
<input type='button' value='Send'
onclick='send_event("alerts_text",
document.getElementById("alert").value);' />
<hr>
<input type='button' value='Order of service'
<input type='button' value='Order of service'
onclick='send_event("servicemanager_list_request");'>
<div id='service'></div>
<hr>
<input type='button' value='Current item'
<input type='button' value='Current item'
onclick='send_event("slidecontroller_live_text_request");'>
<div id='currentitem'></div>
<hr>

19
openlp/plugins/remotes/html/jquery.js vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@ from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
class HttpServer(object):
"""
"""
Ability to control OpenLP via a webbrowser
e.g. http://localhost:4316/send/slidecontroller_live_next
http://localhost:4316/send/alerts_text?q=your%20alert%20text
@ -58,7 +58,7 @@ class HttpServer(object):
def start_tcp(self):
"""
Start the http server, use the port in the settings default to 4316
Listen out for slide and song changes so they can be broadcast to
Listen out for slide and song changes so they can be broadcast to
clients. Listen out for socket connections
"""
log.debug(u'Start TCP server')
@ -66,13 +66,13 @@ class HttpServer(object):
self.parent.settingsSection + u'/remote port',
QtCore.QVariant(4316)).toInt()[0]
self.server = QtNetwork.QTcpServer()
self.server.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any),
self.server.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any),
port)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slidecontroller_live_changed'),
QtCore.SIGNAL(u'slidecontroller_live_changed'),
self.slide_change)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slidecontroller_live_started'),
QtCore.SIGNAL(u'slidecontroller_live_started'),
self.item_change)
QtCore.QObject.connect(self.server,
QtCore.SIGNAL(u'newConnection()'), self.new_connection)
@ -91,7 +91,7 @@ class HttpServer(object):
"""
self.current_item = items[0].title
self.send_poll()
def send_poll(self):
"""
Tell the clients something has changed
@ -99,7 +99,7 @@ class HttpServer(object):
Receiver.send_message(u'remotes_poll_response',
{'slide': self.current_slide,
'item': self.current_item})
def new_connection(self):
"""
A new http connection has been made. Create a client object to handle
@ -109,7 +109,7 @@ class HttpServer(object):
socket = self.server.nextPendingConnection()
if socket:
self.connections.append(HttpConnection(self, socket))
def close_connection(self, connection):
"""
The connection has been closed. Clean up
@ -123,9 +123,9 @@ class HttpServer(object):
"""
log.debug(u'close http server')
self.server.close()
class HttpConnection(object):
"""
"""
A single connection, this handles communication between the server
and the client
"""
@ -133,7 +133,7 @@ class HttpConnection(object):
"""
Initialise the http connection. Listen out for socket signals
"""
log.debug(u'Initialise HttpConnection: %s' %
log.debug(u'Initialise HttpConnection: %s' %
socket.peerAddress().toString())
self.socket = socket
self.parent = parent
@ -175,7 +175,7 @@ class HttpConnection(object):
def serve_file(self, filename):
"""
Send a file to the socket. For now, just .html files
and must be top level inside the html folder.
and must be top level inside the html folder.
If subfolders requested return 404, easier for security for the present.
Ultimately for i18n, this could first look for xx/file.html before
@ -187,7 +187,7 @@ class HttpConnection(object):
if os.path.basename(filename) != filename:
return None
(fileroot, ext) = os.path.splitext(filename)
if ext != u'.html':
if not ext in [u'.html', u'.js', u'.css', u'.png']:
return None
path = os.path.join(self.parent.html_dir, filename)
try:
@ -199,7 +199,7 @@ class HttpConnection(object):
html = f.read()
f.close()
return html
def load_params(self, query):
"""
Decode the query string parameters sent from the browser
@ -208,8 +208,8 @@ class HttpConnection(object):
if not params:
return None
else:
return params['q']
return params['q']
def process_event(self, event, params):
"""
Send a signal to openlp to perform an action.
@ -217,9 +217,9 @@ class HttpConnection(object):
basic parameter checking, otherwise rogue clients could crash openlp
"""
if params:
Receiver.send_message(event, params)
else:
Receiver.send_message(event)
Receiver.send_message(event, params)
else:
Receiver.send_message(event)
return u'OK'
def process_request(self, event, params):
@ -227,8 +227,8 @@ class HttpConnection(object):
Client has requested data. Send the signal and parameters for openlp
to handle, then listen out for a corresponding _request signal
which will have the data to return.
For most event timeout after 10 seconds (i.e. incase the signal
recipient isn't listening)
For most event timeout after 10 seconds (i.e. incase the signal
recipient isn't listening)
remotes_poll_request is a special case, this is a ajax long poll which
is just waiting for slide change/song change activity. This can wait
longer (one minute)
@ -248,14 +248,14 @@ class HttpConnection(object):
else:
self.timer.start(10000)
if params:
Receiver.send_message(event, params)
else:
Receiver.send_message(event)
Receiver.send_message(event, params)
else:
Receiver.send_message(event)
return True
def process_response(self, data):
"""
The recipient of a _request signal has sent data. Convert this to
The recipient of a _request signal has sent data. Convert this to
json and return it to client
"""
if not self.socket:
@ -268,7 +268,7 @@ class HttpConnection(object):
def get_200_ok(self):
"""
Successful request. Send OK headers. Assume html for now.
Successful request. Send OK headers. Assume html for now.
"""
return u'HTTP/1.1 200 OK\r\n' + \
u'Content-Type: text/html; charset="utf-8"\r\n' + \
@ -284,11 +284,11 @@ class HttpConnection(object):
def get_408_timeout(self):
"""
A _request hasn't returned anything in the timeout period.
A _request hasn't returned anything in the timeout period.
Return timeout
"""
return u'HTTP/1.1 408 Request Timeout\r\n'
def timeout(self):
"""
Listener for timeout signal
@ -298,14 +298,14 @@ class HttpConnection(object):
html = self.get_408_timeout()
self.socket.write(html)
self.close()
def disconnected(self):
"""
The client has disconnected. Tidy up
"""
log.debug(u'socket disconnected')
self.close()
def close(self):
"""
The server has closed the connection. Tidy up