Files
raven-client/ayanova/src/api/open-object-handler.js
2020-06-29 22:05:02 +00:00

92 lines
2.7 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] }
//or null which is what is called when asking to check if there is a direct openObject in store and open it
if (tid == null) {
let op = vm.$store.state.openObject;
if (op && op.type) {
tid = op;
window.$gz.store.commit("clearOpenObject");
} else return; //bail out, nothing to open here
}
//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:
vm.$router.push({
name: "adm-user",
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);
console.log("res is", res);
if (res.error) {
throw res.error;
}
if (res.data.id && res.data.id != 0) {
this.handleOpenObjectClick(vm, res.data);
return;
}
} catch (e) {
throw 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;
case ayatype.Translation:
vm.$router.push({
name: "adm-translation",
params: { recordid: tid.id }
});
break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
"open-object-handler: unrecognized type [" + tid.type + "]"
);
}
}
},
///////////////////////////////////
// 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
};