diff --git a/app/assets/images/icons/needs-help-active.png b/app/assets/images/icons/needs-help-active.png new file mode 100644 index 00000000..71a80f50 Binary files /dev/null and b/app/assets/images/icons/needs-help-active.png differ diff --git a/app/assets/images/icons/needs-payment-active.png b/app/assets/images/icons/needs-payment-active.png new file mode 100644 index 00000000..e49f4c0b Binary files /dev/null and b/app/assets/images/icons/needs-payment-active.png differ diff --git a/app/assets/javascripts/qwaiter.js.coffee b/app/assets/javascripts/qwaiter.js.coffee index e0153d67..9d4d6c26 100644 --- a/app/assets/javascripts/qwaiter.js.coffee +++ b/app/assets/javascripts/qwaiter.js.coffee @@ -8,9 +8,10 @@ window.Qwaiter= content = options.content || 'Are you sure?' title = options.title || 'Confirm' wrapper = $('') - callback_wrapper = -> - wrapper.modal('hide') - options.ok() + if typeof(options.ok) == 'function' + callback_wrapper = -> + wrapper.modal('hide') + options.ok() callback_cancel_wrapper = -> wrapper.modal('hide') options.cancel() if options.cancel @@ -18,9 +19,16 @@ window.Qwaiter= .append('') .append('

'+title+'

').appendTo(wrapper) body = $('').append('

'+content+'

').appendTo(wrapper) + ok_button = $('Yes') + if typeof(options.ok) == 'function' + ok_button.click(callback_wrapper) + else + ok_button.click -> + eval(options.ok) + wrapper.modal('hide') footer = $('') .append($('Close').click(callback_cancel_wrapper)) - .append($('Yes').click(callback_wrapper)) + .append(ok_button) .appendTo(wrapper) wrapper.modal() currency: (num) -> diff --git a/app/assets/javascripts/supplier/qsupplier.js.coffee b/app/assets/javascripts/supplier/qsupplier.js.coffee index 3f8c6350..adaaab80 100644 --- a/app/assets/javascripts/supplier/qsupplier.js.coffee +++ b/app/assets/javascripts/supplier/qsupplier.js.coffee @@ -28,6 +28,7 @@ root.Qsupplier= $('#list-is-helped-button-'+list_id).addClass('hide') else if e.event == 'order_being_processed' $('#order-in-process-button-'+e.data.id).hide() + $('#order-row-'+e.data.id).removeClass('placed').addClass('active') else if e.event == 'order_being_delivered' $('#order-row-'+e.data.id).remove() else if e.event == 'list_changed_table' @@ -114,7 +115,7 @@ root.Qsupplier= load_active_orders: () -> $.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) => body = $('#active-orders-table tbody') - body.find('tr').remove() + body.html('') foot = $('#active-orders-table tfoot') if(!res.orders && !res.orders.length) alert('No orders in list') diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 597171fb..d651edaf 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -10,7 +10,10 @@ class Quser watch_events: -> faye = new Faye.Client(event_host) user_id = Qstorage.getItem('user_id') - return unless user_id && user_id.length > 0 + unless user_id + @reset_user() + redirect_to 'obtain_token' + return false faye.subscribe "/user/"+user_id, (e)=> if(e.event == 'list_closed') #redirect_to 'user_root', {list_closed: 'true'} @@ -41,6 +44,8 @@ class Quser $('.list-total-amount').html(currency(e.data.total_amount)) console.log(e) false + ensure_json: (res)-> + if typeof(res) == 'string' then JSON.parse(res) else res reset_user: -> Qstorage.removeItem('auth_token') Qstorage.removeItem('user_id') @@ -51,6 +56,7 @@ class Quser return email.focus() unless email.val() && email.val().length > 0 return password.focus() unless password.val() && password.val().length > 0 $.post(data_host + '/user/obtain_token.json', {"user[email]": email.val(), "user[password]": password.val()}, (res)=> + res = @ensure_json(res) if res.auth_token Qstorage.setItem('auth_token', res.auth_token) Qstorage.setItem('user_id', res.user_id) @@ -111,37 +117,18 @@ class Quser )).modal() false approve_join_request: (user_id)-> - $.post(data_host + '/user/approve_join_request', $.extend({user_id: user_id}, authentication_object), -> window.join_request_active = false) + @ensure_token => + $.post(data_host + '/user/approve_join_request', $.extend({user_id: user_id}, @authentication_object), -> window.join_request_active = false) reject_join_request: (user_id)-> - $.post(data_host + '/user/reject_join_request', $.extend({user_id: user_id}, authentication_object), -> window.join_request_active = false) - bogus1: -> - wrapper = $('') - join_callback = ( (request)-> - -> - $.post(data_host + '/user/approve_join_request', $.extend({user_id: request.user_id}, authentication_object), -> window.join_request_active = false; wrapper.modal('hide') ) - )(join_request) - reject_callback = ( (request)-> - -> - $.post(data_host + '/user/reject_join_request', $.extend({user_id: request.user_id}, authentication_object), -> 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() - + @ensure_token => + $.post(data_host + '/user/reject_join_request', $.extend({user_id: user_id}, @authentication_object), -> window.join_request_active = false) + list_needs_help: -> + return unless window.active_list && !window.active_list.needs_help + @ensure_token => + $.post(data_host + '/user/needs_help.json', @authentication_object, (res) => window.active_list = @ensure_json(res); @list_needs_help_default_action()) list_needs_help_default_action: (response)=> response ||= window.active_list + window.active_list = response needs_help_container = $('#list-needs-help-button') if needs_help_container.length if response.needs_help @@ -158,15 +145,17 @@ class Quser Qwaiter.confirm( title: t('list_needs_help.title') content: t('list_needs_help.content') - ok: window.Quser.list_needs_help + 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', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_help_default_action(res)) + list_needs_payment: -> + return unless window.active_list && !window.active_list.needs_payment + @ensure_token => + $.post(data_host + '/user/list_needs_payment.json', @authentication_object, (res) => window.active_list = @ensure_json(res); @list_needs_payment_default_action()) list_needs_payment_default_action: (response)-> response ||= window.active_list + window.active_list = response needs_payment_container = $('#list-needs-payment-button') if needs_payment_container.length if response.needs_payment @@ -183,13 +172,10 @@ class Quser Qwaiter.confirm( title: t('list_needs_payment.title') content: t('list_needs_payment.content') - ok: window.Quser.list_needs_payment + 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', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_payment_default_action(res)) load_active_list: () -> @ensure_token => $.getJSON(data_host + '/user/active_list.json?'+@authentication_string, (res) => @@ -350,48 +336,49 @@ class Quser @build_product_list() 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 - redirect_to 'user_root', {message: 'table_is_from_other_supplier'} - else if res.current_table_id == table.table_id - #nothing has changed, show product list - redirect_to 'list_products' - else if res.current_table_id != table.table_id + table = @ensure_json(table) + Qstorage.setItem('table_id', table.table_id) + @ensure_token => + $.getJSON(data_host + '/user/table_info.json?'+@authentication_string+'&table_id='+table.table_id, (res)=> + if res.current_table_id + if res.other_supplier + redirect_to 'user_root', {message: 'table_is_from_other_supplier'} + else if res.current_table_id == table.table_id + #nothing has changed, show product list + redirect_to 'list_products' + else if res.current_table_id != table.table_id + if res.occupied + redirect_to 'user_root', {message: 'table_is_occupied'} + else if res.reserved + redirect_to 'user_root', {message: 'table_is_reserved'} + else if table.closed + redirect_to 'user_root', {message: 'table_is_closed'} + else if res.supplier_closed + redirect_to 'user_root', {message: 'supplier_is_closed'} + else + ## Offer to move table + Qwaiter.confirm( + ok: -> + $.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, @authentication_object), (res2)-> + if res2.occupied + redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'} + else + redirect_to 'list_products', {message: 'move_table.moved_to_another_table'} + ) + cancel: -> + redirect_to 'list_products' + title: t('move_table.confirmation_title') + content: t('move_table.confirmation_body') + ) + else if res.occupied - redirect_to 'user_root', {message: 'table_is_occupied'} - else if res.reserved - redirect_to 'user_root', {message: 'table_is_reserved'} - else if table.closed - redirect_to 'user_root', {message: 'table_is_closed'} + redirect_to 'join_occupied_table', {table_id: table.table_id} else if res.supplier_closed redirect_to 'user_root', {message: 'supplier_is_closed'} else - ## Offer to move table - Qwaiter.confirm( - ok: -> - $.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, @authentication_object), (res2)-> - if res2.occupied - redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'} - else - redirect_to 'list_products', {message: 'move_table.moved_to_another_table'} - ) - cancel: -> - redirect_to 'list_products' - title: t('move_table.confirmation_title') - content: t('move_table.confirmation_body') - ) - else - if res.occupied - redirect_to 'join_occupied_table', {table_id: table.table_id} - else if res.supplier_closed - redirect_to 'user_root', {message: 'supplier_is_closed'} - else - #$.post(data_host + '/user/create_list.json', {table_id: table.table_id}, (res)-> Quser.handle_response(res)) - redirect_to 'list_products_for_table', {table_id: table.table_id} - , 'json') + #$.post(data_host + '/user/create_list.json', {table_id: table.table_id}, (res)-> Quser.handle_response(res)) + redirect_to 'list_products_for_table', {table_id: table.table_id} + , 'json') show_table_products: -> unless table_id = Qstorage.table_id redirect_to 'user_root', {message: 'cannot_identify_table'} diff --git a/app/assets/stylesheets/supplier/active_lists.css.sass b/app/assets/stylesheets/supplier/active_lists.css.sass index e17c957e..d9059663 100644 --- a/app/assets/stylesheets/supplier/active_lists.css.sass +++ b/app/assets/stylesheets/supplier/active_lists.css.sass @@ -17,3 +17,19 @@ margin-right: 7px &.hide display: none +#active-orders-table + tbody + tr + td + &:first-child + padding-left: 35px + background-position: 5px center + background-repeat: no-repeat + &.active + td + &:first-child + background-image: image-url('icons/order-check.png') + &.delivered + td + &:first-child + background-image: image-url('icons/order-doublecheck.png') diff --git a/app/assets/stylesheets/user/structure.css.sass b/app/assets/stylesheets/user/structure.css.sass index e8dc2fe0..087b6379 100644 --- a/app/assets/stylesheets/user/structure.css.sass +++ b/app/assets/stylesheets/user/structure.css.sass @@ -104,7 +104,12 @@ body #list-needs-payment-button span background-image: image-url('icons/needs-payment.png') + &.active + span + background-image: image-url('icons/needs-payment-active.png') #list-needs-help-button span background-image: image-url('icons/needs-help.png') - + &.active + span + background-image: image-url('icons/needs-help-active.png') diff --git a/app/templates/supplier/_active_order.mustache b/app/templates/supplier/_active_order.mustache index edab1ace..e579af92 100644 --- a/app/templates/supplier/_active_order.mustache +++ b/app/templates/supplier/_active_order.mustache @@ -1,4 +1,4 @@ - + {{display}} {{table_number}} {{section_title}} @@ -7,4 +7,4 @@ - + diff --git a/config/locales/en.yml b/config/locales/en.yml index 7569cf6d..d1a195d4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -147,6 +147,7 @@ en: obtain_token: title: Authenticate Qwaiter obtain: Authenticate + invalid_combination: The email password combination is incorrect section: first_section_title: Room manage_tables: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index f71e3cde..39d638b2 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -160,6 +160,7 @@ nl: obtain_token: title: Aanmelden bij Qwaiter obtain: Aanmelden + invalid_combination: De inloggegevens zijn onjuist section: first_section_title: Ruimte manage_tables: diff --git a/spec/routing/user_routing_spec.rb b/spec/routing/user_routing_spec.rb index 9deabfb1..1f16e773 100644 --- a/spec/routing/user_routing_spec.rb +++ b/spec/routing/user_routing_spec.rb @@ -3,11 +3,11 @@ require "spec_helper" describe UserController do describe "routing" do - it "routes root to #home" do - get("/user").should route_to("user#home") + it "routes root to #index" do + get("/user").should route_to("user#index") end - it "routes to #home" do - get("/user/home").should route_to("user#home") + it "routes to #index" do + get("/user/index").should route_to("user#index") end it "routes to #active_list" do get("/user/active_list").should route_to("user#active_list") @@ -38,9 +38,6 @@ describe UserController do it "routes to #history_list" do get("/user/history_list").should route_to("user#history_list") end - it "routes to #home" do - get("/user/home").should route_to("user#home") - end it "routes to #order_selected_products" do post("/user/order_selected_products").should route_to("user#order_selected_products") end