159 lines
4.8 KiB
JavaScript
159 lines
4.8 KiB
JavaScript
/* xxxeslint-disable */
|
|
import ayatype from "./ayatype";
|
|
export default {
|
|
///////////////////////////////
|
|
// APP (GLOBAL) openobject CLICK HANDLER
|
|
//
|
|
// Deal with a request to open an object (from main datatables mainly)
|
|
// called from App.vue
|
|
handleOpenObjectClick(vm, tid) {
|
|
//expects extra data (tid) to be one of { type: [AYATYPE], id: [RECORDID] }
|
|
|
|
//NOTE: for new objects all edit pages assume record ID 0 means create rather than open
|
|
|
|
if (tid.type && tid.id != null) {
|
|
switch (tid.type) {
|
|
case ayatype.Widget:
|
|
vm.$router.push({
|
|
name: "widget-edit",
|
|
params: { recordid: tid.id }
|
|
});
|
|
break;
|
|
case ayatype.User:
|
|
//Is it an "Inside" user (staff or subcontractor)
|
|
//or an "outside" user (customer or headoffice)
|
|
//if key doesn't provide this then need to directly find out first before determining which form to redirect to
|
|
if (tid.inside == undefined && tid.id != 0) {
|
|
//lookup which one to open from server
|
|
(async () => {
|
|
try {
|
|
let res = await window.$gz.api.get(
|
|
"user/inside-type/" + tid.id
|
|
);
|
|
|
|
if (res.error) {
|
|
throw new Error(res.error);
|
|
}
|
|
if (res.data) {
|
|
tid.inside = res.data;
|
|
}
|
|
} catch (e) {
|
|
throw new Error(e);
|
|
}
|
|
})();
|
|
}
|
|
if (tid.inside == true) {
|
|
vm.$router.push({
|
|
name: "adm-user",
|
|
params: { recordid: tid.id }
|
|
});
|
|
} else {
|
|
vm.$router.push({
|
|
name: "cust-user",
|
|
params: { recordid: tid.id }
|
|
});
|
|
}
|
|
break;
|
|
case ayatype.NotifySubscription:
|
|
vm.$router.push({
|
|
name: "home-notify-subscription",
|
|
params: { recordid: tid.id }
|
|
});
|
|
break;
|
|
case ayatype.FileAttachment:
|
|
//lookup the actual type
|
|
//then call this method again to do the actual open
|
|
|
|
(async () => {
|
|
try {
|
|
let res = await window.$gz.api.get("attachment/parent/" + tid.id);
|
|
|
|
if (res.error) {
|
|
throw new Error(res.error);
|
|
}
|
|
if (res.data.id && res.data.id != 0) {
|
|
this.handleOpenObjectClick(vm, res.data);
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
throw new Error(e);
|
|
}
|
|
})();
|
|
|
|
//error here? or do nothing, doing nothing for now, should only apply if it's an orphan record and that is kind of obvious
|
|
//or error "Can't open nothing"
|
|
break;
|
|
//TODO: Items that are able to be opened from the adm-history form
|
|
//need to decide to support them and if not then need to modify the message below
|
|
//to be localized and simply say "Can't open this object type" or something along those lines
|
|
//TODO: FORMCUSTOMIZATION
|
|
//TODO: LIST VIEW
|
|
case ayatype.Translation:
|
|
vm.$router.push({
|
|
name: "adm-translation",
|
|
params: { recordid: tid.id }
|
|
});
|
|
break;
|
|
case ayatype.Report:
|
|
vm.$router.push({
|
|
name: "ay-report-edit",
|
|
params: { recordid: tid.id }
|
|
});
|
|
break;
|
|
case ayatype.Backup:
|
|
vm.$router.push({
|
|
name: "ops-backup"
|
|
});
|
|
break;
|
|
|
|
case ayatype.FormCustom:
|
|
//all we have is the id, but need the formkey to open it
|
|
(async () => {
|
|
try {
|
|
let res = await window.$gz.api.get(
|
|
"form-custom/form-key/" + tid.id
|
|
);
|
|
|
|
if (res.error) {
|
|
throw new Error(res.error);
|
|
}
|
|
if (res && res.data) {
|
|
vm.$router.push({
|
|
name: "ay-customize",
|
|
params: { formCustomTemplateKey: res.data }
|
|
});
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
throw new Error(e);
|
|
}
|
|
})();
|
|
|
|
break;
|
|
|
|
default:
|
|
window.$gz.eventBus.$emit(
|
|
"notify-warning",
|
|
`open-object-handler: unknown [${tid.type},${tid.id}]`
|
|
);
|
|
}
|
|
}
|
|
},
|
|
|
|
///////////////////////////////////
|
|
// WIRE UP MENU EVENTS
|
|
//
|
|
// called once from app.vue only
|
|
//
|
|
wireUpEventHandlers(vm) {
|
|
let self = this;
|
|
//expects extra data (tid) to be { type: [AYATYPE], id: [RECORDID] }
|
|
window.$gz.eventBus.$on("openobject", function handleOpenObjectClickHandler(
|
|
tid
|
|
) {
|
|
self.handleOpenObjectClick(vm, tid);
|
|
});
|
|
}
|
|
//new functions above here
|
|
};
|