From 8a0f8a5b3cc771d91b20b0af31064b2a54f89bed Mon Sep 17 00:00:00 2001 From: Malibu Date: Mon, 23 Feb 2015 19:35:01 +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 | 6 +-- SRC/app/Http/routes.php | 2 +- SRC/public/js/ListeOeuvre.js | 48 +++++++++++++++---- SRC/resources/views/referent.blade.php | 9 +++- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/SRC/app/Http/Controllers/ReferentController.php b/SRC/app/Http/Controllers/ReferentController.php index bb7ee5e..acc82b3 100755 --- a/SRC/app/Http/Controllers/ReferentController.php +++ b/SRC/app/Http/Controllers/ReferentController.php @@ -12,6 +12,7 @@ use App\Models\Matiere; use App\Models\Technique; use App\Models\Oeuvre; use Response; +use Illuminate\Pagination\Paginator as Paginator; class ReferentController extends Controller { @@ -44,9 +45,6 @@ class ReferentController extends Controller { $dataSearch['matiere'] = Matiere::orderBy('nom')->get(); $dataSearch['technique'] = Technique::orderBy('nom')->get(); - //$ListeOeuvre = ListeOeuvre::find(2); - //$ListeOeuvre->oeuvres()->attach([22, 23, 24, 25, 26]); - $listeoeuvres = ListeOeuvre::currentUser()->get(); return view('referent', ['nameRoute' => 'Référent', 'me' => $me, 'listeoeuvres' => $listeoeuvres, 'data' => $dataSearch]); } @@ -137,7 +135,7 @@ class ReferentController extends Controller { ->matiereFilter($matieres) ->debutFilter($debut) ->finFilter($fin) - ->get(); + ->paginate(15); return Response::json($res->toArray()); } diff --git a/SRC/app/Http/routes.php b/SRC/app/Http/routes.php index 0a5d503..6927aa9 100644 --- a/SRC/app/Http/routes.php +++ b/SRC/app/Http/routes.php @@ -40,7 +40,7 @@ Route::group(['middleware' => 'auth'], function () Route::post('addListeOeuvre', 'ReferentController@addListeOeuvre'); Route::get('showListOeuvres/{id}', 'ReferentController@showListeOeuvres'); Route::post('setListOeuvres', 'ReferentController@setListOeuvres'); - Route::post('search', 'ReferentController@search'); + Route::post('search/', 'ReferentController@search'); }); Route::group(['middleware' => 'admin'], function () diff --git a/SRC/public/js/ListeOeuvre.js b/SRC/public/js/ListeOeuvre.js index 011dfd1..43accb5 100644 --- a/SRC/public/js/ListeOeuvre.js +++ b/SRC/public/js/ListeOeuvre.js @@ -57,9 +57,22 @@ $('#enregistrer').click(function() { // Afficher résultat de recherche d'oeuvre -$('#search_button').click(function() { +$('#search_button, #previous, #next').click(function(event) { + + event.preventDefault(); + + if (this.id == $('#next').attr('id')) { + str = $("#next").attr('href'); + console.log(/([0-9]+)/.exec(str)); + url = "/search?page="+/([0-9]+)/.exec(str)[0]; + }else if (this.id == $('#previous').attr('id')) { + str = $("#previous").attr('href'); + url = "/search?page="+/([0-9]+)/.exec(str)[0]; + }else { + url = "/search"; + } + $('#oeuvreRes').empty(); - url = "/search"; dataSend = { _token : $('#_tokenRes').val(), auteur: $('#auteur').val(), @@ -74,14 +87,29 @@ $('#search_button').click(function() { dataSend, function( data ) { console.log(data); - if (data.length == 0 ) - $("#oeuvreRes").append("Aucune Oeuvre Trouvé.."); - data.forEach( function(el) { - $("#oeuvreRes").append('
' - +'' - +'' - +'
'); - }) + if (data.length == 0 ) + $("#oeuvreRes").append("Aucune Oeuvre Trouvé.."); + data.data.forEach( function(el) { + $("#oeuvreRes").append('
' + +'' + +'' + +'
'); + }); + + if(data.prev_page_url == null) { + $("#previous").parent().addClass('disabled'); + }else { + $("#previous").attr('href', data.prev_page_url); + $("#previous").parent().removeClass('disabled'); + } + + if(data.next_page_url == null) { + $("#next").parent().addClass('disabled'); + }else { + $("#next").attr('href', data.next_page_url); + $("#next").parent().removeClass('disabled'); + } + }, "json" ) .fail(function() { diff --git a/SRC/resources/views/referent.blade.php b/SRC/resources/views/referent.blade.php index 9e42075..32af813 100755 --- a/SRC/resources/views/referent.blade.php +++ b/SRC/resources/views/referent.blade.php @@ -198,7 +198,14 @@ - + + + @endsection \ No newline at end of file