issue-31322.ver.4.diff

Toshi MARUYAMA, 2019-10-16 04:15

Download (8 KB)

View differences:

app/helpers/issues_helper.rb
315 315
    ids.size
316 316
  end
317 317

  
318
  def add_confirm_dialog_to_issue_submit_button_js_string
319
    confirm_message = l(:text_close_parent_issue_whose_subtasks_are_open_confirmation)
320
    closed_issue_status_ids = @allowed_statuses.select{|i| i.is_closed?}.pluck(:id).map(&:to_s)
321
    "addConfirmDialogToIssueSubmitButton(#{closed_issue_status_ids.to_json}, '#{confirm_message}')".html_safe
322
  end
323

  
318 324
  def issues_destroy_confirmation_message(issues)
319 325
    issues = [issues] unless issues.is_a?(Array)
320 326
    message = l(:text_issues_destroy_confirmation)
app/views/issues/_action_menu.html.erb
1 1
<div class="contextual">
2
<% onclick_functions = 'showAndScrollTo("update", "issue_notes");'
3
   onclick_functions << "#{add_confirm_dialog_to_issue_submit_button_js_string};"
4
   onclick_functions << "return false;" %>
2 5
<%= link_to l(:button_edit), edit_issue_path(@issue),
3
            :onclick => 'showAndScrollTo("update", "issue_notes"); return false;',
6
            :onclick => onclick_functions,
4 7
            :class => 'icon icon-edit', :accesskey => accesskey(:edit) if @issue.editable? %>
5 8
<%= link_to l(:button_log_time), new_issue_time_entry_path(@issue),
6 9
            :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project) %>
app/views/issues/_attributes.html.erb
3 3
<div class="splitcontent">
4 4
<div class="splitcontentleft">
5 5
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
6
<% onchange_functions = "updateIssueFrom('#{escape_javascript(update_issue_form_path(@project, @issue))}', this);"
7
   onchange_functions << "#{add_confirm_dialog_to_issue_submit_button_js_string};" %>
6 8
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
7
                :onchange => "updateIssueFrom('#{escape_javascript(update_issue_form_path(@project, @issue))}', this)" %></p>
9
                :onchange => onchange_functions %></p>
8 10
<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %>
9 11
<% else %>
10 12
<p><label><%= l(:field_status) %></label> <%= @issue.status %></p>
app/views/issues/_edit.html.erb
72 72

  
73 73
    <%= f.hidden_field :lock_version %>
74 74
    <%= hidden_field_tag 'last_journal_id', params[:last_journal_id] || @issue.last_journal_id %>
75
    <%= submit_tag l(:button_submit) %>
75
    <%= submit_tag l(:button_submit), :id => "issue_submit_button" %>
76 76
    <%= link_to l(:button_cancel), issue_path(id: @issue.id), :onclick => params[:action] == 'show' ? "$('#update').hide(); return false;" : '' %>
77 77

  
78 78
    <%= hidden_field_tag 'prev_issue_id', @prev_issue_id if @prev_issue_id %>
config/locales/en.yml
1187 1187
  text_time_logged_by_changeset: "Applied in changeset %{value}."
1188 1188
  text_issues_destroy_confirmation: 'Are you sure you want to delete the selected issue(s)?'
1189 1189
  text_issues_destroy_descendants_confirmation: "This will also delete %{count} subtask(s)."
1190
  text_close_parent_issue_whose_subtasks_are_open_confirmation: Are you sure you want to close parent issue whose subtasks are open?
1190 1191
  text_time_entries_destroy_confirmation: 'Are you sure you want to delete the selected time entr(y/ies)?'
1191 1192
  text_select_project_modules: 'Select modules to enable for this project:'
1192 1193
  text_default_administrator_account_changed: Default administrator account changed
public/javascripts/application.js
570 570
  return key;
571 571
}
572 572

  
573
function addConfirmDialogToIssueSubmitButton(closedIssueStatusIds, confirmMessage) {
574
  var children = $("#issue_tree").find("tr.issue.child");
575
  if (($.inArray($("#issue_status_id").val(), closedIssueStatusIds) > -1) &&
576
      (children.length > 0) &&
577
      ((children.length - $("#issue_tree").find("tr.issue.child.closed").length) > 0)) {
578
    $("#issue_submit_button").attr({
579
        "data-confirm": confirmMessage
580
    });
581
  } else {
582
    $("#issue_submit_button").removeAttr("data-confirm");
583
  }
584
  return true;
585
}
586

  
573 587
function updateIssueFrom(url, el) {
574 588
  $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
575 589
    $(this).data('valuebeforeupdate', $(this).val());
test/system/issues_test.rb
233 233
    assert_equal 5, issue.reload.status.id
234 234
  end
235 235

  
236
  test "add confirm dialog to issue submit button" do
237
    parent = Issue.generate!
238
    child = Issue.generate!(:parent_issue_id => parent.id)
239
    with_settings :close_parent_issue_whose_subtasks_are_open => 1 do
240
      log_user('jsmith', 'jsmith')
241

  
242
      visit "/issues/#{parent.id}"
243
      page.first(:link, 'Edit').click
244
      assert page.has_select?("issue_status_id", {:selected => "New"})
245
      page.find("#issue_status_id").select("Closed")
246
      assert_no_difference 'Issue.count' do
247
        page.accept_confirm /Are you sure/ do
248
          page.first(:button, 'Submit').click
249
        end
250
      end
251
      assert page.has_css?('#flash_notice')
252
      assert_equal 5, parent.reload.status.id
253

  
254
      page.first(:link, 'Edit').click
255
      assert page.has_select?("issue_status_id", {:selected => "Closed"})
256
      fill_in 'Subject', :with => 'test of confirm dialog'
257
      assert_no_difference 'Issue.count' do
258
        page.accept_confirm /Are you sure/ do
259
          page.first(:button, 'Submit').click
260
        end
261
      end
262
      assert page.has_css?('#flash_notice')
263
      assert_equal 5, parent.reload.status.id
264
      assert_equal 'test of confirm dialog', parent.reload.subject
265

  
266
      page.first(:link, 'Edit').click
267
      assert page.has_select?("issue_status_id", {:selected => "Closed"})
268
      page.find("#issue_status_id").select("New")
269
      assert_no_difference 'Issue.count' do
270
        page.first(:button, 'Submit').click
271
      end
272
      assert page.has_css?('#flash_notice')
273
      assert_equal 1, parent.reload.status.id
274

  
275
      visit "/issues/#{child.id}"
276
      page.first(:link, 'Edit').click
277
      assert page.has_select?("issue_status_id", {:selected => "New"})
278
      page.find("#issue_status_id").select("Closed")
279
      assert_no_difference 'Issue.count' do
280
        page.first(:button, 'Submit').click
281
      end
282
      assert page.has_css?('#flash_notice')
283
      assert_equal 5, child.reload.status.id
284

  
285
      visit "/issues/#{parent.id}"
286
      page.first(:link, 'Edit').click
287
      assert page.has_select?("issue_status_id", {:selected => "New"})
288
      page.find("#issue_status_id").select("Closed")
289
      assert_no_difference 'Issue.count' do
290
        page.first(:button, 'Submit').click
291
      end
292
      assert page.has_css?('#flash_notice')
293
      assert_equal 5, parent.reload.status.id
294
    end
295
  end
296

  
236 297
  test "removing issue shows confirm dialog" do
237 298
    log_user('jsmith', 'jsmith')
238 299
    visit '/issues/1'