From fb7d3bf7cefa9aa7d2d3ef5ee8dd1613be42dd9b Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 22 Mar 2020 05:25:39 +0000 Subject: [PATCH] Clean up toggleMultiSelect js function (#32813). Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@19604 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/workflows/edit.html.erb | 23 +++------------------- app/views/workflows/permissions.html.erb | 20 ++----------------- public/javascripts/application.js | 25 +++++++++++++++++++----- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/app/views/workflows/edit.html.erb b/app/views/workflows/edit.html.erb index 3f3e3c2f5..c247097a4 100644 --- a/app/views/workflows/edit.html.erb +++ b/app/views/workflows/edit.html.erb @@ -15,13 +15,13 @@

- - <%= submit_tag l(:button_edit), :name => nil %> @@ -57,21 +57,4 @@ <%= submit_tag l(:button_save) %> <% end %> -<% end %> - -<%= javascript_tag do %> -$("a[data-expands]").click(function(e){ - e.preventDefault(); - var target = $($(this).attr("data-expands")); - if (target.attr("multiple")) { - $(this).find('span').switchClass('icon-toggle-minus', 'icon-toggle-plus'); - target.attr("multiple", false); - target.find("option[value=all]").show(); - } else { - $(this).find('span').switchClass('icon-toggle-plus', 'icon-toggle-minus'); - target.attr("multiple", true); - target.find("option[value=all]").attr("selected", false).hide(); - } -}); - -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/workflows/permissions.html.erb b/app/views/workflows/permissions.html.erb index f2e9fff7b..0b27c378d 100644 --- a/app/views/workflows/permissions.html.erb +++ b/app/views/workflows/permissions.html.erb @@ -15,14 +15,13 @@

- - - <%= submit_tag l(:button_edit), :name => nil %> <%= hidden_field_tag 'used_statuses_only', '0', :id => nil %> @@ -107,19 +106,4 @@ $("a.repeat-value").click(function(e){ var selected = td.find("select").find(":selected").val(); td.nextAll('td').find("select").val(selected); }); - -$("a[data-expands]").click(function(e){ - e.preventDefault(); - var target = $($(this).attr("data-expands")); - if (target.attr("multiple")) { - $(this).find('span').switchClass('icon-toggle-minus', 'icon-toggle-plus'); - target.attr("multiple", false); - target.find("option[value=all]").show(); - } else { - $(this).find('span').switchClass('icon-toggle-plus', 'icon-toggle-minus'); - target.attr("multiple", true); - target.find("option[value=all]").attr("selected", false).hide(); - } -}); - <% end %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index c9b7bb6b5..f33c9caf8 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -120,10 +120,6 @@ function initFilters() { $('#filters-table').on('click', 'td.field input[type=checkbox]', function() { toggleFilter($(this).val()); }); - $('#filters-table').on('click', '.toggle-multiselect', function() { - toggleMultiSelect($(this).siblings('select')) - $(this).toggleClass('icon-toggle-plus icon-toggle-minus') - }); $('#filters-table').on('keypress', 'input[type=text]', function(e) { if (e.keyCode == 13) $(this).closest('form').submit(); }); @@ -151,6 +147,7 @@ function addFilter(field, operator, values) { } $('#cb_'+fieldId).prop('checked', true); toggleFilter(field); + toggleMultiSelectIconInit(); $('#add_filter_select').val('').find('option').each(function() { if ($(this).attr('value') == field) { $(this).attr('disabled', true); @@ -189,7 +186,7 @@ function buildFilterRow(field, operator, values) { case "list_subprojects": tr.find('td.values').append( '' + - '  ' + '  ' ); select = tr.find('td.values select'); if (values.length > 1) { select.attr('multiple', true); } @@ -336,11 +333,14 @@ function toggleOperator(field) { } function toggleMultiSelect(el) { + var isWorkflow = el.closest('.controller-workflows'); if (el.attr('multiple')) { el.removeAttr('multiple'); + if (isWorkflow) { el.find("option[value=all]").show(); } el.attr('size', 1); } else { el.attr('multiple', true); + if (isWorkflow) { el.find("option[value=all]").attr("selected", false).hide(); } if (el.children().length > 10) el.attr('size', 10); else @@ -891,6 +891,15 @@ function toggleDisabledOnChange() { function toggleDisabledInit() { $('input[data-disables], input[data-enables], input[data-shows]').each(toggleDisabledOnChange); } +function toggleMultiSelectIconInit() { + $('.toggle-multiselect:not(.icon-toggle-minus), .toggle-multiselect:not(.icon-toggle-plus)').each(function(){ + if ($(this).siblings('select').find('option:selected').size() > 1){ + $(this).addClass('icon-toggle-minus'); + } else { + $(this).addClass('icon-toggle-plus'); + } + }); +} function toggleNewObjectDropdown() { var dropdown = $('#new-object + ul.menu-children'); @@ -931,6 +940,12 @@ $(document).ready(function(){ $('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange); toggleDisabledInit(); + $('#content').on('click', '.toggle-multiselect', function() { + toggleMultiSelect($(this).siblings('select')); + $(this).toggleClass('icon-toggle-plus icon-toggle-minus'); + }); + toggleMultiSelectIconInit(); + $('#history .tabs').on('click', 'a', function(e){ var tab = $(e.target).attr('id').replace('tab-',''); document.cookie = 'history_last_tab=' + tab -- 2.39.5