Files
raven-client/ayanova/src/components/extension-export-control.vue
2022-01-11 22:08:38 +00:00

67 lines
1.8 KiB
Vue

<template>
<v-expansion-panel v-if="available()">
<v-expansion-panel-header
disable-icon-rotate
expand-icon="$ayiFileDownload"
>{{ $ay.t("Export") }}</v-expansion-panel-header
>
<v-expansion-panel-content>
<v-radio-group v-model="exportFormat">
<v-radio label="JSON" value="json"></v-radio>
<v-radio label="CSV" value="csv"></v-radio>
</v-radio-group>
<v-btn icon @click="goHelp()"><v-icon>$ayiQuestionCircle</v-icon></v-btn>
<v-btn color="blue darken-1" text @click="doAction()">{{
$ay.t("Export")
}}</v-btn>
</v-expansion-panel-content>
</v-expansion-panel>
</template>
<script>
export default {
props: {
dataListSelection: { type: Object, default: null }
},
data: () => ({
exportFormat: "json",
jobActive: false
}),
methods: {
available() {
return (
this.dataListSelection.AType != 0 &&
this.dataListSelection.AType != window.$gz.type.PartInventoryRestock
);
},
goHelp() {
window.open(this.$store.state.helpUrl + "ay-ex-export", "_blank");
},
async doAction() {
try {
const res = await window.$gz.api.upsert(
`export/render/${this.exportFormat}`,
this.dataListSelection
);
if (res.error) {
throw new Error(window.$gz.errorHandler.errorToString(res, this));
}
const href = window.$gz.api.genericDownloadUrl(
"export/download/" + res.data
);
if (window.open(href, "DownloadExport") == null) {
throw new Error(
"Unable to download, your browser rejected navigating to download url."
);
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, this);
window.$gz.eventBus.$emit("notify-error", this.$ay.t("JobFailed"));
}
}
}
};
</script>