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

61 lines
2 KiB
JavaScript
Raw Normal View History

2020-01-21 17:49:45 +08:00
/* global dropdownSelector I18n twemoji */
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 = '';
var selectObject = $(`<select id="${select}"
2020-06-02 21:16:01 +08:00
data-placeholder = "${I18n.t('repositories.table.status.set_status')}"
data-ajax-url = "${url}" ></select>`);
2019-12-23 21:34:11 +08:00
if (value && value.value) {
2020-06-02 21:16:01 +08:00
selectedOption = $(`<option value="${value.value}"></option>`);
selectedOption.text(value.label);
selectedOption.appendTo(selectObject);
2019-12-23 21:34:11 +08:00
}
2020-06-02 21:16:01 +08:00
return selectObject;
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) {
var select = `status-list-${columnId}-${cell.parent()[0].id}`;
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',
2020-01-15 22:22:05 +08:00
closeOnSelect: true,
2020-02-07 21:57:07 +08:00
emptyOptionAjax: true,
2020-06-02 12:15:34 +08:00
labelHTML: true,
2020-01-21 17:49:45 +08:00
onChange: () => {
2019-12-23 21:34:11 +08:00
var values = dropdownSelector.getValues('#' + select);
$hiddenField.val(values);
2020-01-21 17:49:45 +08:00
},
optionClass: 'emoji-status',
optionLabel: (data) => {
return twemoji.parse(data.label);
},
tagClass: 'emoji-status',
tagLabel: (data) => {
2020-06-02 21:16:01 +08:00
var render = $('<div>').html(twemoji.parse(data.label));
render.find(':not(img)').remove();
return render.html();
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
};
}());