All files / web/bundles/pimui/js/menu column.js

92.31% Statements 12/13
100% Branches 2/2
85.71% Functions 6/7
92.31% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                    1183x                         1183x             3549x   3549x             15687x 2220x   13467x                     12201x   12201x                 34259x                                           22058x   22058x                  
'use strict';
 
/**
 * Extension for menu columns
 * This extends the default column and adds some behaviors only used in the menu context (visibility)
 *
 * @author    Pierre Allard <pierre.allard@akeneo.com>
 * @copyright 2017 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
define(
    [
        'underscore',
        'pim/form/common/column',
        'pim/router',
        'oro/mediator'
    ],
    function (
        _,
        Column,
        router,
        mediator
    ) {
        return Column.extend({
            active: false,
 
            /**
             * {@inheritdoc}
             */
            initialize: function () {
                mediator.on('pim_menu:highlight:tab', this.highlight, this);
 
                Column.prototype.initialize.apply(this, arguments);
            },
 
            /**
             * {@inheritdoc}
             */
            render: function () {
                if (this.active) {
                    return Column.prototype.render.apply(this, arguments);
                } else {
                    return this.$el.empty();
                }
            },
 
            /**
             * Highlight or un-highlight tab
             *
             * @param {Event} event
             * @param {string} event.extension The extension code to highlight
             */
            highlight: function (event) {
                this.active = (event.extension === this.getTab());
 
                this.render();
            },
 
            /**
             * Returns the code of the attached tab
             *
             * @returns {string}
             */
            getTab: function () {
                return this.config.tab;
            },
 
            /**
             * The DOM element contains a `data-tab` attribute for compatibility with tab Bootstram tabs.
             *
             * {@inheritdoc}
             */
            redirect: function (event) {
                router.redirectToRoute(event.currentTarget.dataset.tab);
            },
 
            /**
             * Registers a new item to display on navigation template
             *
             * @param {Event}    navigationItem
             * @param {string}   navigationItem.label
             * @param {function} navigationItem.isVisible
             * @param {string}   navigationItem.route
             * @param {number}   navigationItem.position
             */
            registerNavigationItem: function (navigationItem) {
                Column.prototype.registerNavigationItem.apply(this, arguments);
 
                this.getRoot().trigger('pim_menu:register_item', {
                    target: this.getTab(),
                    route: navigationItem.route,
                    position: navigationItem.position,
                    routeParams: navigationItem.routeParams
                });
            }
        });
    });