mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-16 21:59:00 +08:00
Fixes repository items edit action, adds additional event listener for file upload
This commit is contained in:
parent
7aacc2b4a2
commit
23de3abd61
3 changed files with 38 additions and 41 deletions
|
|
@ -69,7 +69,7 @@
|
||||||
$.each(itemData.repository_row.repository_cells, function(i, cell) {
|
$.each(itemData.repository_row.repository_cells, function(i, cell) {
|
||||||
var tableCellId = 'cellId-' + cell.repository_cell_id;
|
var tableCellId = 'cellId-' + cell.repository_cell_id;
|
||||||
if(cell.type === 'RepositoryAssetValue') {
|
if(cell.type === 'RepositoryAssetValue') {
|
||||||
formBindingsData[tableCellId] = new Blob([cell.value], { type: cell.value.file_content_type });
|
formBindingsData[tableCellId] = new File(cell.asset_preview);
|
||||||
} else {
|
} else {
|
||||||
formBindingsData[tableCellId] = cell.value;
|
formBindingsData[tableCellId] = cell.value;
|
||||||
}
|
}
|
||||||
|
|
@ -77,11 +77,10 @@
|
||||||
return formBindingsData;
|
return formBindingsData;
|
||||||
}
|
}
|
||||||
|
|
||||||
RepositoryItemEditForm.prototype.getRowNewData = function() {
|
|
||||||
return this.formData;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Private methods
|
* |-----------------|
|
||||||
|
* | Private methods |
|
||||||
|
* |-----------------|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,7 +99,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes object and creates an input file field
|
* 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 {Object} object
|
||||||
* @param {String} name
|
* @param {String} name
|
||||||
|
|
@ -111,8 +112,9 @@
|
||||||
*/
|
*/
|
||||||
function changeToInputFileField(object, name, value, id) {
|
function changeToInputFileField(object, name, value, id) {
|
||||||
return "<div class='repository-input-file-field'><div class='form-group'>" +
|
return "<div class='repository-input-file-field'><div class='form-group'>" +
|
||||||
"<input type='file' class='form-control' data-object='" +
|
"<input type='file' name='" + name + "' data-id='" + id + "' style='display:none'>" +
|
||||||
object + "' name='" + name + "' value='" + value + "' id='" + id + "'></div>" +
|
"<button class='form-control' data-object='" +
|
||||||
|
object + "' name='" + name + "' value='" + value + "' id='" + id + "'>Choose File</button></div>" +
|
||||||
"<a onClick='clearFileInput(this)'>" +
|
"<a onClick='clearFileInput(this)'>" +
|
||||||
"<i class='fas fa-times'></i>" +
|
"<i class='fas fa-times'></i>" +
|
||||||
"</a></div>";
|
"</a></div>";
|
||||||
|
|
@ -155,6 +157,7 @@
|
||||||
html += '</select>';
|
html += '</select>';
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an object and creates custom html element
|
* Takes an object and creates custom html element
|
||||||
*
|
*
|
||||||
|
|
@ -182,25 +185,46 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append the change listener to file field
|
* Append the change listener to file field
|
||||||
|
*
|
||||||
* @param {String} type
|
* @param {String} type
|
||||||
* @param {Object} input
|
* @param {Object} input
|
||||||
|
* @param {Object} formData
|
||||||
*
|
*
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
function _addSelectedFile(type, input) {
|
function _addSelectedFile(type, input, formData) {
|
||||||
if (type === 'RepositoryAssetValue') {
|
if (type === 'RepositoryAssetValue') {
|
||||||
|
|
||||||
$(input).on('change', function(){
|
$(input).on('change', function(){
|
||||||
this.dataset.changed = 'true';
|
this.dataset.changed = 'true';
|
||||||
|
}).on('click', function(ev) {
|
||||||
|
ev.prevetDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
var input = $(this).closest('input[type="file"]');
|
||||||
|
input.trigger('click');
|
||||||
|
initFileHandler(input, formData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle extraction of file from the input field
|
||||||
|
*
|
||||||
|
* @param {Object} formData
|
||||||
|
*
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
function initFileHandler(inputField, formData) {
|
||||||
|
if (inputField.files[0]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initializeDataBinding(row_node, data) {
|
function initializeDataBinding(row_node, data) {
|
||||||
var uiBindings = {};
|
var uiBindings = {};
|
||||||
$.each(_.keys(data), function(i, element) {
|
$.each(_.keys(data), function(i, element) {
|
||||||
uiBindings['#' + element] = element;
|
uiBindings['#' + element] = element;
|
||||||
})
|
})
|
||||||
$(row_node).my({ui: uiBindings}, data);
|
$(row_node).my({ui: uiBindings}, data);
|
||||||
debugger;
|
|
||||||
}
|
}
|
||||||
})(window);
|
})(window);
|
||||||
|
|
@ -667,35 +667,6 @@ var RepositoryDatatable = (function(global) {
|
||||||
|
|
||||||
var editForm = new RepositoryItemEditForm(data, node);
|
var editForm = new RepositoryItemEditForm(data, node);
|
||||||
editForm.renderForm(TABLE);
|
editForm.renderForm(TABLE);
|
||||||
/**
|
|
||||||
// Record name column
|
|
||||||
var colIndex = getColumnIndex('#row-name');
|
|
||||||
if (colIndex) {
|
|
||||||
$(node).children('td').eq(colIndex)
|
|
||||||
.html(changeToInputField('repository_row', 'name',
|
|
||||||
data.repository_row.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take care of custom cells
|
|
||||||
var cells = data.repository_row.repository_cells;
|
|
||||||
var list_columns = data.repository_row.repository_column_items;
|
|
||||||
$(node).children('td').each(function(i) {
|
|
||||||
var td = $(this);
|
|
||||||
var rawIndex = TABLE.column.index('fromVisible', i);
|
|
||||||
var colHeader = TABLE.column(rawIndex).header();
|
|
||||||
if ($(colHeader).hasClass('repository-column')) {
|
|
||||||
var type = $(colHeader).attr('data-type');
|
|
||||||
// Check if cell on this record exists
|
|
||||||
var cell = cells[$(colHeader).attr('id')] || '';
|
|
||||||
td.html(changeToFormField('repository_cell',
|
|
||||||
$(colHeader).attr('id'),
|
|
||||||
type,
|
|
||||||
cell,
|
|
||||||
list_columns));
|
|
||||||
_addSelectedFile(type, cell, $(this).find('input')[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
_initSelectPicker();
|
_initSelectPicker();
|
||||||
|
|
||||||
// initialize smart annotation
|
// initialize smart annotation
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,8 @@ class RepositoryRowsController < ApplicationController
|
||||||
# Add custom cells ids as key (easier lookup on js side)
|
# Add custom cells ids as key (easier lookup on js side)
|
||||||
@record.repository_cells.each do |cell|
|
@record.repository_cells.each do |cell|
|
||||||
if cell.value_type == 'RepositoryAssetValue'
|
if cell.value_type == 'RepositoryAssetValue'
|
||||||
cell_value = cell.value.asset if cell.value_type == 'RepositoryAssetValue'
|
cell_value = cell.value.asset
|
||||||
|
asset_url = cell.value.asset.url(:original)
|
||||||
else
|
else
|
||||||
cell_value = escape_input(cell.value.data)
|
cell_value = escape_input(cell.value.data)
|
||||||
end
|
end
|
||||||
|
|
@ -94,6 +95,7 @@ class RepositoryRowsController < ApplicationController
|
||||||
json[:repository_row][:repository_cells][cell.repository_column_id] = {
|
json[:repository_row][:repository_cells][cell.repository_column_id] = {
|
||||||
repository_cell_id: cell.id,
|
repository_cell_id: cell.id,
|
||||||
value: cell_value,
|
value: cell_value,
|
||||||
|
asset_preview: (asset_url || ''),
|
||||||
type: cell.value_type,
|
type: cell.value_type,
|
||||||
list_items: fetch_list_items(cell)
|
list_items: fetch_list_items(cell)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue