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 Qsupplier.App = Ember.Application.create
LOG_TRANSITIONS: true 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 Qsupplier.App.IndexController = Ember.ObjectController.extend
needs: ['application']
active_lists: (-> active_lists: (->
if @get('sectionId') if @get('active_section_id')
@get('lists').filter (l)=>( l.get('section.id') == @get('sectionId') && l.get('state') == 'active' ) @get('lists').filter (l)=>( l.get('section.id') == @get('active_section_id') && l.get('state') == 'active' )
else else
@get('lists').filterProperty('state', 'active') @get('lists').filterProperty('state', 'active')
).property('lists.@each.state', 'sectionId') ).property('lists.@each.state', 'active_section_id')
active_orders: (-> active_orders: (->
if @get('sectionId') if @get('active_section_id')
@get('orders').filter (o)=>( o.get('section.id') == @get('sectionId') && o.get('needs_supplier_attention') ) @get('orders').filter (o)=>( o.get('section.id') == @get('active_section_id') && o.get('needs_supplier_attention') )
else else
@get('orders').filter (o)->( o.get('needs_supplier_attention') ) @get('orders').filter (o)->( o.get('needs_supplier_attention') )
).property('orders.@each.state', 'sectionId') ).property('orders.@each.state', 'active_section_id')
markListAsHelped: (id)-> markListAsHelped: (id)->
if list = Qsupplier.App.List.findCached(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) $.post('/supplier/mark_order_in_process', order_id: id)
if order = Qsupplier.App.Order.findCached(id) if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'active') 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 # use filter to create a scope on all the records
lists: @store.filter 'list', -> true lists: @store.filter 'list', -> true
orders: @store.filter 'order', -> true orders: @store.filter 'order', -> true
sections: @store.find 'section'
setupController: (controller, model)-> setupController: (controller, model)->
controller.set('model', 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', @store.all('list')
#controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active') #controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active')
#controller.set 'orders', Qsupplier.App.Order.all() #controller.set 'orders', Qsupplier.App.Order.all()
@@ -1,4 +1,7 @@
.page-header .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'}} h3 {{t 'active_lists.title'}}
.well .well
table.active-lists-table.table 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: () -> 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 = $('#active-lists-table tbody')
body.find('tr').remove() body.find('tr').remove()
foot = $('#active-lists-table tfoot') foot = $('#active-lists-table tfoot')
@@ -161,7 +161,7 @@ root.Qsupplier=
) )
load_active_orders: () -> 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 = $('#active-orders-table tbody')
body.html('') body.html('')
foot = $('#active-orders-table tfoot') foot = $('#active-orders-table tfoot')
+6
View File
@@ -11,6 +11,12 @@ class SupplierController < ApplicationController
@supplier = current_supplier @supplier = current_supplier
end end
def current
respond_to do |format|
format.json { render json: {supplier: current_supplier.as_json} }
end
end
# POST /supplier/settings # POST /supplier/settings
def update def update
@supplier = current_supplier @supplier = current_supplier
+11
View File
@@ -88,6 +88,17 @@ class Supplier
save save
end end
def serializable_hash(*)
{
id: id,
name: name
}
end
def as_json(*)
serializable_hash
end
# Find a user by its confirmation token and try to confirm it. # Find a user by its confirmation token and try to confirm it.
# If no user is found, returns a new user with an error. # If no user is found, returns a new user with an error.
+1 -1
View File
@@ -71,7 +71,7 @@ html lang="en"
.row= yield :row .row= yield :row
.row .row
.span12 .span12
#app #ember-app-container
script#alert-template[type="text/html"]= mustache_template 'supplier/alert' script#alert-template[type="text/html"]= mustache_template 'supplier/alert'
= yield :footer = yield :footer
javascript: javascript:
-3
View File
@@ -1,8 +1,5 @@
- content_for :head do - content_for :head do
= javascript_include_tag 'supplier/app/application' = javascript_include_tag 'supplier/app/application'
.pull-right
= select_tag('current_section_selector', options_for_select([[current_supplier.name, '']] + current_supplier.sections.map{|s| ["- #{s.title}", s.id]}, params[:section_id]), id: :section_selector)
a.icon-arrow-right.go-to-tables-view.hide href=tables_view_suppliers_section_path('0000')
- content_for :footer do - content_for :footer do
javascript: javascript:
$(function(){ $(function(){
+1
View File
@@ -61,6 +61,7 @@ Qwaiter::Application.routes.draw do
get '/user/obtain_token' => 'user#obtain_token', as: :user_obtain_token get '/user/obtain_token' => 'user#obtain_token', as: :user_obtain_token
post '/user/obtain_token' => 'user#obtain_token', constraints: {format: :json} post '/user/obtain_token' => 'user#obtain_token', constraints: {format: :json}
get '/supplier/suppliers/current' => 'supplier#current' #ember
#match '/show_products' => 'dashboard#show_products', as: :user_products #match '/show_products' => 'dashboard#show_products', as: :user_products
@@ -108,12 +108,12 @@ step "I should see the new list and new order but not the list and order" do
end end
step "I select the section in the supplier dashboard" do step "I select the section in the supplier dashboard" do
find(%|#section_selector option[value="#{@section.id}"]|).select_option find(%|.section_selector option[value="#{@section.id}"]|).select_option
end end
step "I select the new section in the supplier dashboard" do step "I select the new section in the supplier dashboard" do
find(%|#section_selector option[value="#{@new_section.id}"]|).select_option find(%|.section_selector option[value="#{@new_section.id}"]|).select_option
end end
step "I reset the section selector in the supplier dashboard" do step "I reset the section selector in the supplier dashboard" do
find(%|#section_selector option[value=""]|).select_option find(%|.section_selector option[value=""]|).select_option
end end