Order cycle interface may update or update and close

This commit is contained in:
Rohan Mitchell
2015-11-17 10:30:55 +11:00
parent efa7c215e2
commit 29bfac5f54
11 changed files with 39 additions and 39 deletions

View File

@@ -74,9 +74,8 @@ angular.module('admin.orderCycles')
$scope.removeDistributionOfVariant = (variant_id) ->
OrderCycle.removeDistributionOfVariant(variant_id)
$scope.submit = (event) ->
event.preventDefault()
OrderCycle.create()
$scope.submit = (destination) ->
OrderCycle.create(destination)
])
.controller('AdminEditOrderCycleCtrl', ['$scope', '$filter', '$location', 'OrderCycle', 'Enterprise', 'EnterpriseFee', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee) ->
@@ -155,9 +154,8 @@ angular.module('admin.orderCycles')
$scope.removeDistributionOfVariant = (variant_id) ->
OrderCycle.removeDistributionOfVariant(variant_id)
$scope.submit = (event) ->
event.preventDefault()
OrderCycle.update()
$scope.submit = (destination) ->
OrderCycle.update(destination)
])
.config(['$httpProvider', ($httpProvider) ->

View File

@@ -39,7 +39,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl"
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
$scope.submit = (event) ->
event.preventDefault()
$scope.submit = (destination) ->
OrderCycle.mirrorIncomingToOutgoingProducts()
OrderCycle.create()
OrderCycle.create(destination)

View File

@@ -32,7 +32,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl",
$event.preventDefault()
OrderCycle.removeCoordinatorFee(index)
$scope.submit = (event) ->
event.preventDefault()
$scope.submit = (destination) ->
OrderCycle.mirrorIncomingToOutgoingProducts()
OrderCycle.update()
OrderCycle.update(destination)

View File

@@ -123,19 +123,19 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window) -
this.order_cycle
create: ->
create: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc.$create (data) ->
if data['success']
$window.location = '/admin/order_cycles'
$window.location = destination
else
console.log('Failed to create order cycle')
update: ->
update: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc.$update {order_cycle_id: this.order_cycle.id}, (data) ->
if data['success']
$window.location = '/admin/order_cycles'
$window.location = destination
else
console.log('Failed to update order cycle')

View File

@@ -62,10 +62,8 @@ module Admin
if @order_cycle.update_attributes(params[:order_cycle])
OpenFoodNetwork::OrderCycleFormApplicator.new(@order_cycle, spree_current_user).go!
flash[:notice] = 'Your order cycle has been updated.'
format.html { redirect_to admin_order_cycles_path }
format.json { render :json => {:success => true} }
else
format.html
format.json { render :json => {:success => false} }
end
end

View File

@@ -43,7 +43,11 @@
= f.submit 'Add distributor', 'ng-click' => 'addDistributor($event)'
.actions
= f.submit @order_cycle.new_record? ? 'Create' : 'Update', 'ng-disabled' => '!loaded()'
- 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 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

View File

@@ -21,9 +21,13 @@
= render 'coordinator_fees', f: f
.actions
= f.submit @order_cycle.new_record? ? 'Create' : 'Update', 'ng-disabled' => '!loaded()'
- 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 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...

View File

@@ -8,7 +8,7 @@
- ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl'
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, 'ng-submit' => 'submit($event)'} do |f|
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {'class' => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f|
- if order_cycles_simple_form
= render 'simple_form', f: f
- else

View File

@@ -3,7 +3,7 @@
- ng_controller = order_cycles_simple_form ? 'AdminSimpleCreateOrderCycleCtrl' : 'AdminCreateOrderCycleCtrl'
= admin_inject_order_cycle_instance
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, 'ng-submit' => 'submit($event)'} do |f|
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f|
- if order_cycles_simple_form
= render 'simple_form', f: f
- else

View File

@@ -339,7 +339,7 @@ feature %q{
select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
# And I click Update
click_button 'Update'
click_button 'Update and Close'
# Then my order cycle should have been updated
page.should have_content 'Your order cycle has been updated.'
@@ -879,7 +879,7 @@ feature %q{
click_button 'Add coordinator fee'
select 'that fee', from: 'order_cycle_coordinator_fee_0_id'
click_button 'Update'
click_button 'Update and Close'
# Then my order cycle should have been updated
page.should have_content 'Your order cycle has been updated.'

View File

@@ -156,9 +156,8 @@ describe 'OrderCycle controllers', ->
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
it 'Submits the order cycle via OrderCycle create', ->
eventMock = { preventDefault: -> }
scope.submit(eventMock)
expect(OrderCycle.create).toHaveBeenCalled()
scope.submit('/admin/order_cycles')
expect(OrderCycle.create).toHaveBeenCalledWith('/admin/order_cycles')
describe 'AdminEditOrderCycleCtrl', ->
ctrl = null
@@ -319,9 +318,8 @@ describe 'OrderCycle controllers', ->
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
it 'Submits the order cycle via OrderCycle update', ->
eventMock = { preventDefault: -> }
scope.submit(eventMock)
expect(OrderCycle.update).toHaveBeenCalled()
scope.submit('/admin/order_cycles')
expect(OrderCycle.update).toHaveBeenCalledWith('/admin/order_cycles')
describe 'OrderCycle services', ->
@@ -760,16 +758,16 @@ describe 'OrderCycle services', ->
expect(OrderCycle.order_cycle.exchanges).toBeUndefined()
describe 'creating an order cycle', ->
it 'redirects to the order cycles page on success', ->
it 'redirects to the destination page on success', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
$httpBackend.expectPOST('/admin/order_cycles.json', {
order_cycle: 'this is the submit data'
}).respond {success: true}
OrderCycle.create()
OrderCycle.create('/destination/page')
$httpBackend.flush()
expect($window.location).toEqual('/admin/order_cycles')
expect($window.location).toEqual('/destination/page')
it 'does not redirect on error', ->
OrderCycle.order_cycle = 'this is the order cycle'
@@ -778,21 +776,21 @@ describe 'OrderCycle services', ->
order_cycle: 'this is the submit data'
}).respond {success: false}
OrderCycle.create()
OrderCycle.create('/destination/page')
$httpBackend.flush()
expect($window.location).toEqual(undefined)
describe 'updating an order cycle', ->
it 'redirects to the order cycles page on success', ->
it 'redirects to the destination page on success', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
$httpBackend.expectPUT('/admin/order_cycles.json', {
order_cycle: 'this is the submit data'
}).respond {success: true}
OrderCycle.update()
OrderCycle.update('/destination/page')
$httpBackend.flush()
expect($window.location).toEqual('/admin/order_cycles')
expect($window.location).toEqual('/destination/page')
it 'does not redirect on error', ->
OrderCycle.order_cycle = 'this is the order cycle'
@@ -801,7 +799,7 @@ describe 'OrderCycle services', ->
order_cycle: 'this is the submit data'
}).respond {success: false}
OrderCycle.update()
OrderCycle.update('/destination/page')
$httpBackend.flush()
expect($window.location).toEqual(undefined)