Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions app/controllers/orders/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,59 @@ import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
isLoading : false,
printThis : service(),
actions : {
downloadInvoice() {
const selector = '.print';
const options = {
header : 'Order Invoice',
printDelay : 800
};
this.get('printThis').print(selector, options);
isLoadingInvoice : false,
isLoadingTickets : false,
printThis : service(),
actions : {
downloadInvoice(eventName, orderId) {
this.set('isLoading', true);
this.loader
.downloadFile(`/orders/invoices/${this.model.order.identifier}`)
.then(res => {
const anchor = document.createElement('a');
anchor.style.display = 'none';
anchor.href = URL.createObjectURL(new Blob([res], { type: 'application/pdf' }));
anchor.download = `${eventName}-Invoice-${orderId}.pdf`;
document.body.appendChild(anchor);
anchor.click();
this.notify.success(this.l10n.t('Here is your Order Invoice'));
document.body.removeChild(anchor);
})
.catch(e => {
console.warn(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't disable the print thing for now, put it inside the catch block, if for some reason the above fails, it will be a fallback invoice.

const selector = '.print';
const options = {
header : 'Order Invoice',
printDelay : 800
};
this.printThis.print(selector, options);
})
.finally(() => {
this.set('isLoadingInvoice', false);
});
}
},

downloadTickets(eventName, orderId) {
this.set('isLoading', true);
this.get('loader')
.downloadFile(`/tickets/${this.get('model.order.identifier')}`)
this.set('isLoadingTickets', true);
this.loader
.downloadFile(`/tickets/${this.model.order.identifier}`)
.then(res => {
const anchor = document.createElement('a');
anchor.style.display = 'none';
anchor.href = URL.createObjectURL(new Blob([res], { type: 'application/pdf' }));
anchor.download = `${eventName}-Tickets-${orderId}.pdf`;
document.body.appendChild(anchor);
anchor.click();
this.get('notify').success(this.get('l10n').t('Here are your tickets'));
this.notify.success(this.l10n.t('Here are your tickets'));
document.body.removeChild(anchor);
})
.catch(e => {
console.warn(e);
this.get('notify').error(this.get('l10n').t('An unexpected Error occurred'));
this.notify.error(this.l10n.t('An unexpected Error occurred'));
})
.finally(() => {
this.set('isLoading', false);
this.set('isLoadingTickets', false);
});
}
});
4 changes: 2 additions & 2 deletions app/templates/orders/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
</div>
</div>
<br>
<a class="ui labeled icon button" href="#" {{action downloadTickets model.event.name model.order.identifier}} target="_blank" rel="noopener nofollow">
<a class="ui labeled icon {{if isLoadingTickets 'loading'}} button" href="#" {{action downloadTickets model.event.name model.order.identifier}} target="_blank" rel="noopener nofollow">
<i class="ticket alternate icon"></i>
{{t 'Download Tickets'}}
</a>
<br>
<br>
<a href="#" {{action 'downloadInvoice'}} class="ui labeled icon blue button">
<a href="#" {{action 'downloadInvoice' model.event.name model.order.identifier }} class="ui labeled icon blue {{if isLoadingInvoice 'loading'}} button">
<i class="print alternate icon"></i>
{{t 'Print Invoice'}}
</a>
Expand Down