mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Extract status message to a service
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout, $http, BulkProducts, DisplayProperties, dataFetcher, DirtyProducts, VariantUnitManager, producers, Taxons, SpreeApiAuth) ->
|
||||
angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout, $http, BulkProducts, DisplayProperties, dataFetcher, DirtyProducts, VariantUnitManager, StatusMessage, producers, Taxons, SpreeApiAuth) ->
|
||||
$scope.loading = true
|
||||
|
||||
$scope.updateStatusMessage =
|
||||
text: ""
|
||||
style: {}
|
||||
$scope.StatusMessage = StatusMessage
|
||||
|
||||
$scope.columns =
|
||||
producer: {name: "Producer", visible: true}
|
||||
@@ -64,7 +62,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
|
||||
$scope.resetProducts = ->
|
||||
DirtyProducts.clear()
|
||||
$scope.setMessage $scope.updateStatusMessage, "", {}, false
|
||||
StatusMessage.clearMessage()
|
||||
|
||||
# $scope.matchProducer = (product) ->
|
||||
# for producer in $scope.producers
|
||||
@@ -182,7 +180,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
if productsToSubmit.length > 0
|
||||
$scope.updateProducts productsToSubmit # Don't submit an empty list
|
||||
else
|
||||
$scope.setMessage $scope.updateStatusMessage, "No changes to save.", color: "grey", 3000
|
||||
StatusMessage.displayMessage 'No changes to save.', 'alert'
|
||||
|
||||
|
||||
$scope.updateProducts = (productsToSubmit) ->
|
||||
@@ -250,31 +248,23 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout
|
||||
|
||||
|
||||
$scope.displayUpdating = ->
|
||||
$scope.setMessage $scope.updateStatusMessage, "Saving...",
|
||||
color: "#FF9906"
|
||||
, false
|
||||
StatusMessage.displayMessage 'Saving...', 'progress'
|
||||
|
||||
|
||||
$scope.displaySuccess = ->
|
||||
$scope.setMessage $scope.updateStatusMessage, "Changes saved.",
|
||||
color: "#9fc820"
|
||||
, 3000
|
||||
StatusMessage.displayMessage 'Changes saved.', 'success'
|
||||
|
||||
|
||||
$scope.displayFailure = (failMessage) ->
|
||||
$scope.setMessage $scope.updateStatusMessage, "Saving failed. " + failMessage,
|
||||
color: "#DA5354"
|
||||
, false
|
||||
StatusMessage.displayMessage "Saving failed. #{failMessage}", 'failure'
|
||||
|
||||
|
||||
$scope.displayDirtyProducts = ->
|
||||
if DirtyProducts.count() > 0
|
||||
message = if DirtyProducts.count() == 1 then "one product" else DirtyProducts.count() + " products"
|
||||
$scope.setMessage $scope.updateStatusMessage, "Changes to " + message + " remain unsaved.",
|
||||
color: "gray"
|
||||
, false
|
||||
StatusMessage.displayMessage "Changes to #{message} remain unsaved.", 'notice'
|
||||
else
|
||||
$scope.setMessage $scope.updateStatusMessage, "", {}, false
|
||||
StatusMessage.clearMessage()
|
||||
|
||||
|
||||
filterSubmitProducts = (productsToFilter) ->
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
angular.module("ofn.admin").factory "StatusMessage", ($timeout) ->
|
||||
new class StatusMessage
|
||||
types:
|
||||
progress: {timeout: false, style: {color: '#ff9906'}}
|
||||
alert: {timeout: 3000, style: {color: 'grey'}}
|
||||
notice: {timeout: false, style: {color: 'grey'}}
|
||||
success: {timeout: 3000, style: {color: '#9fc820'}}
|
||||
failure: {timeout: false, style: {color: '#da5354'}}
|
||||
|
||||
statusMessage:
|
||||
text: ""
|
||||
style: {}
|
||||
|
||||
displayMessage: (text, type) ->
|
||||
@statusMessage.text = text
|
||||
@statusMessage.style = @types[type].style
|
||||
$timeout.cancel @statusMessage.timeout if @statusMessage.timeout
|
||||
timeout = @types[type].timeout
|
||||
if timeout
|
||||
@statusMessage.timeout = $timeout =>
|
||||
@clearMessage()
|
||||
, timeout, true
|
||||
|
||||
clearMessage: ->
|
||||
@statusMessage.text = ''
|
||||
@statusMessage.style = {}
|
||||
@@ -2,8 +2,8 @@
|
||||
%div.four.columns.alpha
|
||||
%input.four.columns.alpha{ :type => 'button', :value => 'Save Changes', 'ng-click' => 'submitProducts()'}
|
||||
%div.nine.columns
|
||||
%h6{ id: "update-status-message", ng: { style: 'updateStatusMessage.style' } }
|
||||
{{ updateStatusMessage.text || " " }}
|
||||
%h6{ id: "update-status-message", ng: { style: 'StatusMessage.statusMessage.style' } }
|
||||
{{ StatusMessage.statusMessage.text || " " }}
|
||||
%div.three.columns.omega
|
||||
%div.ofn_drop_down.three.columns.omega{ 'ng-controller' => "DropDownCtrl", :id => "columns_dropdown", 'ofn-drop-down' => true, :style => 'float:right;' }
|
||||
%span{ :class => 'icon-reorder' } Columns
|
||||
|
||||
Reference in New Issue
Block a user