commit 75459135c4aa323c8605c04aa353783552e5d7bc
parent 68b7235df3af833c04a832e5c0e1d1e0fd7c8d0b
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date: Thu, 14 Apr 2011 10:26:55 +0200
Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable
Diffstat:
2 files changed, 60 insertions(+), 15 deletions(-)
diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php
@@ -1,7 +1,7 @@
<?php
require_once("ressources/strings.inc");
require_once("relations.php");
-require_once("pticlic.php");
+require_once("pticlic2.php");
session_start();
$state = 0;
@@ -203,11 +203,15 @@ else
</select>
</div>
<div id="wordLines">
- <div style="display:none">
- <div class="wordLine" id="templateWordLine">
- <label for="word"></label>
- <input id="word"/>
+ <div id="templates" style="display:none">
+ <div class="wordLine" class="wordLine">
+ <label for="word-"></label>
+ <input type="text" id="word-"/>
<span class="status">●</span>
+ <input type="checkbox" id="r1-"/><label class="r1" for="r1-">Blabla</label>
+ <input type="checkbox" id="r2-"/><label class="r2" for="r2-">Blabla</label>
+ <input type="checkbox" id="r3-"/><label class="r3" for="r3-">Blabla</label>
+ <input type="checkbox" id="r4-"/><label class="r4" for="r4-">Blabla</label>
</div>
</div>
</div>
diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js
@@ -1,5 +1,16 @@
+$.fn.changeId = function(append) {
+ this.find("[id]").each(function(i,e){
+ $(e).attr("id", $(e).attr("id") + append);
+ });
+ this.find('[for="word-"]').text(append);
+ this.find("[for]").each(function(i,e){
+ $(e).attr("for", $(e).attr("for") + append);
+ });
+ return this;
+};
+
$(function() {
- $.getJSON("server.php", {action:"5", user:"foo", passwd:"bar"}, function (data) {
+ $.getJSON("pticlic2.php", {action:"5", user:"foo", passwd:"bar"}, function (data) {
var numWord = 1;
var user = "foo";
var passwd = "bar";
@@ -12,32 +23,47 @@ $(function() {
var displayNWordLines = function (nb) {
for(var i=numWord; i<numWord+nb; i++){
- $("#templateWordLine")
+ $("#templates .wordLine")
.clone()
- .find("label").attr("for", "word"+i).text(i).end()
- .find("input").attr("id", "word"+i).end()
+ .changeId(i)
+// .find("label").attr("for", "word"+i).text(i).end()
+// .find("input").attr("id", "word"+i).end()
.appendTo("#wordLines");
(function (i) {
- $("#word"+i).focusout(checkWord);
+ $("#word-"+i).focusout(checkWord);
wordsOK[i] = false;
})(i);
}
numWord += nb;
+
+ displayRelations();
+ // truc.children("option:nth-child(2)");
+ // $(truc.children("option").get(2 /* ou 1 */))
};
+ var displayRelations = function() {
+ $(".r1").text(relations[$("#relation1").val()]);
+ $(".r2").text(relations[$("#relation2").val()]);
+ $(".r3").text(relations[0]);
+ $(".r4").text(relations[-1]);
+ }
+
var displayCentralWordAndRelations = function() {
$("#centralWord").focusout(checkWord);
$.each(relations, function(i, value) {
- $('<option/>').val(i).text(value).appendTo("#relations select");
+ if(i != 0 && i != -1)
+ $('<option/>').val(i).text(value).appendTo("#relations select");
});
$("#relation1, #relation2").change(function() {
if ($("#relation1").val() == $("#relation2").val())
displayError("Les relations doivent être différentes");
else
displayError("");
+
+ displayRelations();
});
};
@@ -69,11 +95,15 @@ $(function() {
var formOK = function() {
displayError("");
+
+ console.log(wordsOK);
if ($("#relation1").val() == $("#relation2").val())
displayError("Les deux relation doivent être différents");
else if ($("#centralWord").val() == "")
displayError("Le mot central doit être renseigné.");
+ else if (badWord())
+ displayError("Il existe des mots incorrects");
else if (nbWordOK() < nbWordMin)
displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides.");
};
@@ -81,12 +111,23 @@ $(function() {
var nbWordOK = function() {
var count = 0;
- for (word in wordsOK)
- if (word == true)
- count++;
+ for (word in wordsOK)
+ if (word == true)
+ count++;
- return count;
+ return count;
};
+
+ var badWord = function() {
+ for (word in wordsOK)
+ if (word == false)
+ return true;
+
+ return false;
+ }
+
+
+
var displayError = function(message) {
if (message != "")