seperate rails logic for parameters for showing products
This commit is contained in:
@@ -136,9 +136,11 @@ window.Quser=
|
|||||||
row.append($('<td></td>').text(order_txts.join(', ')))
|
row.append($('<td></td>').text(order_txts.join(', ')))
|
||||||
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
||||||
foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>')
|
foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>')
|
||||||
order_selected_products: (h)->
|
order_selected_products: ()->
|
||||||
return if $.isEmptyObject(window.active_products_list)
|
return if $.isEmptyObject(window.active_products_list)
|
||||||
h ||= {}
|
h = {}
|
||||||
|
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||||
|
h['table_id'] = match[1] if match
|
||||||
for product_id, info of window.active_products_list
|
for product_id, info of window.active_products_list
|
||||||
h['products['+product_id+']'] = info.number
|
h['products['+product_id+']'] = info.number
|
||||||
$.post(data_host + '/user/order_selected_products', h, ((res) -> Quser.handle_response(res)), 'json')
|
$.post(data_host + '/user/order_selected_products', h, ((res) -> Quser.handle_response(res)), 'json')
|
||||||
@@ -170,11 +172,23 @@ window.Quser=
|
|||||||
table.show()
|
table.show()
|
||||||
|
|
||||||
load_active_list_products: ->
|
load_active_list_products: ->
|
||||||
Quser.populate_products_table('/user/list_products.json', true)
|
Quser.populate_products_table('/user/list_products.json')
|
||||||
load_table_products: (table_id, occupied)->
|
load_table_products: ->
|
||||||
Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id, !occupied)
|
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||||
populate_products_table: (src, include_order_buttons)->
|
if match
|
||||||
|
table_id = match[1]
|
||||||
|
else
|
||||||
|
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||||
|
return
|
||||||
|
Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id)
|
||||||
|
populate_products_table: (src)->
|
||||||
$.get(data_host + src, (res) ->
|
$.get(data_host + src, (res) ->
|
||||||
|
if res.has_occupied_info
|
||||||
|
include_order_buttons = !res.is_occupied
|
||||||
|
delete(res['has_occupied_info'])
|
||||||
|
delete(res['is_occupied'])
|
||||||
|
else
|
||||||
|
include_order_buttons = true
|
||||||
body = $('#products-table tbody')
|
body = $('#products-table tbody')
|
||||||
if res.table_number
|
if res.table_number
|
||||||
$('.table-number').text(res.table_number)
|
$('.table-number').text(res.table_number)
|
||||||
|
|||||||
@@ -127,7 +127,12 @@ class UserController < ApplicationController
|
|||||||
products = @table.supplier.products
|
products = @table.supplier.products
|
||||||
products.include_relation(:product_categories)
|
products.include_relation(:product_categories)
|
||||||
products.sort_by!{|p| p.product_category.try(:position) || 90000}
|
products.sort_by!{|p| p.product_category.try(:position) || 90000}
|
||||||
h = products.inject({table_number: @table.number, supplier_name: @table.supplier.name}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
h = products.inject({
|
||||||
|
table_number: @table.number,
|
||||||
|
supplier_name: @table.supplier.name,
|
||||||
|
has_occupied_info: true,
|
||||||
|
is_occupied: @table.occupied?
|
||||||
|
}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||||
render json: h
|
render json: h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
tfoot
|
tfoot
|
||||||
tr
|
tr
|
||||||
td colspan=2
|
td colspan=2
|
||||||
button class="btn btn-primary" onClick="Quser.order_selected_products({table_id: '#{@table.id}'})" data-t="selected_products.order"= t('selected_products.order')
|
button class="btn btn-primary" onClick="Quser.order_selected_products()" data-t="selected_products.order"= t('selected_products.order')
|
||||||
|
|
|
|
||||||
button class="btn btn btn-warning" onClick="Quser.clear_selected_products()" data-t="selected_products.clear"= t('selected_products.clear')
|
button class="btn btn btn-warning" onClick="Quser.clear_selected_products()" data-t="selected_products.clear"= t('selected_products.clear')
|
||||||
td.currency
|
td.currency
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
- content_for :footer do
|
- content_for :footer do
|
||||||
javascript:
|
javascript:
|
||||||
jQuery(function(){
|
jQuery(function(){
|
||||||
Quser.load_table_products('#{@table.id}', #{@table.occupied? ? 'true' : 'false'});
|
Quser.load_table_products();
|
||||||
QMobile.activateRotation();
|
QMobile.activateRotation();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user