console.error(e);
}
const validateCodeIsSame = () => {
value = gitlist.viewer.getValue();
if (originalCode === value) {
$.snackbar({
content: 'The code has not changed. No saving.',
})
return true;
}
return false;
}
const commitModal = $('#p3x-gitlist-modal-commit');
buttonEditSave.click(async () => {
if (validateCodeIsSame()) {
return;
}
commitModal.modal('show')
})
const commitInputName = $('#p3x-gitlist-modal-commit-name');
const commitInputEmail = $('#p3x-gitlist-modal-commit-email');
const commitInputComment = $('#p3x-gitlist-modal-commit-comment');
const commitForm = $('#p3x-gitlist-modal-commit-form');
const inputs = {
name: commitInputName,
email: commitInputEmail,
comment: commitInputComment,
}
for(let inputKey in inputs) {
const input = inputs[inputKey]
const cookieName = `p3x-gitlist-commit-${inputKey}`;
const cookie = Cookies.get(cookieName)
if (cookie) {
input.val(cookie.trim());
}
input.change(() => {
const val = input.val().trim();
Cookies.set(cookieName, val);
input.val(val);
})
}
const commitCommitPushButton = $('#p3x-gitlist-modal-commit-push')
commitCommitPushButton.click( async () => {
if (validateCodeIsSame()) {
return;
}
if(commitForm[0].checkValidity() === false) {
$.snackbar({
content: 'The commit form data is invalid..'
})
return;
}
$.snackbar({
htmlAllowed: true,
content: ' <i class="fas fa-cog fa-spin"></i> Saving ...'
})
try {
const url = `${window.gitlist.basepath}/${window.gitlist.repo}/git-helper/${window.gitlist.branch}/save`
const response = await $.ajax({
url: url,
type: 'POST',
data: {
value: value,
email: inputs.email.val(),
name: inputs.name.val(),
comment: inputs.comment.val(),
filename: filename
}
})
const json = JSON.parse(response)
if (json.output !== '') {
$.snackbar({
htmlAllowed: true,
content: json.output,
})
}
if (json.error === true) {
errorHandler(json);
} else {