diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 1b1425756205..47a10778206d 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -111,13 +111,17 @@ def servicetemplate_copy_cancel replace_right_cell end - def servicetemplate_copy_saved() + def servicetemplate_copy_saved add_flash(_("Copy of a Service Catalog Item was successfully saved")) @sb[:action] = @edit = @record = nil @in_a_form = false replace_right_cell end + def servicetemplates_names + render :json => {:names => ServiceTemplate.all.pluck(:name)} + end + def atomic_st_edit # reset the active tree back to :sandt_tree, it was changed temporairly to display automate entry point tree in a popup div self.x_active_tree = 'sandt_tree' diff --git a/app/javascript/components/copy-catalog-form/copy-catalog-form.schema.js b/app/javascript/components/copy-catalog-form/copy-catalog-form.schema.js index 4522c46ee12f..a6f24c27e04b 100644 --- a/app/javascript/components/copy-catalog-form/copy-catalog-form.schema.js +++ b/app/javascript/components/copy-catalog-form/copy-catalog-form.schema.js @@ -1,10 +1,28 @@ import { componentTypes } from '@data-driven-forms/react-form-renderer'; +import debouncePromise from '../../helpers/promise-debounce'; +import { http } from '../../http_api'; + +export const asyncValidator = value => + http.get('/catalog/servicetemplates_names') + .then((json) => { + if (json.names.includes(value)) { + return __('Name has already been taken'); + } + if (value === '' || value === undefined) { + return __("Name can't be blank"); + } + return undefined; + }); +const asyncValidatorDebounced = debouncePromise(asyncValidator); function createSchema() { const fields = [ { component: componentTypes.TEXT_FIELD, name: 'name', + validate: [ + value => asyncValidatorDebounced(value), + ], label: __('Name'), maxLength: 40, }]; diff --git a/config/routes.rb b/config/routes.rb index 617f0555ebe2..3476cb783617 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -289,6 +289,7 @@ ot_edit ot_orchestration_managers ot_show + servicetemplates_names show ), :post => %w(