summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/tools/debug_manager.js
blob: b0560805594e74d2d53dd031b4857d2c73591a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
odoo.define('web.DebugManager', function (require) {
"use strict";

var core = require('web.core');
var session = require('web.session');
var utils = require('web.utils');
var Widget = require('web.Widget');

var QWeb = core.qweb;

/**
 * DebugManager base + general features (applicable to any context)
 */
var DebugManager = Widget.extend({
    template: "WebClient.DebugManager",
    xmlDependencies: ['/web/static/src/xml/debug.xml'],
    events: {
        "click a[data-action]": "perform_callback",
    },
    init: function () {
        this._super.apply(this, arguments);
        this._events = null;
        var debug = odoo.debug;
        this.debug_mode = debug;
        this.debug_mode_help = debug && debug !== '1' ? ' (' + debug + ')' : '';
    },
    start: function () {
        core.bus.on('rpc:result', this, function (req, resp) {
            this._debug_events(resp.debug);
        });

        this.$dropdown = this.$(".o_debug_dropdown");
        // whether the current user is an administrator
        this._is_admin = session.is_system;
        return Promise.resolve(
            this._super()
        ).then(function () {
            return this.update();
        }.bind(this));
    },
    /**
     * Calls the appropriate callback when clicking on a Debug option
     */
    perform_callback: function (evt) {
        evt.preventDefault();
        var params = $(evt.target).data();
        var callback = params.action;

        if (callback && this[callback]) {
            // Perform the callback corresponding to the option
            this[callback](params, evt);
        } else {
            console.warn("No handler for ", callback);
        }
    },

    _debug_events: function (events) {
        if (!this._events) {
            return;
        }
        if (events && events.length) {
            this._events.push(events);
        }
        this.trigger('update-stats', this._events);
    },

    /**
     * Update the debug manager: reinserts all "universal" controls
     */
    update: function () {
        this.$dropdown
            .empty()
            .append(QWeb.render('WebClient.DebugManager.Global', {
                manager: this,
            }));
        return Promise.resolve();
    },
    split_assets: function () {
        window.location = $.param.querystring(window.location.href, 'debug=assets');
    },
    tests_assets: function () {
        // Enable also 'assets' to see non minimized assets
        window.location = $.param.querystring(window.location.href, 'debug=assets,tests');
    },
    /**
     * Delete assets bundles to force their regeneration
     *
     * @returns {void}
     */
    regenerateAssets: function () {
        var self = this;
        var domain = utils.assetsDomain();
        this._rpc({
            model: 'ir.attachment',
            method: 'search',
            args: [domain],
        }).then(function (ids) {
            self._rpc({
                model: 'ir.attachment',
                method: 'unlink',
                args: [ids],
            }).then(window.location.reload());
        });
    },
    leave_debug_mode: function () {
        var qs = $.deparam.querystring();
        qs.debug = '';
        window.location.search = '?' + $.param(qs);
    },
    /**
     * @private
     * @param {string} model
     * @param {string} operation
     * @returns {Promise<boolean>}
     */
    _checkAccessRight(model, operation) {
        return this._rpc({
            model: model,
            method: 'check_access_rights',
            kwargs: {operation, raise_exception: false},
        })
    },
});

return DebugManager;

});