All files / web/bundles/pimui/js/form/common simple-view.js

95.24% Statements 20/21
80% Branches 8/10
100% Functions 4/4
95.24% Lines 20/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                  609x                             609x               2716x   2716x 534x     2716x                 2698x       2698x   2698x   2698x             3424x 3424x   3424x       3424x             39x 39x 39x   39x 39x 39x          
/**
 * Basic view that simply renders a template.
 *
 * @author    Yohan Blain <yohan.blain@akeneo.com>
 * @copyright 2017 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
'use strict';
 
define([
    'jquery',
    'underscore',
    'backbone',
    'oro/translator',
    'pim/form',
    'require-context'
], function (
    $,
    _,
    Backbone,
    __,
    BaseForm,
    requireContext
) {
    return BaseForm.extend({
        config: {},
        template: null,
 
        /**
         * {@inheritdoc}
         */
        initialize: function (meta) {
            this.config = meta.config;
 
            if (_.has(meta, 'forwarded-events')) {
                this.forwardMediatorEvents(meta['forwarded-events']);
            }
 
            BaseForm.prototype.initialize.apply(this, arguments);
        },
 
        /**
         * {@inheritdoc}
         *
         * Waiting for the template to be required.
         */
        configure: function () {
            Iif (undefined === this.config.template) {
                throw new Error('The view "' + this.code + '" must be configured with a template.');
            }
 
            this.template = requireContext(this.config.template);
 
            this.listenTo(this.getRoot(), 'grid:third_column:toggle', this.toggleThirdColumn.bind(this));
 
            return BaseForm.prototype.configure.apply(this, arguments);
        },
 
        /**
         * {@inheritdoc}
         */
        render: function () {
            let templateParams = this.config.templateParams || {};
            templateParams = _.extend({}, {__: __}, templateParams);
 
            this.$el.html(
                _.template(this.template)(templateParams)
            );
 
            this.renderExtensions();
        },
 
        /**
         * Toggle the third column
         */
        toggleThirdColumn() {
            const thirdColumn = this.$el.find('.AknDefault-thirdColumnContainer');
            const thirdColumnContent = this.$el.find('.AknDefault-thirdColumn');
            const width = thirdColumnContent.outerWidth() || 300;
 
            Eif (null !== thirdColumn) {
                thirdColumn.css({marginLeft: -width});
                thirdColumn.toggleClass('AknDefault-thirdColumnContainer--open');
            }
        }
    });
});