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.

90 lines
2.9 KiB

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