App.OrdersDisplayController = Ember.ObjectController.extend
  needs: ['application']
  active_section: null
  sections: (-> @store.all('section') ).property()
  orders: Ember.computed 'model.@each', 'active_section.id', ->
    orders = @get('model').filterBy('needs_supplier_attention')
    orders = orders.filterBy('section.id', id) if id = @get('active_section.id')
    orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
  activeSectionDidChange: Ember.observer 'active_section.id', ->
    container = Ember.$('.orders-display-nav')
    container.find('dd').removeClass('active')
    if id = @get('active_section.id')
      container.find("[data-section='#{id}']").addClass 'active'
    else
      container.find('[data-section="all"]').addClass 'active'
  actions:
    clearActiveSection: ->
      @set 'active_section', null
    setActiveSection: (section)->
      @set 'active_section', section
