From 9edc7af7d34133df2c772dd85064b230faa02327 Mon Sep 17 00:00:00 2001 From: Malibu Date: Thu, 26 Feb 2015 15:07:34 +0100 Subject: [PATCH] modified: SRC/app/Http/Controllers/ReferentController.php modified: SRC/app/Http/routes.php modified: SRC/public/js/ListeOeuvre.js modified: SRC/resources/views/referent.blade.php --- .../Http/Controllers/ReferentController.php | 19 +++++++++++++++++++ SRC/app/Http/routes.php | 1 + SRC/public/js/ListeOeuvre.js | 10 +++++++++- SRC/resources/views/referent.blade.php | 6 +++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SRC/app/Http/Controllers/ReferentController.php b/SRC/app/Http/Controllers/ReferentController.php index 082d19f..f5bff04 100755 --- a/SRC/app/Http/Controllers/ReferentController.php +++ b/SRC/app/Http/Controllers/ReferentController.php @@ -13,6 +13,7 @@ use App\Models\Technique; use App\Models\Oeuvre; use App\Models\Jeu; use Response; +use Session; class ReferentController extends Controller { @@ -95,6 +96,10 @@ class ReferentController extends Controller { public function showListeOeuvres($id) { + if (Session::has('listeoeuvre_current')) + Session::forget('listeoeuvre_current'); + + Session::put('listeoeuvre_current', $id); return Response::json(ListeOeuvre::find($id)->oeuvres->toArray()); } @@ -146,4 +151,18 @@ class ReferentController extends Controller { ; } + public function updateAssoGames() { + + $idListeOeuvre = Session::get('listeoeuvre_current', 'default'); + $res = Input::get('data', array()); + $ListeOeuvre = ListeOeuvre::find($idListeOeuvre); + + $table = []; + foreach ($res as $key => $value){ + if($value == 'true') + array_push($table, $key); + } + $ListeOeuvre->jeux()->sync($table); + } + } diff --git a/SRC/app/Http/routes.php b/SRC/app/Http/routes.php index a06e994..8b814ee 100644 --- a/SRC/app/Http/routes.php +++ b/SRC/app/Http/routes.php @@ -44,6 +44,7 @@ Route::group(['middleware' => 'auth'], function () Route::post('setListOeuvres', 'ReferentController@setListOeuvres'); Route::post('search', 'ReferentController@search'); Route::post('addItemsToList', 'ReferentController@addItemsToList'); + Route::post('updateAssoGames', 'ReferentController@updateAssoGames'); }); Route::group(['middleware' => 'admin'], function () diff --git a/SRC/public/js/ListeOeuvre.js b/SRC/public/js/ListeOeuvre.js index bd93805..a028425 100644 --- a/SRC/public/js/ListeOeuvre.js +++ b/SRC/public/js/ListeOeuvre.js @@ -131,6 +131,7 @@ $('#search_button, #previous, #next').click(function(event) { // Mettre à jour les jeux associés à la liste d'oeuvre $('.checkbox').click(function(event) { + // Recuperation des données necessaire au traitement var searchIDs = $("input#idGame").map(function(){ return $(this).val(); }).get(); @@ -144,7 +145,14 @@ $('.checkbox').click(function(event) { r[searchIDs[i]] = searchValues[i]; } - console.log(r); + dataSend = { _token : $('#_tokenRes').val(), data: r }; + $.post('updateAssoGames', dataSend, function() { + // Nada + }, "json" ) + + .fail(function() { + // Nada + }); }); diff --git a/SRC/resources/views/referent.blade.php b/SRC/resources/views/referent.blade.php index 29dc854..ca25ded 100755 --- a/SRC/resources/views/referent.blade.php +++ b/SRC/resources/views/referent.blade.php @@ -25,8 +25,12 @@ - @foreach ($listeoeuvres as $listeoeuvre) + @foreach ($listeoeuvres as $index => $listeoeuvre) + @if ($index == 0) + @else + + @endif