Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | methods: { | ||||
if (!error.response) { | if (!error.response) { | ||||
// TODO: probably network connection error | // TODO: probably network connection error | ||||
} else if (error.response.status === 401) { | } else if (error.response.status === 401) { | ||||
this.logoutUser() | this.logoutUser() | ||||
} else { | } else { | ||||
this.errorPage(error.response.status, error.response.statusText) | this.errorPage(error.response.status, error.response.statusText) | ||||
} | } | ||||
}, | }, | ||||
downloadFile(url) { | |||||
// TODO: This might not be a best way for big files as the content | |||||
// will be stored (temporarily) in browser memory | |||||
// TODO: This method does not show the download progress in the browser | |||||
// but it could be implemented in the UI, axios has 'progress' property | |||||
axios.get(url, { responseType: 'blob' }) | |||||
.then (response => { | |||||
const link = document.createElement('a') | |||||
const contentDisposition = response.headers['content-disposition'] | |||||
let filename = 'unknown' | |||||
if (contentDisposition) { | |||||
const match = contentDisposition.match(/filename="(.+)"/); | |||||
if (match.length === 2) { | |||||
filename = match[1]; | |||||
} | |||||
} | |||||
link.href = window.URL.createObjectURL(response.data) | |||||
link.download = filename | |||||
link.click() | |||||
}) | |||||
}, | |||||
price(price) { | price(price) { | ||||
return (price/100).toLocaleString('de-DE', { style: 'currency', currency: 'CHF' }) | return (price/100).toLocaleString('de-DE', { style: 'currency', currency: 'CHF' }) | ||||
}, | }, | ||||
priceLabel(cost, units = 1, discount) { | priceLabel(cost, units = 1, discount) { | ||||
let index = '' | let index = '' | ||||
if (units < 0) { | if (units < 0) { | ||||
units = 1 | units = 1 | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |