|
1 | 1 | const cds = require("@sap/cds"); |
2 | | -const LOG = cds.log("print"); |
3 | 2 |
|
4 | | -class PrintService extends cds.Service { |
5 | | - /** |
6 | | - * Sends a document to print. Method print can be used alternatively. |
7 | | - * @param {string} [event] - The print action event. |
8 | | - * @param {object} message - The print request object |
9 | | - */ |
10 | | - emit(event, message) { |
11 | | - if (!event) { |
12 | | - LOG._warn && LOG.warn("No object provided for print"); |
13 | | - return; |
14 | | - } |
15 | | - // Outbox calls us with a req object, e.g. { event, data, headers } |
16 | | - if (event.event) return super.emit(event); |
17 | | - // First argument is optional for convenience |
18 | | - if (!message) [message, event] = [event]; |
19 | | - // CAP events translate to print actions and vice versa |
20 | | - if (event) message.action = event; |
21 | | - else event = message.action || message.ActionKey || "Default"; |
22 | | - // Emit the print request |
23 | | - return super.emit(event, message); |
24 | | - } |
25 | | - |
26 | | - /** |
27 | | - * That's just a semantic alias for emit. |
28 | | - * @param {string} [event] - The print action event. |
29 | | - * @param {object} message - The print request object |
30 | | - */ |
31 | | - print(event, message) { |
32 | | - return this.emit(event, message); |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Get available print queues - implemented by subclasses |
37 | | - * @returns {Promise<Array>} Array of queue objects |
38 | | - async getQueues() { |
39 | | - throw new Error('getQueues method must be implemented by subclass'); |
40 | | - } |
41 | | - */ |
42 | | -} |
| 3 | +class PrintService extends cds.Service {} |
43 | 4 |
|
44 | 5 | module.exports = PrintService; |
45 | 6 |
|
46 | | -// Without Generic Outbox only alert.print() can be used, not alert.emit() |
47 | | -// Remove that when @sap/cds with Generic Outbox is released |
48 | | -if (!cds.outboxed) { |
49 | | - class OutboxedNotificationService extends require("@sap/cds/libx/_runtime/messaging/Outbox") {} |
50 | | - OutboxedNotificationService.prototype.notify = NotificationService.prototype.emit; |
51 | | - module.exports = OutboxedNotificationService; |
52 | | -} |
0 commit comments