0001-Unify-processing-for-switching-multiple-selections.patch

Mizuki ISHIKAWA, 2020-01-15 07:03

Download (7.09 KB)

View differences:

app/views/workflows/edit.html.erb
15 15
<p>
16 16
  <label><%=l(:label_role)%>:
17 17
  <%= options_for_workflow_select 'role_id[]', Role.sorted.select(&:consider_workflow?), @roles, :id => 'role_id', :class => 'expandable' %>
18
  <span class="toggle-multiselect icon-only"></span>
18 19
  </label>
19
  <a href="#" data-expands="#role_id"><span class="toggle-multiselect icon-only icon-toggle-plus"></span></a>
20 20

  
21 21
  <label><%=l(:label_tracker)%>:
22 22
  <%= options_for_workflow_select 'tracker_id[]', Tracker.sorted, @trackers, :id => 'tracker_id', :class => 'expandable' %>
23
  <span class="toggle-multiselect icon-only"></span>
23 24
  </label>
24
  <a href="#" data-expands="#tracker_id"><span class="toggle-multiselect icon-only icon-toggle-plus"></span></a>
25 25

  
26 26
  <%= submit_tag l(:button_edit), :name => nil %>
27 27

  
......
57 57
    </div>
58 58
    <%= submit_tag l(:button_save) %>
59 59
  <% end %>
60
<% end %>
61

  
62
<%= javascript_tag do %>
63
$("a[data-expands]").click(function(e){
64
  e.preventDefault();
65
  var target = $($(this).attr("data-expands"));
66
  if (target.attr("multiple")) {
67
    $(this).find('span').switchClass('icon-toggle-minus', 'icon-toggle-plus');
68
    target.attr("multiple", false);
69
    target.find("option[value=all]").show();
70
  } else {
71
    $(this).find('span').switchClass('icon-toggle-plus', 'icon-toggle-minus');
72
    target.attr("multiple", true);
73
    target.find("option[value=all]").attr("selected", false).hide();
74
  }
75
});
76

  
77
<% end %>
60
<% end %>
app/views/workflows/permissions.html.erb
15 15
<p>
16 16
  <label><%=l(:label_role)%>:
17 17
  <%= options_for_workflow_select 'role_id[]', Role.sorted.select(&:consider_workflow?), @roles, :id => 'role_id', :class => 'expandable' %>
18
  <span class="toggle-multiselect icon-only"></span>
18 19
  </label>
19
  <a href="#" data-expands="#role_id"><span class="toggle-multiselect icon-only icon-toggle-plus"></span></a>
20 20

  
21 21
  <label><%=l(:label_tracker)%>:
22 22
  <%= options_for_workflow_select 'tracker_id[]', Tracker.sorted, @trackers, :id => 'tracker_id', :class => 'expandable' %>
23
  <span class="toggle-multiselect icon-only"></span>
23 24
  </label>
24
  <a href="#" data-expands="#tracker_id"><span class="toggle-multiselect icon-only icon-toggle-plus"></span></a>
25

  
26 25
  <%= submit_tag l(:button_edit), :name => nil %>
27 26

  
28 27
  <%= hidden_field_tag 'used_statuses_only', '0', :id => nil %>
......
107 106
  var selected = td.find("select").find(":selected").val();
108 107
  td.nextAll('td').find("select").val(selected);
109 108
});
110

  
111
$("a[data-expands]").click(function(e){
112
  e.preventDefault();
113
  var target = $($(this).attr("data-expands"));
114
  if (target.attr("multiple")) {
115
    $(this).find('span').switchClass('icon-toggle-minus', 'icon-toggle-plus');
116
    target.attr("multiple", false);
117
    target.find("option[value=all]").show();
118
  } else {
119
    $(this).find('span').switchClass('icon-toggle-plus', 'icon-toggle-minus');
120
    target.attr("multiple", true);
121
    target.find("option[value=all]").attr("selected", false).hide();
122
  }
123
});
124

  
125 109
<% end %>
public/javascripts/application.js
120 120
  $('#filters-table').on('click', 'td.field input[type=checkbox]', function() {
121 121
    toggleFilter($(this).val());
122 122
  });
123
  $('#filters-table').on('click', '.toggle-multiselect', function() {
124
    toggleMultiSelect($(this).siblings('select'))
125
    $(this).toggleClass('icon-toggle-plus icon-toggle-minus')
126
  });
127 123
  $('#filters-table').on('keypress', 'input[type=text]', function(e) {
128 124
    if (e.keyCode == 13) $(this).closest('form').submit();
129 125
  });
......
151 147
  }
152 148
  $('#cb_'+fieldId).prop('checked', true);
153 149
  toggleFilter(field);
150
  toggleMultiSelectIconInit();
154 151
  $('#add_filter_select').val('').find('option').each(function() {
155 152
    if ($(this).attr('value') == field) {
156 153
      $(this).attr('disabled', true);
......
189 186
  case "list_subprojects":
190 187
    tr.find('td.values').append(
191 188
      '<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' +
192
      ' <span class="toggle-multiselect icon-only icon-toggle-plus">&nbsp;</span></span>'
189
      ' <span class="toggle-multiselect icon-only '+(values.length > 1 ? 'icon-toggle-minus' : 'icon-toggle-plus')+'">&nbsp;</span></span>'
193 190
    );
194 191
    select = tr.find('td.values select');
195 192
    if (values.length > 1) { select.attr('multiple', true); }
......
336 333
}
337 334

  
338 335
function toggleMultiSelect(el) {
336
  var isWorkflow = el.closest('.controller-workflows');
339 337
  if (el.attr('multiple')) {
340 338
    el.removeAttr('multiple');
339
    if (isWorkflow) { el.find("option[value=all]").show(); }
341 340
    el.attr('size', 1);
342 341
  } else {
343 342
    el.attr('multiple', true);
343
    if (isWorkflow) { el.find("option[value=all]").attr("selected", false).hide(); }
344 344
    if (el.children().length > 10)
345 345
      el.attr('size', 10);
346 346
    else
......
891 891
function toggleDisabledInit() {
892 892
  $('input[data-disables], input[data-enables], input[data-shows]').each(toggleDisabledOnChange);
893 893
}
894
function toggleMultiSelectIconInit() {
895
  $('.toggle-multiselect:not(.icon-toggle-minus), .toggle-multiselect:not(.icon-toggle-plus)').each(function(){
896
    if ($(this).siblings('select').find('option:selected').size() > 1){
897
      $(this).addClass('icon-toggle-minus');
898
    } else {
899
      $(this).addClass('icon-toggle-plus');
900
    }
901
  });
902
}
894 903

  
895 904
function toggleNewObjectDropdown() {
896 905
  var dropdown = $('#new-object + ul.menu-children');
......
931 940
  $('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange);
932 941
  toggleDisabledInit();
933 942

  
943
  $('#content').on('click', '.toggle-multiselect', function() {
944
    toggleMultiSelect($(this).siblings('select'));
945
    $(this).toggleClass('icon-toggle-plus icon-toggle-minus');
946
  });
947
  toggleMultiSelectIconInit();
948

  
934 949
  $('#history .tabs').on('click', 'a', function(e){
935 950
    var tab = $(e.target).attr('id').replace('tab-','');
936 951
    document.cookie = 'history_last_tab=' + tab
937
-