Skip to content

Commit

Permalink
feat: Add skip unsaved changes confirmation (#13065)
Browse files Browse the repository at this point in the history
- Added a confirmation popup when the user clicks skip if there are unsaved changes.

Closes: #13050
  • Loading branch information
meel-hd authored Nov 19, 2024
1 parent 419ad53 commit 05ed862
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions weblate/static/editor/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ WLT.Utils = (() => ({

WLT.Editor = (() => {
let lastEditor = null;
let hasChanges = false;

function EditorBase() {
const translationAreaSelector = ".translation-editor";
Expand All @@ -40,6 +41,7 @@ WLT.Editor = (() => {

this.$editor.on("input", translationAreaSelector, (e) => {
WLT.Utils.markTranslated($(e.target).closest("form"));
hasChanges = true;
});

this.$editor.on("focusin", translationAreaSelector, function () {
Expand Down Expand Up @@ -103,6 +105,7 @@ WLT.Editor = (() => {
});
}
WLT.Utils.markFuzzy($this.closest("form"));
hasChanges = true;
return false;
});

Expand All @@ -114,6 +117,7 @@ WLT.Editor = (() => {

container.find(".translation-editor").attr("dir", direction);
container.find(".highlighted-output").attr("dir", direction);
hasChanges = true;
});

/* Special characters */
Expand All @@ -126,12 +130,22 @@ WLT.Editor = (() => {
.find(".translation-editor")
.insertAtCaret(text);
e.preventDefault();
hasChanges = true;
});

this.initHighlight();
this.init();

this.$translationArea[0].focus();

// Skip confirmation
this.$editor.on("click", ".skip", (e) => {
if (hasChanges) {
return confirm(
gettext("You have unsaved changes. Are you sure you want to skip?"),
);
}
});
}

EditorBase.prototype.init = () => {};
Expand All @@ -145,6 +159,7 @@ WLT.Editor = (() => {
const $this = $(this);
insertEditor(this.getAttribute("data-value"), $this);
e.preventDefault();
hasChanges = true;
});

/* and shortcuts */
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h4 class="panel-title">
{% endif %}
>{% icon "suggest.svg" %} {% trans "Suggest" %}</button>
{% endif %}
<a class="btn btn-warning btn-spaced" href="{{ next_unit_url }}" rel="next">{% if LANGUAGE_BIDI %}{% icon "rewind.svg" %}{% else %}{% icon "fast-forward.svg" %}{% endif %} {% trans "Skip" %}</a>
<a class="btn btn-warning btn-spaced skip" href="{{ next_unit_url }}" rel="next">{% if LANGUAGE_BIDI %}{% icon "rewind.svg" %}{% else %}{% icon "fast-forward.svg" %}{% endif %} {% trans "Skip" %}</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 05ed862

Please sign in to comment.