|
@@ -1,9 +1,18 @@
|
|
window.pdfjsLib.GlobalWorkerOptions.workerSrc = '/print_engine/static/lib/js/pdf.worker.js';
|
|
window.pdfjsLib.GlobalWorkerOptions.workerSrc = '/print_engine/static/lib/js/pdf.worker.js';
|
|
|
|
+
|
|
|
|
+// Tools
|
|
openerp.pdfJs = window.pdfjsLib || {};
|
|
openerp.pdfJs = window.pdfjsLib || {};
|
|
openerp.printJs = window.printJS || {};
|
|
openerp.printJs = window.printJS || {};
|
|
|
|
+openerp.html2canvas = window.html2canvas || {};
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * @param {*} instance
|
|
|
|
+ * @param {*} local
|
|
|
|
+ */
|
|
openerp.print_engine = function (instance, local) {
|
|
openerp.print_engine = function (instance, local) {
|
|
- local.SocketManager = instance.web.Class.extend({
|
|
|
|
|
|
+
|
|
|
|
+ var SocketManager = instance.web.Class.extend({
|
|
init: function () {
|
|
init: function () {
|
|
this.socket = null;
|
|
this.socket = null;
|
|
this.start();
|
|
this.start();
|
|
@@ -64,7 +73,7 @@ openerp.print_engine = function (instance, local) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- var widget = new local.PrinterSelectionDialog(data);
|
|
|
|
|
|
+ var widget = new PrinterSelectionDialog(data);
|
|
widget.get_selection().then(function (request) {
|
|
widget.get_selection().then(function (request) {
|
|
self.emit('request_print', request);
|
|
self.emit('request_print', request);
|
|
});
|
|
});
|
|
@@ -122,7 +131,7 @@ openerp.print_engine = function (instance, local) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- new local.PdfViewerDialog(null, pdf);
|
|
|
|
|
|
+ preview_pdf(null, pdf);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
get_socket_config: function () {
|
|
get_socket_config: function () {
|
|
@@ -182,7 +191,7 @@ openerp.print_engine = function (instance, local) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- local.DownloadPrinterTools = instance.web.Widget.extend({
|
|
|
|
|
|
+ var DownloadPrinterTools = instance.web.Widget.extend({
|
|
template: 'DownloadPrinterTools',
|
|
template: 'DownloadPrinterTools',
|
|
events: {
|
|
events: {
|
|
'click .download_button': 'handle_download'
|
|
'click .download_button': 'handle_download'
|
|
@@ -239,7 +248,7 @@ openerp.print_engine = function (instance, local) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- local.PrinterTopNotificator = instance.web.Widget.extend({
|
|
|
|
|
|
+ var PrinterTopNotificator = instance.web.Widget.extend({
|
|
template: 'PrinterTopNotificator',
|
|
template: 'PrinterTopNotificator',
|
|
events: {
|
|
events: {
|
|
'click .printer_status_notificator': 'handle_click'
|
|
'click .printer_status_notificator': 'handle_click'
|
|
@@ -251,13 +260,13 @@ openerp.print_engine = function (instance, local) {
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
|
|
|
if (local.socket_manager.socket.disconnected) {
|
|
if (local.socket_manager.socket.disconnected) {
|
|
- var widget = new local.DownloadPrinterTools(this);
|
|
|
|
|
|
+ var widget = new DownloadPrinterTools(this);
|
|
widget.start();
|
|
widget.start();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- local.PrinterUnavailableDialog = instance.web.Widget.extend({
|
|
|
|
|
|
+ var PrinterUnavailableDialog = instance.web.Widget.extend({
|
|
template: 'PrinterUnavailableDialog',
|
|
template: 'PrinterUnavailableDialog',
|
|
events: {
|
|
events: {
|
|
'click li': 'on_download'
|
|
'click li': 'on_download'
|
|
@@ -295,7 +304,7 @@ openerp.print_engine = function (instance, local) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- local.PrinterSelectionDialog = instance.web.Widget.extend({
|
|
|
|
|
|
+ var PrinterSelectionDialog = instance.web.Widget.extend({
|
|
template: 'PrinterSelectionDialog',
|
|
template: 'PrinterSelectionDialog',
|
|
events: {
|
|
events: {
|
|
'click li': 'on_select'
|
|
'click li': 'on_select'
|
|
@@ -343,7 +352,7 @@ openerp.print_engine = function (instance, local) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- local.PdfViewerDialog = instance.web.Widget.extend({
|
|
|
|
|
|
+ var PdfViewerDialog = instance.web.Widget.extend({
|
|
template: 'PdfViewerDialog',
|
|
template: 'PdfViewerDialog',
|
|
events: {
|
|
events: {
|
|
'click a.btn': 'on_action'
|
|
'click a.btn': 'on_action'
|
|
@@ -490,7 +499,16 @@ openerp.print_engine = function (instance, local) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ instance.web.blockUI();
|
|
|
|
+
|
|
self.pdf.getData().then(function (data) {
|
|
self.pdf.getData().then(function (data) {
|
|
|
|
+ instance.web.unblockUI();
|
|
|
|
+
|
|
|
|
+ if (local.socket_manager.socket.connected) {
|
|
|
|
+ local.socket_manager.request_print(data, true);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
instance.printJs({
|
|
instance.printJs({
|
|
printable: instance.pdfJs.createObjectURL(data, 'application/pdf')
|
|
printable: instance.pdfJs.createObjectURL(data, 'application/pdf')
|
|
});
|
|
});
|
|
@@ -517,14 +535,97 @@ openerp.print_engine = function (instance, local) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ var preview_pdf = function (owner, data, name) {
|
|
|
|
+ new PdfViewerDialog(owner, data, name);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var download_pdf = function (source) {
|
|
|
|
+ var matchMimeType = source.match(/data:[a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+.*,/);
|
|
|
|
+
|
|
|
|
+ if (!matchMimeType) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!source.startsWith(matchMimeType[0])) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var a = document.createElement('a');
|
|
|
|
+
|
|
|
|
+ a.href = source;
|
|
|
|
+ a.download = 'documento.pdf';
|
|
|
|
+ a.target = '_parent';
|
|
|
|
+ a.click();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ local.print = function (data) {
|
|
|
|
+ var config = this.socket_manager.config;
|
|
|
|
+
|
|
|
|
+ if (config.is_mobile) {
|
|
|
|
+ download_pdf(data);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.socket_manager.socket.disconnected) {
|
|
|
|
+ if (config.action_download_pdf) {
|
|
|
|
+ download_pdf(data);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var widget = new PrinterUnavailableDialog();
|
|
|
|
+ widget.can_download().then(function (can_download) {
|
|
|
|
+ if (!can_download) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (config.action_preview_pdf) {
|
|
|
|
+ preview_pdf(null, data, null);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ download_pdf(data);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.socket_manager.request_print(data);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ local.TicketTestPage = instance.web.Widget.extend({
|
|
|
|
+ template: 'TicketTestPage',
|
|
|
|
+ events: {
|
|
|
|
+ 'click .ticket-test-btn': 'print_test'
|
|
|
|
+ },
|
|
|
|
+ start: function () {
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ print_test: function (e) {
|
|
|
|
+ e.preventDefault();
|
|
|
|
+
|
|
|
|
+ var html = openerp.web.qweb.render('EiruPosTicket');
|
|
|
|
+ var pdf = new jsPDF({
|
|
|
|
+ unit: 'mm',
|
|
|
|
+ format: [290, 70]
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ pdf.fromHTML(html, 0, 0);
|
|
|
|
+
|
|
|
|
+ var data = pdf.output('datauristring');
|
|
|
|
+ local.print(data);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ instance.web.client_actions.add('printer.test_ticket', 'instance.print_engine.TicketTestPage');
|
|
|
|
+
|
|
if (instance.web) {
|
|
if (instance.web) {
|
|
if (instance.web.UserMenu) {
|
|
if (instance.web.UserMenu) {
|
|
instance.web.UserMenu.include({
|
|
instance.web.UserMenu.include({
|
|
do_update: function () {
|
|
do_update: function () {
|
|
- var printer = new local.PrinterTopNotificator(this);
|
|
|
|
|
|
+ var printer = new PrinterTopNotificator(this);
|
|
printer.appendTo($('.oe_systray'));
|
|
printer.appendTo($('.oe_systray'));
|
|
|
|
|
|
- local.socket_manager = new local.SocketManager();
|
|
|
|
|
|
+ local.socket_manager = new SocketManager();
|
|
|
|
|
|
return this._super.apply(this, arguments);
|
|
return this._super.apply(this, arguments);
|
|
}
|
|
}
|
|
@@ -559,7 +660,7 @@ openerp.print_engine = function (instance, local) {
|
|
url += '?options=' + encodeURIComponent(JSON.stringify(action.data)) + '&context=' + encodeURIComponent(JSON.stringify(action.context));
|
|
url += '?options=' + encodeURIComponent(JSON.stringify(action.data)) + '&context=' + encodeURIComponent(JSON.stringify(action.context));
|
|
}
|
|
}
|
|
|
|
|
|
- new local.PdfViewerDialog(self, url, action.name);
|
|
|
|
|
|
+ preview_pdf(self, url, action.name);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -568,7 +669,7 @@ openerp.print_engine = function (instance, local) {
|
|
token: (new Date()).getTime()
|
|
token: (new Date()).getTime()
|
|
};
|
|
};
|
|
|
|
|
|
- new local.PdfViewerDialog(self, this.session.url('/web/report', params), action.name);
|
|
|
|
|
|
+ preview_pdf(self, this.session.url('/web/report', params), action.name);
|
|
},
|
|
},
|
|
trigger_download_pdf: function (action) {
|
|
trigger_download_pdf: function (action) {
|
|
var regex = /^(?:qweb-(pdf|html)|controller)$/;
|
|
var regex = /^(?:qweb-(pdf|html)|controller)$/;
|
|
@@ -644,7 +745,7 @@ openerp.print_engine = function (instance, local) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- var widget = new local.PrinterUnavailableDialog(this);
|
|
|
|
|
|
+ var widget = new PrinterUnavailableDialog(this);
|
|
widget.can_download().then(function (can_download) {
|
|
widget.can_download().then(function (can_download) {
|
|
if (!can_download) {
|
|
if (!can_download) {
|
|
return;
|
|
return;
|