All files / web/bundles/pimui/js/common form-modal-creator.js

100% Statements 12/12
100% Branches 0/0
100% Functions 5/5
100% Lines 12/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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69    61x                                         61x                   9x       9x   9x 9x 9x 4x     9x 9x                         9x   9x              
'use strict';
 
define(
    [
        'underscore',
        'oro/translator',
        'backbone',
        'pim/form-builder',
        'pim/fetcher-registry',
        'pim/user-context',
        'pim/i18n',
        'pim/template/common/modal-centered'
    ],
    function(
        _,
        __,
        Backbone,
        formBuilder,
        fetcherRegistry,
        UserContext,
        i18n,
        modalTemplate
    ) {
        return {
            /**
             * Create a modal from fetcher and entity identifier
             *
             * @param {String} entityCode
             * @param {String} fetcherCode
             *
             * @return {Promise}
             */
            createModal: function(entityCode, fetcherCode) {
                return fetcherRegistry.getFetcher(fetcherCode).fetch(
                    entityCode,
                    {cached: false}
                ).then((entity) => {
                    return formBuilder.build(entity.meta.form)
                        .then((form) => {
                            form.setData(entity);
                            form.trigger('pim_enrich:form:entity:post_fetch', entity);
                            form.on('pim_enrich:form:entity:post_save', () => {
                                modal.trigger('cancel');
                            });
 
                            const familyVariant = entity;
                            const modal = new Backbone.BootstrapModal({
                                content: form,
                                buttons: false,
                                title: i18n.getLabel(
                                    familyVariant.labels,
                                    UserContext.get('uiLocale'),
                                    familyVariant.code
                                ),
                                subtitle: __('Code')  + ': ' + familyVariant.code,
                                template: _.template(modalTemplate),
                                okText: '',
                                innerClassName: 'AknFullPage--full',
                            });
                            modal.open();
 
                            return modal;
                        });
                });
            }
        }
    }
);