summaryrefslogtreecommitdiff
path: root/addons/base_automation/static/src/js/base_automation_error_dialog.js
blob: 3fa4cf0cc06da52f09f73a17587c1d1f76ebd022 (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
odoo.define('base_automation.BaseAutomatioErrorDialog', function (require) {
    "use strict";

    const CrashManager = require('web.CrashManager');
    const ErrorDialog = CrashManager.ErrorDialog;
    const ErrorDialogRegistry = require('web.ErrorDialogRegistry');
    const session = require('web.session');

    const BaseAutomationErrorDialog = ErrorDialog.extend({
        xmlDependencies: (ErrorDialog.prototype.xmlDependencies || []).concat(
            ['/base_automation/static/src/xml/base_automation_error_dialog.xml']
        ),
        template: 'CrashManager.BaseAutomationError',
        events: {
            'click .o_disable_action_button': '_onDisableAction',
            'click .o_edit_action_button': '_onEditAction',
        },
        /**
        * Assign the `base_automation` object based on the error data,
        * which is then used by the `CrashManager.BaseAutomationError` template
        * and the events defined above.
        * @override
        * @param {Object} error
        * @param {string} error.data.context.base_automation.id  the ID of the failing automated action
        * @param {string} error.data.context.base_automation.name  the name of the failing automated action
        */
        init: function (parent, options, error) {
            this._super.apply(this, arguments);
            this.base_automation = error.data.context.base_automation;
            this.is_admin = session.is_admin;
        },

        //--------------------------------------------------------------------------
        // Handlers
        //--------------------------------------------------------------------------

        /**
        * This method is called when the user clicks on the 'Disable action' button
        * displayed when a crash occurs in the evaluation of an automated action.
        * Then, we write `active` to `False` on the automated action to disable it.
        *
        * @private
        * @param {MouseEvent} ev
        */
        _onDisableAction: function (ev) {
            ev.preventDefault();
            this._rpc({
                model: 'base.automation',
                method: 'write',
                args: [[this.base_automation.id], {
                    active: false,
                }],
            }).then(this.destroy.bind(this));
        },
        /**
        * This method is called when the user clicks on the 'Edit action' button
        * displayed when a crash occurs in the evaluation of an automated action.
        * Then, we redirect the user to the automated action form.
        *
        * @private
        * @param {MouseEvent} ev
        */
        _onEditAction: function (ev) {
            ev.preventDefault();
            this.do_action({
                name: 'Automated Actions',
                res_model: 'base.automation',
                res_id: this.base_automation.id,
                views: [[false, 'form']],
                type: 'ir.actions.act_window',
                view_mode: 'form',
            });
        },
    });

    ErrorDialogRegistry.add('base_automation', BaseAutomationErrorDialog);

});