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 170 171 172 173 174 175 176 177 178
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="web/favicon.ico" />
<title>Bienvenue</title>
<script src="web/js/jquery.js" type="text/javascript"></script>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="web/css/main.css" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
var localUrl = window.location.href;
localUrl = localUrl.replace('web/', '');
var webServiceUrl = window.location.href + 'api.php';
console.log(webServiceUrl);
$('.clean').click(function() {
Clear();
AddText('system ', 'cleaning...');
$('.userMessage').hide();
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
requestType: 'forget'
},
success: function(response) {
AddText('system ', 'Ok!');
$('.userMessage').show();
},
error: function(request, status, error) {
Clear();
alert('error');
$('.userMessage').show();
}
});
});
$('#fMessage').submit(function() {
// get user input
var userInput = $('input[name="userInput"]').val();
// basic check
if (userInput == '')
return false;
//
// clear
$('input[name="userInput"]').val('');
// hide button
$(this).hide();
// show user input
AddText('Vous ', userInput);
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
userInput: userInput,
requestType: 'talk'
},
success: function(response) {
console.log(webServiceUrl);
console.log(userInput);
AddText('Tux ', response.message);
$('#fMessage').show();
$('input[name="userInput"]').focus();
},
error: function(request, status, error) {
console.log(error);
alert('error');
$('#fMessage').show();
}
});
return false;
});
function Clear() {
$('.chatBox').html('');
}
function AddText(user, message) {
console.log(user);
console.log(message);
var div = $('<div>');
var name = $('<label>').addClass('name');
var text = $('<span>').addClass('message');
name.text(user + ':');
text.text('\t' + message);
div.append(name);
div.append(text);
$('.chatBox').append(div);
$('.chatBox').scrollTop($(".chatBox").scrollTop() + 100);
}
});
</script>
</head>
<body id="body">
<div class="container-fluid">
<div class="row">
<div class="col-4 img-fluid text-center">
<img src="web/img/tux.png">
</div>
<div id="box1" class="col-4">
<p class="h2 p-3 mb-2 bg-info text-white">Tux The Bot</p>
<br>
<div class="chatBox">
Bienvenue, en quoi puis-je vous aider ?
</div>
</div>
<div class="col-4">
</div>
</div>
<div class="row">
<div class="col-4">
</div>
<div id="box2" class="col-4 userMessage">
<form id="fMessage">
<div class="form">
<div class="rep">
<input type="text" name="userInput" id="userInput" />
</div>
<div class="but">
<input id="clean" type="button" class="btn btn-secondary" value="Effacer" />
<input id="send" type="submit" value="Envoyer" class="btn btn-primary" />
</div>
</div>
</form>
</div>
<div class="col-4">
</div>
</div>
</div>
</body>
</html> |
Partager