-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Products pagination based on ajax calls was added
- Loading branch information
vilgefortzz
committed
Apr 30, 2017
1 parent
5815e40
commit dd9f48f
Showing
10 changed files
with
306 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
$(function() { | ||
|
||
$('.pagination a').on('click', function (e) { | ||
e.preventDefault(); | ||
|
||
var url = $(this).attr('href'); | ||
getProducts(url); | ||
}) | ||
|
||
}); | ||
|
||
function getProducts(url) { | ||
|
||
$.ajax({ | ||
type: 'GET', | ||
url: url, | ||
|
||
beforeSend: function() { | ||
$('#products').css('opacity', '0.1'); | ||
$('#products').append('<img id="loading" style="position: absolute; left: 0; top: 0; z-index: 100000;" src="/images/loading.gif" />'); | ||
}, | ||
complete: function(){ | ||
$('#products').css('opacity', '1'); | ||
$('#looading').remove(); | ||
}, | ||
success: function(data){ | ||
$('#products').html(data); | ||
|
||
// Set active class to grid when go to another page with ajax calls | ||
$('#grid').addClass('active'); | ||
$('#list').removeClass('active'); | ||
|
||
// Attach localstorage - without page reload | ||
|
||
if ($('#is_session').val() == ('1')){ | ||
if (localStorage.length > 0){ | ||
for (var i = 0; i < localStorage.length; i++){ | ||
|
||
var id = localStorage.getItem(localStorage.key(i)); | ||
$('#add_' + id).hide(); | ||
$('#remove_' + id).show(); | ||
} | ||
} | ||
else | ||
localStorage.clear(); | ||
} | ||
else { | ||
localStorage.clear(); | ||
} | ||
|
||
// Add listeners | ||
|
||
// Again to paginate | ||
|
||
$('.pagination a').on('click', function (e) { | ||
e.preventDefault(); | ||
|
||
var url = $(this).attr('href'); | ||
getProducts(url); | ||
}); | ||
|
||
// Add to cart | ||
|
||
$('.add_to_cart').on('click', function (e) { | ||
e.preventDefault(); | ||
|
||
var url = $(this).attr("href"); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: url, | ||
|
||
success: function(data) { | ||
$('#removed_from_cart').hide(); | ||
$('#added_to_cart').show(); | ||
$('#added_to_cart').delay(7000).fadeOut('slow'); | ||
|
||
var $badge = $('.badge'), | ||
count = Number($badge.text()); | ||
|
||
$badge.text(count + 1); | ||
|
||
$('#add_' + data.id).hide(); | ||
$('#remove_' + data.id).show(); | ||
|
||
localStorage.setItem('product_' + data.id, data.id); | ||
} | ||
}) | ||
}); | ||
|
||
// Remove from cart | ||
|
||
$('.remove_from_cart').on('click', function (e) { | ||
e.preventDefault(); | ||
|
||
var url = $(this).attr("href"); | ||
|
||
$.ajax({ | ||
type: 'DELETE', | ||
url: url, | ||
|
||
success: function(data) { | ||
$('#added_to_cart').hide(); | ||
$('#removed_from_cart').show(); | ||
$('#removed_from_cart').delay(7000).fadeOut('slow'); | ||
|
||
var $badge = $('.badge'), | ||
count = Number($badge.text()); | ||
|
||
$badge.text(count - 1); | ||
|
||
$('#remove_' + data.id).hide(); | ||
$('#add_' + data.id).show(); | ||
|
||
localStorage.removeItem('product_' + data.id); | ||
} | ||
}) | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{{-- Pagination links --}} | ||
{{ $products->links() }} | ||
|
||
<div id="load" style="position: relative;"> | ||
@foreach($products as $product) | ||
|
||
<div class="item col-xs-4 col-lg-4"> | ||
<div class="thumbnail"> | ||
<img class="group list-group-image" src="/images/{{$product->image}}" width="200" height="200"/> | ||
<div class="caption"> | ||
<h2 class="group inner list-group-item-heading"> | ||
<b> | ||
{{$product->name}} | ||
<a href="{{ url('/products/'.$product->id) }}" style="font-size: 12px"> | ||
<span class="glyphicon glyphicon-triangle-right"></span>See details | ||
</a> | ||
</b> | ||
</h2> | ||
|
||
<div class="row" style="margin-top: 50px"> | ||
<div class="col-xs-12 col-md-4 group_div"> | ||
<p><b>Buy now:</b></p> | ||
<p class="lead_sub"><b>{{$product->price}}$</b></p> | ||
</div> | ||
<div class="col-xs-12 col-md-6 group_div"> | ||
<a id="add_{{$product->id}}" class="add_to_cart" href="{{ url('/cart/add/'.$product->id) }}"> | ||
<div id="add_to_cart_btn{{$product->id}}"> | ||
<span class="glyphicon glyphicon-shopping-cart"></span><b>Add to cart</b> | ||
</div> | ||
</a> | ||
|
||
{{-- Hidden link - dynamically change--}} | ||
<a id="remove_{{$product->id}}" class="remove_from_cart" href="{{ url('/cart/delete/'.$product->id) }}" hidden> | ||
<div id="remove_from_cart_btn{{$product->id}}"> | ||
<span class="glyphicon glyphicon-remove"></span><b>Remove</b> | ||
</div> | ||
</a> | ||
|
||
{{--For autheniticated users--}} | ||
@if(Auth::check()) | ||
<a class="give_review" href="{{ url('/products/'.$product->id) }}"> | ||
<div id="give_review_btn"> | ||
<span class="glyphicon glyphicon-comment"></span><b>Give a review</b> | ||
</div> | ||
</a> | ||
@endif | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endforeach | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.