|
@@ -10,19 +10,18 @@ openerp.print_engine = function (instance, local) {
|
|
open_socket: function () {
|
|
open_socket: function () {
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
- var set_socket = function (socket) {
|
|
|
|
|
|
+ var setup_socket = function (config) {
|
|
var protocol = window.location.protocol;
|
|
var protocol = window.location.protocol;
|
|
- self.socket = io(protocol + '//' + socket.host + ':' + socket.port, {
|
|
|
|
- path: socket.path
|
|
|
|
|
|
+ self.socket = io(protocol + '//' + config.host + ':' + config.port, {
|
|
|
|
+ path: config.path
|
|
});
|
|
});
|
|
self.socket.on('connect', self.handle_connect);
|
|
self.socket.on('connect', self.handle_connect);
|
|
self.socket.on('connect_error', self.handle_connect_error);
|
|
self.socket.on('connect_error', self.handle_connect_error);
|
|
self.socket.on('show-printers', self.handle_printers);
|
|
self.socket.on('show-printers', self.handle_printers);
|
|
- self.socket.on('print-error', self.handle_print_error);
|
|
|
|
- self.socket.on('print-finished', self.handle_print_finished);
|
|
|
|
|
|
+ self.socket.on('show-print-status', self.handle_print_status);
|
|
}
|
|
}
|
|
|
|
|
|
- this.get_socket_config().then(set_socket);
|
|
|
|
|
|
+ this.get_socket_config().then(setup_socket);
|
|
},
|
|
},
|
|
handle_connect: function () {
|
|
handle_connect: function () {
|
|
$('#printer-status').removeClass();
|
|
$('#printer-status').removeClass();
|
|
@@ -33,13 +32,29 @@ openerp.print_engine = function (instance, local) {
|
|
$('#printer-status').addClass('printer-status-offline');
|
|
$('#printer-status').addClass('printer-status-offline');
|
|
},
|
|
},
|
|
handle_printers: function (printers) {
|
|
handle_printers: function (printers) {
|
|
- console.log(printers);
|
|
|
|
- },
|
|
|
|
- handle_print_error: function () {
|
|
|
|
- console.log('error');
|
|
|
|
|
|
+ instance.web.unblockUI();
|
|
|
|
+
|
|
|
|
+ var widget = new local.PrinterSelectionWidget(printers);
|
|
|
|
+ widget.get_selection().then(function (printer) {
|
|
|
|
+ console.log(printer);
|
|
|
|
+ });
|
|
},
|
|
},
|
|
- handle_print_finished: function () {
|
|
|
|
- console.log('finished');
|
|
|
|
|
|
+ handle_print_status: function (data) {
|
|
|
|
+ instance.web.unblockUI();
|
|
|
|
+
|
|
|
|
+ if (_.isEqual(data.status, 'printing')) {
|
|
|
|
+ instance.web.notification.do_notify('Impresión', 'La impresora ' + data.printer + ' está imprimiendo');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (_.isEqual(data.status, 'printed')) {
|
|
|
|
+ instance.web.notification.do_notify('Impresión', 'La impresora ' + data.printer + ' finalizó la impresión');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (_.isEqual(data.status, 'error')) {
|
|
|
|
+ instance.web.notification.do_notify('Impresión', 'Ocurrió un error al imprimir: ' + data.printer);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
get_socket_config: function () {
|
|
get_socket_config: function () {
|
|
var url = '/print_engine/socket_config';
|
|
var url = '/print_engine/socket_config';
|
|
@@ -57,39 +72,79 @@ openerp.print_engine = function (instance, local) {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- request_print: function (b64_data) {
|
|
|
|
|
|
+ request_print: function (data) {
|
|
if (!this.socket || !this.socket.connected) {
|
|
if (!this.socket || !this.socket.connected) {
|
|
instance.web.notification.do_warn('Impresión', 'La impresora no está preparada');
|
|
instance.web.notification.do_warn('Impresión', 'La impresora no está preparada');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ instance.web.blockUI();
|
|
|
|
+
|
|
try {
|
|
try {
|
|
this.socket.emit('request-print', {
|
|
this.socket.emit('request-print', {
|
|
- data: b64_data
|
|
|
|
|
|
+ data: data
|
|
});
|
|
});
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
|
+ instance.web.unblockUI();
|
|
instance.webclient.crashmanager.show_message(e);
|
|
instance.webclient.crashmanager.show_message(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
local.PrinterTopWidget = instance.web.Widget.extend({
|
|
local.PrinterTopWidget = instance.web.Widget.extend({
|
|
- template: 'printEngine.PrinterTopWidget',
|
|
|
|
|
|
+ template: 'PrinterTopWidget',
|
|
init: function (parent) {
|
|
init: function (parent) {
|
|
- this._super(parent)
|
|
|
|
|
|
+ this._super(parent);
|
|
},
|
|
},
|
|
start: function () {
|
|
start: function () {
|
|
// this.$el.click(this, this.selectDefaultPrinter);
|
|
// this.$el.click(this, this.selectDefaultPrinter);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ local.PrinterSelectionWidget = instance.web.Widget.extend({
|
|
|
|
+ template: 'PrinterSelectionWidget',
|
|
|
|
+ events: {
|
|
|
|
+ 'click li': 'on_select'
|
|
|
|
+ },
|
|
|
|
+ printers: [],
|
|
|
|
+ init: function (printers) {
|
|
|
|
+ this.printers = printers;
|
|
|
|
+ this.start();
|
|
|
|
+ },
|
|
|
|
+ start: function () {
|
|
|
|
+ this.defer = $.Deferred();
|
|
|
|
+ this.render_widget();
|
|
|
|
+ },
|
|
|
|
+ render_widget: function () {
|
|
|
|
+ this.renderElement();
|
|
|
|
+ $('body').append(this.$el);
|
|
|
|
+
|
|
|
|
+ this.$el.on('hidden.bs.modal', this, this.on_hide);
|
|
|
|
+
|
|
|
|
+ this.$el.modal('show');
|
|
|
|
+ },
|
|
|
|
+ get_selection: function () {
|
|
|
|
+ return this.defer;
|
|
|
|
+ },
|
|
|
|
+ on_select: function (e) {
|
|
|
|
+ var $el = $(e.target).closest('li');
|
|
|
|
+ var name = $el.data('name');
|
|
|
|
+ this.selected_printer = name;
|
|
|
|
+ this.$el.modal('hide');
|
|
|
|
+ },
|
|
|
|
+ on_hide: function (e) {
|
|
|
|
+ var self = e.data;
|
|
|
|
+ self.defer.resolve(self.selected_printer);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
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.PrinterTopWidget(this);
|
|
var printer = new local.PrinterTopWidget(this);
|
|
printer.appendTo($('.oe_systray'));
|
|
printer.appendTo($('.oe_systray'));
|
|
- local.socket = new local.SocketManager()
|
|
|
|
|
|
+ local.socket = new local.SocketManager();
|
|
return this._super.apply(this, arguments);
|
|
return this._super.apply(this, arguments);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -114,4 +169,4 @@ openerp.print_engine = function (instance, local) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|