Promotion Backend v1
This commit is contained in:
parent
0ed47d3553
commit
f0da981737
43 changed files with 2765 additions and 45 deletions
|
|
@ -81,4 +81,8 @@ a[aria-expanded='true'] > .fa-caret-expand:before {
|
|||
|
||||
.spinner {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table-striped tbody tr:nth-of-type(odd) {
|
||||
background-color: rgba(38, 64, 95, 0.04);
|
||||
}
|
||||
120
public/js/iq-promotion-cart.js
Normal file
120
public/js/iq-promotion-cart.js
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
|
||||
var IqPromotionCart = {
|
||||
table: "#datatables-promotion-list",
|
||||
btn_add: '.add-product-promotion',
|
||||
btn_remove: '.remove-product-promotion',
|
||||
input_event: '.input-event-promotion-onchange',
|
||||
check_event: '.check-event-promotion-onchange',
|
||||
url: null,
|
||||
action: null,
|
||||
cart_holder: '#holder_html_view_cart',
|
||||
|
||||
init: function () {
|
||||
var _self = this;
|
||||
_self.url = $(_self.table).data('url');
|
||||
_self.action = $(_self.table).data('action');
|
||||
_self.initElements();
|
||||
return _self;
|
||||
},
|
||||
initElements: function (){
|
||||
var _self = this;
|
||||
$(_self.table).find(_self.btn_add).on('click', function(){
|
||||
_self.add_product($(this))
|
||||
});
|
||||
$(_self.table).find(_self.btn_remove).on('click', function(){
|
||||
_self.remove_product($(this))
|
||||
});
|
||||
$(_self.table).find(_self.input_event).off('change').on('change', function(){
|
||||
_self.update_input_table($(this));
|
||||
});
|
||||
$(_self.table).find(_self.check_event).off('change').on('change', function(){
|
||||
_self.update_input_table($(this));
|
||||
});
|
||||
},
|
||||
|
||||
add_product: function (_obj){
|
||||
var _self = this;
|
||||
var input = $(_self.table).find('input#product_qty_'+_obj.data('product-id'));
|
||||
var qty = parseInt(input.val()) + 1;
|
||||
qty = _self.checkNumber(qty);
|
||||
input.val(qty);
|
||||
_self.update_cart();
|
||||
},
|
||||
remove_product: function (_obj){
|
||||
var _self = this;
|
||||
var input = $(_self.table).find('input#product_qty_'+_obj.data('product-id'));
|
||||
var qty = parseInt(input.val()) - 1;
|
||||
if(qty < 0){
|
||||
qty = 0;
|
||||
}
|
||||
input.val(qty);
|
||||
_self.update_cart();
|
||||
},
|
||||
update_input_table: function (_obj){
|
||||
var _self = this;
|
||||
var qty = parseInt(_obj.val());
|
||||
qty = _self.checkNumber(qty);
|
||||
_obj.val(qty);
|
||||
_self.update_cart();
|
||||
},
|
||||
checkNumber : function(number){
|
||||
if(number < 0 || isNaN(number)){
|
||||
return 0;
|
||||
}
|
||||
if(number >= 100){
|
||||
return 100;
|
||||
}
|
||||
return number;
|
||||
},
|
||||
update_cart: function (){
|
||||
var _self = this;
|
||||
var data = {};
|
||||
var tempData = [];
|
||||
$(_self.table).find(_self.input_event).each(function(){
|
||||
//push, is checked
|
||||
if($(_self.table).find('#product_check_'+$(this).data('product-id')).is(':checked')){
|
||||
tempData.push({product_id: $(this).data('product-id'), qty: $(this).val()});
|
||||
}
|
||||
});
|
||||
data.action = $(_self.table).data('action');
|
||||
data.user_promotion_id = $(_self.table).data('user_promotion_id');
|
||||
data.products = tempData;
|
||||
_self.performRequest(data)
|
||||
.done(_self.refreshItemsAndView);
|
||||
},
|
||||
|
||||
refreshItemsAndView: function (data){
|
||||
var _self = IqPromotionCart;
|
||||
//console.log(data.html_cart);
|
||||
$(_self.cart_holder).html(data.html_cart);
|
||||
},
|
||||
performRequest : function(data) {
|
||||
var _self = this;
|
||||
var url = _self.url,
|
||||
contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
// console.log(data);
|
||||
// console.log(url);
|
||||
return $.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
contentType: contentType,
|
||||
encode: true,
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||
}
|
||||
})
|
||||
.done(function (data) {
|
||||
// console.log('performRequest');
|
||||
// console.log(data);
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
console.log(jqXHR);
|
||||
console.log(jqXHR.responseText);
|
||||
console.log(textStatus);
|
||||
console.log(errorThrown);
|
||||
console.log("Sorry, there was a problem!");
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue