Supplier main board section selector

This commit is contained in:
2013-12-11 18:31:32 +01:00
parent 8aede39b27
commit 391c8a7613
15 changed files with 58 additions and 18 deletions
@@ -1,3 +1,3 @@
Qsupplier.App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#app'
rootElement: '#ember-app-container'
@@ -0,0 +1,4 @@
Qsupplier.App.ApplicationController = Ember.Controller.extend
init: ->
#@set 'supplier', @store.createRecord('supplier', name: 'kkkl')
@set 'supplier', @store.find('supplier', 'current')
@@ -1,17 +1,18 @@
Qsupplier.App.IndexController = Ember.ObjectController.extend
needs: ['application']
active_lists: (->
if @get('sectionId')
@get('lists').filter (l)=>( l.get('section.id') == @get('sectionId') && l.get('state') == 'active' )
if @get('active_section_id')
@get('lists').filter (l)=>( l.get('section.id') == @get('active_section_id') && l.get('state') == 'active' )
else
@get('lists').filterProperty('state', 'active')
).property('lists.@each.state', 'sectionId')
).property('lists.@each.state', 'active_section_id')
active_orders: (->
if @get('sectionId')
@get('orders').filter (o)=>( o.get('section.id') == @get('sectionId') && o.get('needs_supplier_attention') )
if @get('active_section_id')
@get('orders').filter (o)=>( o.get('section.id') == @get('active_section_id') && o.get('needs_supplier_attention') )
else
@get('orders').filter (o)->( o.get('needs_supplier_attention') )
).property('orders.@each.state', 'sectionId')
).property('orders.@each.state', 'active_section_id')
markListAsHelped: (id)->
if list = Qsupplier.App.List.findCached(id)
@@ -30,4 +31,3 @@ Qsupplier.App.IndexController = Ember.ObjectController.extend
$.post('/supplier/mark_order_in_process', order_id: id)
if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'active')
sectionId: ''
@@ -0,0 +1,3 @@
attr = DS.attr
Qsupplier.App.Supplier = DS.Model.extend
name: attr 'string'
@@ -11,9 +11,10 @@ Qsupplier.App.IndexRoute = Ember.Route.extend
# use filter to create a scope on all the records
lists: @store.filter 'list', -> true
orders: @store.filter 'order', -> true
sections: @store.find 'section'
setupController: (controller, model)->
controller.set('model', model)
$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
#$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
#controller.set 'lists', @store.all('list')
#controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active')
#controller.set 'orders', Qsupplier.App.Order.all()
@@ -1,4 +1,7 @@
.page-header
div.pull-right
'{{view 'Qsupplier.App.HomeSectionSelectorView' content=controller.sections prompt=controllers.application.supplier.name}}
'{{view 'Qsupplier.App.HomeSectionJumperView'}}
h3 {{t 'active_lists.title'}}
.well
table.active-lists-table.table
@@ -0,0 +1,6 @@
Qsupplier.App.HomeSectionJumperView = Ember.View.extend
tagName: 'a'
attributeBindings: ['href']
href: (-> Routes.suppliers_section_path(@get('controller.active_section_id') || 'nothing')).property('controller.active_section_id')
isVisible: (-> !!@get('controller.active_section_id') ).property('controller.active_section_id')
template: Ember.Handlebars.compile('=>')
@@ -0,0 +1,8 @@
HomeSectionOption = Ember.SelectOption.extend
select_label: (-> "- #{@get('content.title')}").property('content.title')
Qsupplier.App.HomeSectionSelectorView = Ember.Select.extend
classNames: 'section_selector'
optionView: HomeSectionOption
valueBinding: 'controller.active_section_id'
optionValuePath: 'content.id'
optionLabelPath: 'select_label'
@@ -146,7 +146,7 @@ root.Qsupplier=
)
load_active_lists: () ->
$.get('/supplier/active_lists.json?section_id='+($('#section_selector').val() || ''), (res) =>
$.get('/supplier/active_lists.json?section_id='+($('.section_selector').val() || ''), (res) =>
body = $('#active-lists-table tbody')
body.find('tr').remove()
foot = $('#active-lists-table tfoot')
@@ -161,7 +161,7 @@ root.Qsupplier=
)
load_active_orders: () ->
$.get('/supplier/active_orders.json?section_id='+($('#section_selector').val() || ''), (res) =>
$.get('/supplier/active_orders.json?section_id='+($('.section_selector').val() || ''), (res) =>
body = $('#active-orders-table tbody')
body.html('')
foot = $('#active-orders-table tfoot')