summaryrefslogtreecommitdiff
path: root/addons/survey/static/src/js/survey_breadcrumb.js
blob: 4cc3796f9cb79456aa33b26a1702121c43cac309 (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
odoo.define('survey.breadcrumb', function (require) {
'use strict';

var publicWidget = require('web.public.widget');

publicWidget.registry.SurveyBreadcrumbWidget = publicWidget.Widget.extend({
    xmlDependencies: ['/survey/static/src/xml/survey_breadcrumb_templates.xml'],
    template: "survey.survey_breadcrumb_template",
    events: {
        'click .breadcrumb-item a': '_onBreadcrumbClick',
    },

    /**
     * @override
     */
    init: function (parent, options) {
        this._super.apply(this, arguments);
        this.canGoBack = options.canGoBack;
        this.currentPageId = options.currentPageId;
        this.pages = options.pages;
    },

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

    _onBreadcrumbClick: function (event) {
        event.preventDefault();
        this.trigger_up('breadcrumb_click', {
            'previousPageId': this.$(event.currentTarget)
                .closest('.breadcrumb-item')
                .data('pageId')
        });
    },

    // PUBLIC METHODS
    // -------------------------------------------------------------------

    updateBreadcrumb: function (pageId) {
        if (pageId) {
            this.currentPageId = pageId;
            this.renderElement();
        } else {
            this.$('.breadcrumb').addClass('d-none');
        }
    },
});

return publicWidget.registry.SurveyBreadcrumbWidget;

});