All files / web/bundles/pimdatagrid/js/datagrid history-row.js

100% Statements 20/20
100% Branches 6/6
100% Functions 3/3
100% Lines 19/19

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  32x                                                         32x                 76x   76x       76x         76x 28x 28x 28x     76x 456x 456x 456x 456x     76x 76x 76x   76x   76x        
/* global define */
define(
    [
        'jquery',
        'underscore',
        'backgrid',
        'oro/datagrid/row',
        'pim/template/datagrid/row/version',
        'pim/template/datagrid/row/changes'
    ],
    function(
        $,
        _,
        Backgrid,
        BaseRow,
        versionTemplate,
        changesTemplate
    ) {
    'use strict';
 
    /**
     * Grid row.
     *
     * Triggers events:
     *  - "clicked" when row is clicked
     *
     * @export  oro/datagrid/row
     * @class   oro.datagrid.Row
     * @extends Backgrid.Row
     */
    return BaseRow.extend({
        tagName: 'div',
        versionTemplate: _.template(versionTemplate),
        changesTemplate: _.template(changesTemplate),
 
        /**
         Renders a row of cells for this row's model.
        */
        render: function () {
            this.$el.empty();
 
            const mainLine = $(this.versionTemplate({
                version: this.model.get('version'),
                id: this.model.get('id')
            }));
            const changesLine = $(this.changesTemplate({
                version: this.model.get('version'),
                id: this.model.get('id')
            }));
 
            mainLine.on('click', function () {
                changesLine.toggle();
                mainLine.toggleClass('AknGrid-bodyRow--expanded')
                mainLine.find('.AknGrid-expand').toggleClass('AknGrid-expand--expanded')
            });
 
            for (let i = 0; i < this.cells.length; i++) {
                const cell = this.cells[i];
                const line = 'changes' === cell.column.get('name') ? changesLine : mainLine;
                line.append(cell.render().el);
                if (!cell.column.get('renderable') && 'changes' !== cell.column.get('name')) cell.$el.hide();
            }
 
            this.$el.append(mainLine);
            this.$el.append(changesLine);
            changesLine.hide();
 
            this.delegateEvents();
 
            return this;
        }
    });
});