return false;
} {
return true
}
}
window.gitlist.preloadCommitValues = (options) => {
const { type } = options
const inputs = {
name: $(`#p3x-gitlist-modal-${ type }-name`),
email: $(`#p3x-gitlist-modal-${ type }-email`),
comment: $(`#p3x-gitlist-modal-${ type }-comment`),
}
for(let inputKey in inputs) {
const input = inputs[inputKey]
//console.log(inputKey, commentCookie)
let cookieName = `p3x-gitlist-commit-${inputKey}`;
if (inputKey === 'comment') {
cookieName = `p3x-gitlist-commit-${type }-${inputKey}`;
}
const cookie = Cookies.get(cookieName)
if (cookie) {
input.val(cookie.trim());
}
input.change(() => {
const val = input.val().trim();
Cookies.set(cookieName, val, window.gitlist.cookieSettings);
input.val(val);
})
}
window.gitlist.commitModelInputs[type] = inputs
}
window.gitlist.gitHelperAjax = async (options) => {
const { modal, action, inputs, upload, fileUpload } = options
let { data, filename } = options
if (filename === undefined) {
filename = window.gitlist.getPath();
}
const defaultData = {
email: inputs.email.val(),
name: inputs.name.val(),
comment: inputs.comment.val(),
}
if (data !== undefined) {
data = Object.assign(defaultData, data)
} else {
data = defaultData
}
data.filename = filename
modal.modal('hide')
const url = `${window.gitlist.basepath}/${window.gitlist.repo}/git-helper/${window.gitlist.branch}/${action}`
let request;
if (upload === true) {
const uploadData = new FormData();
for(let dataKey of Object.keys(data)) {
uploadData.append(dataKey, data[dataKey]);
}
// console.log(fileUpload)
uploadData.append('upload-file', fileUpload[0].files[0], data.filename );
request = $.ajax({
url: url,
type: 'POST',
data: uploadData,
processData: false,
contentType: false,
})
} else {
request = $.ajax({
url: url,
type: 'POST',
data: data,
})
}
const response = await request;
const json = JSON.parse(response)
if (json.error === true) {
window.gitlist.ajaxErrorHandler(json);
}