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.

69 lines
2.9 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*
  2. OpenERP, Open Source Management Solution
  3. This module copyright (C) 2014 Therp BV (<http://therp.nl>)
  4. (C) 2013 Marcel van der Boom <marcel@hsdev.com>
  5. Copyright (C) 2016 Serpent Consulting Services Pvt. Ltd.
  6. (<http://www.serpentcs.com>)
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as
  9. published by the Free Software Foundation, either version 3 of the
  10. License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  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. odoo.define('web.WebTreeImage', function (require) {
  19. "use strict";
  20. var core = require('web.core');
  21. var session = require('web.session');
  22. var QWeb = core.qweb;
  23. var list_widget_registry = core.list_widget_registry;
  24. var WebTreeImage = list_widget_registry.get('field.binary').extend({
  25. format: function (row_data, options) {
  26. /* Return a valid img tag. For image fields, test if the
  27. field's value contains just the binary size and retrieve
  28. the image from the dedicated controller in that case.
  29. Otherwise, assume a character field containing either a
  30. stock Odoo icon name without path or extension or a fully
  31. fledged location or data url */
  32. if (!row_data[this.id] || !row_data[this.id].value) {
  33. return '';
  34. }
  35. var value = row_data[this.id].value, src;
  36. if (this.type === 'binary') {
  37. if (value && value.substr(0, 10).indexOf(' ') === -1) {
  38. // The media subtype (png) seems to be arbitrary
  39. src = "data:image/png;base64," + value;
  40. } else {
  41. var imageArgs = {
  42. model: options.model,
  43. field: this.id,
  44. id: options.id
  45. }
  46. if (this.resize) {
  47. imageArgs.resize = this.resize;
  48. }
  49. src = session.url('/web/binary/image', imageArgs);
  50. }
  51. } else {
  52. if (!/\//.test(row_data[this.id].value)) {
  53. src = '/web/static/src/img/icons/' + row_data[this.id].value + '.png';
  54. } else {
  55. src = row_data[this.id].value;
  56. }
  57. }
  58. return QWeb.render('ListView.row.image', {widget: this, src: src});
  59. }
  60. });
  61. list_widget_registry
  62. .add('field.image', WebTreeImage)
  63. });