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.

59 lines
2.6 KiB

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. 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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Affero General Public License for more details.
  13. You should have received a copy of the GNU Affero General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. openerp.web_tree_image = function (instance) {
  17. instance.web.list.Image = instance.web.list.Column.extend({
  18. format: function (row_data, options) {
  19. /* Return a valid img tag. For image fields, test if the
  20. field's value contains just the binary size and retrieve
  21. the image from the dedicated controller in that case.
  22. Otherwise, assume a character field containing either a
  23. stock Odoo icon name without path or extension or a fully
  24. fledged location or data url */
  25. if (!row_data[this.id] || !row_data[this.id].value) {
  26. return '';
  27. }
  28. var value = row_data[this.id].value, src;
  29. if (this.type === 'binary') {
  30. if (value && value.substr(0, 10).indexOf(' ') === -1) {
  31. // The media subtype (png) seems to be arbitrary
  32. src = "data:image/png;base64," + value;
  33. } else {
  34. var imageArgs = {
  35. model: options.model,
  36. field: this.id,
  37. id: options.id
  38. }
  39. if (this.resize) {
  40. imageArgs.resize = this.resize;
  41. }
  42. src = instance.session.url('/web/binary/image', imageArgs);
  43. }
  44. } else {
  45. if (!/\//.test(row_data[this.id].value)) {
  46. src = '/web/static/src/img/icons/' + row_data[this.id].value + '.png';
  47. } else {
  48. src = row_data[this.id].value;
  49. }
  50. }
  51. return instance.web.qweb.render('ListView.row.image', {widget: this, src: src});
  52. }
  53. });
  54. instance.web.list.columns.add('field.image', 'instance.web.list.Image');
  55. };