Move user to local storage part one, should work already
This commit is contained in:
@@ -173,11 +173,7 @@ class Quser
|
||||
@build_list_table(body, foot, res)
|
||||
)
|
||||
load_history_list: () ->
|
||||
match = window.document.URL.toString().match('list_id=([0-9a-zA-Z]+)')
|
||||
if match
|
||||
list_id = match[1]
|
||||
else
|
||||
return
|
||||
return unless list_id = Qstorage.list_id
|
||||
$.getJSON(data_host + '/user/history_list.json?list_id='+list_id+'&'+ authentication_string, (res) =>
|
||||
body = $('#history-list-table tbody')
|
||||
foot = $('#history-list-table tfoot')
|
||||
@@ -187,37 +183,38 @@ class Quser
|
||||
$('.supplier-name').text(res.supplier_name)
|
||||
)
|
||||
load_list_history: ->
|
||||
match = window.document.URL.toString().match('page=([0-9]+)')
|
||||
if match
|
||||
page = match[1]
|
||||
else
|
||||
page = 1
|
||||
page = Qstorage.page || 1
|
||||
page = parseInt(page)
|
||||
$.getJSON(data_host + '/user/list_history.json?'+authentication_string+'&page='+page, (res) =>
|
||||
@paginate(res, '/user/list_history.html')
|
||||
container = $('#list-history-container')
|
||||
@paginate(res, @load_list_history)
|
||||
container = $('#list-history-container').html('')
|
||||
for list in res.lists
|
||||
li = $('<li></li>').appendTo(container)
|
||||
link = $('<a></a>').appendTo(li)
|
||||
link.attr('href', root_url + '/user/history_list.html?list_id='+list._id)
|
||||
link = $('<a href="#"></a>').appendTo(li)
|
||||
link.click(-> redirect_to 'history_list', list_id: list._id)
|
||||
txt = list.supplier_name
|
||||
txt += ' - '
|
||||
txt += @format_date(list.created_at)
|
||||
link.text(txt)
|
||||
)
|
||||
paginate: (wrapper, src) ->
|
||||
paginate: (wrapper, callback) ->
|
||||
container = $('nav.pagination')
|
||||
container.html('')
|
||||
list = $('<ul></ul>').appendTo(container)
|
||||
if wrapper.num_pages && wrapper.num_pages > 1
|
||||
for i in [1..wrapper.num_pages]
|
||||
li = $('<li class="page"></li>')
|
||||
link = $('<a></a>')
|
||||
link = $('<a href="#"></a>')
|
||||
link.text(i)
|
||||
if wrapper.current_page && wrapper.current_page == i
|
||||
li.addClass('active')
|
||||
link.attr('href', 'javascript:void(0)')
|
||||
else
|
||||
link.attr('href', root_url + src + '?'+authentication_string+'&page='+i)
|
||||
callback = ((i)->
|
||||
->
|
||||
Qstorage.page = i
|
||||
window.Quser.load_list_history()
|
||||
)(i)
|
||||
link.click(callback)
|
||||
li.append(link)
|
||||
list.append(li)
|
||||
mustache: (selector, locals)->
|
||||
@@ -239,9 +236,9 @@ class Quser
|
||||
|
||||
order_selected_products: ()->
|
||||
return if $.isEmptyObject(window.active_products_list)
|
||||
return unless Qstorage.table_id
|
||||
h = {}
|
||||
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||
h['table_id'] = match[1] if match
|
||||
h['table_id'] = Qstorage.table_id
|
||||
for product_id, number of window.active_products_list
|
||||
h['products['+product_id+']'] = number
|
||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) => @handle_response(res)), 'json')
|
||||
@@ -274,13 +271,8 @@ class Quser
|
||||
load_active_list_products: ->
|
||||
@populate_products_table('/user/list_products.json?'+authentication_string)
|
||||
load_table_products: ->
|
||||
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||
if match
|
||||
table_id = match[1]
|
||||
else
|
||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||
return
|
||||
@populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
||||
return redirect_to 'user_root', {message: 'cannot_identify_table'} unless Qstorage.table_id
|
||||
@populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+Qstorage.table_id)
|
||||
populate_products_table: (src)->
|
||||
$.getJSON(data_host + src, (res) =>
|
||||
include_order_buttons = res.my_list || !res.table_occupied
|
||||
@@ -325,6 +317,7 @@ class Quser
|
||||
false
|
||||
actions_for_table: (table)->
|
||||
table = JSON.parse(table) if typeof(table) == 'string'
|
||||
Qstorage.table_id = table.table_id
|
||||
$.getJSON(data_host + '/user/table_info.json?'+authentication_string+'&table_id='+table.table_id, (res)=>
|
||||
if res.current_table_id
|
||||
if res.other_supplier
|
||||
@@ -366,12 +359,12 @@ class Quser
|
||||
redirect_to 'list_products_for_table', {table_id: table.table_id}
|
||||
, 'json')
|
||||
show_table_products: ->
|
||||
unless table_id = getUrlVars().table_id
|
||||
unless table_id = Qstorage.table_id
|
||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||
return
|
||||
redirect_to 'list_products_for_table', table_id: table_id
|
||||
join_occupied_table: () ->
|
||||
unless table_id = getUrlVars().table_id
|
||||
unless table_id = Qstorage.table_id
|
||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||
return
|
||||
$('.form-actions').remove()
|
||||
|
||||
Reference in New Issue
Block a user