Files
mozo-backend/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb
T

95 lines
4.4 KiB
Plaintext

App.ApplicationRoute = Ember.Route.extend
beforeModel: ->
# Preload only active lists and orders
@supplier = @store.push 'supplier', supplier_object
@product_categories = @store.find 'product_category'
@sections = @store.find 'section'
Ember.RSVP.all([@product_categories, @sections]).then (results)=>
@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
# @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
controller.set 'modal_options', $.extend(defaultModalOptions, 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
events:
list_needs_help: (data) -> list.markNeedsHelp() if list = @store.getById('list', data.id)
list_needs_payment: (data) -> list.markNeedsPayment() if list = @store.getById('list', data.id)
list_is_paid: (data) -> list.markIsPaid() if list = @store.getById('list', data.id)
list_update: (data) ->
@store.pushPayload('list', data)
# Fix broken reference. TODO: remove this when single source of
# truth is working
@store.findById('list', e.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.markClosed() if list = @store.getById('list', data.id)
list_helped: (data) -> list.markHelped() 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.markClosed() if order = @store.getById('order', data.id)
order_being_processed: (data) -> order.markActive() if order = @store.getById('order', data.id)
order_being_delivered: (data) -> order.markDelivered() if order = @store.getById('order', data.id)
order_cancelled: (data) -> order.markCancelled() 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()