diff --git a/app/assets/javascripts/repository_columns/columns_initializers/list_column_type.js b/app/assets/javascripts/repository_columns/columns_initializers/list_column_type.js index 24c52b53c..033b362dd 100644 --- a/app/assets/javascripts/repository_columns/columns_initializers/list_column_type.js +++ b/app/assets/javascripts/repository_columns/columns_initializers/list_column_type.js @@ -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); }); } diff --git a/app/assets/javascripts/repository_columns/index.js b/app/assets/javascripts/repository_columns/index.js index e2e7f9746..6e73dcec9 100644 --- a/app/assets/javascripts/repository_columns/index.js +++ b/app/assets/javascripts/repository_columns/index.js @@ -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', diff --git a/app/views/repository_columns/manage_column_partials/_list.html.erb b/app/views/repository_columns/manage_column_partials/_list.html.erb index 316009a56..566c0b2c5 100644 --- a/app/views/repository_columns/manage_column_partials/_list.html.erb +++ b/app/views/repository_columns/manage_column_partials/_list.html.erb @@ -1,3 +1,4 @@ +<%= hidden_field_tag 'dropdown_options' %>