Correction des derniers bugs pour la création de partie.

This commit is contained in:
Yoann 2011-05-25 16:46:05 +02:00
parent 4b2757572a
commit 0945b12fae
2 changed files with 29 additions and 32 deletions

View File

@ -102,7 +102,7 @@ if(!isset($_SESSION['userId']))
</head> </head>
<body> <body>
<?php include("ressources/menu.inc"); ?> <?php include("ressources/menu.inc"); ?>
<div class="content creategame"> <form class="content creategame">
<h2>Création de parties</h2> <h2>Création de parties</h2>
<p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br /> <p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
<div id="errorDiv" class="message warning" style="display:none;"></div> <div id="errorDiv" class="message warning" style="display:none;"></div>
@ -159,9 +159,7 @@ if(!isset($_SESSION['userId']))
</table> </table>
</div> </div>
<div id="button"></div> <div id="button"></div>
</div> </form>
<div id="templates" style="display:none">
</div>
<?php include("ressources/footer.inc"); ?> <?php include("ressources/footer.inc"); ?>
</body> </body>
</html> </html>

View File

@ -42,14 +42,14 @@ $(function() {
var updateRelationLabels = function() { var updateRelationLabels = function() {
$('#relations option').each(function(i,e) { $('#relations option').each(function(i,e) {
$(e).text(applyFormat($(e).data("format"), $('#centralWord').val() || 'mot central', '…')); $(e).text(applyFormat($(e).data("format"), $('#centralWord').val().trim() || 'mot central', '…'));
}); });
$('.relationLabel').each(function(i,e) { $('.relationLabel').each(function(i,e) {
$(e).text(applyFormat( $(e).text(applyFormat(
$(e).data("format"), $(e).data("format"),
$('#centralWord').val() || 'mot central', $('#centralWord').val().trim() || 'mot central',
$(e).closest('.wordLine').find('.word').val() || '…')); $(e).closest('.wordLine').find('.word').val().trim() || '…'));
}); });
} }
@ -92,26 +92,22 @@ $(function() {
$("#button").html('<input type="button" id="addLine" name="addLine" value="Ajouter" />'); $("#button").html('<input type="button" id="addLine" name="addLine" value="Ajouter" />');
$("#addLine").click(function(){ displayNWordLines(1); }); $("#addLine").click(function(){ displayNWordLines(1); });
$("#button").append('<input type="button" id="validate" name="validate" value="Valider" />'); $("#button").append('<input type="submit" id="validate" name="validate" value="Valider" />');
$("#validate").click(function(){ formOK(); }); $("form").submit(formOK);
}; };
var checkWord = function () { var checkWord = function () {
updateRelationLabels(); updateRelationLabels();
var input = $(this); var input = $(this);
var word = input.val(); var word = input.val().trim();
input.closest(".wordLine, #center").removeClass("valid invalid"); input.closest(".wordLine, #center").removeClass("valid invalid");
if (word != "") { if (word != "") {
$.ajax({ $.getJSON("server.php",{action:4,word:word}, function(msg){
type: "GET", input.closest(".wordLine, #center").addClass(msg ? "valid" : "invalid");
url: "server.php?", wordsOK[input.attr("id")] = !(msg == false);
data: "action=4&word="+word, //+"&user="+user+"&passwd="+passwd, });
success: function(msg){
input.closest(".wordLine, #center").addClass(msg == false ? "invalid" : "valid");
wordsOK[input.attr("id")] = !(msg == false);
}});
} }
}; };
@ -120,7 +116,7 @@ $(function() {
if ($("#relation1").val() == $("#relation2").val()) if ($("#relation1").val() == $("#relation2").val())
displayError("Les deux relation doivent être différents"); displayError("Les deux relation doivent être différents");
else if ($("#centralWord").val() == "") else if ($("#centralWord").val().trim() == "")
displayError("Le mot central doit être renseigné."); displayError("Le mot central doit être renseigné.");
else if (badWord()) else if (badWord())
displayError("Il existe des mots incorrects"); displayError("Il existe des mots incorrects");
@ -146,7 +142,7 @@ $(function() {
var badWord = function() { var badWord = function() {
for (word in wordsOK) for (word in wordsOK)
if ($("#"+word).val() != "" && wordsOK[word] == false) if ($("#"+word).val().trim() != "" && wordsOK[word] == false)
return true; return true;
return false; return false;
@ -167,13 +163,13 @@ $(function() {
var exit; var exit;
var cloud = ""; var cloud = "";
exit = {center:$("#centralWord").val(), exit = {center:$("#centralWord").val().trim(),
relations:[$("#relation1").val(),$("#relation2").val(),0,-1], relations:[$("#relation1").val(),$("#relation2").val(),0,-1],
cloud:[]}; cloud:[]};
for(i=1;i<numWord;i++) { for(i=1;i<numWord;i++) {
exit.cloud.push({ exit.cloud.push({
name:$("#word-"+i).val(), name:$("#word-"+i).val().trim(),
relations:[ relations:[
$("#r1-"+i).is(":checked") ? "1":"0", $("#r1-"+i).is(":checked") ? "1":"0",
$("#r2-"+i).is(":checked") ? "1":"0", $("#r2-"+i).is(":checked") ? "1":"0",
@ -183,9 +179,9 @@ $(function() {
}); });
} }
$.get("server.php",{action:"6",game:exit},function (data) { $.getJSON("server.php",{action:6,game:exit},function (data) {
//$(".word").closest(".wordLine, #center").removeClass("valid invalid"); //$(".word").closest(".wordLine, #center").removeClass("valid invalid");
if(data == true) { if(data === true) {
displaySuccess("La partie à bien été enregistrée"); displaySuccess("La partie à bien été enregistrée");
$('#newCreationLink').show(); $('#newCreationLink').show();
$('#center').hide(); $('#center').hide();
@ -193,22 +189,25 @@ $(function() {
$('#wordLines').hide(); $('#wordLines').hide();
$('#button').hide(); $('#button').hide();
} }
else if (data == false) { else if (data === false) {
$('input').removeAttr('disabled'); $('input').removeAttr('disabled');
displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides."); displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides.");
} }
else if (data != true) { else if (data.length) {
$('input').removeAttr('disabled'); $('input').removeAttr('disabled');
var that = $(this);
$.each(data,function(i,bad) {
$.each(data,function(i,e) {
$('.word') $('.word')
.filter(function() { return that.val() == e; }) .removeClass("invalid")
.addClass("valid")
.filter(function(i,w) { return $(w).val().trim() == bad; })
.closest(".wordLine, #center") .closest(".wordLine, #center")
.removeClass("valid invalid") .removeClass("valid")
.addClass("invalid"); .addClass("invalid");
}); });
} else {
$('input').removeAttr('disabled');
displayError("Une erreur inconnue est survenue. 42.");
} }
}); });