diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index 933bed39a..d030666ce 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -328,6 +328,40 @@ var RepositoryDatatable = (function(global) { }); } + function initDeleteAssetValueConfirmModal() { + $('#deleteRepositoryAssetValueModal').on('shown.bs.modal', function() { + let $fileBtn = $(this).data('cellFileBtn'); + let $input = $(this).data('cellInput'); + let $label = $(this).data('cellLabel'); + + $('#confirmAssetValueDelete').one('click', function() { + $fileBtn.addClass('new-file'); + $label.text(''); + $input.val(''); + $fileBtn.removeClass('error'); + + if (!$input.data('is-empty')) { // set hidden field for deletion only if original value has been set on rendering + $input + .prev('.file-hidden-field-container') + .html(``); + } + + $('#deleteRepositoryAssetValueModal').modal('hide'); + }); + }); + + $('#deleteRepositoryAssetValueModal').on('hidden.bs.modal', function() { + const $deleteRepositoryAssetValueModal = $('#deleteRepositoryAssetValueModal'); + + $deleteRepositoryAssetValueModal.data('cellFileBtn', null); + $deleteRepositoryAssetValueModal.data('cellInput', null); + $deleteRepositoryAssetValueModal.data('cellLabel', null); + }); + } + function initActiveRemindersFilter() { $(TABLE_WRAPPER_ID).find('#only_reminders').on('change', function() { var $activeRemindersFilter = $(this).closest('.active-reminders-filter'); @@ -804,6 +838,7 @@ var RepositoryDatatable = (function(global) { initSaveButton(); initCancelButton(); initBSTooltips(); + initDeleteAssetValueConfirmModal(); window.initRepositoryStateMenu(); DataTableHelpers.initLengthAppearance($(TABLE_ID).closest('.dataTables_wrapper')); diff --git a/app/assets/javascripts/repositories/row_editor.js b/app/assets/javascripts/repositories/row_editor.js index 490b6f63d..422b01acf 100644 --- a/app/assets/javascripts/repositories/row_editor.js +++ b/app/assets/javascripts/repositories/row_editor.js @@ -80,25 +80,17 @@ var RepositoryDatatableRowEditor = (function() { $fileBtn.removeClass('error'); }); - deleteButtons.on('click', function() { + const $deleteRepositoryAssetValueModal = $('#deleteRepositoryAssetValueModal'); let $fileBtn = $(this).parent(); let $input = $fileBtn.prev('input[type=file]'); let $label = $fileBtn.find('label'); - $fileBtn.addClass('new-file'); - $label.text(''); - $input.val(''); - $fileBtn.removeClass('error'); + $deleteRepositoryAssetValueModal.data('cellFileBtn', $fileBtn); + $deleteRepositoryAssetValueModal.data('cellInput', $input); + $deleteRepositoryAssetValueModal.data('cellLabel', $label); - if (!$input.data('is-empty')) { // set hidden field for deletion only if original value has been set on rendering - $input - .prev('.file-hidden-field-container') - .html(``); - } + $('#deleteRepositoryAssetValueModal').modal('show'); }); } diff --git a/app/views/repositories/_delete_asset_value_modal.html.erb b/app/views/repositories/_delete_asset_value_modal.html.erb new file mode 100644 index 000000000..81ccb9356 --- /dev/null +++ b/app/views/repositories/_delete_asset_value_modal.html.erb @@ -0,0 +1,19 @@ +
Deleting this file will remove the entire column history.
This action is irreversible.
To retain version history, replace the file with a new one instead.
" + delete: "Delete" modal_delete_column: title: "Delete a column" message: "Are you sure you wish to permanently delete selected column %{column}? This action is irreversible."