Fixes for user app table scanning and using the data host url for requests

This commit is contained in:
2014-08-27 20:05:57 +02:00
parent 2f820bc0b7
commit ecab6af4bb
8 changed files with 58 additions and 52 deletions
@@ -10,6 +10,7 @@ App.ApplicationController = Ember.Controller.extend
@set 'notice', null
openDebugger: ->
debugger
currentPathDidChange: (->
@set 'notice', ''
).observes('currentPath')
@@ -2,8 +2,8 @@ App.JoinRequestsController = Ember.ArrayController.extend
join_requests: (-> @get('controllers.application.list.join_requests') ).property('controllers.application.list.join_requests')
actions:
rejectRequest: (join_request)->
Ember.$.post('/user/reject_join_request', user_id: join_request.get('user.id')).then (response)->
Ember.$.post("#{$data_host}/user/reject_join_request", user_id: join_request.get('user.id')).then (response)->
join_request.eraseRecord()
approveRequest: (join_request)->
Ember.$.post('/user/approve_join_request', user_id: join_request.get('user.id')).then (response)->
Ember.$.post("#{$data_host}/user/approve_join_request", user_id: join_request.get('user.id')).then (response)->
join_request.eraseRecord()
@@ -1,37 +1 @@
App.SelectQrcodeController = Ember.Controller.extend
actions:
selectQr: (table)->
@secured ->
$.getJSON($data_host + '/user/table_info.json?'+@authentication_string+'&table_id='+table._id).then (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._id
#nothing has changed, show product list
@redirect_to 'table', table._id
else if res.current_table_id != 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
@send 'confirm',
title: t('move_table.confirmation_title')
body: t('move_table.confirmation_body')
ok: =>
Ember.$.post '/user/move_table.json', table_id: table._id, (res2)=>
if res2.occupied
@redirect_to 'user_root', message: 'move_table.cannot_move_to_occupied_tabe'
else
# Now we can move table
Qstorage.setItem 'table_id', table._id
@redirect_to 'table', table._id, message: 'move_table.moved_to_another_table'
cancel: =>
@redirect_to 'table', res.current_table_id
else
@redirect_to 'table', table._id
App.SelectQrcodeController = Ember.Controller.extend {}
@@ -24,7 +24,7 @@ App.TableController = Ember.ObjectController.extend
@store.createRecord 'product_order', product: product, price: product.get('price')
joinOccupiedTable: ->
#@secured =>
Ember.$.post('/user/join_occupied_table.json', table_id: @get('model.id'))
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@set 'controllers.application.join_request_sent', true # keeps the button deactivated
toggleProductCategory: (product_category)->
product_category.set 'collapsed', not product_category.get('collapsed')
@@ -1,4 +1,5 @@
ControllerExtensions = Ember.Mixin.create
needs: ['application']
ajaxError: (callback)->
handler = (emberError)=>
console.log "Error: status #{emberError.status}"
@@ -14,8 +15,8 @@ ControllerExtensions = Ember.Mixin.create
@set 'controllers.application.modal.content', options.content if options.content
Ember.ArrayController.reopen ControllerExtensions
Ember.Controller.reopen ControllerExtensions
Ember.ObjectController.reopen ControllerExtensions
Ember.Controller.reopen
needs: ['application']
secured: (callback)->
unless Qstorage.getItem('auth_token') && typeof(Qstorage.getItem('auth_token')) == 'string' && Qstorage.getItem('auth_token').length > 0
return App.obtain_token()
@@ -58,7 +59,6 @@ Ember.Controller.reopen
#$('#confirm-modal').css('visibility', 'visible').show()
Ember.ArrayController.reopen
needs: ['application']
secured: (callback)->
unless Qstorage.getItem('auth_token') && typeof(Qstorage.getItem('auth_token')) == 'string' && Qstorage.getItem('auth_token').length > 0
return App.obtain_token()
@@ -71,6 +71,3 @@ Ember.ArrayController.reopen
if options.message
tkey = if options.message.indexOf('.') > -1 then options.message else "messages.#{options.message}"
@set 'controllers.application.notice', t(tkey)
Ember.ObjectController.reopen
needs: ['application']
@@ -33,13 +33,13 @@ App.ApplicationRoute = Ember.Route.extend
ok: options.ok
listNeedsPayment: ->
@get('controller').secured ->
Ember.$.post '/user/list_needs_payment.json'
#Ember.$.post('/user/list_needs_payment.json').then (res) =>
Ember.$.post "#{$data_host}/user/list_needs_payment.json"
#Ember.$.post("#{$data_host}/user/list_needs_payment.json").then (res) =>
#@set('list.needs_payment', true) # also done by faye
listNeedsHelp: ->
@get('controller').secured ->
Ember.$.post '/user/needs_help.json'
#Ember.$.post('/user/needs_help.json').then (res) =>
Ember.$.post "#{$data_host}/user/needs_help.json"
#Ember.$.post("#{$data_host}/user/needs_help.json").then (res) =>
#@set('list.needs_help', true) # also done by faye
error: (error, transition, klass)->
message = null
@@ -53,7 +53,48 @@ App.ApplicationRoute = Ember.Route.extend
$log
action: 'applicationerror'
error: error.message
selectQr: (table)->
@get('controller').secured ->
appcontroller = @
$.getJSON( "#{$data_host}/user/table_info.json?table_id=#{table._id}").then (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._id
#nothing has changed, show product list
@redirect_to 'table', table._id
else if res.current_table_id != 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
@send 'confirm',
title: t('move_table.confirmation_title')
body: t('move_table.confirmation_body')
ok: =>
Ember.$.post "#{$data_host}/user/move_table.json", table_id: table._id, (res2)=>
if res2.occupied
@redirect_to 'user_root', message: 'move_table.cannot_move_to_occupied_tabe'
else
# Now we can move table
Qstorage.setItem 'table_id', table._id
@redirect_to 'table', table._id, message: 'move_table.moved_to_another_table'
cancel: =>
@redirect_to 'table', res.current_table_id
else
@redirect_to 'table', table._id
, (error)->
if error.status is 404
message = 'table_not_found'
else
message = 'general_error'
appcontroller.redirect_to 'index', message: message
scanQr: ->
<% if Rails.env.user_app? %>
ar = @
@@ -68,7 +109,9 @@ App.ApplicationRoute = Ember.Route.extend
table_id_index = result.text.indexOf('s?t=');
if table_id_index > -1
table_id = result.text.substr(table_id_index + 4);
ar.transitionTo 'table', table_id
# ar.transitionTo 'table', table_id
# ar.actions.selectQr.call(ar, table: {_id: table_id})
ar.send('selectQr', _id: table_id)
else
ar.transitionTo('index').then (route)->
route.get('controller.controllers.application').set 'notice', "we got a barcode: '#{result.text}' but cannot extract a table id"
@@ -85,6 +128,5 @@ App.ApplicationRoute = Ember.Route.extend
ar.transitionTo('index').then (route)->
route.get('controller.controllers.application').set 'notice', "scanning failed: #{error}"
<% else %>
# @transitionTo 'table', 'abc'
@transitionTo 'select_qrcode'
<% end %>