diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb
index 4336f8008..7b0fa55df 100644
--- a/app/controllers/storage_locations_controller.rb
+++ b/app/controllers/storage_locations_controller.rb
@@ -49,7 +49,7 @@ class StorageLocationsController < ApplicationController
if @storage_location.discard
render json: {}
else
- render json: { errors: @storage_location.errors.full_messages }, status: :unprocessable_entity
+ render json: { error: @storage_location.errors.full_messages }, status: :unprocessable_entity
end
end
diff --git a/app/javascript/vue/storage_locations/table.vue b/app/javascript/vue/storage_locations/table.vue
index 9f9096a58..945046335 100644
--- a/app/javascript/vue/storage_locations/table.vue
+++ b/app/javascript/vue/storage_locations/table.vue
@@ -12,6 +12,7 @@
@duplicate="duplicate"
@tableReloaded="reloadingTable = false"
@move="move"
+ @delete="deleteStorageLocation"
/>
${this.i18n.t('storage_locations.index.delete_modal.description_1_html', + { name: rows[0].name, type: storageLocationType, num_of_items: event.number_of_items })}
+${this.i18n.t('storage_locations.index.delete_modal.description_2_html')}
`; + + this.storageLocationDeleteDescription = description; + this.storageLocationDeleteTitle = this.i18n.t('storage_locations.index.delete_modal.title', { type: storageLocationType }); + const ok = await this.$refs.deleteStorageLocationModal.show(); + if (ok) { + axios.delete(event.path).then((_) => { + this.reloadingTable = true; + HelperModule.flashAlertMsg(this.i18n.t('storage_locations.index.delete_modal.success_message', + { + type: storageLocationType[0].toUpperCase() + storageLocationType.slice(1), + name: rows[0].name + }), 'success'); + }).catch((error) => { + HelperModule.flashAlertMsg(error.response.data.error, 'danger'); + }); + } } } }; diff --git a/app/services/toolbars/storage_locations_service.rb b/app/services/toolbars/storage_locations_service.rb index a6b275b01..900b3004b 100644 --- a/app/services/toolbars/storage_locations_service.rb +++ b/app/services/toolbars/storage_locations_service.rb @@ -74,11 +74,19 @@ module Toolbars return unless can_manage_storage_locations?(current_user.current_team) + storage_location = @storage_locations.first + + number_of_items = storage_location.storage_location_repository_rows.count + + StorageLocation.inner_storage_locations(current_user.current_team, storage_location) + .where(container: true) + .joins(:storage_location_repository_rows) + .count { name: 'delete', label: I18n.t('storage_locations.index.toolbar.delete'), icon: 'sn-icon sn-icon-delete', - path: storage_location_path(@storage_locations.first), + number_of_items: number_of_items, + path: storage_location_path(storage_location), type: :emit } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 1e576d17f..a81190bb9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2671,6 +2671,8 @@ en: errors: my_module_references_missing: 'Task references are not set' storage_locations: + box: 'box' + location: 'location' show: table: position: "Position" @@ -2733,6 +2735,11 @@ en: error_flash: "An error occurred. The selected location/box has not been moved." placeholder: find_storage_locations: 'Find location' + delete_modal: + title: 'Delete a %{type}' + description_1_html: "You're about to delete %{name}. This action will delete the %{type}. %{num_of_items} items inside will lose their assigned positions." + description_2_html: 'Are you sure you want to delete it?' + success_message: "%{type} %{name} successfully deleted." libraries: manange_modal_column_index: