Exemplo n.º 1
0
    on_message_received: function (ev) {
        // Check the origin of the received message.
        var message_origin = utils.build_origin(ev.originalEvent.source.location.protocol, ev.originalEvent.source.location.host);
        if (message_origin === this.trusted_origin) {

            // Check the syntax of the received message.
            var message = ev.originalEvent.data;
            if (_.isObject(message)) {
                message = message.message;
            }
            if (! _.isString(message) || (_.isString(message) && ! _.contains(AUTHORIZED_MESSAGES, message))) {
                return;
            }

            switch(message) {
                case 'report.editor:save_ok':
                    // Reload the iframe in order to disable the editor.
                    this.iframe.src = this.report_url;
                    this.in_edit_mode = false;
                    this._update_control_panel_buttons();
                    break;
                case 'report.editor:discard_ok':
                    // Reload the iframe in order to disable the editor.
                    this.iframe.src = this.report_url;
                    this.in_edit_mode = false;
                    this._update_control_panel_buttons();
                    break;
                case 'report:do_action':
                    return this.do_action(ev.originalEvent.data.action);
                default:
            }
        }
    },
Exemplo n.º 2
0
        return $.when(this._super.apply(this, arguments), session.is_bound).then(function () {
            var web_base_url = session['web.base.url'];
            var trusted_host = utils.get_host_from_url(web_base_url);
            var trusted_protocol = utils.get_protocol_from_url(web_base_url);
            self.trusted_origin = utils.build_origin(trusted_protocol, trusted_host);

            self.$buttons = $(QWeb.render('report.client_action.ControlButtons', {}));
            self.$buttons.on('click', '.o_report_edit', self.on_click_edit);
            self.$buttons.on('click', '.o_report_print', self.on_click_print);
            self.$buttons.on('click', '.o_report_save', self.on_click_save);
            self.$buttons.on('click', '.o_report_discard', self.on_click_discard);

            self._update_control_panel();

            // Load the report in the iframe. Note that we use a relative URL.
            self.iframe.src = self.report_url;

            // Once the iframe is loaded, check if we can edit the report.
            self.iframe.onload = function () {
                self._on_iframe_loaded();
            };
        });
Exemplo n.º 3
0
    window.addEventListener('message', function (ev) {
        // Check the origin of the received message.
        var message_origin = utils.build_origin(ev.source.location.protocol, ev.source.location.host);
        if (message_origin === trusted_origin) {
            // Check the syntax of the received message.
            var message = ev.data;
            if (! _.isString(message) || (_.isString(message) && ! _.contains(AUTHORIZED_MESSAGES, message))) {
                return;
            }

            switch(message) {
                case 'report.editor:ask_save':
                    editor.editor_bar.save();
                    break;
                case 'report.editor:ask_discard':
                    editor.editor_bar.cancel();
                    break;
                default:
            }
        }
    }, false);
