(function($) { $(document).ready(function() { var menuList = []; var scPartieId = 0; var menuMode = ''; function refreshScreen(data) { if(data['mode'] != menuMode) { menuMode = data['mode']; if(menuMode == 'p') { $('#creerTitre').html('Karuba - Choisir une partie'); $('#creerTitre').removeClass('creer-titre-joueur'); $('#creerTitre').addClass('creer-titre-partie'); scPartieId = 0; } if(menuMode == 'j') { $('#creerTitre').html('
<<
Karuba - Partie : ' + data['nom'] + ' - Choisir un joueur'); $('#creerTitre').removeClass('creer-titre-partie'); $('#creerTitre').addClass('creer-titre-joueur'); } $('#creerListeTab').empty(); menuList = []; } // Parties/Joueurs ajoutes ou modifies ? for(var key in data['liste']) { var val = data['liste'][key]; if( menuList[key] ) { if( menuList[key] != val ) $('#creerListeItem' + key + ' .creer-liste-nom').html( val ); } else { var tr = $('' + val + '
Entrer
Supprimer
'); $('#creerListeTab').prepend(tr); tr.hide().fadeIn(); menuList[key] = val; } } // Parties/Joueurs supprimes ? for(var key in menuList) { if( !data['liste'][key] ) { $('#creerListeItem' + key).fadeOut(); menuList[key] = false; } } } function refresh() { $.get('backend/creer.php?p=' + scPartieId) .done(function(data, text, jqxhr) { refreshScreen( JSON.parse(jqxhr.responseText) ); }) .fail(function(jqxhr){ // alert(jqxhr.responseText); }) .always(function(){ refreshTimer = setTimeout(refresh, 1000); }); } refresh(); var refreshTimer; function creerSwitchTo(id) { if(scPartieId > 0) window.location.href = 'index.php?j=' + id; else { scPartieId = id; clearTimeout(refreshTimer); refresh(); } } $('#creerTitre').on('click', '.creer-titre-retour', function(e) { scPartieId = 0; creerSwitchTo(0); }); $('#creerListeTab').on('click', '.creer-liste-btn-entrer', function(e) { e.preventDefault(); var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length); creerSwitchTo(id); }); $('#creerListeTab').on('click', '.creer-liste-btn-suppr', function(e) { e.preventDefault(); var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length); // $(this).parents('td').empty(); $(this).parents('tr').fadeOut(); menuList[id] = false; $.get('backend/creer.php?p=' + scPartieId + '&suppr=' + id) .done(function(data, text, jqxhr) { }) .fail(function(jqxhr){ // alert(jqxhr.responseText); }) .always(function(){ }); }); $('#creerForm').on('submit', function(e) { e.preventDefault(); if($('#creerForm .creer-form-input').val().length < 2) return; var $form = $(this); $form.hide(); $.post('backend/creer.php?p=' + scPartieId, $form.serializeArray()) .done(function(data, text, jqxhr) { creerSwitchTo( jqxhr.responseText ); $('#creerForm .creer-form-input').val(''); }) .fail(function(jqxhr){ // alert(jqxhr.responseText); }) .always(function(){ $form.show(); }); }); }); })(jQuery);