diff --git a/app/assets/javascripts/repositories/stock.js b/app/assets/javascripts/repositories/stock.js index 30efdd7ad..4e08ba0b6 100644 --- a/app/assets/javascripts/repositories/stock.js +++ b/app/assets/javascripts/repositories/stock.js @@ -4,8 +4,8 @@ var RepositoryStockValues = (function() { const UNIT_SELECTOR = '#repository-stock-value-units'; function formatDecimalValue(value, decimals) { - let regexp = decimals === 0 ? /[^0-9]/g : /[^0-9.]/g; - return value.replace(regexp, '').match(new RegExp(`^\\d*(\\.\\d{0,${decimals}})?`))[0]; + let regexp = decimals === 0 ? /[^-0-9]/g : /[^-0-9.]/g; + return value.replace(regexp, '').match(new RegExp(`^-?\\d*(\\.\\d{0,${decimals}})?`))[0]; } function updateChangeAmount($element) { @@ -36,6 +36,7 @@ var RepositoryStockValues = (function() { $('#change_amount').val(inputAmount); $('#repository_stock_value_amount').val(newAmount); + $('.stock-final-container').toggleClass('negative', newAmount < 0); $('.stock-final-container .value').text( formatDecimalValue(String(newAmount), $('#stock-input-amount').data('decimals')) ); diff --git a/app/assets/stylesheets/repository/stock_modal.scss b/app/assets/stylesheets/repository/stock_modal.scss index 1970db839..c20cd68b1 100644 --- a/app/assets/stylesheets/repository/stock_modal.scss +++ b/app/assets/stylesheets/repository/stock_modal.scss @@ -32,6 +32,12 @@ @include font-small; } + &.negative { + .value { + color: $brand-danger; + } + } + &.error { .value { color: $brand-danger; diff --git a/app/views/repository_stock_values/_manage_modal_content.html.erb b/app/views/repository_stock_values/_manage_modal_content.html.erb index 8d4d0da24..ea9357d92 100644 --- a/app/views/repository_stock_values/_manage_modal_content.html.erb +++ b/app/views/repository_stock_values/_manage_modal_content.html.erb @@ -114,7 +114,7 @@
-
+
<%= t('repository_stock_values.manage_modal.current_stock') %> <%= repository_stock_value.formatted_value %> <%= repository_stock_value.repository_stock_unit_item&.data %> @@ -122,7 +122,7 @@
-
+
<%= t('repository_stock_values.manage_modal.new_stock') %> <%= repository_stock_value.formatted_value %> <%= repository_stock_value.repository_stock_unit_item&.data %>