all files / grid/renderer/ boolean-edit-cell.js

98.44% Statements 63/64
90% Branches 36/40
100% Functions 15/15
98.36% Lines 60/61
11 statements, 6 functions, 9 branches Ignored     
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 89 90 91          66× 66× 66×   55× 55× 55× 13×   55× 55×   28×   52× 52× 52× 50×   52× 17×   52× 11× 11× 11× 11× 11×   11×   52×           52× 52×   52× 52×   51×     51×                  
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-base", "../base/util", "../base/string-literals", "./edit-cell-base"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_base_2, util_1, literals, edit_cell_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BooleanEditCell = (function (_super) {
        __extends(BooleanEditCell, _super);
        function BooleanEditCell() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.activeClasses = ['e-selectionbackground', 'e-active'];
            return _this;
        }
        BooleanEditCell.prototype.create = function (args) {
            var col = args.column;
            var classNames = 'e-field e-boolcell';
            if (col.type === 'checkbox') {
                classNames = 'e-field e-boolcell e-edit-checkselect';
            }
            this.removeEventHandler = this.removeEventListener;
            return util_1.createEditElement(this.parent, args.column, classNames, { type: 'checkbox', value: args.value });
        };
        BooleanEditCell.prototype.read = function (element) {
            return element.checked;
        };
        BooleanEditCell.prototype.write = function (args) {
            var selectChkBox;
            var chkState;
            if (!ej2_base_1.isNullOrUndefined(args.row)) {
                selectChkBox = args.row.querySelector('.e-edit-checkselect');
            }
            if (util_1.getObject(args.column.field, args.rowData)) {
                chkState = JSON.parse(util_1.getObject(args.column.field, args.rowData).toString().toLowerCase());
            }
            if (!ej2_base_1.isNullOrUndefined(selectChkBox) && args.column.type === 'checkbox') {
                this.editType = this.parent.editSettings.mode;
                this.editRow = args.row;
                Eif (args.requestType !== 'add') {
                    var row = this.parent.getRowObjectFromUID(args.row.getAttribute('data-uid'));
                    chkState = row ? row.isSelected : false;
                }
                util_1.addRemoveActiveClasses.apply(void 0, [[].slice.call(args.row.getElementsByClassName(literals.rowCell)), chkState].concat(this.activeClasses));
            }
            this.obj = new ej2_buttons_1.CheckBox(ej2_base_2.extend({
                label: this.parent.editSettings.mode !== 'Dialog' ? ' ' : args.column.headerText,
                checked: chkState,
                disabled: !util_1.isEditable(args.column, args.requestType, args.element), enableRtl: this.parent.enableRtl,
                cssClass: this.parent.cssClass ? this.parent.cssClass : ''
            }, args.column.edit.params));
            this.addEventListener();
            this.obj.appendTo(args.element);
        };
        BooleanEditCell.prototype.addEventListener = function () {
            this.cbChange = this.checkBoxChange.bind(this);
            this.obj.addEventListener(literals.change, this.cbChange);
        };
        BooleanEditCell.prototype.removeEventListener = function () {
            Iif (this.obj.isDestroyed) {
                return;
            }
            this.obj.removeEventListener(literals.change, this.cbChange);
        };
        BooleanEditCell.prototype.checkBoxChange = function (args) {
            Eif (this.editRow && this.editType !== 'Dialog') {
                var add = false;
                if (!args.checked) {
                    this.editRow.removeAttribute('aria-selected');
                }
                else {
                    add = true;
                    this.editRow.setAttribute('aria-selected', add.toString());
                }
                util_1.addRemoveActiveClasses.apply(void 0, [[].slice.call(this.editRow.getElementsByClassName(literals.rowCell)), add].concat(this.activeClasses));
            }
        };
        return BooleanEditCell;
    }(edit_cell_base_1.EditCellBase));
    exports.BooleanEditCell = BooleanEditCell;
});