blob: c13b92fafe2597774c7b9650c9a44a62e8c496da [file] [log] [blame]
Matteo Scandoloe3ed0162016-12-01 10:09:12 -08001<!doctype html>
2<html>
3 <head>
4 <title>Socket.IO chat</title>
Matteo Scandolof05d8a62016-12-06 13:36:49 -08005 <script src="http://localhost:4000/socket.io/socket.io.js"></script>
Matteo Scandoloe3ed0162016-12-01 10:09:12 -08006 <script
7 src="https://code.jquery.com/jquery-1.12.4.min.js"
8 integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
9 crossorigin="anonymous"></script>
10 <script src="https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js"></script>
11
12 <style>
13 body {
14 max-width: 100%;
15 }
16 </style>
Matteo Scandolof05d8a62016-12-06 13:36:49 -080017 <script>
18 /* global io $ alert*/
19 function enableSocket(auth) {
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080020
Matteo Scandolof05d8a62016-12-06 13:36:49 -080021 auth.user = JSON.parse(auth.user);
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080022
Matteo Scandolof05d8a62016-12-06 13:36:49 -080023 var socket = io.connect('http://localhost:4000', {
24 query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id
25 });
26 socket.on('event', function(data) {
27 var p = $('body').append('<p></p>');
28 p.append('<b>' + data.model + '</b><br/>');
29 p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>');
30 p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>');
31 console.log(data.object);
32 $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success');
33 });
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080034 }
Matteo Scandolof05d8a62016-12-06 13:36:49 -080035
36 function login() {
37 var username = $('#username').val();
38 var password = $('#password').val();
39
40 $.get('http://localhost:4000/api/utility/login?username='+username+'&password='+password,
41 function(res) {
42 enableSocket(res);
43 $('#login').hide();
44 }
45 )
46 .fail(function(e) {
47 alert( 'error' );
48 console.log(e);
49 });
50 }
51 </script>
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080052 </head>
53 <body>
54 <form onsubmit="login()" id="login">
55 <input type="text" id="username">
56 <input type="password" id="password">
57 <input type="button" value="Login" onclick="login()">
58 </form>
59 </body>
60</html>