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

138 lines
4.8 KiB
JavaScript
Raw Normal View History

/*
2019-12-23 21:34:11 +08:00
global ListColumnHelper ChecklistColumnHelper StatusColumnHelper SmartAnnotation I18n
DateTimeHelper AssetColumnHelper
*/
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(`
2020-01-23 20:12:58 +08:00
<div class="sci-input-container text-field error-icon">
2020-01-15 23:46:01 +08:00
<input class="sci-input-field"
form="${formId}"
type="text"
2019-12-10 15:41:09 +08:00
name="repository_row[name]"
value="${text}"
2020-01-09 21:57:37 +08:00
placeholder="${I18n.t('repositories.table.enter_row_name')}"
data-type="RowName">
</div>
`);
};
$.fn.dataTable.render.editRepositoryAssetValue = function(formId, columnId, cell) {
2019-12-04 21:52:52 +08:00
let $cell = $(cell.node());
AssetColumnHelper.renderCell($cell, formId, columnId);
};
$.fn.dataTable.render.editRepositoryTextValue = function(formId, columnId, cell) {
2019-11-29 19:52:27 +08:00
let $cell = $(cell.node());
let text = $cell.find('.text-value').data('edit-value');
2019-11-29 19:52:27 +08:00
$cell.html(`
2020-01-23 20:12:58 +08:00
<div class="sci-input-container text-field error-icon">
2020-01-15 23:46:01 +08:00
<input class="sci-input-field"
2019-11-29 19:52:27 +08:00
form="${formId}"
type="text"
name="repository_cells[${columnId}]"
value="${text}"
2020-01-09 21:57:37 +08:00
placeholder="${I18n.t('repositories.table.text.enter_text')}"
2019-11-29 19:52:27 +08:00
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());
2019-12-23 21:34:11 +08:00
var currentElement = $cell.find('.status-label');
var iconElement = $cell.find('.repository-status-value-icon');
var currentValue = null;
if (currentElement.length) {
currentValue = {
value: currentElement.attr('data-value-id'),
2020-01-21 17:49:45 +08:00
label: iconElement.find('img').attr('alt') + ' ' + currentElement.text()
2019-12-23 21:34:11 +08:00
};
}
2019-12-02 18:03:05 +08:00
2019-12-23 21:34:11 +08:00
StatusColumnHelper.initialStatusEditMode(formId, columnId, $cell, currentValue);
};
2019-11-29 19:52:27 +08:00
$.fn.dataTable.render.editRepositoryDateTimeValue = function(formId, columnId, cell) {
let $cell = $(cell.node());
DateTimeHelper.initDateTimeEditMode(formId, columnId, $cell, '', 'RepositoryDateTimeValue');
2019-11-29 19:52:27 +08:00
};
$.fn.dataTable.render.editRepositoryDateValue = function(formId, columnId, cell) {
let $cell = $(cell.node());
DateTimeHelper.initDateTimeEditMode(formId, columnId, $cell, 'dateonly', 'RepositoryDateValue');
2019-11-29 19:52:27 +08:00
};
$.fn.dataTable.render.editRepositoryTimeValue = function(formId, columnId, cell) {
let $cell = $(cell.node());
DateTimeHelper.initDateTimeEditMode(formId, columnId, $cell, 'timeonly', 'RepositoryTimeValue');
2019-11-29 19:52:27 +08:00
};
$.fn.dataTable.render.editRepositoryDateTimeRangeValue = function(formId, columnId, cell) {
2019-12-17 18:27:07 +08:00
let $cell = $(cell.node());
DateTimeHelper.initDateTimeRangeEditMode(formId, columnId, $cell, '', 'RepositoryDateTimeRangeValue');
2019-11-29 19:52:27 +08:00
};
$.fn.dataTable.render.editRepositoryDateRangeValue = function(formId, columnId, cell) {
2019-12-17 20:42:25 +08:00
let $cell = $(cell.node());
DateTimeHelper.initDateTimeRangeEditMode(formId, columnId, $cell, 'dateonly', 'RepositoryDateRangeValue');
2019-11-29 19:52:27 +08:00
};
$.fn.dataTable.render.editRepositoryTimeRangeValue = function(formId, columnId, cell) {
2019-12-17 20:42:25 +08:00
let $cell = $(cell.node());
DateTimeHelper.initDateTimeRangeEditMode(formId, columnId, $cell, 'timeonly', 'RepositoryTimeRangeValue');
2019-11-29 19:52:27 +08:00
};
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 = $header.data('metadata-decimals');
let number = $cell.find('.number-value').data('value');
if (!number) number = '';
$cell.html(`
2020-01-23 20:12:58 +08:00
<div class="sci-input-container text-field error-icon">
2020-01-15 23:46:01 +08:00
<input class="sci-input-field"
form="${formId}"
type="text"
oninput="regexp = ${decimals} === 0 ? /[^0-9]/g : /[^0-9.]/g
this.value = this.value.replace(regexp, '');
this.value = this.value.match(/^\\d*(\\.\\d{0,${decimals}})?/)[0];"
name="repository_cells[${columnId}]"
2020-01-09 21:57:37 +08:00
placeholder="${I18n.t('repositories.table.number.enter_number')}"
value="${number}"
data-type="RepositoryNumberValue">
</div>`);
};