Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
12882 Переглядів

Hello,

is there any addon or code by which I can embed a preview of pdf documents in a form view? Or if this is not possible, to embed an image in an form view. Optionally, this opens or increases by clicking.

I'm using Odoo 10. Thank you for your help.

Аватар
Відмінити
Найкраща відповідь

Hi


Check out this video will helpful: 

https://youtu.be/Ozikktx0Ovs

Аватар
Відмінити
Найкраща відповідь

odoo.define('module_name.image_widget_extend', function (require) {
"use strict";


    var core = require('web.core');
    var form_common = require('web.form_common');
    var imageWidget = core.form_widget_registry.get('image');
    var session = require('web.session');
    var utils = require('web.utils');
    var QWeb = core.qweb;

imageWidget.include({
    render_value: function() {
        var self = this;
        var url;
        this.session = session;
        if (this.get('value') && !utils.is_bin_size(this.get('value'))) {
            url = 'data:image/png;base64,' + this.get('value');
        } else if (this.get('value')) {
            var id = JSON.stringify(this.view.datarecord.id || null);
            var field = this.name;
            if (this.options.preview_image)
                field = this.options.preview_image;
            url = session.url('/web/image', {
                                        model: this.view.dataset.model,
                                        id: id,
                                        field: field,
                                        unique: (this.view.datarecord.__last_update || '').replace(/[^0-9]/g, ''),
            });
        } else {
            url = this.placeholder;
        }

        var record_id = this.getParent().get_fields_values()['id'];
        var current_model = this.getParent().model;
        var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
        $($img).click(function(e) {
            if(self.view.get("actual_mode") == "view") {

                var $button = $(".oe_form_button_edit");
                $button.openerpBounce();
                e.stopPropagation();
                window.location.href = "/web/image/" + current_model + "/" + record_id + "/image"
            }
        });
        this.$el.find('> img').remove();
        this.$el.prepend($img);
        $img.load(function() {
            if (! self.options.size)
                return;
            $img.css("max-width", "" + self.options.size[0] + "px");
            $img.css("max-height", "" + self.options.size[1] + "px");
        });
        $img.on('error', function() {
            self.on_clear();
            $img.attr('src', self.placeholder);
            self.do_warn(_t("Image"), _t("Could not display the selected image."));
        });
    },

});


});


Try to implement above. Hope this will help you.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
лип. 17
6332
0
лист. 22
3949
2
січ. 25
3920
1
груд. 22
5308
2
лист. 21
4108