mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Styling save button for standing order panels, and updating pristineByID array on update/save
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
angular.module("admin.standingOrders").controller "ProductsPanelController", ($scope) ->
|
||||
angular.module("admin.standingOrders").controller "ProductsPanelController", ($scope, StandingOrders) ->
|
||||
$scope.standingOrder = $scope.object
|
||||
$scope.distributor_id = $scope.standingOrder.shop_id
|
||||
$scope.saving = false
|
||||
|
||||
$scope.saved = ->
|
||||
pristine = StandingOrders.pristineByID[$scope.standingOrder.id].standing_line_items
|
||||
return false unless angular.equals($scope.standingOrder.standing_line_items, pristine)
|
||||
true
|
||||
|
||||
$scope.save = ->
|
||||
$scope.saving = true
|
||||
$scope.standingOrder.update().then ->
|
||||
$scope.saving = false
|
||||
, ->
|
||||
$scope.saving = false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, InfoDialog, StatusMessage) ->
|
||||
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, $injector, InfoDialog, StatusMessage) ->
|
||||
errors: {}
|
||||
|
||||
buildItem: (item) ->
|
||||
@@ -14,6 +14,7 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
|
||||
index = @standing_line_items.indexOf(item)
|
||||
if item.id?
|
||||
$http.delete("/admin/standing_line_items/#{item.id}").then (response) =>
|
||||
$injector.get('StandingOrders').afterRemoveItem(@id, item.id) if $injector.has('StandingOrders')
|
||||
@standing_line_items.splice(index,1)
|
||||
, (response) ->
|
||||
InfoDialog.open 'error', response.data.errors[0]
|
||||
@@ -25,6 +26,7 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
|
||||
delete @errors[k] for k, v of @errors
|
||||
@$save().then (response) =>
|
||||
StatusMessage.display 'success', 'Saved'
|
||||
$injector.get('StandingOrders').afterCreate(@id) if $injector.has('StandingOrders')
|
||||
, (response) =>
|
||||
StatusMessage.display 'failure', 'Oh no! I was unable to save your changes.'
|
||||
angular.extend(@errors, response.data.errors)
|
||||
@@ -34,6 +36,7 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
|
||||
delete @errors[k] for k, v of @errors
|
||||
@$update().then (response) =>
|
||||
StatusMessage.display 'success', 'Saved'
|
||||
$injector.get('StandingOrders').afterUpdate(@id) if $injector.has('StandingOrders')
|
||||
, (response) =>
|
||||
StatusMessage.display 'failure', 'Oh no! I was unable to save your changes.'
|
||||
angular.extend(@errors, response.data.errors)
|
||||
|
||||
@@ -11,3 +11,13 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOr
|
||||
for standingOrder in standingOrders
|
||||
@byID[standingOrder.id] = standingOrder
|
||||
@pristineByID[standingOrder.id] = angular.copy(standingOrder)
|
||||
|
||||
afterCreate: (id) ->
|
||||
@pristineByID[id] = angular.copy(@byID[id])
|
||||
|
||||
afterUpdate: (id) ->
|
||||
@pristineByID[id] = angular.copy(@byID[id])
|
||||
|
||||
afterRemoveItem: (id, deletedItemID) ->
|
||||
for item, i in @pristineByID[id].standing_line_items when item.id == deletedItemID
|
||||
@pristineByID[id].standing_line_items.splice(i, 1)
|
||||
|
||||
Reference in New Issue
Block a user