All files / web/bundles/pimui/js/controller/channel edit.js

100% Statements 17/17
100% Branches 2/2
100% Functions 6/6
100% Lines 17/17

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    29x                         29x         32x 32x 6x   6x                               26x     26x               26x         32x   32x   31x 7x   31x 31x 31x   31x              
'use strict';
 
define(
    [
        'underscore',
        'oro/translator',
        'pim/controller/front',
        'pim/form-builder',
        'pim/fetcher-registry',
        'pim/user-context',
        'pim/dialog',
        'pim/page-title',
        'pim/i18n'
    ],
    function (_, __, BaseController, FormBuilder, FetcherRegistry, UserContext, Dialog, PageTitle, i18n) {
        return BaseController.extend({
            /**
             * {@inheritdoc}
             */
            renderForm: function (route) {
                FetcherRegistry.getFetcher('locale').clear();
                if (undefined === route.params.code) {
                    var label = 'pim_enrich.entity.channel.label.create';
 
                    return createForm.call(
                        this,
                        this.$el,
                        {
                            'code': '',
                            'currencies': [],
                            'locales': [],
                            'category_tree': '',
                            'conversion_units': [],
                            'labels': {},
                            'meta': {}
                        },
                        label,
                        'pim-channel-create-form'
                    );
                } else {
                    return FetcherRegistry.getFetcher('channel')
                        .fetch(route.params.code, {cached: false, 'filter_locales': 0})
                        .then((channel) => {
                            const label = _.escape(
                                i18n.getLabel(
                                    channel.labels,
                                    UserContext.get('catalogLocale'),
                                    channel.code
                                )
                            );
 
                            return createForm.call(this, this.$el, channel, label, channel.meta.form);
                        });
                }
 
                function createForm(domElement, channel, label, formExtension) {
                    PageTitle.set({'channel.label': _.escape(label)});
 
                    return FormBuilder.build(formExtension)
                        .then((form) => {
                            this.on('pim:controller:can-leave', function (event) {
                                form.trigger('pim_enrich:form:can-leave', event);
                            });
                            form.setData(channel);
                            form.trigger('pim_enrich:form:entity:post_fetch', channel);
                            form.setElement(domElement).render();
 
                            return form;
                        });
                }
            }
        });
    }
);