scinote-web/app/assets/javascripts/repositories/renderers/columns/status.js

47 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-01-09 21:57:37 +08:00
/* global dropdownSelector I18n */
2019-12-02 18:03:05 +08:00
/* eslint-disable no-unused-vars */
2019-12-23 21:34:11 +08:00
var StatusColumnHelper = (function() {
function statusSelect(select, url, value) {
var selectedOption = '';
if (value && value.value) {
selectedOption = `<option value="${value.value}">${value.label}</option>`;
}
return $(`<select
id="${select}"
2020-01-09 21:57:37 +08:00
data-placeholder = "${I18n.t('repositories.table.status.set_status')}"
2019-12-23 21:34:11 +08:00
data-ajax-url = "${url}"
>${selectedOption}</select>`);
2019-12-02 18:03:05 +08:00
}
2019-12-23 21:34:11 +08:00
function statusHiddenField(formId, columnId, value) {
var originalValue = value ? value.value : '';
return $(`<input form="${formId}"
type="hidden"
name="repository_cells[${columnId}]"
value="${originalValue}"
data-type="RepositoryStatusValue">`);
2019-12-02 18:03:05 +08:00
}
2019-12-23 21:34:11 +08:00
function initialStatusEditMode(formId, columnId, cell, value = null) {
2019-12-24 15:13:30 +08:00
var select = 'status-list-' + columnId;
2019-12-23 21:34:11 +08:00
var listUrl = $('.repository-column#' + columnId).data('items-url');
var $select = statusSelect(select, listUrl, value);
var $hiddenField = statusHiddenField(formId, columnId, value);
cell.html($select).append($hiddenField);
dropdownSelector.init('#' + select, {
2019-12-02 18:03:05 +08:00
singleSelect: true,
selectAppearance: 'simple',
onChange: function() {
2019-12-23 21:34:11 +08:00
var values = dropdownSelector.getValues('#' + select);
$hiddenField.val(values);
2019-12-02 18:03:05 +08:00
}
});
}
return {
2019-12-23 21:34:11 +08:00
initialStatusEditMode: initialStatusEditMode
2019-12-02 18:03:05 +08:00
};
}());