La connexion marche à merveille :)

This commit is contained in:
Georges Dupéron 2011-05-20 11:51:08 +02:00
parent 6a4d689226
commit d0e9b2f56a
4 changed files with 39 additions and 32 deletions

View File

@ -13,6 +13,7 @@
<script src="ressources/pticlic.js"></script> <script src="ressources/pticlic.js"></script>
<script src="server.php?callback=prefs.loadPrefs&action=7"></script> <script src="server.php?callback=prefs.loadPrefs&action=7"></script>
<style> <style>
img { border: none; }
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; } body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; }
.screen { width:100%; height:100%; position:absolute; } .screen { width:100%; height:100%; position:absolute; }
.highlight { display:none; width:100%; height:100%; border-width:medium; border-style:solid; border-radius:2em; position:absolute; } .highlight { display:none; width:100%; height:100%; border-width:medium; border-style:solid; border-radius:2em; position:absolute; }
@ -151,12 +152,15 @@
</div> </div>
<div id="connection" class="screen"> <div id="connection" class="screen">
<form action="#" method="GET" style="width:100%; height:100%;" class="fitFontGroup"> <form action="#" method="GET" style="width:100%; height:100%;" class="fitFontGroup">
<div class="formElement subFitFont" style="right: 55%; top: 25%;"><label id="user-label" for="user">Login : </label></div> <div class="formElement subFitFont" style="right: 55%; top: 25%; text-align:right;"><label id="user-label" for="user">Login : </label></div>
<div class="formElement subFitFont" style="left: 55%; top: 25%;"><input type="text" name="user" id="user" class="setFont" /></div> <div class="formElement subFitFont" style="left: 55%; top: 25%; text-align:left;"><input type="text" name="user" id="user" class="setFont" /></div>
<div class="formElement subFitFont" style="right: 55%; top: 50%;"><label id="passwd-label" for="passwd">Mot de passe : </label></div> <div class="formElement subFitFont" style="right: 55%; top: 50%; text-align:right;"><label id="passwd-label" for="passwd">Mot de passe : </label></div>
<div class="formElement subFitFont" style="left: 55%; top: 50%;"><input type="password" name="passwd" id="passwd" class="setFont" /></div> <div class="formElement subFitFont" style="left: 55%; top: 50%; text-align:left;"><input type="password" name="passwd" id="passwd" class="setFont" /></div>
<div class="formElement subFitFont" style="left: 25%; width:50%; top: 75%;"> <div class="formElement subFitFont" style="right: 55%; top: 75%; text-align:right;">
<input type="submit" name="connect" id="connect" value="Se connecter" class="center setFont" /> <input type="button" value="Retour" class="setFont goFrontpage" />
</div>
<div class="formElement subFitFont" style="left: 55%; top: 75%; text-align:left;">
<input type="submit" name="connect" id="connect" value="Se connecter" class="setFont" />
</div> </div>
</form> </form>
</div> </div>

View File

@ -188,9 +188,9 @@ function encodeHash(data) {
} }
function Cache(resolver) { function Cache(resolver) {
var cache = []; var cache = {};
this.get = function(k) { this.get = function(k) {
return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd); }).fail(cache[k] = false).promise(); return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd); }).fail(function() { cache[k] = false; }).promise();
}; };
} }

View File

@ -120,6 +120,11 @@ init(function() {
}); });
// ==== Écran d'accueil
init(function() {
$('.goFrontpage').click(function() { location.hash = "#frontpage"; });
});
// ==== Écran connexion // ==== Écran connexion
runstate.pendingGetPrefs = function() { runstate.pendingGetPrefs = function() {
console.log('Should execute pendingGetPrefs'); console.log('Should execute pendingGetPrefs');
@ -134,8 +139,8 @@ init(function() {
} else { } else {
runstate.pendingGetPrefs(); runstate.pendingGetPrefs();
} }
if (state.screen == game) { if (state.screen == 'game') {
$('#game').trigger('pre-enter'); $('#game').trigger('goto');
} else { } else {
location.hash = "#frontpage"; location.hash = "#frontpage";
} }
@ -150,42 +155,37 @@ init(function() {
// ==== Écran game // ==== Écran game
$.ajaj = function(url, data, callback) { $.ajaj = function(url, data, callback) {
var user = '' + UI().getPreference("user"); var user = runstate.user; /* '' + UI().getPreference("user"); */
var passwd = '' + UI().getPreference("passwd"); var passwd = runstate.passwd; /* '' + UI().getPreference("passwd"); */
if (user != '' && passwd != '') { if (user && passwd) {
if (!data.user) data.user = user; if (!data.user) data.user = user;
if (!data.passwd) data.passwd = passwd; if (!data.passwd) data.passwd = passwd;
} }
$.getJSON(url, data, callback); console.log('ajaj', data, user, passwd);
return $.getJSON(url, data, callback);
}; };
function getGame(k, dfd, retry) { function getGame(k, dfd) {
$.ajaj("getGame.php?callback=?", {pgid:k}, function(data) { $.ajaj("getGame.php?callback=?", {pgid:k}, function(data) {
if (data.error == 10) { if (data.isError) {
dfd.reject(data); dfd.reject(data);
if (state.screen == 'game' && state.pgid == k) {
if (retry) {
$('#connection.screen').trigger('goto');
} else {
location.hash = "#frontpage";
message("Erreur", "Vous n'êtes pas connecté.");
}
}
} else if (data.isError) {
dfd.reject(data);
location.hash = "#frontpage";
message("Erreur", data.msg); message("Erreur", data.msg);
if ((data.error == 10 || data.error == 3) && state.screen == 'game' && state.pgid == k) {
$.screen('connection').trigger('goto');
} else {
$.screen('frontpage').trigger('goto');
}
} else { } else {
dfd.resolve(data); dfd.resolve(data);
} }
}).fail(function() { }).fail(function(data) {
dfd.reject(data); dfd.reject(data);
location.hash = "#frontpage"; $("#frontpage").trigger('goto');
message("Erreur", "Une erreur est survenue, veuillez nous en excuser."); message("Erreur", "Une erreur est survenue, veuillez nous en excuser.");
}); });
} }
runstate.gameCache = new Cache(function(k, dfd) { getGame(k, dfd, true); }); runstate.gameCache = new Cache(function(k, dfd) { getGame(k, dfd); });
init(function() { init(function() {
var game = $('#game.screen'); var game = $('#game.screen');

View File

@ -132,10 +132,13 @@ function server() {
ob_end_flush(); ob_end_flush();
} catch (Exception $e) { } catch (Exception $e) {
ob_end_clean(); ob_end_clean();
$code = $e->getCode();
$msg = $e->getMessage();
if ($code != 10 && $code != 3) $msg = "Erreur ".$code." : " . $msg;
echo json_encode( echo json_encode(
Array( Array(
"error" => $e->getCode(), "error" => $code,
"msg" => "Erreur ".$e->getCode()." : ".$e->getMessage(), "msg" => $msg,
"isError" => true "isError" => true
) )
); );