You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.8 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_preview_markdown.PreviewContentCSV', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var ajax = require('web.ajax');
  23. var utils = require('web.utils');
  24. var session = require('web.session');
  25. var registry = require('muk_preview.registry');
  26. var AbstractPreviewContent = require('muk_preview.AbstractPreviewContent');
  27. var QWeb = core.qweb;
  28. var _t = core._t;
  29. var PreviewContentCSV = AbstractPreviewContent.extend({
  30. template: "muk_preview.PreviewContentCSV",
  31. cssLibs: [
  32. '/muk_web_preview_csv/static/lib/pikaday/pikaday.css',
  33. '/muk_web_preview_csv/static/lib/handsontable/handsontable.css',
  34. ],
  35. jsLibs: [
  36. '/muk_web_preview_csv/static/lib/papaparse/papaparse.js',
  37. '/muk_web_preview_csv/static/lib/numbro/numbro.js',
  38. '/muk_web_preview_csv/static/lib/pikaday/pikaday.js',
  39. '/muk_web_preview_csv/static/lib/handsontable/handsontable.js',
  40. ],
  41. willStart: function() {
  42. var def = $.Deferred();
  43. this._super.apply(this, arguments).then(function() {
  44. Papa.parse(this.url, {
  45. download: true,
  46. dynamicTyping: true,
  47. complete: function(results) {
  48. this.csv = results.data;
  49. def.resolve();
  50. }.bind(this),
  51. });
  52. }.bind(this));
  53. return def;
  54. },
  55. renderPreviewContent: function() {
  56. console.log(this.csv);
  57. this.$('.mk_preview_csv').handsontable({
  58. data: this.csv,
  59. rowHeaders: true,
  60. colHeaders: true,
  61. stretchH: 'all',
  62. readOnly: true,
  63. columnSorting: true,
  64. autoColumnSize: true,
  65. });
  66. return this._super.apply(this, arguments);
  67. },
  68. downloadable: true,
  69. printable: false,
  70. });
  71. registry.add('csv', PreviewContentCSV);
  72. registry.add('.csv', PreviewContentCSV);
  73. registry.add('text/csv', PreviewContentCSV);
  74. registry.add('application/csv', PreviewContentCSV);
  75. registry.add('text/comma-separated-values', PreviewContentCSV);
  76. return PreviewContentCSV;
  77. });