/report/static/src/js/qwebactionmanager.js

https://gitlab.com/darmawan.fatria/provjabar-pelayanan-pendidikan-addons · JavaScript · 97 lines · 86 code · 6 blank · 5 comment · 29 complexity · eac897cac650fea179eb567eb5b2eba3 MD5 · raw file

  1. openerp.report = function(instance) {
  2. var wkhtmltopdf_state;
  3. var trigger_download = function(session, response, c, action, options) {
  4. session.get_file({
  5. url: '/report/download',
  6. data: {data: JSON.stringify(response)},
  7. complete: openerp.web.unblockUI,
  8. error: c.rpc_error.bind(c),
  9. success: function(){
  10. if (action && options && !action.dialog) {
  11. options.on_close();
  12. }
  13. },
  14. });
  15. };
  16. instance.web.ActionManager = instance.web.ActionManager.extend({
  17. ir_actions_report_xml: function(action, options) {
  18. var self = this;
  19. instance.web.blockUI();
  20. action = _.clone(action);
  21. _t = instance.web._t;
  22. // QWeb reports
  23. if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
  24. var report_url = '';
  25. switch (action.report_type) {
  26. case 'qweb-html':
  27. report_url = '/report/html/' + action.report_name;
  28. break;
  29. case 'qweb-pdf':
  30. report_url = '/report/pdf/' + action.report_name;
  31. break;
  32. case 'controller':
  33. report_url = action.report_file;
  34. break;
  35. default:
  36. report_url = '/report/html/' + action.report_name;
  37. break;
  38. }
  39. // generic report: no query string
  40. // particular: query string of action.data.form and context
  41. if (!('data' in action) || !(action.data)) {
  42. if ('active_ids' in action.context) {
  43. report_url += "/" + action.context.active_ids.join(',');
  44. }
  45. } else {
  46. report_url += "?options=" + encodeURIComponent(JSON.stringify(action.data));
  47. report_url += "&context=" + encodeURIComponent(JSON.stringify(action.context));
  48. }
  49. var response = new Array();
  50. response[0] = report_url;
  51. response[1] = action.report_type;
  52. var c = openerp.webclient.crashmanager;
  53. if (action.report_type == 'qweb-html') {
  54. window.open(report_url, '_blank', 'scrollbars=1,height=900,width=1280');
  55. instance.web.unblockUI();
  56. } else if (action.report_type === 'qweb-pdf') {
  57. // Trigger the download of the pdf/controller report
  58. (wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
  59. // Fallback on html if wkhtmltopdf is not installed or if OpenERP is started with one worker
  60. if (presence === 'install') {
  61. self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
  62. system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
  63. wkhtmltopdf.org</a>'), true);
  64. report_url = report_url.substring(12)
  65. window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
  66. instance.web.unblockUI();
  67. return;
  68. } else if (presence === 'workers') {
  69. self.do_notify(_t('Report'), _t('You need to start OpenERP with at least two \
  70. workers to print a pdf version of the reports.'), true);
  71. report_url = report_url.substring(12)
  72. window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
  73. instance.web.unblockUI();
  74. return;
  75. } else if (presence === 'upgrade') {
  76. self.do_notify(_t('Report'), _t('You should upgrade your version of\
  77. Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
  78. support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
  79. target="_blank">wkhtmltopdf.org</a>'), true);
  80. }
  81. return trigger_download(self.session, response, c, action, options);
  82. });
  83. } else if (action.report_type === 'controller') {
  84. return trigger_download(self.session, response, c, action, options);
  85. }
  86. } else {
  87. return self._super(action, options);
  88. }
  89. }
  90. });
  91. };