|
@@ -19,6 +19,7 @@ openerp.print_engine = function (instance, local) {
|
|
|
path: config.path
|
|
|
});
|
|
|
self.socket.on('connect', self.handle_connect);
|
|
|
+ self.socket.on('error', self.handle_error);
|
|
|
self.socket.on('connect_error', self.handle_connect_error);
|
|
|
self.socket.on('request_printer_name', self.handle_printer_selection);
|
|
|
self.socket.on('show_print_status', self.handle_print_status);
|
|
@@ -31,7 +32,10 @@ openerp.print_engine = function (instance, local) {
|
|
|
$('#printer-status').removeClass();
|
|
|
$('#printer-status').addClass('printer-status-online');
|
|
|
},
|
|
|
- handle_connect_error: function () {
|
|
|
+ handle_error: function (e) {
|
|
|
+ console.log(e);
|
|
|
+ },
|
|
|
+ handle_connect_error: function (e) {
|
|
|
$('#printer-status').removeClass();
|
|
|
$('#printer-status').addClass('printer-status-offline');
|
|
|
},
|
|
@@ -220,17 +224,48 @@ openerp.print_engine = function (instance, local) {
|
|
|
if (instance.web.ActionManager) {
|
|
|
instance.web.ActionManager.include({
|
|
|
trigger_preview_pdf: function (action) {
|
|
|
- console.log(action);
|
|
|
+ var regex = /^(?:qweb-(pdf|html)|controller)$/;
|
|
|
+
|
|
|
+ if (_.has(action, 'report_type') && regex.test(action.report_type)) {
|
|
|
+ var format = action.report_type.match(regex)[1];
|
|
|
+ var url = action.report_file || ('/report/' + format + action.report_name);
|
|
|
+
|
|
|
+ if (_.isEmpty(action.data) && _.has(action.context, 'active_ids')) {
|
|
|
+ url += '/' + action.context.active_ids.join(',');
|
|
|
+ } else {
|
|
|
+ url += '?options=' + encodeURIComponent(JSON.stringify(action.data)) + '&context=' + encodeURIComponent(JSON.stringify(action.context));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_.isEqual(format, 'html')) {
|
|
|
+ open(url, '_blank', 'scrollbars=1,height=900,width=1280');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_.isEqual(format, 'pdf')) {
|
|
|
+ open('/report/html/' + url, '_blank', 'height=768,width=1024');
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ var params = {
|
|
|
+ action: JSON.stringify(action),
|
|
|
+ token: (new Date()).getTime()
|
|
|
+ };
|
|
|
+
|
|
|
+ open(this.session.url('/web/report', params), 'report', '');
|
|
|
+ instance.web.unblockUI();
|
|
|
+ }
|
|
|
},
|
|
|
trigger_download_pdf: function (action) {
|
|
|
console.log(action);
|
|
|
},
|
|
|
ir_actions_report_xml: function (action, options) {
|
|
|
var self = this;
|
|
|
- var config = instance.print_engine.socket_manager.config.is_mobile;
|
|
|
+ var config = instance.print_engine.socket_manager.config;
|
|
|
+
|
|
|
+ var eval_contexts = ([instance.session.user_context] || []).concat([action.context]);
|
|
|
+ action.context = instance.web.pyeval.eval('contexts', eval_contexts);
|
|
|
|
|
|
if (config.is_mobile) {
|
|
|
- this.trigger_preview_pdf(ctx)
|
|
|
+ this.trigger_preview_pdf(action);
|
|
|
return;
|
|
|
}
|
|
|
|