From 103e20ee9a39674367f6aaa4ded9e5797fad8677 Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Mon, 28 Mar 2022 21:31:49 +0200 Subject: [PATCH] Update front end validation for columns managment [SCI-6657] (#3962) Co-authored-by: Anton --- .../columns_initializers/stock_column_type.js | 8 ++++++- .../javascripts/repository_columns/index.js | 15 ++++++++----- .../repository_columns/stock_type.scss | 19 ++++++++++++++++ .../_manage_column_modal_content.html.erb | 12 +++++----- .../manage_column_partials/_stock.html.erb | 22 ++++++++++--------- config/locales/en.yml | 3 +++ 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/repository_columns/columns_initializers/stock_column_type.js b/app/assets/javascripts/repository_columns/columns_initializers/stock_column_type.js index c58a44081..1a2068cae 100644 --- a/app/assets/javascripts/repository_columns/columns_initializers/stock_column_type.js +++ b/app/assets/javascripts/repository_columns/columns_initializers/stock_column_type.js @@ -31,7 +31,7 @@ var RepositoryStockColumnType = (function() { dropdownOptions, GLOBAL_CONSTANTS.REPOSITORY_LIST_ITEMS_PER_COLUMN ); - $('.changing-existing-list-items-warning').removeClass('hidden'); + $('.changing-existing-stock-units-warning').removeClass('hidden'); initStockUnitDropdown(); }) .on('columnModal::partialLoadedForRepositoryStockValue', function() { @@ -53,6 +53,12 @@ var RepositoryStockColumnType = (function() { checkValidation: () => { var $manageModal = $(manageModal); var count = $manageModal.find('.items-count').attr('data-count'); + if ($manageModal.find('.stock-column-type .items-textarea').val().length) { + $manageModal.find('.stock-column-type .items-textarea').parent().removeClass('error'); + } else { + $manageModal.find('.stock-column-type .items-textarea').parent().addClass('error'); + return false; + } return count <= GLOBAL_CONSTANTS.REPOSITORY_STOCK_UNIT_ITEMS_PER_COLUMN; }, loadParams: () => { diff --git a/app/assets/javascripts/repository_columns/index.js b/app/assets/javascripts/repository_columns/index.js index e9a495b7b..0fe71a2d0 100644 --- a/app/assets/javascripts/repository_columns/index.js +++ b/app/assets/javascripts/repository_columns/index.js @@ -68,13 +68,18 @@ var RepositoryColumns = (function() { } function checkData() { + var status = true; var currentPartial = $('#repository-column-data-type').val(); - - if (columnTypeClassNames[currentPartial]) { - return eval(columnTypeClassNames[currentPartial]) - .checkValidation(); + if ($('#repository-column-name').val().length === 0) { + $('#repository-column-name').parent().addClass('error'); + status = false; + } else { + $('#repository-column-name').parent().removeClass('error'); } - return true; + if (columnTypeClassNames[currentPartial]) { + status = eval(columnTypeClassNames[currentPartial]).checkValidation() && status; + } + return status; } function addSpecificParams(type, params) { diff --git a/app/assets/stylesheets/repository_columns/stock_type.scss b/app/assets/stylesheets/repository_columns/stock_type.scss index 153aaa115..e8bfb7ccc 100644 --- a/app/assets/stylesheets/repository_columns/stock_type.scss +++ b/app/assets/stylesheets/repository_columns/stock_type.scss @@ -4,5 +4,24 @@ @include font-small; color: $color-silver-chalice; } + + .changing-existing-stock-units-warning { + @include font-small; + background-color: $brand-warning-light; + padding: .5em; + } + + .sci-input-container.error { + margin-bottom: 3em; + + .changing-existing-stock-units-warning { + bottom: -3.5em; + position: absolute; + } + + .units-info-description { + display: none; + } + } } } diff --git a/app/views/repository_columns/_manage_column_modal_content.html.erb b/app/views/repository_columns/_manage_column_modal_content.html.erb index 5ceb1adcb..0deb20dc9 100644 --- a/app/views/repository_columns/_manage_column_modal_content.html.erb +++ b/app/views/repository_columns/_manage_column_modal_content.html.erb @@ -22,11 +22,13 @@ <%= t('libraries.manange_modal_column.name') %>
- +
+ +
diff --git a/app/views/repository_columns/manage_column_partials/_stock.html.erb b/app/views/repository_columns/manage_column_partials/_stock.html.erb index d28ea919c..270dfabb1 100644 --- a/app/views/repository_columns/manage_column_partials/_stock.html.erb +++ b/app/views/repository_columns/manage_column_partials/_stock.html.erb @@ -24,17 +24,19 @@
- <% units = column.new_record? ? RepositoryStockUnitItem::DEFAULT_UNITS : column.repository_stock_unit_items.pluck(:data) %> - <%= text_area_tag 'items-textarea', units.join(Constants::REPOSITORY_LIST_ITEMS_DELIMITERS_MAP[:return]), - rows: 10, class: 'form-control items-textarea', - placeholder: t('libraries.manange_modal_column.stock_type.textarea_placeholder_html') %> - <% unless column.new_record? %> - diff --git a/config/locales/en.yml b/config/locales/en.yml index 3162cb11d..e02768ae2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1731,6 +1731,7 @@ en: add_column: "Add column" manange_modal_column: name_placeholder: "Enter column name..." + empty_name_error: "Colmun must have a name." name: "Name" colum_type: "Column type" dropdown_item_descirption: "Dropdown items should be separated by comma." @@ -1802,6 +1803,8 @@ en: stock_consumption_locked: "Can't consume" no_item_stock: 'No item stock' textarea_placeholder_html: 'Enter your preferred units in separate rows Just Like This' + units_changing_warning: 'Careful: Changing units will remove previously selected units' + empty_units_error: 'Enter at least one unit.' checklist_type: multiple_options: 'selected' all_options: 'All options'