Refactor for authorization sanity
This commit is contained in:
@@ -15,6 +15,7 @@ App.ApplicationController = Ember.Controller.extend
|
||||
#@set 'supplier', null
|
||||
#@store.find('supplier', 'current').then success, error
|
||||
# @set 'supplier', @store.find('supplier', supplier_id)
|
||||
current_employee: (-> @get('employee') ).property('employee')
|
||||
actions:
|
||||
signOut: ->
|
||||
window.location = Routes.destroy_employee_session_path()
|
||||
|
||||
@@ -34,16 +34,19 @@ App.IndexController = Ember.ObjectController.extend
|
||||
toggleDashboardOrders: ->@set 'show_orders', !@get('show_orders')
|
||||
|
||||
markOrderDelivered: (id)->
|
||||
$.post('/supplier/order_is_delivered', order_id: id)
|
||||
#$.post('/supplier/order_is_delivered', order_id: id)
|
||||
Ember.$.post Routes.mark_delivered_suppliers_order_path(id)
|
||||
if order = App.Order.findCached(id)
|
||||
order.set('state', 'delivered')
|
||||
|
||||
markOrderActive: (id)->
|
||||
$.post('/supplier/mark_order_in_process', order_id: id)
|
||||
#$.post('/supplier/mark_order_in_process', order_id: id)
|
||||
Ember.$.post Routes.mark_in_process_suppliers_order_path(id)
|
||||
if order = App.Order.findCached(id)
|
||||
order.set('state', 'active')
|
||||
cancelOrder: (order)->
|
||||
$.post "/supplier/orders/#{order.id}/cancel"
|
||||
#$.post "/supplier/orders/#{order.id}/cancel"
|
||||
Ember.$.post Routes.cancel_suppliers_order_path(order.id)
|
||||
order.set 'state', 'cancelled'
|
||||
showList: (id)->
|
||||
@transitionToRoute 'list', id
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Ember.Handlebars.registerHelper 'can', (operation, resource, options)->
|
||||
if operation is 'manage' and @get('controllers.application.employee_settings.manager')
|
||||
if operation is 'manage' and @get('current_employee.manager')
|
||||
options.fn @
|
||||
else
|
||||
options.inverse @
|
||||
|
||||
@@ -2,6 +2,8 @@ attr = DS.attr
|
||||
App.Employee= DS.Model.extend Ember.Validations.Mixin,
|
||||
name: attr 'string'
|
||||
email: attr 'string'
|
||||
manager: attr 'boolean', defaultValue: false
|
||||
active: attr 'boolean', defaultValue: true
|
||||
|
||||
validations:
|
||||
name: {presence: true}
|
||||
|
||||
@@ -45,11 +45,11 @@ App.List = DS.Model.extend
|
||||
).property('state', 'orders.@each.state')
|
||||
close: ->
|
||||
@markClosed()
|
||||
$.post Routes.supplier_close_list_path(), list_id: @id
|
||||
$.post Routes.close_suppliers_list_pat(@id)
|
||||
|
||||
is_helped: ->
|
||||
@markHelped()
|
||||
$.post Routes.supplier_mark_list_as_helped_path(), list_id: @id
|
||||
$.post Routes.mark_helped_suppliers_list_path(@id)
|
||||
remove_needs_payment: ->
|
||||
@set 'needs_payment', false
|
||||
$.post Routes.supplier_remove_list_needs_payment_path(), list_id: @id
|
||||
|
||||
@@ -11,6 +11,7 @@ ControllerExtensions = Ember.Mixin.create
|
||||
@send "openModal", name, options
|
||||
|
||||
all_sections: (-> @store.all('section')).property()
|
||||
current_employee: (-> @get('controllers.application.employee') ).property('controllers.application.employee')
|
||||
|
||||
Ember.Controller.reopen ControllerExtensions
|
||||
Ember.ArrayController.reopen ControllerExtensions
|
||||
|
||||
@@ -14,7 +14,6 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
setupController: (controller)->
|
||||
controller.set 'supplier', @supplier
|
||||
controller.set 'employee', @employee
|
||||
controller.set 'employee_settings', Ember.Object.create(employee_settings)
|
||||
# @set 'supplier', @store.find('supplier', supplier_id)
|
||||
#controller.set 'sections', @sections
|
||||
#controller.set 'product_categories', @product_categories
|
||||
|
||||
@@ -2,14 +2,15 @@ aside.side-menu
|
||||
ul
|
||||
li.title: h3 Menu
|
||||
li.supplier-name= supplier.name
|
||||
if supplier.open
|
||||
li: a.supplier-close-shop{action "markSupplierClosed"}= t 'supplier.close_for_orders'
|
||||
else
|
||||
li: a.supplier-open-shop{action "markSupplierOpen"}= t 'supplier.open_for_orders'
|
||||
li
|
||||
=link-to 'settings' class="supplier-settings-link"
|
||||
span.settings-icon
|
||||
span= t 'supplier.settings'
|
||||
can manage supplier
|
||||
if supplier.open
|
||||
li: a.supplier-close-shop{action "markSupplierClosed"}= t 'supplier.close_for_orders'
|
||||
else
|
||||
li: a.supplier-open-shop{action "markSupplierOpen"}= t 'supplier.open_for_orders'
|
||||
li
|
||||
=link-to 'settings' class="supplier-settings-link"
|
||||
span.settings-icon
|
||||
span= t 'supplier.settings'
|
||||
li class="supplier-sign-out-link"
|
||||
a{action "signOut"}
|
||||
span.sign-out-icon
|
||||
|
||||
Reference in New Issue
Block a user