Files
mozo-backend/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb
T
2015-03-01 18:34:57 +01:00

144 lines
6.6 KiB
Plaintext

App.ApplicationRoute = Ember.Route.extend
beforeModel: ->
# Preload only active lists and orders
@supplier = @store.push 'supplier', supplier_object
@employee = @store.push 'employee', employee_object
#@product_categories = @store.find 'product_category'
#@sections = @store.find 'section'
#Ember.RSVP.all([@product_categories, @sections]).then (results)=>
@supplier.reload().then =>
@store.find('list', state: 'active') #.then (lists) -> lists.invoke('get', 'table')
#@lists = @store.all 'list'
# product_categories = controller.set 'product_categories', @store.all('product_category')
#@store.find 'order', state: 'active' included in list
setupController: (controller)->
controller.set 'supplier', @supplier
controller.set 'employee', @employee
# @set 'supplier', @store.find('supplier', supplier_id)
#controller.set 'sections', @sections
#controller.set 'product_categories', @product_categories
faye = new Faye.Client(event_host)
faye.subscribe "/supplier/#{supplier_object.id}", (e)=>
@set('supplier.orders_placed_count', e.data.supplier_orders_placed_count) if e.data.supplier_orders_placed_count?
@set('supplier.orders_in_process_count', e.data.supplier_orders_in_process_count) if e.data.supplier_orders_in_process_count?
@events[e.event].call(@, e.data) if @events[e.event]
<% if Rails.env.test? %>
window.faye_log ||= []
faye_message = {}
faye_message[e.event] = JSON.parse(JSON.stringify(e.data))
faye_log.push faye_message
<% elsif Rails.env.development? %>
console.log "Event: #{e.event}"
console.log e.data
<% end %>
actions:
# openModal: (modalName, model, options={})->
# controller_name = options.controller || modalName
# controller = @controllerFor(controller_name)
# controller.set 'model', model
# controller.set 'modal_options', options
# @render modalName,
# into: 'application'
# outlet: 'modal'
# controller: controller_name
openModal: (modalName, options={})->
controller_name = options.controller || modalName
try
controller = @controllerFor("modals/#{modalName}")
catch error
controller = @controllerFor("modals/base")
controller ||= @controllerFor("modals/base")
controller.set 'model', options.model
defaultModalOptions =
closeOnOverlay: true
closeOnModalClick: false
modal_options = Ember.Object.create($.extend(defaultModalOptions, options))
controller.set 'modal_options', modal_options
@render "modals/#{modalName}",
into: 'application'
outlet: 'modal'
view: 'modal'
controller: controller
closeModal: ->
@disconnectOutlet
outlet: 'modal'
parentView: 'application'
confirm: (options = {})->
@send 'openModal', 'confirm',
model: Ember.Object.create
title: options.title
body: options.body
cancel: options.cancel
ok: options.ok
newOrder: (order_id)->
@store.findById('order', order_id).then (order)=>
controller = @controllerFor('application')
return if controller.get('active_section.id') and order.get('section.id') isnt controller.get('active_section.id')
$('body').addClass('new-order')
controller.set 'flash_message', order.get('display_with_table')
setTimeout (-> $('body').removeClass('new-order')), 4000
try ion.sound.play('water_droplet')
showDashboardOrders: (section)->
@controllerFor('application').set 'active_section', section
@transitionTo 'index'
markSupplierClosed: ->
controller = @controllerFor('application')
return unless supplier = controller.get('supplier')
controller.modal 'confirm',
title_path: 'supplier.close_for_orders_confirmation'
model: supplier
ok: -> supplier.close()
markSupplierOpen: ->
return unless supplier = @controllerFor('application').get('supplier')
supplier.open_the_place()
rotateLeft: (record)->
new_rotation = -90 + record.get('rotation')
new_rotation += 360 if new_rotation < 0
record.set 'rotation', new_rotation
rotateRight: (record)->
new_rotation = 90 + record.get('rotation')
new_rotation -= 360 if new_rotation >= 360
record.set 'rotation', new_rotation
editTable: (table)->
@send 'openModal', 'table_edit',
model: table
close: -> table.rollback()
events:
list_needs_help: (data) ->
if list = @store.getById('list', data.id)
list.isNeedingHelp()
controller = @controllerFor('application')
return if controller.get('active_section.id') and list.get('section.id') isnt controller.get('active_section.id')
try ion.sound.play 'bell_ring'
list_needs_payment: (data) ->
if list = @store.getById('list', data.id)
list.isNeedingPayment()
controller = @controllerFor('application')
return if controller.get('active_section.id') and list.get('section.id') isnt controller.get('active_section.id')
try ion.sound.play 'water_droplet_3'
list_is_paid: (data) -> list.isPaid() if list = @store.getById('list', data.id)
list_update: (data) ->
if data.new_order_id
@send 'newOrder', data.new_order_id
@store.pushPayload('list', data)
# Fix broken reference. TODO: remove this when single source of
# truth is working
#@store.findById('list', data.list.id).then (list)->
# list.get('table').then (table)->table.set('active_list', list)
list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list])
list_closed: (data) -> list.isClosed() if list = @store.getById('list', data.id)
list_helped: (data) -> list.isHelped() if list = @store.getById('list', data.id)
remove_list_needs_payment: (data) -> list.set('needs_payment', false) if list = @store.getById('list', data.id)
order_closed: (data) -> order.isClosed() if order = @store.getById('order', data.id)
order_being_processed: (data) -> order.isActive() if order = @store.getById('order', data.id)
order_being_delivered: (data) -> order.isDelivered() if order = @store.getById('order', data.id)
order_cancelled: (data) -> order.isCancelled() if order = @store.getById('order', data.id)
orders_in_process_count: (data) -> @set('supplier.orders_in_process_count', data.count)
orders_placed_count: (data) -> @set('supplier.orders_placed_count', data.count)
#return new Ember.Handlebars.SafeString('<span class="highlight">' + escaped + '</span>');
#"<span class='highlight'>#{escaped}</span>".htmlSafe()