This commit is contained in:
2020-06-19 23:22:20 +00:00
parent 3935d43db5
commit f02888fae7
3 changed files with 128 additions and 142 deletions

View File

@@ -820,12 +820,13 @@ export default {
this.imageMenu = true; this.imageMenu = true;
}); });
}, },
getAttachments() { async getAttachments() {
let vm = this; let vm = this;
try {
vm.attachments = []; vm.attachments = [];
window.$gz.api let res = await window.$gz.api.get(
.get("attachment/list?ayatype=" + vm.ayaType + "&ayaid=" + vm.ayaId) "attachment/list?ayatype=" + vm.ayaType + "&ayaid=" + vm.ayaId
.then(res => { );
if (res.error) { if (res.error) {
window.$gz.errorHandler.handleFormError(res.error); window.$gz.errorHandler.handleFormError(res.error);
} else { } else {
@@ -850,12 +851,11 @@ export default {
} }
vm.attachments = ret; vm.attachments = ret;
} }
}) } catch (error) {
.catch(function handleGetListError(error) {
window.$gz.errorHandler.handleFormError(error); window.$gz.errorHandler.handleFormError(error);
}); }
}, },
upload() { async upload() {
//similar code in attachment-control upload //similar code in attachment-control upload
let vm = this; let vm = this;
let at = { let at = {
@@ -864,10 +864,9 @@ export default {
files: vm.uploadFiles, files: vm.uploadFiles,
notes: "" notes: ""
}; };
try {
let res = await window.$gz.api.uploadAttachment(at);
window.$gz.api
.uploadAttachment(at)
.then(res => {
if (res.error) { if (res.error) {
window.$gz.errorHandler.handleFormError(res.error); window.$gz.errorHandler.handleFormError(res.error);
} else { } else {
@@ -875,12 +874,6 @@ export default {
for (let i = 0; i < res.data.length; i++) { for (let i = 0; i < res.data.length; i++) {
let o = res.data[i]; let o = res.data[i];
// if (
// window.$gz.util.isImageAttachment(
// o.displayFileName,
// o.contentType
// )
// ) {
//let them attach any file type to the wiki since it supports it anyway //let them attach any file type to the wiki since it supports it anyway
ret.push({ ret.push({
id: o.id, id: o.id,
@@ -907,10 +900,9 @@ export default {
//finally, clear the upload files //finally, clear the upload files
vm.uploadFiles = []; vm.uploadFiles = [];
} }
}) } catch (error) {
.catch(function handleUploadError(error) {
window.$gz.errorHandler.handleFormError(error); window.$gz.errorHandler.handleFormError(error);
}); }
}, },
onDrop(ev) { onDrop(ev) {
//Drop image file //Drop image file

View File

@@ -88,28 +88,24 @@
const FORM_KEY = "adm-global-select-templates"; const FORM_KEY = "adm-global-select-templates";
const API_BASE_URL = "pick-list/template/"; const API_BASE_URL = "pick-list/template/";
export default { export default {
beforeRouteLeave(to, from, next) { async beforeRouteLeave(to, from, next) {
//let vm = this; if (!this.formState.dirty) {
if (this.formState.dirty) { next();
window.$gz.dialog.confirmLeaveUnsaved().then(dialogResult => { return;
if (dialogResult == true) { }
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
next(); next();
} else { } else {
next(false); next(false);
} }
});
} else {
next();
}
}, },
beforeDestroy() { beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler); window.$gz.eventBus.$off("menu-click", clickHandler);
}, },
created() { async created() {
let vm = this; let vm = this;
try {
initForm(vm) await initForm(vm);
.then(() => {
vm.formState.ready = true; vm.formState.ready = true;
vm.readOnly = !vm.rights.change; vm.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler); window.$gz.eventBus.$on("menu-click", clickHandler);
@@ -120,11 +116,10 @@ export default {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save"); window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete"); window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete");
vm.formState.loading = false; vm.formState.loading = false;
}) } catch (err) {
.catch(err => {
vm.formState.ready = true; vm.formState.ready = true;
window.$gz.errorHandler.handleFormError(err, vm); window.$gz.errorHandler.handleFormError(err, vm);
}); }
}, },
data() { data() {
return { return {
@@ -236,7 +231,7 @@ export default {
vm.getDataFromApi(); vm.getDataFromApi();
} }
}, },
getDataFromApi() { async getDataFromApi() {
let vm = this; let vm = this;
vm.formState.loading = true; vm.formState.loading = true;
if (!vm.templateId || vm.templateId == 0) { if (!vm.templateId || vm.templateId == 0) {
@@ -244,11 +239,12 @@ export default {
} }
vm.lastFetchedTemplateId = vm.templateId; vm.lastFetchedTemplateId = vm.templateId;
window.$gz.form.deleteAllErrorBoxErrors(vm); window.$gz.form.deleteAllErrorBoxErrors(vm);
try {
//get available fields //get available fields
window.$gz.api let res = await window.$gz.api.get(
.get(API_BASE_URL + "listfields/" + vm.templateId) API_BASE_URL + "listfields/" + vm.templateId
.then(res => { );
if (res.error) { if (res.error) {
vm.formState.serverError = res.error; vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm); window.$gz.form.setErrorBoxErrors(vm);
@@ -258,13 +254,13 @@ export default {
for (let i = 0; i < res.data.length; i++) { for (let i = 0; i < res.data.length; i++) {
vm.fieldKeys.push(res.data[i].tKey); vm.fieldKeys.push(res.data[i].tKey);
} }
return window.$gz.translation.cacheTranslations(vm.fieldKeys); await window.$gz.translation.cacheTranslations(vm.fieldKeys);
} }
})
.then(function() {
//weirdly, this wasn't working properly until I put it in a function, it was just executing immediately before translations were resolved from fetch above //weirdly, this wasn't working properly until I put it in a function, it was just executing immediately before translations were resolved from fetch above
//get current edited template //get current edited template
window.$gz.api.get(API_BASE_URL + vm.templateId).then(res => { res = await window.$gz.api.get(API_BASE_URL + vm.templateId);
if (res.error) { if (res.error) {
vm.formState.serverError = res.error; vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm); window.$gz.form.setErrorBoxErrors(vm);
@@ -279,16 +275,14 @@ export default {
loading: false loading: false
}); });
} }
}); } catch (error) {
})
.catch(function handleGetDataFromAPIError(error) {
//Update the form status //Update the form status
window.$gz.form.setFormState({ window.$gz.form.setFormState({
vm: vm, vm: vm,
loading: false loading: false
}); });
window.$gz.errorHandler.handleFormError(error, vm); window.$gz.errorHandler.handleFormError(error, vm);
}); }
}, },
submit() { submit() {
let vm = this; let vm = this;

View File

@@ -312,7 +312,7 @@ export default {
next(); next();
return; return;
} }
if ((await window.$gz.dialog.confirmLeaveUnsaved()) == true) { if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
next(); next();
} else { } else {
next(false); next(false);