All files / web/bundles/pimui/js/attribute-option form.js

91.67% Statements 11/12
50% Branches 1/2
100% Functions 4/4
91.67% Lines 11/12

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    2x                     2x           4x   4x 4x 4x           4x 4x     2x       2x                 2x          
'use strict';
 
define(
    [
        'underscore',
        'oro/translator',
        'backbone',
        'pim/form',
        'pim/template/attribute-option/form',
        'pim/user-context',
        'pim/i18n'
    ],
    function (_, __, Backbone, BaseForm, template, UserContext, i18n) {
        return BaseForm.extend({
            template: _.template(template),
            events: {
                'change input': 'updateModel'
            },
            updateModel: function () {
                var optionValues = {};
 
                _.each(this.$('input[name^="label-"]'), function (labelInput) {
                    var locale = labelInput.dataset.locale;
                    optionValues[locale] = {
                        locale: locale,
                        value: labelInput.value
                    };
                });
 
                this.getFormModel().set('code', this.$('input[name="code"]').val());
                this.getFormModel().set('optionValues', optionValues);
            },
            render: function () {
                Iif (!this.configured) {
                    return this;
                }
 
                this.$el.html(
                    this.template({
                        locale: UserContext.get('catalogLocale'),
                        i18n: i18n,
                        option: this.getFormData(),
                        __
                    })
                );
 
                return this.renderExtensions();
            }
        });
    }
);