All files / web/bundles/pimdatagrid/js/datagrid/cell boolean-cell.js

94.44% Statements 17/18
81.82% Branches 9/11
100% Functions 4/4
94.44% Lines 17/18

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  54x                     54x               1316x 1316x 1316x     1316x   1316x             43x 43x 43x 43x                 42x 1x   42x             1358x 686x   672x          
/* global define */
define(['jquery', 'underscore', 'backgrid'],
function($, _, Backgrid) {
    'use strict';
 
    /**
     * Boolean column cell. Added missing behaviour.
     *
     * @export  oro/datagrid/boolean-cell
     * @class   oro.datagrid.BooleanCell
     * @extends Backgrid.BooleanCell
     */
    return Backgrid.BooleanCell.extend({
        /** @property {Boolean} */
        listenRowClick: true,
 
        /**
         * @inheritDoc
         */
        render: function() {
            Backgrid.BooleanCell.prototype.render.apply(this, arguments);
            this.$input = this.$el.find('input');
            Iif (!this.column.get('editable')) {
                this.$input.prop('disabled', true);
            }
            this.updateStyle(this.$el.find('input[type=checkbox]').prop('checked'));
 
            return this;
        },
 
        /**
         * @inheritDoc
         */
        enterEditMode: function(e) {
            Backgrid.BooleanCell.prototype.enterEditMode.apply(this, arguments);
            Eif (this.column.get('editable')) {
                var $editor = this.currentEditor.$el;
                $editor.prop('checked', !$editor.prop('checked')).change();
            }
        },
 
        /**
         * @param {Backgrid.Row} row
         * @param {Event} e
         */
        onRowClicked: function(row, e) {
            if (!this.$input.is(e.target) && !this.$el.is(e.target) && !this.$el.has(e.target).length){
                this.enterEditMode(e);
            }
            this.updateStyle($(e.target).prop('checked'));
        },
 
        /**
         * Updates the current element to highlight it
         */
        updateStyle(checked) {
            if (checked) {
                this.$el.addClass('AknGrid-bodyCell--checked');
            } else {
                this.$el.removeClass('AknGrid-bodyCell--checked');
            }
        }
    });
});