Emberfy supplier progress

This commit is contained in:
2014-12-01 14:54:15 +01:00
parent c714a7a74d
commit 9ef3d4b725
15 changed files with 131 additions and 315 deletions
@@ -1,4 +1,5 @@
#= require_self
#= require handlebars
#= require ember
#= require ember-data
#= require_directory ./modifications
@@ -8,7 +8,7 @@ App.MenuController = Ember.ObjectController.extend
if filter_day = @get('filter.day')
list = list.filterBy "active_on_#{filter_day}"
if filter_minute = @get('filter.minute_of_day')
list = list.filter (r) -> r.get('full_day') or (filter_minute > r.get('start_from') and filter_minute < r.get('end_on'))
list = list.filter (r) -> r.get('full_day') or (filter_minute >= r.get('start_from') and filter_minute <= r.get('end_on'))
list.sortBy('position')
).property('product_categories.@each', 'product_categories.@each.position', 'filter.day', 'filter.minute_of_day')
@@ -16,6 +16,8 @@ App.Supplier = DS.Model.extend
lng: attr 'number'
week_starts_on_monday: attr 'boolean'
product_categories: DS.hasMany 'product_category'
orders_in_process_count: attr('number')
orders_placed_count: attr('number')
close: ->
$.post Routes.supplier_mark_as_closed_path(), =>
@@ -1,55 +0,0 @@
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
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.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
@@ -0,0 +1,93 @@
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.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()
@@ -13,17 +13,15 @@ header.top-menu
= t 'models.plural.table'
= link-to "lists" class="top-menu-lists"
= t 'models.plural.list'
section.extra-info
.supplier-info-row
.supplier-name= supplier.name
.table-number
.extra-info
.supplier-info-row
.counter.supplier-orders-placed-count
span.supplier-orders-placed-count-number= supplier.orders_placed_count
span.supplier-orders-placed-count-icon
= supplier.orders_placed_count
span.orders-placed-count-icon
.supplier-info-row
.counter.supplier-orders-in-process-count
span.supplier-orders-in-process-count-number= supplier.orders_in_process_count
span.supplier-orders-in-process-count-icon
= supplier.orders_in_process_count
span.orders-in-process-count-icon
aside.side-menu
ul
li.title: h3 Menu
@@ -1,7 +1,6 @@
App.ApplicationView = Ember.View.extend
classNames: ['application-view']
didInsertElement: ->
Qsupplier.watch_events()
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')