add customer cart
This commit is contained in:
@@ -3,24 +3,31 @@ function ProductSell(o){
|
||||
/**reference for the instance*/
|
||||
var app = this;
|
||||
/**currently loaded product*/
|
||||
var product = null;
|
||||
this.product = null;
|
||||
|
||||
this.defaults = {
|
||||
/**id of filter text*/
|
||||
selector_filter_text: '#filter_text',
|
||||
/**selector for customer cart container*/
|
||||
selector_customer_cart: '.customer-cart',
|
||||
selector_user_cart: '.user-cart',
|
||||
selector_btn_pay_customer_cart: '#btn_pay_customer_cart',
|
||||
selector_btn_pay_user_cart: '#btn_pay_user_cart',
|
||||
url_pay_customer_card: '-',
|
||||
/** ajax url for lookup service*/
|
||||
lookup_product_url: '',
|
||||
/**mark list paid url*/
|
||||
clear_list_url: '',
|
||||
url_pay_user_cart: '',
|
||||
/**the id of form*/
|
||||
selector_form: '#product_form',
|
||||
/**form contains error text*/
|
||||
form_invalid: 'Az ürlap hibákat tartalmaz',
|
||||
message_paid: 'Tételek fizetve',
|
||||
/**list of sold items by current user*/
|
||||
sold_items: [],
|
||||
user_cart: [],
|
||||
discounts: [],
|
||||
customer_cart: []
|
||||
customer_cart: [],
|
||||
|
||||
};
|
||||
|
||||
init();
|
||||
@@ -30,20 +37,60 @@ function ProductSell(o){
|
||||
app.keyDate = null;
|
||||
app.keySeq = '';
|
||||
app.enterPressed = 0;
|
||||
addBehaviourBtnSell();
|
||||
addBehaviourBtnSellAndAppendToBill();
|
||||
addBehaviorAjaxSubmit();
|
||||
|
||||
addSellBehaiours();
|
||||
|
||||
setFocus();
|
||||
addEnterPressedBehaviours();
|
||||
addBehaviorCountChangedListener();
|
||||
addBehaviourDisocuntChanged();
|
||||
createUserSoldItemsTable();
|
||||
createCustomerCartTable();
|
||||
addBehaviourBtnPaid();
|
||||
|
||||
addListenerBehaviours();
|
||||
|
||||
createCarts();
|
||||
|
||||
addPayoutButtons();
|
||||
|
||||
productChanged();
|
||||
addDocumentKeypressedListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* payout out user or customer cart
|
||||
* */
|
||||
function addPayoutButtons(){
|
||||
addBehaviourPayoutUserCart();
|
||||
addBehaviourPayoutCustomerCart();
|
||||
}
|
||||
/**
|
||||
* display user and customer cart on page load
|
||||
* */
|
||||
function createCarts(){
|
||||
createUserCartTable();
|
||||
createCustomerCartTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* add change and enter pressed listeners
|
||||
* */
|
||||
function addListenerBehaviours(){
|
||||
addEnterPressedBehaviours();
|
||||
addBehaviorCountChangedListener();
|
||||
addBehaviourDisocuntChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* sell a product. there are three type of sell:
|
||||
* - sell inmadietly
|
||||
* - sell and put it to user cart
|
||||
* - sell and put it to customer cart
|
||||
* */
|
||||
function addSellBehaiours(){
|
||||
addBehaviourBtnSell();
|
||||
addBehaviourBtnSellAndAppendToBill();
|
||||
addBehaviourBtnAddToCustomerCart();
|
||||
|
||||
addBehaviorAjaxSubmit();
|
||||
}
|
||||
|
||||
|
||||
function addBehaviourDisocuntChanged(){
|
||||
$("#productsaleform-id_discount").change(refreshCalculatedValues);
|
||||
}
|
||||
@@ -103,6 +150,9 @@ function ProductSell(o){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add traversing between input elements on enter key pressed
|
||||
* */
|
||||
function addEnterPressedBehaviours(){
|
||||
addBehaviorEnterPressedListener();
|
||||
addBehaviorCountEnterPressedListener();
|
||||
@@ -277,24 +327,20 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
function submitSell(){
|
||||
$('#productsaleform-append_to_sold_list').val('');
|
||||
$('#productsaleform-cart').val('');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
function submitSellAndAppend(){
|
||||
$('#productsaleform-append_to_sold_list').val('append');
|
||||
$('#productsaleform-cart').val('user');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
|
||||
|
||||
function submitAddToCustomerCart(){
|
||||
$('#productsaleform-append_to_sold_list').val('append');
|
||||
$('#productsaleform-cart').val('customer');
|
||||
$('#product_form').submit();
|
||||
}
|
||||
|
||||
function refreshSoldUseritems(){
|
||||
$('.sold-items-container').transferList('option','transfers' , app.defaults.sold_items );
|
||||
}
|
||||
|
||||
function addBehaviorAjaxSubmit(){
|
||||
|
||||
$('body').on('afterValidate', '#product_form', function () {
|
||||
@@ -327,8 +373,10 @@ function ProductSell(o){
|
||||
refreshCalculatedValues();
|
||||
$("#filter_text").val('');
|
||||
setFocus();
|
||||
app.defaults.sold_items = response.transfers;
|
||||
refreshSoldItemsList();
|
||||
app.defaults.user_cart = response.transfers;
|
||||
app.defaults.customer_cart = response.customer_cart;
|
||||
refreshUserCart();
|
||||
refreshCustomerCart();
|
||||
}else if ( response.code == 'invalid'){
|
||||
if ( response.errors ){
|
||||
$.each(response.errors, function (key, value){
|
||||
@@ -347,36 +395,60 @@ function ProductSell(o){
|
||||
}
|
||||
|
||||
|
||||
function refreshSoldItemsList(){
|
||||
$('.sold-items-container').transferList( 'option', 'transfers' , app.defaults.sold_items );
|
||||
function refreshUserCart(){
|
||||
$(app.defaults.selector_user_cart).transferList( 'option', 'transfers' , app.defaults.user_cart );
|
||||
}
|
||||
function refreshCustomerCart(){
|
||||
$(app.defaults.selector_customer_cart ).transferList( 'option', 'transfers' , app.defaults.customer_cart );
|
||||
}
|
||||
|
||||
function addBehaviourBtnPaid( ){
|
||||
$('#btn_paid').on('click',function(){
|
||||
function addBehaviourPayoutUserCart( ){
|
||||
$( app.defaults.selector_btn_pay_user_cart ).on('click',function(){
|
||||
|
||||
$.ajax({
|
||||
url: app.defaults.clear_list_url,
|
||||
url: app.defaults.url_pay_user_cart,
|
||||
type: 'post',
|
||||
data: {},
|
||||
success: function (response) {
|
||||
if ( response.code == 'success'){
|
||||
app.defaults.user_cart = response.transfers;
|
||||
refreshUserCart();
|
||||
$.notify(app.defaults.message_paid, { 'type' : 'success' });
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
function addBehaviourPayoutCustomerCart( ){
|
||||
$( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){
|
||||
alert('ok');
|
||||
$.ajax({
|
||||
url: app.defaults.url_pay_customer_card,
|
||||
type: 'post',
|
||||
data: {},
|
||||
success: function (response) {
|
||||
if ( response.code == 'success'){
|
||||
app.defaults.sold_items= response.transfers;
|
||||
refreshSoldItemsList();
|
||||
$.notify(app.defaults.message_paid, { 'type' : 'success' });
|
||||
app.defaults.customer_cart = response.customer_cart;
|
||||
refreshCustomerCart();
|
||||
}
|
||||
$.notify(response.message, { 'type' : response.code });
|
||||
},
|
||||
error: function(){
|
||||
alert('Hiba történt');
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function createUserSoldItemsTable(){
|
||||
$('.sold-items-container').transferList({
|
||||
'transfers' : app.defaults.sold_items
|
||||
function createUserCartTable(){
|
||||
$(app.defaults.selector_user_cart).transferList({
|
||||
'transfers' : app.defaults.user_cart
|
||||
});
|
||||
}
|
||||
function createCustomerCartTable(){
|
||||
$('.customer-cart').transferList({
|
||||
$(app.defaults.selector_customer_cart).transferList({
|
||||
'transfers' : app.defaults.customer_cart
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,7 +136,6 @@ $.widget( "fitness.transferList", {
|
||||
self._refresh();
|
||||
},
|
||||
};
|
||||
|
||||
// base
|
||||
this._super(key, value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user