commit 63212ad368e2d0cffb6be823b6ab7ac07b0654d9
parent 5f0d0ef758db97db803cf07cd6098acff46eca7c
Author: Yoann <yoann.b87@voila.fr>
Date: Thu, 31 Mar 2011 11:28:31 +0200
Continuation de la page de création de partie.
la vérification et la signalisation de l'existance des mots est au
point.
Diffstat:
4 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php
@@ -166,15 +166,16 @@ else
<script type="text/javascript" src="ressources/jquery-1.5.1.min.js" /></script>
<script type="text/javascript" src="ressources/createGame.js" /></script>
<style type="text/css">
-
+ #wordLines input{
+ border : 2px solid grey;
+ }
</style>
</head>
<body>
<?php include("ressources/menu.inc"); ?>
<div class="content creategame">
<h2>Création de parties</h2>
- <label for="centralWord"> Le mot central : </label>
- <input type="text" id="centralWord" name="centralWord" />
+ <div id="center">Mot central</div>
<div id="wordLines"></div>
<input type="button" id="addLine" value="Ajouter un ligne" />
diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php
@@ -666,4 +666,10 @@ function getNodeEid($node) {
return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';");
}
+
+function wordExist($node) {
+ $db = getDB();
+
+ return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';") ? true : false;
+}
?>
diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js
@@ -4,13 +4,54 @@ $(function () {
var displayNWordLines = function (nb) {
var wLines = "";
- for(var i=0; i<nb;i++){
- wLines += '<div><label for="word'+numWord+'">'+numWord+' </label><input id="word'+numWord+'" /></div>';
- numWord++;
+ for(var i=numWord; i<numWord+nb; i++){
+ wLines += '<div><label for="word'+i+'">'+i+' </label><input id="word'+i+'" /></div>';
}
-
+
$("#wordLines").html(wLines);
+
+ for(var i=numWord; i<numWord+nb; i++){
+ function f(id) {
+ $("#word"+id).focusout(function () {
+ var input = "word"+id;
+
+ checkWord(input)});
+ };
+
+ f(i);
+ }
+
+ numWord += nb;
+ }
+
+ var displayCentralWord = function () {
+ $("#center").html('<label for="centralWord"> Le mot central : </label><input type="text" id="centralWord" name="centralWord" />');
+ $("#centralWord").focusout(function () {
+ var input = "centralWord";
+
+ checkWord(input)
+ }
+ );
}
+
+ var checkWord = function (inputId) {
+ var input = "#"+inputId;
+ var word = $(input).val();
+
+ if(word == "")
+ $(input).css("background-color", "white");
+ else {
+ $.ajax({type: "GET", url: "server.php?",
+ data: "action=4&word="+word+"&user=foo&passwd=bar",
+ success: function(msg){
+ if(msg == "false")
+ $(input).css("background-color", "orange");
+ else
+ $(input).css("background-color", "#55FF55");
+ }});
+ }
+ }
+ displayCentralWord();
displayNWordLines(10);
});
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
@@ -57,13 +57,15 @@ function main()
}
createGame(intval($_GET['nb']), $_GET['mode']);
echo '{"success":1}';
- } else if($action == 0) { // "Get partie"
+ }
+ else if($action == 0) { // "Get partie"
// Requête POST : http://serveur/server.php?action=0&nb=2&mode=normal&user=foo&passwd=bar
if(!isset($_GET['nb']) || !isset($_GET['mode'])) {
throw new Exception("La requête est incomplète", 2);
}
getGame($user, intval($_GET['nb']), $_GET['mode']);
- } else if($action == 1) { // "Set partie"
+ }
+ else if($action == 1) { // "Set partie"
// Requête POST : http://serveur/server.php?action=1&mode=normal&user=foo&passwd=bar&gid=1234&pgid=12357&0=0&1=-1&2=22&3=13&9=-1
if (!isset($_GET['pgid']) || !isset($_GET['gid'])) {
throw new Exception("La requête est incomplète", 2);
@@ -71,7 +73,17 @@ function main()
// TODO : il faudrait filtrer les paramètres qui correspondent à une réponse
// au lieu d'envoyer $_GET en entier, mais on ne connaît pas leur nom à l'avance.
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET);
- } else {
+ }
+ else if($action == 4) { // CheckWord
+ if (!isset($_GET['word']))
+ throw new Exception("La requête est incomplète", 2);
+
+ if(wordExist($_GET['word']))
+ echo 'true';
+ else
+ echo 'false';
+ }
+ else {
throw new Exception("Commande inconnue", 2);
}
}