User app error handling upgrades

This commit is contained in:
2014-08-25 16:56:30 +02:00
parent 7a16650129
commit 1eeda440ab
11 changed files with 86 additions and 6 deletions
@@ -0,0 +1,87 @@
App.ApplicationRoute = Ember.Route.extend
setupController: (controller)->
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('order')) # does not work (yet)
@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
controller.secured ->
faye = new Faye.Client($event_host)
user_id = Qstorage.getItem('user_id')
faye.subscribe "/user/"+user_id, (e)=>
console.log e
@events[e.event].call(@, e.data) if @events[e.event]
@setCurrentList()
unauthorized: ->
Qstorage.setItem('auth_token', '')
@controllerFor('application').set 'list', null
App.obtain_token(t('messages.unauthorized'))
@controllerFor('application').redirect_to 'index', message: 'unauthorized'
actions:
openModal: (modalName, model)->
@controllerFor(modalName).set('model', model)
@render modalName,
into: 'application'
outlet: 'modal'
closeModal: ->
@disconnectOutlet
outlet: 'modal'
parentView: 'application'
confirm: (options = {})->
@send 'openModal', 'modal_confirm', Ember.Object.create
title: options.title
body: options.body
cancel: options.cancel
ok: options.ok
listNeedsPayment: ->
@get('controller').secured ->
Ember.$.post '/user/list_needs_payment.json'
#Ember.$.post('/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) =>
#@set('list.needs_help', true) # also done by faye
error: (error, transition, klass)->
message = null
if error.status is 404
if klass.routeName is 'table'
message = t('errors.404.model.message', model: t("models.#{klass.routeName}"), id: transition.state.params.table.table_id)
else
message = t('errors.404.general.message')
@transitionTo('index').then (route)->
route.get('controller.controllers.application').set 'notice', message
scanQr: ->
<% if Rails.env.user_app? %>
ar = @
scanner = cordova.require("cordova/plugin/BarcodeScanner")
scanner.scan (result)->
if result.cancelled
ar.transitionTo('index')
$log
action: 'qrscan'
result: 'cancel'
else
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
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"
$log
action: 'qrscan'
error: 'cannot extract table id'
info: result.text
, (error)->
$log
action: 'qrscan'
error: 'scan failed'
info: error
ar.transitionTo('index').then (route)->
route.get('controller.controllers.application').set 'notice', "scanning failed: #{error}"
<% else %>
# @transitionTo 'table', 'abc'
@transitionTo 'select_qrcode'
<% end %>