From 92a4a54ae7a3dbb456e678870ee23f983529d5c8 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 21 Aug 2018 16:46:47 +0200 Subject: [PATCH] Slighty change the parameter parsing of removed file cells --- .../javascripts/repositories/forms/repository_item_edit.js | 5 ++++- app/controllers/repository_rows_controller.rb | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/repositories/forms/repository_item_edit.js b/app/assets/javascripts/repositories/forms/repository_item_edit.js index acb2b1cce..0a36e2d9e 100644 --- a/app/assets/javascripts/repositories/forms/repository_item_edit.js +++ b/app/assets/javascripts/repositories/forms/repository_item_edit.js @@ -115,6 +115,7 @@ RepositoryItemEditForm.prototype.parseToFormObject = function(tableID, selectedRecord) { var formData = this.formData; var formDataObj = new FormData(); + var removeFileColumns = []; formDataObj.append('request_url', $(tableID).data('current-uri')); formDataObj.append('repository_row_id', $(selectedRecord).attr('id')); @@ -132,7 +133,8 @@ if($el.attr('type') === 'file') { // handle deleting of element if($el.attr('remove') === "true") { - formDataObj.append('repository_cells[' + colId + ']', 'remove'); + removeFileColumns.push(colId); + formDataObj.append('repository_cells[' + colId + ']', null); } else { formDataObj.append('repository_cells[' + colId + ']', getFileValue($el)); @@ -142,6 +144,7 @@ } } }); + formDataObj.append('remove_file_columns', JSON.stringify(removeFileColumns)); return formDataObj; } /** diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 084a0d9df..942634b2f 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -134,7 +134,7 @@ class RepositoryRowsController < ApplicationController existing.delete end elsif existing.value_type == 'RepositoryAssetValue' - existing.value.destroy && next if value == 'remove' + existing.value.destroy && next if remove_file_columns_params.include?(key) if existing.value.asset.update(file: value) existing.value.asset.created_by = current_user existing.value.asset.last_modified_by = current_user @@ -365,6 +365,10 @@ class RepositoryRowsController < ApplicationController params.permit(repository_cells: {}).to_h[:repository_cells] end + def remove_file_columns_params + JSON.parse(params.fetch(:remove_file_columns) { '[]' }) + end + def selected_params params.permit(selected_rows: []).to_h[:selected_rows] end