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
    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
