Feature #31322 » 20191218-02-ajax-modal-form.diff
| app/controllers/issues_controller.rb | ||
|---|---|---|
| 199 | 199 |
return |
| 200 | 200 |
end |
| 201 | 201 | |
| 202 |
render( |
|
| 203 |
:partial => 'close_confirm', |
|
| 204 |
:layout => false, |
|
| 205 |
:locals => {}
|
|
| 206 |
) |
|
| 202 | 207 |
return |
| 203 | 208 |
end |
| 204 | 209 | |
| app/views/issues/_close_confirm.js.erb | ||
|---|---|---|
| 1 |
$('#ajax-modal').html(
|
|
| 2 |
'<%= escape_javascript( |
|
| 3 |
render( |
|
| 4 |
:partial => 'close_confirm_dialog', |
|
| 5 |
:locals => {}
|
|
| 6 |
) |
|
| 7 |
) |
|
| 8 |
%>' |
|
| 9 |
); |
|
| 10 |
showModal('ajax-modal', '400px');
|
|
| app/views/issues/_close_confirm_dialog.html.erb | ||
|---|---|---|
| 1 |
<h3 class="title"> </h3> |
|
| 2 |
<p> |
|
| 3 |
<%= l(:text_close_parent_issue_whose_subtasks_are_open_confirmation) %> |
|
| 4 |
</p> |
|
| 5 |
<p class="buttons"> |
|
| 6 |
<%= button_tag l(:button_apply), :type => "button", :onclick => "run_submit();" %> |
|
| 7 |
<%= link_to_function l(:button_cancel), "hideModal(this);" %> |
|
| 8 |
</p> |
|
| 9 | ||
| 10 |
<%= javascript_tag do %> |
|
| 11 |
function run_submit() {
|
|
| 12 |
$("#issue-form").off('submit');
|
|
| 13 |
$("#issue-form").submit();
|
|
| 14 |
} |
|
| 15 |
<% end %> |
|
| app/views/issues/_edit.html.erb | ||
|---|---|---|
| 85 | 85 |
<%= javascript_tag do %> |
| 86 | 86 |
$('#issue-form').submit(function(){
|
| 87 | 87 |
var status_id = 0; |
| 88 |
var result = false; |
|
| 89 | 88 |
if ($("#issue_status_id").length > 0) {
|
| 90 | 89 |
status_id = $("#issue_status_id").val();
|
| 91 | 90 |
} |
| 92 | 91 |
$.ajax({
|
| 93 | 92 |
url: $("#issue-form").attr('action'),
|
| 94 | 93 |
type: 'patch', |
| 95 |
async: false, |
|
| 96 | 94 |
data: {
|
| 97 | 95 |
"check_go_to_close_confirm": "", |
| 98 | 96 |
"status_id": status_id |
| ... | ... | |
| 100 | 98 |
}) |
| 101 | 99 |
.then( |
| 102 | 100 |
function(data){
|
| 103 |
result = data["result"]; |
|
| 101 |
if (data["result"]) {
|
|
| 102 |
$.ajax({
|
|
| 103 |
url: $("#issue-form").attr('action'),
|
|
| 104 |
type: 'patch', |
|
| 105 |
data: {}
|
|
| 106 |
}); |
|
| 107 |
} else {
|
|
| 108 |
$("#issue-form").off('submit');
|
|
| 109 |
$("#issue-form").submit();
|
|
| 110 |
} |
|
| 104 | 111 |
} |
| 105 | 112 |
); |
| 106 |
if (result) {
|
|
| 107 |
if (!confirm( |
|
| 108 |
"<%= l(:text_close_parent_issue_whose_subtasks_are_open_confirmation) %>" |
|
| 109 |
)){
|
|
| 110 |
return false; |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
$("#issue-form").off('submit');
|
|
| 114 |
$("#issue-form").submit();
|
|
| 113 |
return false; |
|
| 115 | 114 |
}); |
| 116 | 115 |
<% end %> |
| test/system/issues_test.rb | ||
|---|---|---|
| 247 | 247 |
page.find("#issue_status_id").select("Closed")
|
| 248 | 248 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
| 249 | 249 |
assert_no_difference 'parent.journals.count' do |
| 250 |
page.dismiss_confirm /Are you sure/ do |
|
| 251 |
page.first(:button, 'Submit').click |
|
| 250 |
page.first(:button, 'Submit').click |
|
| 251 |
within('#ajax-modal') do
|
|
| 252 |
assert page.has_text?(/Are you sure/) |
|
| 253 |
page.first(:link, 'Cancel').click |
|
| 252 | 254 |
end |
| 253 | 255 |
assert_equal 1, parent.reload.status.id |
| 254 | 256 |
end |
| 255 | 257 |
assert_difference 'parent.journals.count' do |
| 256 |
page.accept_confirm /Are you sure/ do |
|
| 257 |
page.first(:button, 'Submit').click |
|
| 258 |
page.first(:button, 'Submit').click |
|
| 259 |
within('#ajax-modal') do
|
|
| 260 |
assert page.has_text?(/Are you sure/) |
|
| 261 |
page.first(:button, 'Apply').click |
|
| 258 | 262 |
end |
| 259 | 263 |
assert page.has_css?('#flash_notice')
|
| 260 | 264 |
assert_equal 5, parent.reload.status.id |
| ... | ... | |
| 266 | 270 |
fill_in 'Subject', :with => 'test of confirm dialog' |
| 267 | 271 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
| 268 | 272 |
assert_no_difference 'parent.journals.count' do |
| 269 |
page.dismiss_confirm /Are you sure/ do |
|
| 270 |
page.first(:button, 'Submit').click |
|
| 273 |
page.first(:button, 'Submit').click |
|
| 274 |
within('#ajax-modal') do
|
|
| 275 |
assert page.has_text?(/Are you sure/) |
|
| 276 |
page.first(:link, 'Cancel').click |
|
| 271 | 277 |
end |
| 272 | 278 |
assert_equal 5, parent.reload.status.id |
| 273 | 279 |
end |
| 274 | 280 |
assert_difference 'parent.journals.count' do |
| 275 |
page.accept_confirm /Are you sure/ do |
|
| 276 |
page.first(:button, 'Submit').click |
|
| 281 |
page.first(:button, 'Submit').click |
|
| 282 |
within('#ajax-modal') do
|
|
| 283 |
assert page.has_text?(/Are you sure/) |
|
| 284 |
page.first(:button, 'Apply').click |
|
| 277 | 285 |
end |
| 278 | 286 |
assert page.has_css?('#flash_notice')
|
| 279 | 287 |
assert_equal 5, parent.reload.status.id |