mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-12 09:20:45 +08:00
Check for locked inventory rows when enabling edit, instead of preload [SCI-11135] (#7926)
This commit is contained in:
parent
9c288c2021
commit
a24726ec39
5 changed files with 35 additions and 9 deletions
|
|
@ -317,9 +317,7 @@ var RepositoryDatatable = (function(global) {
|
||||||
|
|
||||||
checkAvailableColumns();
|
checkAvailableColumns();
|
||||||
|
|
||||||
RepositoryDatatableRowEditor.switchRowToEditMode(row);
|
RepositoryDatatableRowEditor.switchRowToEditMode(row, changeToEditMode);
|
||||||
|
|
||||||
changeToEditMode();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -692,6 +690,7 @@ var RepositoryDatatable = (function(global) {
|
||||||
},
|
},
|
||||||
rowCallback: function(row, data) {
|
rowCallback: function(row, data) {
|
||||||
$(row).attr('data-editable', data.recordEditable);
|
$(row).attr('data-editable', data.recordEditable);
|
||||||
|
$(row).attr('data-info-url', data.recordInfoUrl);
|
||||||
$(row).attr('data-manage-stock-url', data.manageStockUrl);
|
$(row).attr('data-manage-stock-url', data.manageStockUrl);
|
||||||
// Get row ID
|
// Get row ID
|
||||||
let rowId = data.DT_RowId;
|
let rowId = data.DT_RowId;
|
||||||
|
|
@ -1003,10 +1002,8 @@ var RepositoryDatatable = (function(global) {
|
||||||
$(TABLE_ID).find('.repository-row-edit-icon').remove();
|
$(TABLE_ID).find('.repository-row-edit-icon').remove();
|
||||||
|
|
||||||
rowsSelected.forEach(function(rowNumber) {
|
rowsSelected.forEach(function(rowNumber) {
|
||||||
RepositoryDatatableRowEditor.switchRowToEditMode(TABLE.row('#' + rowNumber));
|
RepositoryDatatableRowEditor.switchRowToEditMode(TABLE.row('#' + rowNumber), changeToEditMode);
|
||||||
});
|
});
|
||||||
|
|
||||||
changeToEditMode();
|
|
||||||
})
|
})
|
||||||
.on('click', '#assignRepositoryRecords', function(e) {
|
.on('click', '#assignRepositoryRecords', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -173,11 +173,17 @@ var RepositoryDatatableRowEditor = (function() {
|
||||||
TABLE.columns.adjust();
|
TABLE.columns.adjust();
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchRowToEditMode(row) {
|
function enableEditMode(row, isEditable) {
|
||||||
|
if (!isEditable) {
|
||||||
|
HelperModule.flashAlertMsg(I18n.t('repositories.table.row_locked'), 'danger');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let $row = $(row.node());
|
let $row = $(row.node());
|
||||||
let itemId = row.id();
|
let itemId = row.id();
|
||||||
let formId = `repositoryRowForm${itemId}`;
|
let formId = `repositoryRowForm${itemId}`;
|
||||||
let requestUrl = $(TABLE.table().node()).data('current-uri');
|
let requestUrl = $(TABLE.table().node()).data('current-uri');
|
||||||
|
|
||||||
let rowForm = $(`
|
let rowForm = $(`
|
||||||
<form id="${formId}"
|
<form id="${formId}"
|
||||||
class="${EDIT_FORM_CLASS_NAME} ${GLOBAL_CONSTANTS.HAS_UNSAVED_DATA_CLASS_NAME}"
|
class="${EDIT_FORM_CLASS_NAME} ${GLOBAL_CONSTANTS.HAS_UNSAVED_DATA_CLASS_NAME}"
|
||||||
|
|
@ -213,6 +219,26 @@ var RepositoryDatatableRowEditor = (function() {
|
||||||
initAssetCellActions($row);
|
initAssetCellActions($row);
|
||||||
|
|
||||||
TABLE.columns.adjust();
|
TABLE.columns.adjust();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchRowToEditMode(row, editEnabledCallback) {
|
||||||
|
// Editable property was already preloaded
|
||||||
|
if (row.data().editable !== undefined) {
|
||||||
|
if (enableEditMode(row, row.data().editable)) editEnabledCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to fetch editable property
|
||||||
|
$.ajax({
|
||||||
|
url: row.data().recordInfoUrl,
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json',
|
||||||
|
success: (data) => {
|
||||||
|
if (enableEditMode(row, data.editable)) editEnabledCallback();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.freeze({
|
return Object.freeze({
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ module RepositoryDatatableHelper
|
||||||
unless options[:view_mode] || repository.is_a?(SoftLockedRepository)
|
unless options[:view_mode] || repository.is_a?(SoftLockedRepository)
|
||||||
row['recordUpdateUrl'] =
|
row['recordUpdateUrl'] =
|
||||||
Rails.application.routes.url_helpers.repository_repository_row_path(repository, record)
|
Rails.application.routes.url_helpers.repository_repository_row_path(repository, record)
|
||||||
row['recordEditable'] = record.editable?
|
|
||||||
|
# if the editable? property will be checked in a separate request, we can default it to true
|
||||||
|
row['recordEditable'] = options[:omit_editable] ? true : record.editable?
|
||||||
end
|
end
|
||||||
|
|
||||||
row['0'] = record[:row_assigned] if options[:my_module]
|
row['0'] = record[:row_assigned] if options[:my_module]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ json.data do
|
||||||
@repository,
|
@repository,
|
||||||
@columns_mappings,
|
@columns_mappings,
|
||||||
@repository.team,
|
@repository.team,
|
||||||
@datatable_params || {})
|
(@datatable_params || {}).merge(omit_editable: true))
|
||||||
end
|
end
|
||||||
json.recordsFiltered @repository_rows.first ? @repository_rows.first.filtered_count : 0
|
json.recordsFiltered @repository_rows.first ? @repository_rows.first.filtered_count : 0
|
||||||
json.recordsTotal @all_rows_count
|
json.recordsTotal @all_rows_count
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ json.repository do
|
||||||
json.name @repository.name
|
json.name @repository.name
|
||||||
json.is_snapshot @repository.is_a?(RepositorySnapshot)
|
json.is_snapshot @repository.is_a?(RepositorySnapshot)
|
||||||
end
|
end
|
||||||
|
json.editable @repository_row.editable?
|
||||||
json.notification @notification
|
json.notification @notification
|
||||||
|
|
||||||
json.update_path update_cell_repository_repository_row_path(@repository, @repository_row)
|
json.update_path update_cell_repository_repository_row_path(@repository, @repository_row)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue