mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-01 12:38:30 +08:00
Fix repository table state updates after column creation/deletion [SCI-4196]
This commit is contained in:
parent
54c78cf4d1
commit
2faab14444
3 changed files with 2 additions and 451 deletions
|
@ -1,260 +0,0 @@
|
|||
// /* global Promise _ ActiveStorage RepositoryItemEditForm */
|
||||
//
|
||||
// //= require sugar.min
|
||||
// //= require jquerymy-1.2.14.min
|
||||
//
|
||||
// (function(global) {
|
||||
// 'use strict';
|
||||
//
|
||||
// /**
|
||||
// * Creates a FormData object with the repository row data ready to be
|
||||
// * sended on the server
|
||||
// *
|
||||
// * @param {Object} tableID
|
||||
// * @param {Object} selectedRecord
|
||||
// *
|
||||
// * @returns (Object)
|
||||
// */
|
||||
// RepositoryItemEditForm.prototype.parseToFormObject = function(tableID, selectedRecord) {
|
||||
// var formData = this.formData;
|
||||
// var formDataObj = new FormData();
|
||||
// var removeFileColumns = [];
|
||||
// var filesToUploadCntr = 0;
|
||||
// var filesUploadedCntr = 0;
|
||||
// const directUploadUrl = $(tableID).data('directUploadUrl');
|
||||
//
|
||||
// formDataObj.append('request_url', $(tableID).data('current-uri'));
|
||||
// formDataObj.append('repository_row_id', $(selectedRecord).attr('id'));
|
||||
//
|
||||
// return new Promise((resolve, reject) => {
|
||||
// $(_.keys(this.formData)).each(function(_, element) {
|
||||
// var value = formData[element];
|
||||
// if (element === 'rowName') {
|
||||
// formDataObj.append('repository_row_name', value);
|
||||
// } else {
|
||||
// let colId = element.replace('colId-', '');
|
||||
// let $el = $('#' + element);
|
||||
// // don't save anything if element is not visible
|
||||
// if ($el.length === 0) {
|
||||
// return;
|
||||
// }
|
||||
// if ($el.attr('type') === 'file') {
|
||||
// // handle deleting of element
|
||||
// if ($el.attr('remove') === 'true') {
|
||||
// removeFileColumns.push(colId);
|
||||
// formDataObj.append('repository_cells[' + colId + ']', null);
|
||||
// } else if ($el[0].files.length > 0) {
|
||||
// filesToUploadCntr += 1;
|
||||
// }
|
||||
// } else if (value.length >= 0) {
|
||||
// formDataObj.append('repository_cells[' + colId + ']', value);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// formDataObj.append('remove_file_columns', JSON.stringify(removeFileColumns));
|
||||
//
|
||||
// // No files for upload, so return earlier
|
||||
// if (filesToUploadCntr === 0) {
|
||||
// resolve(formDataObj);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Second run, just for files
|
||||
// $(_.keys(this.formData)).each(function(_, element) {
|
||||
// let $el = $('#' + element);
|
||||
// let colId = element.replace('colId-', '');
|
||||
//
|
||||
// if ($el.attr('type') === 'file' && $el.attr('remove') !== 'true') {
|
||||
// let upload = new ActiveStorage.DirectUpload($el[0].files[0], directUploadUrl);
|
||||
//
|
||||
// upload.create(function(error, blob) {
|
||||
// if (error) {
|
||||
// reject(error);
|
||||
// } else {
|
||||
// formDataObj.append('repository_cells[' + colId + ']', blob.signed_id);
|
||||
// filesUploadedCntr += 1;
|
||||
//
|
||||
// if (filesUploadedCntr === filesToUploadCntr) {
|
||||
// resolve(formDataObj);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
//
|
||||
// /**
|
||||
// * Takes object and creates an input file field, contains a hidden
|
||||
// * input field which is triggered on button click and we get the uploaded
|
||||
// * file from there.
|
||||
// *
|
||||
// * @param {Object} object
|
||||
// * @param {String} name
|
||||
// * @param {String} value
|
||||
// * @param {String} id
|
||||
// *
|
||||
// * @returns (String)
|
||||
// */
|
||||
// function changeToInputFileField(object, name, value, id) {
|
||||
// var fileName = (value.file_name) ? value.file_name : I18n.t('general.file.no_file_chosen');
|
||||
// var buttonLabel = I18n.t('general.file.choose');
|
||||
// var html = "<div class='repository-input-file-field'>" +
|
||||
// "<div class='form-group'><div><input type='file' name='" + name + "' id='" +
|
||||
// id + "' style='display:none' /><button class='btn btn-default' " +
|
||||
// "data-object='" + object + "' name='" + name + "' value='" + value +
|
||||
// "' data-id='" + id + "'>" + buttonLabel +
|
||||
// "</button></div><div><p class='file-name-label'>" + truncateLongString(fileName, 20) +
|
||||
// "</p></div>";
|
||||
// if(value.file_name) {
|
||||
// html += "<div><a data-action='removeAsset' ";
|
||||
// html += "onClick='clearFileInput(this)'><i class='fas fa-times'></i></a>";
|
||||
// } else {
|
||||
// html += "<div><a data-action='removeAsset' onClick='clearFileInput(this)' ";
|
||||
// html += "style='display:none'><i class='fas fa-times'></i></a>";
|
||||
// }
|
||||
// html += "</div></div></div>";
|
||||
//
|
||||
// return html;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the colum index
|
||||
// *
|
||||
// * @param {Object} table
|
||||
// * @param {String} id
|
||||
// *
|
||||
// * @returns (Boolean | Number)
|
||||
// */
|
||||
// function getColumnIndex(table, id) {
|
||||
// if(id < 0)
|
||||
// return false;
|
||||
// return table.column(id).index('visible');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Genrates list items dropdown element
|
||||
// *
|
||||
// * @param {Array} options
|
||||
// * @param {String} current_value
|
||||
// * @param {Number} columnId
|
||||
// * @param {String} id
|
||||
// *
|
||||
// * @returns (String)
|
||||
// */
|
||||
// function _listItemDropdown(options, current_value, columnId, id) {
|
||||
// var val = undefined;
|
||||
// var html = '<select id="' + id + '" class="form-control selectpicker repository-dropdown" ';
|
||||
// html += 'data-selected-value="" data-abs-min-length="2" data-live-search="true" ';
|
||||
// html += 'data-container="body" column_id="' + columnId +'">';
|
||||
// html += '<option value="-1"></option>';
|
||||
// $.each(options, function(index, value) {
|
||||
// var selected = '';
|
||||
// if (current_value === value[1]) {
|
||||
// selected = 'selected';
|
||||
// val = value[0];
|
||||
// }
|
||||
// html += '<option value="' + value[0] + '" ' + selected + '>';
|
||||
// html += value[1] + '</option>';
|
||||
// });
|
||||
// html += '</select>';
|
||||
// return (val) ? $(html).attr('data-selected-value', val)[0] : html;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Takes an object and creates custom html element
|
||||
// *
|
||||
// * @param {String} object
|
||||
// * @param {String} name
|
||||
// * @param {String} column_type
|
||||
// * @param {Object} cell
|
||||
// * @param {Object} listColumns
|
||||
// *
|
||||
// * @returns (String)
|
||||
// */
|
||||
// function changeToFormField(object, name, column_type, cell, listColumns) {
|
||||
// var cellId = generateInputFieldReference(name);
|
||||
// var value = cell.value || '';
|
||||
// if (column_type === 'RepositoryListValue') {
|
||||
// var column = _.findWhere(listColumns,
|
||||
// { column_id: parseInt(name, 10) });
|
||||
// var list_items = column.list_items || cell.list_items;
|
||||
// return _listItemDropdown(list_items, value, parseInt(name, 10), cellId);
|
||||
// } else if (column_type === 'RepositoryAssetValue') {
|
||||
// return changeToInputFileField('repository_cell_file', name, value, cellId);
|
||||
// } else {
|
||||
// return changeToInputField(object, name, value, cellId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Append the change listener to file field
|
||||
// *
|
||||
// * @param {String} type
|
||||
// * @param {String} name
|
||||
// *
|
||||
// * @returns {undefined}
|
||||
// */
|
||||
// function addSelectedFile(type, name) {
|
||||
// var button = $('button[data-id="' +
|
||||
// generateInputFieldReference(name) +
|
||||
// '"]');
|
||||
// if (type === 'RepositoryAssetValue') {
|
||||
// var fileInput = $(button.parent().find('input[type="file"]')[0]);
|
||||
// button.on('click', function(ev) {
|
||||
// ev.preventDefault();
|
||||
// ev.stopPropagation();
|
||||
// fileInput.trigger('click');
|
||||
// initFileHandler(fileInput);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Handle extraction of file from the input field
|
||||
// *
|
||||
// * @param {Object} $inputField
|
||||
// *
|
||||
// * @returns {undefined}
|
||||
// */
|
||||
// function initFileHandler($inputField) {
|
||||
// $inputField.on('change', function() {
|
||||
// var input = $(this);
|
||||
// var $label = $($(this).closest('.repository-input-file-field')
|
||||
// .find('.file-name-label')[0]);
|
||||
// var file = this.files[0];
|
||||
// if (file) {
|
||||
// $label.text(truncateLongString(file.name, 20));
|
||||
// input.attr('remove', false);
|
||||
// $($label.closest('.repository-input-file-field')
|
||||
// .find('[data-action="removeAsset"]')[0]).show();
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Generates the input tag id that will be used in the formData object
|
||||
// *
|
||||
// * @param {String} columnId
|
||||
// *
|
||||
// * @returns {String}
|
||||
// */
|
||||
// function generateInputFieldReference(columnId) {
|
||||
// return 'colId-' + columnId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Appends aditional fields to form data object
|
||||
// * @param {Object} cell
|
||||
// * @param {String} columnId
|
||||
// * @param {Object} formData
|
||||
// *
|
||||
// * @returns {undefined}
|
||||
// */
|
||||
// function appendNewElementToFormData(cell, columnId, formData) {
|
||||
// if (!cell.repository_cell_id) {
|
||||
// formData[generateInputFieldReference(columnId)] = undefined;
|
||||
// }
|
||||
// }
|
||||
// }(window));
|
|
@ -144,21 +144,6 @@ var RepositoryDatatable = (function(global) {
|
|||
}
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
// function listItemDropdown(options, currentValue, columnId) {
|
||||
// var html = `<select class="form-control selectpicker repository-dropdown"
|
||||
// data-abs-min-length="2" data-live-search="true"
|
||||
// data-container="body" column_id="${columnId}">
|
||||
// <option value="-1"></option>`;
|
||||
// $.each(options, function(index, value) {
|
||||
// var selected = (currentValue === value[1]) ? 'selected' : '';
|
||||
// html += '<option value="' + value[0] + '" ' + selected + '>';
|
||||
// html += value[1] + '</option>';
|
||||
// });
|
||||
// html += '</select>';
|
||||
// return html;
|
||||
// }
|
||||
|
||||
function initRowSelection() {
|
||||
// Handle clicks on checkbox
|
||||
$('.dt-body-center .repository-row-selector').change(function(ev) {
|
||||
|
@ -279,23 +264,6 @@ var RepositoryDatatable = (function(global) {
|
|||
);
|
||||
}
|
||||
|
||||
// Takes object and surrounds it with input
|
||||
// function changeToInputField(object, name, value) {
|
||||
// return "<div class='form-group'><input class='form-control' data-object='"
|
||||
// + object + "' name='" + name + "' value='" + value + "'></input></div>";
|
||||
// }
|
||||
|
||||
// Takes object and surrounds it with input
|
||||
function changeToInputFileField(object, name, value) {
|
||||
return "<div class='repository-input-file-field'>"
|
||||
+ "<div class='new-input-file-field-div'><div class='form-group'>"
|
||||
+ "<input type='file' class='form-control' data-object='"
|
||||
+ object + "' name='" + name + "' value='" + value + "'></div>"
|
||||
+ "<a onClick='clearFileInput(this)'>"
|
||||
+ "<i class='fas fa-times'></i>"
|
||||
+ '</a></div></div>';
|
||||
}
|
||||
|
||||
function initHeaderTooltip() {
|
||||
// Fix compatibility of fixed table header and column names modal-tooltip
|
||||
$('.modal-tooltip').off();
|
||||
|
@ -402,75 +370,6 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
}
|
||||
|
||||
// function initialListItemsRequest(columnId) {
|
||||
// var massageResponse = [];
|
||||
// $.ajax({
|
||||
// url: $(TABLE_ID).data('list-items-path'),
|
||||
// type: 'POST',
|
||||
// dataType: 'json',
|
||||
// async: false,
|
||||
// data: {
|
||||
// q: '',
|
||||
// column_id: columnId
|
||||
// }
|
||||
// }).done(function(data) {
|
||||
// $.each(data.list_items, function(index, el) {
|
||||
// massageResponse.push([el.id, el.data]);
|
||||
// });
|
||||
// });
|
||||
// return listItemDropdown(massageResponse, '-1', columnId);
|
||||
// }
|
||||
|
||||
function initSelectPicker() {
|
||||
$('.selectpicker')
|
||||
.selectpicker({ liveSearch: true })
|
||||
.ajaxSelectPicker({
|
||||
ajax: {
|
||||
url: $(TABLE_ID).data('list-items-path'),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: function() {
|
||||
var params = {
|
||||
q: '{{{q}}}',
|
||||
column_id: $(this.valueOf().plugin.$element).attr('column_id')
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
},
|
||||
locale: {
|
||||
emptyTitle: 'Nothing selected'
|
||||
},
|
||||
preprocessData: function(data) {
|
||||
var items = [];
|
||||
if (Object.prototype.hasOwnProperty.call(data, 'list_items')) {
|
||||
items.push({
|
||||
value: '-1',
|
||||
text: '',
|
||||
disabled: false
|
||||
});
|
||||
$.each(data.list_items, function(index, el) {
|
||||
items.push(
|
||||
{
|
||||
value: el.id,
|
||||
text: el.data,
|
||||
disabled: false
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
return items;
|
||||
},
|
||||
emptyRequest: true,
|
||||
clearOnEmpty: false,
|
||||
preserveSelected: false
|
||||
}).on('change.bs.select', function(el) {
|
||||
$(this).closest('td').attr('list_item_id', el.target.value);
|
||||
$(this).closest('td').attr('column_id', $(this).attr('column_id'));
|
||||
})
|
||||
.trigger('change.bs.select');
|
||||
}
|
||||
|
||||
// Adjust columns width in table header
|
||||
function adjustTableHeader() {
|
||||
TABLE.columns.adjust();
|
||||
|
@ -480,18 +379,6 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
}
|
||||
|
||||
// Clear all has-error tags
|
||||
// function clearAllErrors() {
|
||||
// // Remove any validation errors
|
||||
// $(selectedRecord)
|
||||
// .find('.has-error')
|
||||
// .removeClass('has-error')
|
||||
// .find('span')
|
||||
// .remove();
|
||||
// // Remove any alerts
|
||||
// $('#alert-container').find('div').remove();
|
||||
// }
|
||||
|
||||
function dataTableInit() {
|
||||
viewAssigned = 'assigned';
|
||||
TABLE = $(TABLE_ID).DataTable({
|
||||
|
@ -852,82 +739,6 @@ var RepositoryDatatable = (function(global) {
|
|||
adjustTableHeader();
|
||||
};
|
||||
|
||||
// function submitForm(url, formData) {
|
||||
// var type;
|
||||
// if (saveAction === 'update') {
|
||||
// type = 'PUT';
|
||||
// } else {
|
||||
// type = 'POST';
|
||||
// }
|
||||
// $.ajax({
|
||||
// url: url,
|
||||
// type: type,
|
||||
// dataType: 'json',
|
||||
// data: formData,
|
||||
// processData: false,
|
||||
// contentType: false,
|
||||
// success: function(data) {
|
||||
// HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
// SmartAnnotation.closePopup();
|
||||
// SCINOTE_REPOSITORY_EDITED_ROWS = [];
|
||||
// onClickCancel();
|
||||
// animateSpinner(null, false);
|
||||
// },
|
||||
// error: function(ev) {
|
||||
// var data = ev.responseJSON;
|
||||
// animateSpinner(null, false);
|
||||
// SmartAnnotation.closePopup();
|
||||
// clearAllErrors();
|
||||
//
|
||||
// if (ev.status === 404) {
|
||||
// HelperModule.flashAlertMsg(
|
||||
// I18n.t('repositories.js.not_found_error'), 'danger'
|
||||
// );
|
||||
// changeToViewMode();
|
||||
// } else if (ev.status === 403) {
|
||||
// HelperModule.flashAlertMsg(
|
||||
// I18n.t('repositories.js.permission_error'), 'danger'
|
||||
// );
|
||||
// changeToViewMode();
|
||||
// } else if (ev.status === 400) {
|
||||
// if (data.default_fields) {
|
||||
// let defaultFields = data.default_fields;
|
||||
//
|
||||
// // Validate record name
|
||||
// if (defaultFields.name) {
|
||||
// let input = $(selectedRecord).find('input[name = name]');
|
||||
//
|
||||
// if (input) {
|
||||
// input.closest('.form-group').addClass('has-error');
|
||||
// input.parent().append("<span class='help-block'>" + defaultFields.name + '<br /></span>');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Validate custom cells
|
||||
// $.each(data.repository_cells || [], function(_, val) {
|
||||
// $.each(val, function(key, val2) {
|
||||
// let input = $(selectedRecord).find('input[name=' + key + ']');
|
||||
// if (input) {
|
||||
// let message = Array.isArray(val2.data) ? val2.data[0] : val2.data;
|
||||
// // handle custom input field
|
||||
// if (input.attr('type') === 'file') {
|
||||
// let container = input.closest('.repository-input-file-field');
|
||||
// $(container.find('.form-group')[0]).addClass('has-error');
|
||||
// container.addClass('has-error');
|
||||
// container.append("<span class='help-block'>" + message + '<br /></span>');
|
||||
// } else {
|
||||
// input.closest('.form-group').addClass('has-error');
|
||||
// input.parent().append("<span class='help-block'>" + message + '<br /></span>');
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// Delete record
|
||||
global.onClickDelete = function() {
|
||||
$('#deleteRepositoryRecord').modal('show');
|
||||
|
|
|
@ -19,7 +19,7 @@ class RepositoryTableStateColumnUpdateService
|
|||
state['columns'][index] = Constants::REPOSITORY_TABLE_STATE_CUSTOM_COLUMN_TEMPLATE
|
||||
state['ColReorder'] << index
|
||||
state['length'] = (index + 1)
|
||||
state['time'] = Time.new.to_i
|
||||
state['time'] = (Time.now.to_f * 1_000).to_i
|
||||
table_state.save
|
||||
end
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ class RepositoryTableStateColumnUpdateService
|
|||
end
|
||||
|
||||
state['length'] = (state['length'] - 1)
|
||||
state['time'] = Time.new.to_i
|
||||
state['time'] = (Time.now.to_f * 1_000).to_i
|
||||
table_state.save
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue