|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
needs: ['product_orders']
|
|
|
|
|
#list: Ember.computed.alias 'globals.list'
|
|
|
|
|
#notice: ''
|
|
|
|
|
actions:
|
|
|
|
|
confirmCancel: ->
|
|
|
|
@@ -10,7 +11,7 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
@set 'globals.notice', ''
|
|
|
|
|
showSupplierStatusInfo: ->
|
|
|
|
|
@modal 'supplier_status_info',
|
|
|
|
|
model: @get('list.supplier')
|
|
|
|
|
model: @get('globals.list.supplier')
|
|
|
|
|
title_path: 'supplier_status_info.title'
|
|
|
|
|
|
|
|
|
|
openDebugger: ->
|
|
|
|
@@ -21,14 +22,14 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
).observes('currentPath')
|
|
|
|
|
events:
|
|
|
|
|
notify: (notification) -> @set 'globals.notice', notification.message
|
|
|
|
|
list_helped: -> @set 'list.needs_help', false
|
|
|
|
|
list_needs_help: -> @set 'list.needs_help', true # incoming from other users
|
|
|
|
|
list_is_paid: -> @set 'list.needs_payment', false
|
|
|
|
|
list_needs_payment: -> @set 'list.needs_payment', true # incoming from other users
|
|
|
|
|
list_helped: -> @set 'globals.list.needs_help', false
|
|
|
|
|
list_needs_help: -> @set 'globals.list.needs_help', true # incoming from other users
|
|
|
|
|
list_is_paid: -> @set 'globals.list.needs_payment', false
|
|
|
|
|
list_needs_payment: -> @set 'globals.list.needs_payment', true # incoming from other users
|
|
|
|
|
list_closed: (data)->
|
|
|
|
|
@transitionToRoute('list', data.id).then =>
|
|
|
|
|
@set 'list.state', 'closed'
|
|
|
|
|
@set 'list', null
|
|
|
|
|
@set 'globals.list.state', 'closed'
|
|
|
|
|
@set 'globals.list', null
|
|
|
|
|
join_request_approved: (data)->
|
|
|
|
|
@setCurrentList -> @transitionToRoute('active_list')
|
|
|
|
|
order_being_processed: (data)->
|
|
|
|
@@ -38,22 +39,22 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
order = @store.all('order').findBy 'id', data.id
|
|
|
|
|
order.set('state', 'delivered') if order
|
|
|
|
|
user_join_request: (data)->
|
|
|
|
|
list = @store.all('list').findBy 'id', data.join_request.list_id
|
|
|
|
|
list = @store.peekRecord('list', data.join_request.list_id)
|
|
|
|
|
user_data = data.users[0]
|
|
|
|
|
user = @store.all('user').findBy 'id', user_data.id
|
|
|
|
|
user = @store.peekRecord('user', user_data.id)
|
|
|
|
|
user = @store.createRecord 'user', user_data unless user
|
|
|
|
|
data.join_request.list = list
|
|
|
|
|
data.join_request.user = user
|
|
|
|
|
join_request = @store.createRecord 'join_request', data.join_request
|
|
|
|
|
@transitionToRoute 'join_requests'
|
|
|
|
|
order_cancelled: (data)->
|
|
|
|
|
if order = @store.all('order').findBy('id', data.id)
|
|
|
|
|
if order = @store.peekRecord('order', data.id)
|
|
|
|
|
order.markCancelled()
|
|
|
|
|
@events.orders_placed_count.call(@, count: data.supplier_orders_placed_count) if data.supplier_orders_placed_count == 0 or data.supplier_orders_placed_count
|
|
|
|
|
@events.orders_in_process_count.call(@, count: data.supplier_orders_in_process_count) if data.supplier_orders_in_process_count == 0 or data.supplier_orders_in_process_count
|
|
|
|
|
join_request_rejected: (data)->
|
|
|
|
|
# Remove join request from connected users
|
|
|
|
|
join_request = @store.all('join_request').findBy 'id', data.id
|
|
|
|
|
join_request = @store.peekRecord('join_request', data.id)
|
|
|
|
|
join_request.eraseRecord() if join_request
|
|
|
|
|
|
|
|
|
|
# Notify requestor in a proper manner
|
|
|
|
@@ -64,7 +65,7 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
@set 'globals.join_request_sent', false
|
|
|
|
|
|
|
|
|
|
join_request_approved: ->
|
|
|
|
|
return if @get('list.id')
|
|
|
|
|
return if @get('globals.list.id') # Not interested when there is an active list
|
|
|
|
|
@setCurrentList ->
|
|
|
|
|
@transitionToRoute('active_list').then =>
|
|
|
|
|
@set 'globals.notice', t('join_request.requestor.join_request_approved')
|
|
|
|
@@ -73,9 +74,9 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
list_changed_table: ->
|
|
|
|
|
@setCurrentList()
|
|
|
|
|
orders_in_process_count: (data)->
|
|
|
|
|
@set 'list.supplier.orders_in_process_count', data.count
|
|
|
|
|
@set 'globals.list.supplier.orders_in_process_count', data.count
|
|
|
|
|
orders_placed_count: (data)->
|
|
|
|
|
@set 'list.supplier.orders_placed_count', data.count
|
|
|
|
|
@set 'globals.list.supplier.orders_placed_count', data.count
|
|
|
|
|
new_order: (data)->
|
|
|
|
|
# return if @store.all('order').findProperty('id', data.order.id)
|
|
|
|
|
@store.pushPayload data
|
|
|
|
@@ -86,7 +87,7 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remove_list_needs_payment: (data)->
|
|
|
|
|
if list = @store.all('list').findBy 'id', data.id
|
|
|
|
|
if list = @store.peekRecord('list', data.id)
|
|
|
|
|
list.set 'needs_payment', false
|
|
|
|
|
setCurrentList: (callback)->
|
|
|
|
|
success = (list)=>
|
|
|
|
@@ -94,10 +95,10 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
|
|
|
|
|
# A list record with id current and with the content of the returned list is created
|
|
|
|
|
# at the moment remove the dummy list, this should be resolved by Ember eventually
|
|
|
|
|
if error_list = @store.all('list').findBy('id', 'current')
|
|
|
|
|
if error_list = @store.peekRecord('list', 'current')
|
|
|
|
|
error_list.eraseRecord()
|
|
|
|
|
#TODO: depricate list on application controller
|
|
|
|
|
@set 'list', list
|
|
|
|
|
#@set 'list', list
|
|
|
|
|
@set 'globals.list', list
|
|
|
|
|
if list.get('join_requests.length')
|
|
|
|
|
@transitionToRoute 'join_requests'
|
|
|
|
@@ -108,11 +109,11 @@ App.ApplicationController = Ember.Controller.extend
|
|
|
|
|
# if jqXHR.status == 404 officially, now assume close list on error
|
|
|
|
|
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
|
|
|
|
#console.log "Error: #{emberError.message}" if emberError.message
|
|
|
|
|
if error_list = @store.all('list').findBy('id', 'current')
|
|
|
|
|
if error_list = @store.peekRecord('list', 'current')
|
|
|
|
|
error_list.eraseRecord()
|
|
|
|
|
@set 'list', null
|
|
|
|
|
@set 'globals.list', null
|
|
|
|
|
switch @currentRouteName
|
|
|
|
|
when 'table' then # nothing
|
|
|
|
|
else @redirect_to 'user_root'
|
|
|
|
|
|
|
|
|
|
@store.find('list', 'current').then(success, error)
|
|
|
|
|
@store.findRecord('list', 'current').then(success, error)
|
|
|
|
|