data_host = window.data_host root_url = window.root_url window.Quser= format_date: (utc) -> formatted = '' formatted += utc.substr(0,10) formatted += ' ' formatted += utc.substr(11, 5) formatted home_loader: -> $.getJSON(data_host + '/user/list_info.json', (res) -> Quser.handle_active_list_default_actions(res)) handle_active_list: (callback) -> $.getJSON(data_host + '/user/list_info.json', (res) -> if !res.list_active redirect_to 'user_root', {list_closed: 'true'} return window.active_list = res callback.call() if callback Quser.handle_active_list_default_actions(res) ) handle_active_list_default_actions: (response)-> response ||= {} if response.table_number $('.table-number').text(response.table_number) if response.supplier_name $('.supplier-name').text(response.supplier_name) if response.not_present $('.home-link').hide() else $('.home-link').show() Quser.list_needs_payment_default_action(response) Quser.list_needs_help_default_action(response) # 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) if !window.join_request_active && response.join_requests && response.join_requests.length window.join_request_active = true for join_request in response.join_requests wrapper = $('
') join_callback = ( (request)-> -> $.post(data_host + '/user/approve_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide') ) )(join_request) reject_callback = ( (request)-> -> $.post(data_host + '/user/reject_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide' )) )(join_request) header = $('') .append('') .append($('').text(t('join_request.title'))).appendTo(wrapper) body = $('') #body.append(join_request.user_email + ' wants to join the table') body.text(t('join_request.body', {email: join_request.user_email})) body.appendTo(wrapper) footer = $('') .append($('').text(t('join_request.reject')).click(reject_callback)) .append($('').text(t('join_request.approve')).click(join_callback)) .appendTo(wrapper) wrapper.modal() list_needs_help_default_action: (response)-> response ||= window.active_list needs_help_container = $('#list-needs-help-button') if needs_help_container.length if response.needs_help needs_help_container.data('needs-help', true) needs_help_container.addClass('active') else needs_help_container.data('needs-help', false) needs_help_container.removeClass('active') unless needs_help_container.data('click-initialized') needs_help_container.click( -> if $(this).data('needs-help') Qwaiter.alert(t('list_needs_help.help_is_on_its_way')) else Qwaiter.confirm( title: t('list_needs_help.title') content: t('list_needs_help.content') ok: Quser.list_needs_help ) ) needs_help_container.data('click-initialized', true) list_needs_help: -> return unless window.active_list && !window.active_list.needs_help $.post(data_host + '/user/needs_help.json', (res) -> window.active_list = res; Quser.list_needs_help_default_action(res)) list_needs_payment_default_action: (response)-> response ||= window.active_list needs_payment_container = $('#list-needs-payment-button') if needs_payment_container.length if response.needs_payment needs_payment_container.data('needs-payment', true) needs_payment_container.addClass('active') else needs_payment_container.data('needs-payment', false) needs_payment_container.removeClass('active') unless needs_payment_container.data('click-initialized') needs_payment_container.click( -> if $(this).data('needs-payment') Qwaiter.alert(t('list_needs_payment.payment_already_requested')) else Qwaiter.confirm( title: t('list_needs_payment.title') content: t('list_needs_payment.content') ok: Quser.list_needs_payment ) ) needs_payment_container.data('click-initialized', true) list_needs_payment: -> return unless window.active_list && !window.active_list.needs_payment $.post(data_host + '/user/list_needs_payment.json', (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res)) load_active_list: () -> $.getJSON(data_host + '/user/active_list.json', (res) -> window.active_list = res unless res.list_active window.location = root_url + '/user/list_history/'+res._id + '.html?list_closed=true' return Quser.handle_active_list_default_actions(res) body = $('#active-list-table tbody') foot = $('#active-list-table tfoot') Quser.build_list_table(body, foot, res) ) load_history_list: () -> match = window.document.URL.toString().match('([0-9a-zA-Z]+)(.html)?(\\?|$)') if match list_id = match[1] else return $.getJSON(data_host + '/user/list_history/'+list_id+'.json', (res) -> body = $('#history-list-table tbody') foot = $('#history-list-table tfoot') Quser.build_list_table(body, foot, res) $('.list-created-at').text(Quser.format_date(res.created_at)) $('.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 $.getJSON(data_host + '/user/list_history.json?page='+page, (res) -> Quser.paginate(res, '/user/list_history.html') container = $('#list-history-container') for list in res.lists li = $('').appendTo(container) link = $('').appendTo(li) link.attr('href', '/user/list_history/'+list._id + '.html') txt = list.supplier_name txt += ' - ' txt += Quser.format_date(list.created_at) link.text(txt) ) paginate: (wrapper, src) -> container = $('nav.pagination') container.html('') list = $('
')
cont.append $('Waiting for approval of the person on this table
') $.post(data_host + '/user/join_occupied_table', {table_id: table_id}) setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500) check_if_can_join_occupied_table: (table_id)-> $.post(data_host + '/user/check_table_join_status', {table_id: table_id}, (res) -> res ||= {} if res.approved redirect_to 'list_products' else if res.waiting # do nothing, keep waiting.... else redirect_to 'user_root', {message: 'join_request_rejected'} ) add_product: (product, count) -> count ||= 1 window.active_products_list = {} unless window.active_products_list window.active_products_list[product._id] = {product: product, number: 0} unless window.active_products_list[product._id] window.active_products_list[product._id].number += count Quser.build_product_list() clear_selected_products: -> window.active_products_list = {} $('#active-order-table').hide()