update coffee model
This commit is contained in:
@@ -2,7 +2,7 @@ data_host = window.data_host
|
|||||||
root_url = QMobile.root_url()
|
root_url = QMobile.root_url()
|
||||||
authentication_string = QMobile.authentication_string()
|
authentication_string = QMobile.authentication_string()
|
||||||
authentication_object = $.parseJSON(QMobile.authentication_object())
|
authentication_object = $.parseJSON(QMobile.authentication_object())
|
||||||
window.Quser=
|
class Quser
|
||||||
format_date: (utc) ->
|
format_date: (utc) ->
|
||||||
formatted = ''
|
formatted = ''
|
||||||
formatted += utc.substr(0,10)
|
formatted += utc.substr(0,10)
|
||||||
@@ -10,9 +10,9 @@ window.Quser=
|
|||||||
formatted += utc.substr(11, 5)
|
formatted += utc.substr(11, 5)
|
||||||
formatted
|
formatted
|
||||||
home_loader: ->
|
home_loader: ->
|
||||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) -> Quser.handle_active_list_default_actions(res))
|
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res))
|
||||||
handle_active_list: (callback) ->
|
handle_active_list: (callback) ->
|
||||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) ->
|
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) =>
|
||||||
if(res.ok == false && res.status && res.status == 401)
|
if(res.ok == false && res.status && res.status == 401)
|
||||||
direct_to_site('obtain_user_token')
|
direct_to_site('obtain_user_token')
|
||||||
else if !res.list_active
|
else if !res.list_active
|
||||||
@@ -20,7 +20,7 @@ window.Quser=
|
|||||||
return
|
return
|
||||||
window.active_list = res
|
window.active_list = res
|
||||||
callback.call() if callback
|
callback.call() if callback
|
||||||
Quser.handle_active_list_default_actions(res)
|
@handle_active_list_default_actions(res)
|
||||||
)
|
)
|
||||||
handle_active_list_default_actions: (response)->
|
handle_active_list_default_actions: (response)->
|
||||||
response ||= {}
|
response ||= {}
|
||||||
@@ -35,8 +35,8 @@ window.Quser=
|
|||||||
$('.home-link').hide()
|
$('.home-link').hide()
|
||||||
else
|
else
|
||||||
$('.home-link').show()
|
$('.home-link').show()
|
||||||
Quser.list_needs_payment_default_action(response)
|
@list_needs_payment_default_action(response)
|
||||||
Quser.list_needs_help_default_action(response)
|
@list_needs_help_default_action(response)
|
||||||
# join_request_active is to ensure that there are no more modals loaded when one is still active
|
# join_request_active is to ensure that there are no more modals loaded when one is still active
|
||||||
# console.log('join_request_active=' + window.join_request_active)
|
# console.log('join_request_active=' + window.join_request_active)
|
||||||
if !window.join_request_active && response.join_requests && response.join_requests.length
|
if !window.join_request_active && response.join_requests && response.join_requests.length
|
||||||
@@ -67,7 +67,7 @@ window.Quser=
|
|||||||
.appendTo(wrapper)
|
.appendTo(wrapper)
|
||||||
wrapper.modal()
|
wrapper.modal()
|
||||||
|
|
||||||
list_needs_help_default_action: (response)->
|
list_needs_help_default_action: (response)=>
|
||||||
response ||= window.active_list
|
response ||= window.active_list
|
||||||
needs_help_container = $('#list-needs-help-button')
|
needs_help_container = $('#list-needs-help-button')
|
||||||
if needs_help_container.length
|
if needs_help_container.length
|
||||||
@@ -85,13 +85,13 @@ window.Quser=
|
|||||||
Qwaiter.confirm(
|
Qwaiter.confirm(
|
||||||
title: t('list_needs_help.title')
|
title: t('list_needs_help.title')
|
||||||
content: t('list_needs_help.content')
|
content: t('list_needs_help.content')
|
||||||
ok: Quser.list_needs_help
|
ok: window.Quser.list_needs_help
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
needs_help_container.data('click-initialized', true)
|
needs_help_container.data('click-initialized', true)
|
||||||
list_needs_help: ->
|
list_needs_help: ->
|
||||||
return unless window.active_list && !window.active_list.needs_help
|
return unless window.active_list && !window.active_list.needs_help
|
||||||
$.post(data_host + '/user/needs_help.json', authentication_object, (res) -> window.active_list = res; Quser.list_needs_help_default_action(res))
|
$.post(data_host + '/user/needs_help.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_help_default_action(res))
|
||||||
list_needs_payment_default_action: (response)->
|
list_needs_payment_default_action: (response)->
|
||||||
response ||= window.active_list
|
response ||= window.active_list
|
||||||
needs_payment_container = $('#list-needs-payment-button')
|
needs_payment_container = $('#list-needs-payment-button')
|
||||||
@@ -110,23 +110,23 @@ window.Quser=
|
|||||||
Qwaiter.confirm(
|
Qwaiter.confirm(
|
||||||
title: t('list_needs_payment.title')
|
title: t('list_needs_payment.title')
|
||||||
content: t('list_needs_payment.content')
|
content: t('list_needs_payment.content')
|
||||||
ok: Quser.list_needs_payment
|
ok: window.Quser.list_needs_payment
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
needs_payment_container.data('click-initialized', true)
|
needs_payment_container.data('click-initialized', true)
|
||||||
list_needs_payment: ->
|
list_needs_payment: ->
|
||||||
return unless window.active_list && !window.active_list.needs_payment
|
return unless window.active_list && !window.active_list.needs_payment
|
||||||
$.post(data_host + '/user/list_needs_payment.json', authentication_object, (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res))
|
$.post(data_host + '/user/list_needs_payment.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_payment_default_action(res))
|
||||||
load_active_list: () ->
|
load_active_list: () ->
|
||||||
$.getJSON(data_host + '/user/active_list.json?'+authentication_string, (res) ->
|
$.getJSON(data_host + '/user/active_list.json?'+authentication_string, (res) =>
|
||||||
window.active_list = res
|
window.active_list = res
|
||||||
unless res.list_active
|
unless res.list_active
|
||||||
redirect_to 'history_list', {list_id: res._id, list_closed: true}
|
redirect_to 'history_list', {list_id: res._id, list_closed: true}
|
||||||
return
|
return
|
||||||
Quser.handle_active_list_default_actions(res)
|
@handle_active_list_default_actions(res)
|
||||||
body = $('#active-list-table tbody')
|
body = $('#active-list-table tbody')
|
||||||
foot = $('#active-list-table tfoot')
|
foot = $('#active-list-table tfoot')
|
||||||
Quser.build_list_table(body, foot, res)
|
@build_list_table(body, foot, res)
|
||||||
)
|
)
|
||||||
load_history_list: () ->
|
load_history_list: () ->
|
||||||
match = window.document.URL.toString().match('list_id=([0-9a-zA-Z]+)')
|
match = window.document.URL.toString().match('list_id=([0-9a-zA-Z]+)')
|
||||||
@@ -134,11 +134,11 @@ window.Quser=
|
|||||||
list_id = match[1]
|
list_id = match[1]
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
$.getJSON(data_host + '/user/history_list.json?list_id='+list_id+'&'+ authentication_string, (res) ->
|
$.getJSON(data_host + '/user/history_list.json?list_id='+list_id+'&'+ authentication_string, (res) =>
|
||||||
body = $('#history-list-table tbody')
|
body = $('#history-list-table tbody')
|
||||||
foot = $('#history-list-table tfoot')
|
foot = $('#history-list-table tfoot')
|
||||||
Quser.build_list_table(body, foot, res)
|
@build_list_table(body, foot, res)
|
||||||
$('.list-created-at').text(Quser.format_date(res.created_at))
|
$('.list-created-at').text(@format_date(res.created_at))
|
||||||
$('.supplier-name').text(res.supplier_name)
|
$('.supplier-name').text(res.supplier_name)
|
||||||
)
|
)
|
||||||
load_list_history: ->
|
load_list_history: ->
|
||||||
@@ -147,8 +147,8 @@ window.Quser=
|
|||||||
page = match[1]
|
page = match[1]
|
||||||
else
|
else
|
||||||
page = 1
|
page = 1
|
||||||
$.getJSON(data_host + '/user/list_history.json?'+authentication_string+'&page='+page, (res) ->
|
$.getJSON(data_host + '/user/list_history.json?'+authentication_string+'&page='+page, (res) =>
|
||||||
Quser.paginate(res, '/user/list_history.html')
|
@paginate(res, '/user/list_history.html')
|
||||||
container = $('#list-history-container')
|
container = $('#list-history-container')
|
||||||
for list in res.lists
|
for list in res.lists
|
||||||
li = $('<li></li>').appendTo(container)
|
li = $('<li></li>').appendTo(container)
|
||||||
@@ -156,7 +156,7 @@ window.Quser=
|
|||||||
link.attr('href', root_url + '/user/history_list.html?list_id='+list._id)
|
link.attr('href', root_url + '/user/history_list.html?list_id='+list._id)
|
||||||
txt = list.supplier_name
|
txt = list.supplier_name
|
||||||
txt += ' - '
|
txt += ' - '
|
||||||
txt += Quser.format_date(list.created_at)
|
txt += @format_date(list.created_at)
|
||||||
link.text(txt)
|
link.text(txt)
|
||||||
)
|
)
|
||||||
paginate: (wrapper, src) ->
|
paginate: (wrapper, src) ->
|
||||||
@@ -204,7 +204,7 @@ window.Quser=
|
|||||||
h['table_id'] = match[1] if match
|
h['table_id'] = match[1] if match
|
||||||
for product_id, number of window.active_products_list
|
for product_id, number of window.active_products_list
|
||||||
h['products['+product_id+']'] = number
|
h['products['+product_id+']'] = number
|
||||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) -> Quser.handle_response(res)), 'json')
|
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) => @handle_response(res)), 'json')
|
||||||
handle_response: (res) ->
|
handle_response: (res) ->
|
||||||
if(typeof(res) == 'string')
|
if(typeof(res) == 'string')
|
||||||
return unless res.length
|
return unless res.length
|
||||||
@@ -232,7 +232,7 @@ window.Quser=
|
|||||||
Qupdate('#active-order-container')
|
Qupdate('#active-order-container')
|
||||||
|
|
||||||
load_active_list_products: ->
|
load_active_list_products: ->
|
||||||
Quser.populate_products_table('/user/list_products.json?'+authentication_string)
|
@populate_products_table('/user/list_products.json?'+authentication_string)
|
||||||
load_table_products: ->
|
load_table_products: ->
|
||||||
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||||
if match
|
if match
|
||||||
@@ -240,9 +240,9 @@ window.Quser=
|
|||||||
else
|
else
|
||||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||||
return
|
return
|
||||||
Quser.populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
@populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
||||||
populate_products_table: (src)->
|
populate_products_table: (src)->
|
||||||
$.getJSON(data_host + src, (res) ->
|
$.getJSON(data_host + src, (res) =>
|
||||||
if res.has_occupied_info
|
if res.has_occupied_info
|
||||||
include_order_buttons = !res.is_occupied
|
include_order_buttons = !res.is_occupied
|
||||||
delete(res['has_occupied_info'])
|
delete(res['has_occupied_info'])
|
||||||
@@ -260,7 +260,7 @@ window.Quser=
|
|||||||
body.find('tr').remove()
|
body.find('tr').remove()
|
||||||
script_id = if include_order_buttons then '#products-category-for-order-template' else '#products-category-template'
|
script_id = if include_order_buttons then '#products-category-for-order-template' else '#products-category-template'
|
||||||
for category, products of res
|
for category, products of res
|
||||||
body.append Quser.mustache(script_id,
|
body.append @mustache(script_id,
|
||||||
category: category,
|
category: category,
|
||||||
products: products,
|
products: products,
|
||||||
include_order_buttons: include_order_buttons
|
include_order_buttons: include_order_buttons
|
||||||
@@ -287,11 +287,11 @@ window.Quser=
|
|||||||
window.active_products_list[product_id] ||= 0
|
window.active_products_list[product_id] ||= 0
|
||||||
window.active_products_list[product_id] += count
|
window.active_products_list[product_id] += count
|
||||||
delete(window.active_products_list[product_id]) if window.active_products_list[product_id] < 1
|
delete(window.active_products_list[product_id]) if window.active_products_list[product_id] < 1
|
||||||
Quser.build_product_list()
|
@build_product_list()
|
||||||
false
|
false
|
||||||
actions_for_table: (table)->
|
actions_for_table: (table)->
|
||||||
table = JSON.parse(table) if typeof(table) == 'string'
|
table = JSON.parse(table) if typeof(table) == 'string'
|
||||||
$.getJSON(data_host + '/user/table_info.json?'+authentication_string+'&table_id='+table.table_id, (res)->
|
$.getJSON(data_host + '/user/table_info.json?'+authentication_string+'&table_id='+table.table_id, (res)=>
|
||||||
if res.current_table_id
|
if res.current_table_id
|
||||||
if res.other_supplier
|
if res.other_supplier
|
||||||
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
|
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
|
||||||
@@ -361,7 +361,8 @@ window.Quser=
|
|||||||
window.active_products_list ||= {}
|
window.active_products_list ||= {}
|
||||||
window.active_products_list[product_id] ||= 0
|
window.active_products_list[product_id] ||= 0
|
||||||
window.active_products_list[product_id] += count
|
window.active_products_list[product_id] += count
|
||||||
Quser.build_product_list()
|
@build_product_list()
|
||||||
clear_selected_products: ->
|
clear_selected_products: ->
|
||||||
window.active_products_list = {}
|
window.active_products_list = {}
|
||||||
$('#active-order-table').hide()
|
$('#active-order-table').hide()
|
||||||
|
@Quser = new Quser
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
def layout_by_resource
|
def layout_by_resource
|
||||||
if devise_controller?
|
if devise_controller?
|
||||||
session[:user_return_to] =~ /obtain_token/ ? 'obtain_token' : 'theme1'
|
case session[:user_return_to]
|
||||||
|
when /\/user\// then 'phone'
|
||||||
|
when /obtain_token/ then 'obtain_token'
|
||||||
|
else 'theme1'
|
||||||
|
end
|
||||||
else
|
else
|
||||||
"application"
|
"application"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ dl.dl-horizontal
|
|||||||
tr
|
tr
|
||||||
td colspan=2 = slider_image
|
td colspan=2 = slider_image
|
||||||
tfoot
|
tfoot
|
||||||
|
script#active-list-orders-template[type="text/html"]= render 'active_list_orders.mustache'
|
||||||
|
script#active-list-orders-footer-template[type="text/html"]= render 'active_list_orders_footer.mustache'
|
||||||
- content_for :footer do
|
- content_for :footer do
|
||||||
javascript:
|
javascript:
|
||||||
jQuery(function(){
|
jQuery(function(){
|
||||||
|
|||||||
Reference in New Issue
Block a user