All files / web/bundles/pimui/js/form/common grid-title.js

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 11/11

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                485x                   485x             737x   737x 737x             2460x 1730x     730x 8x                       1730x   1730x          
'use strict';
/**
 * Grid title extension
 *
 * @author    Pierre Allard <pierre.allard@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)
 */
define(
    [
        'pim/form',
        'oro/translator',
        'oro/mediator'
    ], function (
        BaseForm,
        __,
        mediator
    ) {
        return BaseForm.extend({
            count: null,
 
            /**
             * {@inheritdoc}
             */
            initialize(config) {
                this.config = config.config;
 
                mediator.once('grid_load:start', this.setupCount.bind(this));
                mediator.on('grid_load:complete', this.setupCount.bind(this));
            },
 
            /**
             * {@inheritdoc}
             */
            render() {
                if (null !== this.count) {
                    this.$el.text(
                        __(this.config.title, {count: this.count}, this.count)
                    );
                } else if (false === this.config.countable) {
                    this.$el.text(
                        __(this.config.title)
                    );
                }
            },
 
            /**
             * Setup the count from the collection
             *
             * @param {Object} collection
             */
            setupCount(collection) {
                this.count = collection.state.totalRecords;
 
                this.render();
            }
        });
    }
);