This commit is contained in:
@@ -34,7 +34,6 @@ export default {
|
||||
if (!window.$gz._.isArray(enumKey)) {
|
||||
enumKey = [enumKey];
|
||||
}
|
||||
|
||||
for (let i = 0; i < enumKey.length; i++) {
|
||||
//check if list
|
||||
//if not then fetch it and store it
|
||||
@@ -43,27 +42,25 @@ export default {
|
||||
if (!window.$gz._.has(window.$gz.store.state.enums, k)) {
|
||||
let that = this;
|
||||
// eslint-disable-next-line
|
||||
await that.fetchEnumKey(k).then((dat) => {
|
||||
//massage the data as necessary
|
||||
let e = { enumKey: k, items: {} };
|
||||
for (let i = 0; i < dat.length; i++) {
|
||||
let o = dat[i];
|
||||
e.items[o.id] = o.name;
|
||||
}
|
||||
//stuff the data into the store
|
||||
window.$gz.store.commit("setEnum", e);
|
||||
});
|
||||
let dat = await that.fetchEnumKey(k);
|
||||
//massage the data as necessary
|
||||
let e = { enumKey: k, items: {} };
|
||||
for (let i = 0; i < dat.length; i++) {
|
||||
let o = dat[i];
|
||||
e.items[o.id] = o.name;
|
||||
}
|
||||
//stuff the data into the store
|
||||
window.$gz.store.commit("setEnum", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
fetchEnumKey(enumKey) {
|
||||
async fetchEnumKey(enumKey) {
|
||||
// eslint-disable-next-line
|
||||
return window.$gz.api.get("enum-list/list/" + enumKey).then((res) => {
|
||||
//We never expect there to be no data here
|
||||
if (!res.data) {
|
||||
throw res;
|
||||
}
|
||||
return res.data;
|
||||
});
|
||||
let res = await window.$gz.api.get("enum-list/list/" + enumKey);
|
||||
//We never expect there to be no data here
|
||||
if (!res.data) {
|
||||
throw res;
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,30 +17,19 @@ function addDataKeyNames(obj) {
|
||||
|
||||
export default {
|
||||
// cache the form customization data if it's not already present
|
||||
//cache invalidation is hard, this needs it...hmmm....
|
||||
//for now will rely on logout and back in to clear up any customization issues
|
||||
get(formKey) {
|
||||
return new Promise(function getFormTemplate(resolve) {
|
||||
if (
|
||||
!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)
|
||||
) {
|
||||
//fetch and populate the store
|
||||
window.$gz.api.get("form-custom/" + formKey).then(res => {
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
}
|
||||
window.$gz.store.commit("setFormCustomTemplateItem", {
|
||||
formKey: formKey,
|
||||
concurrency: res.data.concurrency,
|
||||
value: addDataKeyNames(JSON.parse(res.data.template))
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
async get(formKey) {
|
||||
if (!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)) {
|
||||
//fetch and populate the store
|
||||
let res = await window.$gz.api.get("form-custom/" + formKey);
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
}
|
||||
});
|
||||
window.$gz.store.commit("setFormCustomTemplateItem", {
|
||||
formKey: formKey,
|
||||
concurrency: res.data.concurrency,
|
||||
value: addDataKeyNames(JSON.parse(res.data.template))
|
||||
});
|
||||
}
|
||||
},
|
||||
set(formKey, token, template) {
|
||||
window.$gz.store.commit("setFormCustomTemplateItem", {
|
||||
|
||||
@@ -423,7 +423,7 @@ export default {
|
||||
///////////////////////////////////
|
||||
// GET DATA FROM API SERVER
|
||||
//
|
||||
async getEx(route) {
|
||||
async get(route) {
|
||||
try {
|
||||
let that = this;
|
||||
let r = await fetch(that.APIUrl(route), that.fetchGetOptions());
|
||||
@@ -435,25 +435,7 @@ export default {
|
||||
handleError("GET", error, route, reject);
|
||||
}
|
||||
},
|
||||
///////////////////////////////////
|
||||
// GET DATA FROM API SERVER
|
||||
//
|
||||
get(route) {
|
||||
let that = this;
|
||||
return new Promise(function getDataFromServer(resolve, reject) {
|
||||
fetch(that.APIUrl(route), that.fetchGetOptions())
|
||||
.then(that.status)
|
||||
.then(that.extractBody)
|
||||
// eslint-disable-next-line
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function handleGetError(error) {
|
||||
//fundamental error, can't proceed with this call
|
||||
handleError("GET", error, route, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////
|
||||
// Test delay for troubleshooting
|
||||
//
|
||||
@@ -504,7 +486,7 @@ export default {
|
||||
///////////////////////////////////
|
||||
// DELETE DATA FROM API SERVER
|
||||
//
|
||||
async removeEx(route) {
|
||||
async remove(route) {
|
||||
let that = this;
|
||||
try {
|
||||
let r = await fetch(that.APIUrl(route), that.fetchRemoveOptions());
|
||||
@@ -517,67 +499,27 @@ export default {
|
||||
handleError("DELETE", error, route);
|
||||
}
|
||||
},
|
||||
///////////////////////////////////
|
||||
// DELETE DATA FROM API SERVER
|
||||
//
|
||||
remove(route) {
|
||||
let that = this;
|
||||
return new Promise(function removeDataFromServer(resolve, reject) {
|
||||
fetch(that.APIUrl(route), that.fetchRemoveOptions())
|
||||
.then(that.status)
|
||||
//.then(that.extractBody)
|
||||
// eslint-disable-next-line
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function handleRemoveError(error) {
|
||||
//fundamental error, can't proceed with this call
|
||||
handleError("DELETE", error, route, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
///////////////////////////////////
|
||||
// POST DUPLICATE TO API SERVER
|
||||
//
|
||||
duplicate(route) {
|
||||
let that = this;
|
||||
return new Promise(function duplicateRecordOnServer(resolve, reject) {
|
||||
fetch(that.APIUrl(route), that.fetchPostOptions(null))
|
||||
.then(that.status)
|
||||
.then(that.extractBody)
|
||||
// eslint-disable-next-line
|
||||
.then((response) => {
|
||||
//Note: response.error indicates there is an error, however this is not an unusual condition
|
||||
//it could be validation errors or other general error so we need to treat it here like it's normal
|
||||
//and let the caller deal with it appropriately
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function handleDuplicateError(error) {
|
||||
handleError("DUPLICATE", error, route, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
///////////////////////////////////
|
||||
// POST FILE ATTACHMENTS
|
||||
// @param {ayaId:objectid, ayaType:objectType, files:[array of files]}
|
||||
//
|
||||
uploadAttachment(at) {
|
||||
async uploadAttachment(at) {
|
||||
let that = this;
|
||||
try {
|
||||
var files = at.files;
|
||||
var data = new FormData();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
data.append(files[i].name, files[i]);
|
||||
}
|
||||
|
||||
var files = at.files;
|
||||
var data = new FormData();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
data.append(files[i].name, files[i]);
|
||||
}
|
||||
data.append("AttachToObjectType", at.ayaType);
|
||||
data.append("AttachToObjectId", at.ayaId);
|
||||
data.append("Notes", at.notes);
|
||||
data.append("FileData", at.fileData);
|
||||
|
||||
data.append("AttachToObjectType", at.ayaType);
|
||||
data.append("AttachToObjectId", at.ayaId);
|
||||
data.append("Notes", at.notes);
|
||||
data.append("FileData", at.fileData);
|
||||
//-----------------
|
||||
|
||||
//-----------------
|
||||
|
||||
return new Promise(function postAttachmentToServer(resolve, reject) {
|
||||
let fetchOptions = {
|
||||
method: "post",
|
||||
mode: "cors",
|
||||
@@ -587,19 +529,15 @@ export default {
|
||||
body: data
|
||||
};
|
||||
|
||||
fetch(that.APIUrl("attachment"), fetchOptions)
|
||||
.then(that.status)
|
||||
.then(that.extractBody)
|
||||
// eslint-disable-next-line
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function handlePostAttachment(error) {
|
||||
handleError("POSTATTACHMENT", error, route, reject);
|
||||
});
|
||||
});
|
||||
//---------------
|
||||
let r = await fetch(that.APIUrl("attachment"), fetchOptions);
|
||||
that.statusEx(r);
|
||||
r = await that.extractBodyEx(r);
|
||||
return r;
|
||||
} catch (error) {
|
||||
handleError("POSTATTACHMENT", error, route, reject);
|
||||
}
|
||||
}
|
||||
//---------------
|
||||
|
||||
//new functions above here
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user