Merge pull request #1261 from mlorb/ml-sci-2634

fix editing of inventory items of hidden columns [SCI-2634]
This commit is contained in:
Luka Murn 2018-08-21 16:59:37 +02:00 committed by GitHub
commit 92eab25a07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 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'));
@ -125,18 +126,25 @@
} else {
var colId = element.replace('colId-', '');
var $el = $('#' + element);
// don't save anything if element is not visible
if($el.length == 0) {
return true;
}
if($el.attr('type') === 'file') {
// don't save anything if element is deleted
// handle deleting of element
if($el.attr('remove') === "true") {
return true;
removeFileColumns.push(colId);
formDataObj.append('repository_cells[' + colId + ']', null);
} else {
formDataObj.append('repository_cells[' + colId + ']',
getFileValue($el));
}
formDataObj.append('repository_cells[' + colId + ']',
getFileValue($el));
} else if(value.length > 0) {
} else if(value.length >= 0) {
formDataObj.append('repository_cells[' + colId + ']', value);
}
}
});
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'
next if value.blank?
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
@ -145,6 +145,7 @@ class RepositoryRowsController < ApplicationController
}
end
else
existing.value.destroy && next if value == ''
existing.value.data = value
if existing.value.save
record_annotation_notification(@record, existing)
@ -156,17 +157,12 @@ class RepositoryRowsController < ApplicationController
end
end
else
next if value == ''
# Looks like it is a new cell, so we need to create new value, cell
# will be created automatically
next if create_cell_value(@record, key, value, errors).nil?
end
end
# Clean up empty cells, not present in updated record
@record.repository_cells.each do |cell|
next if cell.value_type == 'RepositoryListValue'
cell.value.destroy unless cell_params
.key?(cell.repository_column_id.to_s)
end
else
@record.repository_cells.each { |c| c.value.destroy }
end
@ -369,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