mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-13 16:45:28 +02:00
Enable commit button only if something has changed
This commit is contained in:
parent
9811c28627
commit
3ad1e7e215
@ -77,7 +77,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<button id="commit-button" type="submit" class="ui primary button">
|
<button id="commit-button" type="submit" class="ui primary button" {{if .PageIsEdit}}disabled{{end}}>
|
||||||
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
|
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
|
||||||
</button>
|
</button>
|
||||||
<a class="ui button red" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
|
<a class="ui button red" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
|
||||||
|
@ -141,38 +141,39 @@ export function initRepoEditor() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const elForm = document.querySelector<HTMLFormElement>('.repository.editor .edit.form');
|
||||||
|
|
||||||
|
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
|
||||||
|
// to enable or disable the commit button
|
||||||
|
const commitButton = document.querySelector<HTMLButtonElement>('#commit-button');
|
||||||
|
const dirtyFileClass = 'dirty-file';
|
||||||
|
|
||||||
|
// Enabling the button at the start if the page has posted
|
||||||
|
if (document.querySelector<HTMLInputElement>('input[name="page_has_posted"]')?.value === 'true') {
|
||||||
|
commitButton.disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registering a custom listener for the file path and the file content
|
||||||
|
// FIXME: it is not quite right here (old bug), it causes double-init, the global areYouSure "dirty" class will also be added
|
||||||
|
applyAreYouSure(elForm, {
|
||||||
|
silent: true,
|
||||||
|
dirtyClass: dirtyFileClass,
|
||||||
|
fieldSelector: ':input:not(.commit-form-wrapper :input)',
|
||||||
|
change($form: any) {
|
||||||
|
const dirty = $form[0]?.classList.contains(dirtyFileClass);
|
||||||
|
commitButton.disabled = !dirty;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// on the upload page, there is no editor(textarea)
|
// on the upload page, there is no editor(textarea)
|
||||||
const editArea = document.querySelector<HTMLTextAreaElement>('.page-content.repository.editor textarea#edit_area');
|
const editArea = document.querySelector<HTMLTextAreaElement>('.page-content.repository.editor textarea#edit_area');
|
||||||
if (!editArea) return;
|
if (!editArea) return;
|
||||||
|
|
||||||
const elForm = document.querySelector<HTMLFormElement>('.repository.editor .edit.form');
|
|
||||||
initEditPreviewTab(elForm);
|
initEditPreviewTab(elForm);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const editor = await createCodeEditor(editArea, filenameInput);
|
const editor = await createCodeEditor(editArea, filenameInput);
|
||||||
|
|
||||||
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
|
|
||||||
// to enable or disable the commit button
|
|
||||||
const commitButton = document.querySelector<HTMLButtonElement>('#commit-button');
|
|
||||||
const dirtyFileClass = 'dirty-file';
|
|
||||||
|
|
||||||
// Disabling the button at the start
|
|
||||||
if (document.querySelector<HTMLInputElement>('input[name="page_has_posted"]').value !== 'true') {
|
|
||||||
commitButton.disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Registering a custom listener for the file path and the file content
|
|
||||||
// FIXME: it is not quite right here (old bug), it causes double-init, the global areYouSure "dirty" class will also be added
|
|
||||||
applyAreYouSure(elForm, {
|
|
||||||
silent: true,
|
|
||||||
dirtyClass: dirtyFileClass,
|
|
||||||
fieldSelector: ':input:not(.commit-form-wrapper :input)',
|
|
||||||
change($form: any) {
|
|
||||||
const dirty = $form[0]?.classList.contains(dirtyFileClass);
|
|
||||||
commitButton.disabled = !dirty;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Update the editor from query params, if available,
|
// Update the editor from query params, if available,
|
||||||
// only after the dirtyFileClass initialization
|
// only after the dirtyFileClass initialization
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user