mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 19:24:10 +08:00
Strip length of dropdown items, unique items, add specific params to request
This commit is contained in:
parent
6fbb99c8d2
commit
db2943a1b7
3 changed files with 30 additions and 3 deletions
|
@ -1,7 +1,12 @@
|
|||
/* global GLOBAL_CONSTANTS */
|
||||
/* eslint-disable no-unused-vars */
|
||||
var RepositoryListColumnType = (function() {
|
||||
var manageModal = '#manageRepositoryColumn';
|
||||
|
||||
function onlyUnique(value, index, self) {
|
||||
return self.indexOf(value) === index;
|
||||
}
|
||||
|
||||
function textToItems(text, delimiter) {
|
||||
var res = [];
|
||||
var definedDelimiters = {
|
||||
|
@ -26,7 +31,12 @@ var RepositoryListColumnType = (function() {
|
|||
}
|
||||
});
|
||||
|
||||
return res.filter(Boolean);
|
||||
res = res.filter(Boolean).filter(onlyUnique);
|
||||
|
||||
$.each(res, (index, option) => {
|
||||
res[index] = option.slice(0, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
function drawDropdownPreview(items) {
|
||||
|
@ -47,11 +57,15 @@ var RepositoryListColumnType = (function() {
|
|||
var dropdownDelimiter = 'select#delimiter';
|
||||
|
||||
$manageModal.off('change keyup paste', listItemsTextarea).on('change keyup paste', listItemsTextarea, function() {
|
||||
drawDropdownPreview(textToItems($(listItemsTextarea).val(), $(dropdownDelimiter).val()));
|
||||
var items = textToItems($(listItemsTextarea).val(), $(dropdownDelimiter).val());
|
||||
drawDropdownPreview(items);
|
||||
$('#dropdown_options').val(items);
|
||||
});
|
||||
|
||||
$manageModal.off('change', dropdownDelimiter).on('change', dropdownDelimiter, function() {
|
||||
drawDropdownPreview(textToItems($(listItemsTextarea).val(), $(dropdownDelimiter).val()));
|
||||
var items = textToItems($(listItemsTextarea).val(), $(dropdownDelimiter).val());
|
||||
drawDropdownPreview(items);
|
||||
$('#dropdown_options').val(items);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -80,11 +80,21 @@ var RepositoryColumns = (function() {
|
|||
$('li[data-id=' + column.id + ']').find('span').first().text(name);
|
||||
}
|
||||
|
||||
function loadSpecificParams(type, params) {
|
||||
var newParams = params;
|
||||
if (type === 'RepositoryListValue') {
|
||||
newParams.repository_column.list_items = $('#dropdown_options').val();
|
||||
}
|
||||
return newParams;
|
||||
}
|
||||
|
||||
function initCreateSubmitAction() {
|
||||
var $manageModal = $(manageModal);
|
||||
$manageModal.off('click', '#new-repo-column-submit').on('click', '#new-repo-column-submit', function() {
|
||||
var url = $('#repository-column-data-type').find(':selected').data('create-url');
|
||||
var params = { repository_column: { name: $('#repository-column-name').val() } };
|
||||
var selectedType = $('#repository-column-data-type').find(':selected').val();
|
||||
params = loadSpecificParams(selectedType, params);
|
||||
$.post(url, params, (result) => {
|
||||
var data = result.data;
|
||||
insertNewListItem(data);
|
||||
|
@ -101,6 +111,8 @@ var RepositoryColumns = (function() {
|
|||
$manageModal.off('click', '#update-repo-column-submit').on('click', '#update-repo-column-submit', function() {
|
||||
var url = $('#repository-column-data-type').find(':selected').data('edit-url');
|
||||
var params = { repository_column: { name: $('#repository-column-name').val() } };
|
||||
var selectedType = $('#repository-column-data-type').find(':selected').val();
|
||||
params = loadSpecificParams(selectedType, params);
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'PUT',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<%= hidden_field_tag 'dropdown_options' %>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3" for="repository-column-data-type">
|
||||
<%= t('libraries.manange_modal_column.list_type.delimiter_label') %>
|
||||
|
|
Loading…
Reference in a new issue