Highlight negative stock in modal with red [SCI-6729]

This commit is contained in:
Anton 2022-04-15 12:08:29 +02:00
parent 6b309871a3
commit ed49e93a6a
3 changed files with 11 additions and 4 deletions

View file

@ -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'))
);

View file

@ -32,6 +32,12 @@
@include font-small;
}
&.negative {
.value {
color: $brand-danger;
}
}
&.error {
.value {
color: $brand-danger;

View file

@ -114,7 +114,7 @@
<div class="row">
<div class="col-sm-12">
<div class="stock-update-view">
<div class="stock-initial-container">
<div class="stock-initial-container <%= 'negative' if repository_stock_value.amount.negative? %>">
<span class="subtitle"><%= t('repository_stock_values.manage_modal.current_stock') %></span>
<span class="value"><%= repository_stock_value.formatted_value %></span>
<span class="units"><%= repository_stock_value.repository_stock_unit_item&.data %></span>
@ -122,7 +122,7 @@
<div class="stock-arrow">
<i class="fas fa-arrow-right"></i>
</div>
<div class="stock-final-container">
<div class="stock-final-container <%= 'negative' if repository_stock_value.amount.negative? %> ">
<span class="subtitle"><%= t('repository_stock_values.manage_modal.new_stock') %></span>
<span class="value"><%= repository_stock_value.formatted_value %></span>
<span class="units"><%= repository_stock_value.repository_stock_unit_item&.data %></span>