Skip to content

Commit babac82

Browse files
committed
Add a modal to confirm the commit of an empty file
Signed-off-by: LukBukkit <[email protected]>
1 parent 1f2ec0b commit babac82

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ editor.file_editing_no_longer_exists = The file being edited, '%s', no longer ex
726726
editor.file_deleting_no_longer_exists = The file being deleted, '%s', no longer exists in this repository.
727727
editor.file_changed_while_editing = The file contents have changed since you started editing. <a target="_blank" rel="noopener noreferrer" href="%s">Click here</a> to see them or <strong>Commit Changes again</strong> to overwrite them.
728728
editor.file_already_exists = A file named '%s' already exists in this repository.
729+
editor.commit_empty_file_header = Commit an empty file
730+
editor.commit_empty_file_text = The file you're about commit is empty. Proceed?
729731
editor.no_changes_to_show = There are no changes to show.
730732
editor.fail_to_update_file = Failed to update/create file '%s' with error: %v
731733
editor.add_subdir = Add a directory…

public/js/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function initRepoStatusChecker() {
262262
location.reload();
263263
return
264264
}
265-
265+
266266
setTimeout(function () {
267267
initRepoStatusChecker()
268268
}, 2000);
@@ -1571,6 +1571,18 @@ function initEditor() {
15711571
codeMirrorEditor.setOption("tabSize", editorconfig.tab_width || 4);
15721572
});
15731573
}).trigger('keyup');
1574+
1575+
$('#commit-button').click(function (event) {
1576+
// A modal which asks if an empty file should be committed
1577+
if ($editArea.val().length === 0) {
1578+
$('#edit-empty-content-modal').modal({
1579+
onApprove: function () {
1580+
$('.edit.form').submit();
1581+
}
1582+
}).modal('show');
1583+
event.preventDefault();
1584+
}
1585+
});
15741586
}
15751587

15761588
function initOrganization() {

templates/repo/editor/edit.tmpl

+22
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,27 @@
5252
{{template "repo/editor/commit_form" .}}
5353
</form>
5454
</div>
55+
56+
57+
<div class="ui small basic modal" id="edit-empty-content-modal">
58+
<div class="ui icon header">
59+
<i class="file icon"></i>
60+
{{.i18n.Tr "repo.editor.commit_empty_file_header"}}
61+
</div>
62+
<div class="center content">
63+
<p>{{.i18n.Tr "repo.editor.commit_empty_file_text"}}</p>
64+
</div>
65+
<div class="actions">
66+
<div class="ui red basic cancel inverted button">
67+
<i class="remove icon"></i>
68+
{{.i18n.Tr "repo.editor.cancel"}}
69+
</div>
70+
<div class="ui green basic ok inverted button">
71+
<i class="save icon"></i>
72+
{{.i18n.Tr "repo.editor.commit_changes"}}
73+
</div>
74+
</div>
75+
</div>
76+
5577
</div>
5678
{{template "base/footer" .}}

0 commit comments

Comments
 (0)