2019-12-02 18:03:05 +08:00
|
|
|
/* global dropdownSelector */
|
|
|
|
/* 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}"
|
|
|
|
data-placeholder = "Select option..."
|
|
|
|
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
|
|
|
};
|
|
|
|
}());
|