| 1 |
import { Component, onMounted, useState, useRef } from "@odoo/owl"; |
| 2 |
import { isBarcodeScannerSupported } from "@web/core/barcode/barcode_video_scanner"; |
| 3 |
import { Dialog } from "@web/core/dialog/dialog"; |
| 4 |
import { useService } from "@web/core/utils/hooks"; |
| 5 |
|
| 6 |
export class EventRegistrationSummaryDialog extends Component { |
| 7 |
static template = "event.EventRegistrationSummaryDialog"; |
| 8 |
static components = { Dialog }; |
| 9 |
static props = { |
| 10 |
close: Function, |
| 11 |
doNextScan: { type: Function, optional: true }, |
| 12 |
model: { type: Object, optional: true }, |
| 13 |
playSound: { type: Function, optional: true }, |
| 14 |
registration: { type: Object }, |
| 15 |
}; |
| 16 |
|
| 17 |
setup() { |
| 18 |
this.actionService = useService("action"); |
| 19 |
this.isBarcodeScannerSupported = isBarcodeScannerSupported(); |
| 20 |
this.orm = useService("orm"); |
| 21 |
this.notification = useService("notification"); |
| 22 |
this.continueButtonRef = useRef("continueButton"); |
| 23 |
this.button = useState({enabled: true}); |
| 24 |
|
| 25 |
this.registrationStatus = useState({value: this.registration.status}); |
| 26 |
|
| 27 |
onMounted(() => { |
| 28 |
if (['already_registered', 'need_manual_confirmation'].includes(this.props.registration.status) && this.props.playSound) { |
| 29 |
this.props.playSound("notify"); |
| 30 |
} else if (['not_ongoing_event', 'canceled_registration'].includes(this.props.registration.status) && this.props.playSound) { |
| 31 |
this.props.playSound("error"); |
| 32 |
} |
| 33 |
|
| 34 |
this.continueButtonRef.el?.focus(); |
| 35 |
}); |
| 36 |
} |
| 37 |
|
| 38 |
get registration() { |
| 39 |
return this.props.registration; |
| 40 |
} |
| 41 |
|
| 42 |
get needManualConfirmation() { |
| 43 |
return this.registrationStatus.value === "need_manual_confirmation"; |
| 44 |
} |
| 45 |
|
| 46 |
async onRegistrationConfirm() { |
| 47 |
if (this.registrationStatus.value !== "confirmed_registration") { |
| 48 |
this.button.enabled = false |
| 49 |
await this.orm.call("event.registration", "action_set_done", [this.registration.id]).catch(() => this.button.enabled = true); |
| 50 |
this.registrationStatus.value = "confirmed_registration"; |
| 51 |
} |
| 52 |
this.props.close(); |
| 53 |
if (this.props.model) { |
| 54 |
this.props.model.load(); |
| 55 |
} |
| 56 |
if (this.props.doNextScan) { |
| 57 |
this.onScanNext(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
async undoRegistration() { |
| 62 |
if (["confirmed_registration", "already_registered"].includes(this.registrationStatus.value)) { |
| 63 |
await this.orm.call("event.registration", "action_confirm", [this.registration.id]); |
| 64 |
} else if (this.registrationStatus.value == "unconfirmed_registration") { |
| 65 |
await this.orm.call("event.registration", "action_set_draft", [this.registration.id]); |
| 66 |
} |
| 67 |
this.props.close(); |
| 68 |
if (this.props.model) { |
| 69 |
this.props.model.load(); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
async onRegistrationPrintPdf() { |
| 74 |
await this.actionService.doAction({ |
| 75 |
type: "ir.actions.report", |
| 76 |
report_type: "qweb-pdf", |
| 77 |
report_name: `event.event_registration_report_template_badge/${this.registration.id}`, |
| 78 |
}); |
| 79 |
if (this.props.doNextScan) { |
| 80 |
this.onScanNext(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
async onRegistrationView() { |
| 85 |
await this.actionService.doAction({ |
| 86 |
type: "ir.actions.act_window", |
| 87 |
res_model: "event.registration", |
| 88 |
res_id: this.registration.id, |
| 89 |
views: [[false, "form"]], |
| 90 |
target: "current", |
| 91 |
}); |
| 92 |
this.props.close(); |
| 93 |
} |
| 94 |
|
| 95 |
async onScanNext() { |
| 96 |
this.props.close(); |
| 97 |
if (this.isBarcodeScannerSupported) { |
| 98 |
this.props.doNextScan(); |
| 99 |
} |
| 100 |
} |
| 101 |
} |