blob: 191dbf2985d06ba315736870044afc0c737e7107 [file] [log] [blame]
Matteo Scandolobd13aab2017-08-08 13:05:24 -07001
2<!--
3Copyright 2017-present Open Networking Foundation
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16-->
17
18
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080019<!doctype html>
20<html>
21 <head>
22 <title>Socket.IO chat</title>
Matteo Scandolof05d8a62016-12-06 13:36:49 -080023 <script src="http://localhost:4000/socket.io/socket.io.js"></script>
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080024 <script
25 src="https://code.jquery.com/jquery-1.12.4.min.js"
26 integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
27 crossorigin="anonymous"></script>
28 <script src="https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js"></script>
29
30 <style>
31 body {
32 max-width: 100%;
33 }
34 </style>
Matteo Scandolof05d8a62016-12-06 13:36:49 -080035 <script>
36 /* global io $ alert*/
37 function enableSocket(auth) {
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080038
Matteo Scandolof05d8a62016-12-06 13:36:49 -080039 auth.user = JSON.parse(auth.user);
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080040
Matteo Scandolof05d8a62016-12-06 13:36:49 -080041 var socket = io.connect('http://localhost:4000', {
42 query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id
43 });
44 socket.on('event', function(data) {
45 var p = $('body').append('<p></p>');
46 p.append('<b>' + data.model + '</b><br/>');
47 p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>');
48 p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>');
49 console.log(data.object);
50 $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success');
51 });
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080052 }
Matteo Scandolof05d8a62016-12-06 13:36:49 -080053
54 function login() {
55 var username = $('#username').val();
56 var password = $('#password').val();
57
58 $.get('http://localhost:4000/api/utility/login?username='+username+'&password='+password,
59 function(res) {
60 enableSocket(res);
61 $('#login').hide();
62 }
63 )
64 .fail(function(e) {
65 alert( 'error' );
66 console.log(e);
67 });
68 }
69 </script>
Matteo Scandoloe3ed0162016-12-01 10:09:12 -080070 </head>
71 <body>
72 <form onsubmit="login()" id="login">
73 <input type="text" id="username">
74 <input type="password" id="password">
75 <input type="button" value="Login" onclick="login()">
76 </form>
77 </body>
78</html>