Exemplo n.º 4
0
odoo.define('report.editor', function (require) {
'use strict';

var ajax = require('web.ajax');
var core = require('web.core');
var utils = require('report.utils');
var editor = require('web_editor.editor');
var options = require('web_editor.snippets.options');

var web_base_url = $('html').attr('web-base-url');
var trusted_host = utils.get_host_from_url(web_base_url);
var trusted_protocol = utils.get_protocol_from_url(web_base_url);
var trusted_origin = utils.build_origin(trusted_protocol, trusted_host);

// Patch the editor's behavior when it is launched inside an iframe.
if (window.self !== window.top) {
    $(document.body).addClass('o_in_iframe'); //  in order to apply css rules

    // As `reload` is called after `save` and `cancel`, we nullify this function
    // if the editor in order to be able to chain some deferred to `save` and
    // `cancel`.
    editor.reload = function () {
        return $.when();
    };

    // And now we chain some deferred to `save` and `cancel` in order to inform
    // the report's client action that the actions are done.
    editor.Class.include({
        save: function () {
            return this._super.apply(this, arguments).then(function () {
                window.parent.postMessage('report.editor:save_ok', trusted_origin);
            });
        },
        cancel: function () {
            return this._super.apply(this, arguments).then(function () {
                window.parent.postMessage('report.editor:discard_ok', trusted_origin);
            });
        },
    });

    // postMessage logic.
    var AUTHORIZED_MESSAGES = [
        'report.editor:ask_discard',
        'report.editor:ask_save',
    ];

    window.addEventListener('message', function (ev) {
        // Check the origin of the received message.
        var message_origin = utils.build_origin(ev.source.location.protocol, ev.source.location.host);
        if (message_origin === trusted_origin) {
            // Check the syntax of the received message.
            var message = ev.data;
            if (! _.isString(message) || (_.isString(message) && ! _.contains(AUTHORIZED_MESSAGES, message))) {
                return;
            }

            switch(message) {
                case 'report.editor:ask_save':
                    editor.editor_bar.save();
                    break;
                case 'report.editor:ask_discard':
                    editor.editor_bar.cancel();
                    break;
                default:
            }
        }
    }, false);

    // Allow to send commands to the webclient when the editor is disabled.
    if (window.location.search.indexOf('enable_editor') === -1) {
        // `do_action` command
        $('[res-id][res-model][view-type]')
            .wrap('<a/>')
                .attr('href', '#')
            .on('click', function (ev) {
                ev.preventDefault();
                var action = {
                    'type': 'ir.actions.act_window',
                    'view_type': $(this).attr('view-type'),
                    'view_mode': $(this).attr('view-mode') || $(this).attr('view-type'),
                    'res_id': Number($(this).attr('res-id')),
                    'res_model': $(this).attr('res-model'),
                    'views': [[$(this).attr('view-id') || false, $(this).attr('view-type')]],
                };
                window.parent.postMessage({
                    'message': 'report:do_action',
                    'action': action,
                }, trusted_origin);
            });
    }
}

options.registry.many2one.include({
    select_record: function (li) {
        var self = this;
        this._super(li);
        if (this.$target.data('oe-field') === "partner_id") {
            var $img = $('.header .row img:first');
            var css = window.getComputedStyle($img[0]);
            $img.css("max-height", css.height+'px');
            $img.attr("src", "/web/image/res.partner/"+self.ID+"/image");
            setTimeout(function () { $img.removeClass('o_dirty'); },0);
        }
    }
});

});
Exemplo n.º 5
0
odoo.define('report.editor', function (require) {
'use strict';

require('web.dom_ready')
var core = require('web.core');
var utils = require('report.utils');
var editor = require('web_editor.editor');
var options = require('web_editor.snippets.options');

var web_base_url = $('html').attr('web-base-url');
var trusted_host = utils.get_host_from_url(web_base_url);
var trusted_protocol = utils.get_protocol_from_url(web_base_url);
var trusted_origin = utils.build_origin(trusted_protocol, trusted_host);

// Patch the editor's behavior when it is launched inside an iframe.
if (window.self !== window.top) {

    // And now we chain some deferred to `save` and `cancel` in order to inform
    // the report's client action that the actions are done.
    editor.Class.include({
        save: function () {
            // Force to not reload
            return this._super(false).then(function () {
                window.parent.postMessage('report.editor:save_ok', trusted_origin);
            });
        },
        cancel: function () {
            // Force to not reload
            return this._super(false).then(function () {
                window.parent.postMessage('report.editor:discard_ok', trusted_origin);
            });
        },
    });

    // postMessage logic.
    var AUTHORIZED_MESSAGES = [
        'report.editor:ask_discard',
        'report.editor:ask_save',
    ];

    window.addEventListener('message', function (ev) {
        // Check the origin of the received message.
        var message_origin = utils.build_origin(ev.source.location.protocol, ev.source.location.host);
        if (message_origin === trusted_origin) {
            // Check the syntax of the received message.
            var message = ev.data;
            if (! _.isString(message) || (_.isString(message) && ! _.contains(AUTHORIZED_MESSAGES, message))) {
                return;
            }

            switch (message) {
                case 'report.editor:ask_save':
                    core.bus.trigger('editor_save_request');
                    break;
                case 'report.editor:ask_discard':
                    core.bus.trigger('editor_discard_request');
                    break;
                default:
            }
        }
    }, false);
}

options.registry.many2one.include({
    _selectRecord: function ($li) {
        this._super.apply(this, arguments);
        if (this.$target.data('oe-field') !== 'partner_id') {
            return;
        }

        var $img = $('.header .row img:first');
        var css = window.getComputedStyle($img[0]);
        $img.css('max-height', css.height+'px');
        $img.attr('src', '/web/image/res.partner/' + this.ID + '/image');
        _.defer(function () {
            $img.removeClass('o_dirty');
        });
    }
});

});