scinote-web/app/assets/javascripts/repositories/renderers/edit_renderers.js

137 lines
4.5 KiB
JavaScript
Raw Normal View History

2019-12-11 21:49:14 +08:00
/* global ListColumnHelper ChecklistColumnHelper Status SmartAnnotation I18n GLOBAL_CONSTANTS */
2019-11-29 19:52:27 +08:00
$.fn.dataTable.render.editRowName = function(formId, cell) {
let $cell = $(cell.node());
let text = $cell.find('a').first().text();
$cell.html(`
<div class="form-group">
<input class="form-control editing"
form="${formId}"
type="text"
2019-12-10 15:41:09 +08:00
name="repository_row[name]"
value="${text}"
data-type="RowName">
</div>
`);
};
$.fn.dataTable.render.editRepositoryAssetValue = function(formId, columnId, cell) {
2019-12-04 21:52:52 +08:00
let $cell = $(cell.node());
let empty = $cell.is(':empty');
let fileName = $cell.find('a.file-preview-link').text();
$cell.html(`
<div class="file-editing">
<div class="file-hidden-field-container hidden"></div>
<input class=""
id="repository_file_${columnId}"
form="${formId}"
type="file"
data-col-id="${columnId}"
data-is-empty="${empty}"
value=""
data-type="RepositoryAssetValue">
<div class="file-upload-button ${empty ? 'new-file' : ''}">
<label for="repository_file_${columnId}">${I18n.t('repositories.table.assets.select_file_btn', { max_size: GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB })}</label>
2019-12-04 21:52:52 +08:00
<span class="icon"><i class="fas fa-paperclip"></i></span><span class="label-asset">${fileName}</span>
<span class="delete-action fas fa-trash"> </span>
</div>
</div>`);
};
$.fn.dataTable.render.editRepositoryTextValue = function(formId, columnId, cell) {
2019-11-29 19:52:27 +08:00
let $cell = $(cell.node());
let text = $cell.text();
$cell.html(`
<div class="form-group">
<input class="form-control editing"
form="${formId}"
type="text"
name="repository_cells[${columnId}]"
value="${text}"
data-type="RepositoryTextValue">
</div>`);
SmartAnnotation.init($cell.find('input'));
};
$.fn.dataTable.render.editRepositoryListValue = function(formId, columnId, cell) {
var $cell = $(cell.node());
2019-12-11 21:49:14 +08:00
var currentElement = $cell.find('.list-label');
var currentValue = null;
if (currentElement.length) {
currentValue = {
value: currentElement.attr('data-value-id'),
label: currentElement.text()
};
}
2019-12-11 21:49:14 +08:00
ListColumnHelper.initialListEditMode(formId, columnId, $cell, currentValue);
};
$.fn.dataTable.render.editRepositoryStatusValue = function(formId, columnId, cell) {
2019-12-02 18:03:05 +08:00
let $cell = $(cell.node());
let currentValueId = $cell.find('.status-label').attr('data-value-id');
let url = $cell.closest('table').data('status-items-path');
let hiddenField = `
<input form="${formId}"
type="hidden"
name="repository_cells[${columnId}]"
value=""
data-type="RepositoryStatusValue">`;
$cell.html(hiddenField + Status.initialStatusItemsRequest(columnId, currentValueId, formId, url));
Status.initStatusSelectPicker($cell.find('select'), $cell.find(`[name='repository_cells[${columnId}]']`));
};
2019-11-29 19:52:27 +08:00
$.fn.dataTable.render.editRepositoryDateTimeValue = function(formId, columnId, cell) {
return '';
};
$.fn.dataTable.render.editRepositoryDateValue = function(formId, columnId, cell) {
return '';
};
$.fn.dataTable.render.editRepositoryTimeValue = function(formId, columnId, cell) {
return '';
};
$.fn.dataTable.render.editRepositoryDateTimeRangeValue = function(formId, columnId, cell) {
return '';
};
$.fn.dataTable.render.editRepositoryDateRangeValue = function(formId, columnId, cell) {
return '';
};
$.fn.dataTable.render.editRepositoryTimeRangeValue = function(formId, columnId, cell) {
return '';
};
2019-12-06 20:18:35 +08:00
$.fn.dataTable.render.editRepositoryChecklistValue = function(formId, columnId, cell) {
2019-12-11 21:49:14 +08:00
var $cell = $(cell.node());
var currentValue = $cell.find('.checklist-options').data('checklist-items');
ChecklistColumnHelper.initialChecklistEditMode(formId, columnId, $cell, currentValue);
2019-12-06 20:18:35 +08:00
};
$.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cell, $header) {
let $cell = $(cell.node());
let decimals = Number($header.data('metadata-decimals'));
let number = parseFloat(Number($cell.text()).toFixed(decimals));
$cell.html(`
<div class="form-group">
<input class="form-control editing"
form="${formId}"
type="number"
name="repository_cells[${columnId}]"
value="${number}"
onchange="if (this.value !== '') { this.value = parseFloat(Number(this.value).toFixed(${decimals})); }"
data-type="RepositoryNumberValue">
</div>`);
};