All files / web/bundles/pimui/js/family/form family-variant.js

100% Statements 15/15
75% Branches 3/4
100% Functions 5/5
100% Lines 15/15

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    61x                                         61x                 77x 77x   77x             77x         77x       1x   1x       77x             14x 13x                 14x   14x 14x          
'use strict';
 
define(
    [
        'underscore',
        'pim/form',
        'oro/mediator',
        'pim/common/grid',
        'oro/translator',
        'pim/user-context',
        'pim/common/form-modal-creator',
        'pim/template/family/tab/family-variant'
    ],
    function (
        _,
        BaseForm,
        mediator,
        Grid,
        __,
        UserContext,
        formModalCreator,
        template
    ) {
        return BaseForm.extend({
            template: _.template(template),
            className: 'tabbable variant',
            variantGrid: null,
 
            /**
             * @param {Object} meta
             */
            initialize: function (meta) {
                this.config = _.extend({}, meta.config);
                this.config.modelDependent = false;
 
                return BaseForm.prototype.initialize.apply(this, arguments);
            },
 
            /**
             * {@inheritdoc}
             */
            configure: function () {
                this.trigger('tab:register', {
                    code: this.config.tabCode ? this.config.tabCode : this.code,
                    label: __(this.config.title)
                });
 
                this.listenTo(
                    this.getRoot(),
                    'pim_enrich.entity.family.family_variant.post_create',
                    (familyVariant) => {
                        mediator.trigger(`datagrid:doRefresh:${this.config.gridName}`);
 
                        formModalCreator.createModal(familyVariant.code, 'family-variant');
                    }
                );
 
                return BaseForm.prototype.configure.apply(this, arguments);
            },
 
            /**
             * {@inheritdoc}
             */
            render: function () {
                if (!this.variantGrid) {
                    this.variantGrid = new Grid(
                        this.config.gridName,
                        {
                            family_id: this.getFormData().meta.id,
                            localeCode: UserContext.get('uiLocale')
                        }
                    );
                }
 
                this.$el.html(this.template());
 
                this.renderExtensions();
                this.getZone('grid').appendChild(this.variantGrid.render().el);
            }
        });
    }
);