Files
raven-client/ayanova/src/views/acc-service-banks.vue
2021-02-10 15:53:45 +00:00

226 lines
5.5 KiB
Vue

<template>
<div>
<div v-if="objectType && objectId" class="mb-6">
<v-icon @click="navToTarget()" large>{{ iconForType() }}</v-icon
><span @click="navToTarget()" class="text-h5"> {{ name }}</span>
</div>
<gz-report-selector ref="reportSelector"></gz-report-selector>
<gz-extensions
:aya-type="ayType"
:selected-items="selectedItems"
ref="extensions"
>
</gz-extensions>
<gz-data-table
ref="gzdatatable"
form-key="service-bank-list"
data-list-key="ServiceBankDataList"
:client-criteria="clientCriteria"
:show-select="rights.read"
:reload="reload"
:rid-column-openable="false"
@selection-change="handleSelected"
data-cy="serviceBanksTable"
>
</gz-data-table>
</div>
</template>
<script>
const FORM_KEY = "service-bank-list";
export default {
async created() {
let vm = this;
vm.rights = window.$gz.role.getRights(window.$gz.type.ServiceBank);
window.$gz.eventBus.$on("menu-click", clickHandler);
vm.objectId = window.$gz.util.stringToIntOrNull(vm.$route.params.objectId);
vm.objectType = window.$gz.util.stringToIntOrNull(
vm.$route.params.objectType
);
if (vm.objectId && vm.objectId != 0 && vm.objectType) {
// //DYNAMIC FILTER
// vm.mxetaView = JSON.stringify([
// {
// fld: "metaservicebankobjectid",
// filter: {
// items: [{ op: "=", value: vm.objectId }]
// }
// },
// {
// fld: "AyaType",
// filter: {
// items: [{ op: "=", value: vm.objectType }]
// }
// }
// ]);
// vm.name = await window.$gz.api.fetchBizObjectName(
// vm.objectType,
// vm.objectId
// );
//OBJECTID,AYATYPE
vm.clientCriteria = `${vm.objectId},${vm.objectType}`;
}
generateMenu(vm);
},
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
data() {
return {
rights: window.$gz.role.defaultRightsObject(),
ayType: window.$gz.type.ServiceBank,
selectedItems: [],
reload: false,
clientCriteria: undefined,
objectId: null,
objectType: null,
name: null
};
},
// computed: {
// iconForType() {
// return window.$gz.util.iconForType(this.objectType);
// }
// },
methods: {
navToTarget: function() {
window.$gz.eventBus.$emit("openobject", {
type: this.objectType,
id: this.objectId
});
},
handleSelected(selected) {
this.selectedItems = selected;
},
iconForType() {
return window.$gz.util.iconForType(this.objectType, 10);
}
}
};
/////////////////////////////
//
//
async function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
case "new":
m.vm.$router.push({
name: "service-bank-edit",
params: {
recordid: 0,
objectType: m.vm.objectType,
objectId: m.vm.objectId,
name: m.vm.name
}
});
break;
case "extensions":
let res = await m.vm.$refs.extensions.open(
m.vm.$refs.gzdatatable.getDataListSelection(
window.$gz.type.ServiceBank
)
);
if (res && res.refresh == true) {
m.vm.reload = !m.vm.reload;
}
break;
case "report":
if (m.id != null) {
//last report selected is in m.id
m.vm.$router.push({
name: "ay-report",
params: { recordid: m.id, ayatype: window.$gz.type.ServiceBank }
});
} else {
//general report selector chosen
let res = await m.vm.$refs.reportSelector.open(
m.vm.$refs.gzdatatable.getDataListSelection(
window.$gz.type.ServiceBank
)
);
//if null for no selection
//just bail out
if (res == null) {
return;
}
//persist last report selected
window.$gz.form.setLastReport(FORM_KEY, res);
//Now open the report viewer...
m.vm.$router.push({
name: "ay-report",
params: { recordid: res.id, ayatype: window.$gz.type.ServiceBank }
});
}
break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
FORM_KEY + "::context click: [" + m.key + "]"
);
}
}
}
//////////////////////
//
//
function generateMenu(vm) {
let menuOptions = {
isMain: true,
icon: "$ayiCarBattery",
title: "ServiceBankList",
helpUrl: "acc-service-banks",
menuItems: [],
formData: {
ayaType: window.$gz.type.ServiceBank
}
};
if (vm.rights.change) {
if (vm.objectId && vm.objectType) {
menuOptions.menuItems.push({
title: "New",
icon: "$ayiPlus",
surface: true,
key: FORM_KEY + ":new",
vm: vm
});
}
}
//REPORTS
//Report not Print, print is a further option
menuOptions.menuItems.push({
title: "Report",
icon: "$ayiFileAlt",
key: FORM_KEY + ":report",
vm: vm
});
//get last report selected
let lastReport = window.$gz.form.getLastReport(FORM_KEY);
if (lastReport != null) {
menuOptions.menuItems.push({
title: lastReport.name,
icon: "$ayiFileAlt",
key: FORM_KEY + ":report:" + lastReport.id,
vm: vm
});
}
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
</script>