All files / web/bundles/pimui/js/controller/product index.js

85.71% Statements 18/21
66.67% Branches 4/6
100% Functions 2/2
85.71% Lines 18/21

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 97301x                                                 301x                   498x   498x             498x   498x 498x 498x   498x 497x 497x 497x   497x                                     497x 497x 27x               497x             498x          
define(
    [
        'underscore',
        'jquery',
        'pim/controller/front',
        'pim/form-builder',
        'pim/user-context',
        'oro/mediator',
        'pim/page-title',
        'routing',
        'pim/fetcher-registry',
        'pim/provider/sequential-edit-provider'
    ],
    function (
        _,
        $,
        BaseController,
        FormBuilder,
        UserContext,
        mediator,
        PageTitle,
        Routing,
        fetcherRegistry,
        sequentialEditProvider
    ) {
        return BaseController.extend({
            config: {
                gridExtension: 'pim-product-index',
                gridName: 'product-grid'
            },
 
            /**
            * {@inheritdoc}
            */
            initialize(options) {
                this.config = Object.assign(this.config, options.config || {});
 
                return BaseController.prototype.initialize.apply(this, arguments);
            },
 
            /**
            * {@inheritdoc}
            */
            renderForm() {
                this.selectMenuTab();
 
                const { gridName, gridExtension } = this.config;
                fetcherRegistry.getFetcher('datagrid-view').clear();
                sequentialEditProvider.clear();
 
                return FormBuilder.build(gridExtension).then((form) => {
                    this.setupLocale();
                    this.setupMassEditAttributes();
                    form.setElement(this.$el).render({ gridName });
 
                    return form;
                });
            },
 
            /**
            * {@inheritdoc}
            */
            renderTemplate(content) {
                if (!this.active) {
                    return;
                }
 
                this.$el.html(content);
            },
 
            /**
             * Get the locale from url and set to UserContext
             */
            setupLocale() {
                const locale = window.location.hash.split('?dataLocale=')[1];
                if (locale) {
                    UserContext.set('catalogLocale', locale);
                }
            },
 
            /**
             * Clear mass edit selected attributes
             */
            setupMassEditAttributes() {
                sessionStorage.setItem('mass_edit_selected_attributes', JSON.stringify([]));
            },
 
            /**
             * Select products menu tab
             */
            selectMenuTab() {
                mediator.trigger('pim_menu:highlight:tab', { extension: 'pim-menu-products' });
            }
        });
    }
);