-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
executable file
·169 lines (141 loc) · 4.86 KB
/
client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="client.css">
<head>
<title>WebSocket</title>
</head>
<body onload="init()">
<div id="global">
<h2>WebSocket v2.00</h2>
<div id="log"></div>
<div id="corp">
<br><br>
•Quelle competence choisissez-vous ?
<br><br>
<select id="metier">
<option>Carleur</option>
<option>Cuisinier</option>
<option>Electricien</option>
<option>Jardinier</option>
<option>Menage</option>
<option>Plombier</option>
<option>Promenade</option>
</select>
<br><br>
•Quelle ville voulez-vous ?
<br><br>
<input type="text" id="ville" size="15">
<br><br>
•Quel creneau choisissez-vous ?
<br><br>
<div id="mydiv">
<select id="myselect">
<option>matin</option>
<option>aprem</option>
<option>journee</option>
</select>
<input id="date" type="date">
<br><br>
</div>
<button onclick="clonev2()">Plus de crenaux ?</button>
<br><br>
•Choisissez un type de requete :
<br><br>
<select id="requete">
<option>Rechercher</option>
<option>Deposer</option>
</select>
<br><br>
<center>
<button type="button" id="sumbut" onclick="sendreq()">Soumettre</button>
<!--<input type="submit" value="Valider" onblur="senddmd()" />-->
<button id="quit" onclick="quit()">Quitter</button>
</center>
</div>
</div>
<script>
var socket;
var i=0;
var j=100;
//var idgene=100; //version happenchild
//initialisation co
function init(){
var host = "ws://localhost:12345";
try{
socket = new WebSocket(host);
log('WebSocket - status '+socket.readyState);
socket.onopen = function(msg){ log("Welcome - status "+this.readyState); };
socket.onmessage = function(msg){ log("Received: "+msg.data); };
socket.onclose = function(msg){ log("Disconnected - status "+this.readyState); };
}
catch(ex){ log(ex); }
}
function clonev2(){
var newSelect = document.createElement("select");
newSelect.id=i;
var newDate = document.createElement("input");
newDate.id=j;
newDate.type="date";
var newOption1 = document.createElement("option");
var newOption2 = document.createElement("option");
var newOption3 = document.createElement("option");
var textnode1 = document.createTextNode("matin");
var textnode2 = document.createTextNode("aprem");
var textnode3 = document.createTextNode("journee");
newOption1.appendChild(textnode1);
newOption2.appendChild(textnode2);
newOption3.appendChild(textnode3);
var div = document.getElementById("mydiv");
div.insertBefore(newDate, div.childNodes[0]);
div.insertBefore(newSelect, div.childNodes[0]);
var select = document.getElementById(i);
select.insertBefore(newOption1, select.childNodes[0]);
select.insertBefore(newOption2, select.childNodes[0]);
select.insertBefore(newOption3, select.childNodes[0]);
i=i+1;
j=j+1;
}
//sendreq
function sendreq(){
var msg;
var x = document.getElementById("metier").selectedIndex;
var y = document.getElementById("metier").options;
var a = document.getElementById("myselect").selectedIndex;
var b = document.getElementById("myselect").options;
var Rdate = document.getElementById("date").value;
var d = document.getElementById("requete").selectedIndex;
var e = document.getElementById("requete").options;
var Rvil = document.getElementById("ville").value;
var chaine ="";
for (var t = 0; t < i; t++) {
var titi = document.getElementById(t).selectedIndex;
var toto = document.getElementById(t).options;
var date = document.getElementById(t+100).value;
chaine = chaine + "," + toto[titi].text + "." + date;
}
if (e[d].index==0){
msg = "DMD " + b[a].text + "." + Rdate + chaine + " " + y[x].text + " " + Rvil;
if(!msg){ alert("Le message n'est pas conforme [vide]."); return; }
try{ socket.send(msg); log('Votre requête: '+msg); } catch(ex){ log(ex); }
//try{log('Votre requete: ' + msg);} catch(ex){ log(ex); }
}
else {
msg = "CPT " + b[a].text + "." + Rdate + chaine + " " + y[x].text + " " + Rvil;
if(!msg){ alert("Le message n'est pas conforme [vide]."); return; }
try{ socket.send(msg); log('Votre requête: '+msg); } catch(ex){ log(ex); }
//try{log('Votre requete: ' + msg);} catch(ex){ log(ex); }
}
}
//quitter
function quit(){
log("Goodbye!");
socket.close();
socket=null;
}
// Utilities
function $(id){ return document.getElementById(id); }
function log(msg){ $("log").innerHTML+="<br>"+msg; }
function onkey(event){ if(event.keyCode==13){ send(); } }
</script>
</body>
</html>