summaryrefslogtreecommitdiff
path: root/addons/web_tour/static/src/js/debug_manager.js
blob: f7bf46ba0ce33781d7a3710dbe9215dca698a39f (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
odoo.define('web_tour.DebugManager.Backend', function (require) {
"use strict";

var core = require("web.core");
var DebugManager = require('web.DebugManager.Backend');
var Dialog = require("web.Dialog");
var local_storage = require('web.local_storage');

var tour = require('web_tour.tour');
var utils = require('web_tour.utils');

var get_debugging_key = utils.get_debugging_key;

function get_active_tours () {
    return _.difference(_.keys(tour.tours), tour.consumed_tours);
}

DebugManager.include({
    start: function () {
        this.consume_tours_enabled = get_active_tours().length > 0;
        return this._super.apply(this, arguments);
    },
    consume_tours: function () {
        var active_tours = get_active_tours();
        if (active_tours.length > 0) { // tours might have been consumed meanwhile
            this._rpc({
                    model: 'web_tour.tour',
                    method: 'consume',
                    args: [active_tours],
                })
                .then(function () {
                    for (const tourName of active_tours) {
                        local_storage.removeItem(get_debugging_key(tourName));
                    }
                    window.location.reload();
                });
        }
    },
    start_tour: async function () {
        const tours = Object.values(tour.tours).sort((t1, t2) => {
            return (t1.sequence - t2.sequence) || (t1.name < t2.name ? -1 : 1);
        });
        const dialog = new Dialog(this, {
            title: 'Tours',
            $content: core.qweb.render('web_tour.ToursDialog', {
                onboardingTours: tours.filter(t => !t.test),
                testingTours: tours.filter(t => t.test),
            }),
        });
        await dialog.open().opened();
        dialog.$('.o_start_tour').on('click', this._onStartTour.bind(this));
        dialog.$('.o_test_tour').on('click', this._onTestTour.bind(this));
    },

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

    /**
     * Resets the given tour to its initial step, in onboarding mode.
     *
     * @private
     * @param {MouseEvent}
     */
    _onStartTour(ev) {
        ev.preventDefault();
        tour.reset($(ev.target).data('name'));
    },
    /**
     * Starts the given tour in test mode.
     *
     * @private
     * @param {MouseEvent}
     */
    _onTestTour(ev) {
        ev.preventDefault();
        tour.run($(ev.target).data('name'));
    },
});

});