When order cycle is updated, display message instead of reloading the page

This commit is contained in:
Rohan Mitchell
2015-11-17 11:29:25 +11:00
parent 29bfac5f54
commit 9fef0a9909
7 changed files with 27 additions and 6 deletions

View File

@@ -84,6 +84,7 @@ angular.module('admin.orderCycles')
$scope.supplied_products = Enterprise.supplied_products
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id)
$scope.OrderCycle = OrderCycle
$scope.order_cycle = OrderCycle.load(order_cycle_id)
$scope.loaded = ->

View File

@@ -4,6 +4,7 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl",
$scope.enterprises = Enterprise.index(order_cycle_id: $scope.orderCycleId())
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.orderCycleId())
$scope.OrderCycle = OrderCycle
$scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) =>
$scope.init()

View File

@@ -1,4 +1,4 @@
angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window) ->
angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $timeout) ->
OrderCycle = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
'index': { method: 'GET', isArray: true}
'new' : { method: 'GET', params: { action_name: "new" } }
@@ -127,15 +127,18 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window) -
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc.$create (data) ->
if data['success']
$window.location = destination
$window.location = destination
else
console.log('Failed to create order cycle')
update: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc.$update {order_cycle_id: this.order_cycle.id}, (data) ->
oc.$update {order_cycle_id: this.order_cycle.id}, (data) =>
if data['success']
$window.location = destination
if destination?
$window.location = destination
else
this.displayMessage 'Your order cycle has been updated.'
else
console.log('Failed to update order cycle')
@@ -200,4 +203,11 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window) -
for id, active of incoming.variants
outgoing.variants[id] = active
displayMessage: (message) ->
this.message = message
$timeout =>
this.message = null
, 5000
})

View File

@@ -107,6 +107,10 @@ form.order_cycle {
margin-top: 3em;
}
.message {
font-weight: bold;
}
/* This styling makes it easier to read the debug info at the same time as working with the
* interface, but it breaks the tests. Enable when you need it.
#order-cycles-debug {

View File

@@ -46,12 +46,13 @@
- if @order_cycle.new_record?
= f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
- else
= f.submit 'Update', 'ng-click' => "submit('#{main_app.edit_admin_order_cycle_path(@order_cycle)}')", 'ng-disabled' => '!loaded()'
= f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()'
= f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
%span{'ng-show' => 'loaded()'}
or
= link_to 'Cancel', main_app.admin_order_cycles_path
%span{'ng-hide' => 'loaded()'} Loading...
%h6.message {{ OrderCycle.message }}
- unless Rails.env.production?

View File

@@ -24,10 +24,11 @@
- if @order_cycle.new_record?
= f.submit 'Create', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
- else
= f.submit 'Update', 'ng-click' => "submit('#{main_app.edit_admin_order_cycle_path(@order_cycle)}')", 'ng-disabled' => '!loaded()'
= f.submit 'Update', 'ng-click' => "submit(null)", 'ng-disabled' => '!loaded()'
= f.submit 'Update and Close', 'ng-click' => "submit('#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()'
%span{'ng-show' => 'loaded()'}
or
= link_to 'Cancel', main_app.admin_order_cycles_path
%span{'ng-hide' => 'loaded()'} Loading...
%h6.message {{ OrderCycle.message }}

View File

@@ -879,6 +879,9 @@ feature %q{
click_button 'Add coordinator fee'
select 'that fee', from: 'order_cycle_coordinator_fee_0_id'
# When I update, or update and close, both work
click_button 'Update'
page.should have_content 'Your order cycle has been updated.'
click_button 'Update and Close'
# Then my order cycle should have been updated