Skip to content

Commit

Permalink
Merge pull request #36 from sk-ys/issue-35
Browse files Browse the repository at this point in the history
Fix unexpected page switch on submission failure
  • Loading branch information
sk-ys authored Nov 3, 2024
2 parents 5572f5d + b4ee416 commit f9ead77
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions app/views/enhanced_ux/issues/_custom_issue.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,37 @@
$("#issue_assigned_to_id").after($("<br>"));
}

function isActionCompleted($contents, type) {
const contentsPathName = $contents[0].location.pathname;
if (RegExp(issuePathname + "$").test(contentsPathName)) {
// Create
return 2;
} else if (
(type === "issues"
? /issues\/new$/
: type === "time_entries"
? /\/time_entries\/.*[new|edit]$/
: false
).test(contentsPathName)
) {
if ($contents.find("#flash_notice.notice").length > 0) {
// Create and add anothor
return 1;
} else {
// Continue editing
return 0;
}
} else if (RegExp("/" + type + "$").test(contentsPathName)) {
if ($contents.find("#errorExplanation").length > 0) {
// Continue editing
return 0;
}
}

// Is another page (Create and follow)
return -1;
}

function showTimeEntryDialog(e) {
e.preventDefault();

Expand All @@ -910,25 +941,6 @@
}
}

function isActionCompleted($contents) {
if (RegExp(issuePathname + "$").test($contents[0].location.pathname)) {
// Current issue page
return 2;
} else if (
/\/time_entries\/.*[new|edit]$/.test($contents[0].location.pathname)
) {
if ($contents.find("#flash_notice.notice").length > 0) {
// Continue editing
return 1;
} else {
return 0;
}
}

// Another page
return -1;
}

const url = $(this).attr("href");
const $iframe = $("<iframe>")
.hide()
Expand All @@ -938,7 +950,7 @@
.closest(".ui-dialog")
.find(".ui-dialog-content");
const $contents = $(this).contents();
switch (isActionCompleted($contents)) {
switch (isActionCompleted($contents, "time_entries")) {
case -1:
// Go to another issue page
location.href = $contents[0].documentURI;
Expand Down Expand Up @@ -1166,30 +1178,13 @@
function showAddChildIssueDialog(e) {
e.preventDefault();

function isActionCompleted($contents) {
if (RegExp(issuePathname + "$").test($contents[0].location.pathname)) {
// Is current issue page
return 2;
} else if (/issues\/new$/.test($contents[0].location.pathname)) {
if ($contents.find("#flash_notice.notice").length > 0) {
// Continue editing
return 1;
} else {
return 0;
}
}

// Is another page
return -1;
}

const url = $(this).attr("href");
const $iframe = $("<iframe>")
.hide()
.attr("src", url)
.on("load", function () {
const $contents = $(this).contents();
switch (isActionCompleted($contents)) {
switch (isActionCompleted($contents, "issues")) {
case -1:
// Go to another issue page
location.href = $contents[0].documentURI;
Expand Down

0 comments on commit f9ead77

Please sign in to comment.