Slighty change the parameter parsing of removed file cells

This commit is contained in:
Luka Murn 2018-08-21 16:46:47 +02:00
parent f52ccfd606
commit 92a4a54ae7
2 changed files with 9 additions and 2 deletions

View file

@ -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;
}
/**

View file

@ -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