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

68.89% Statements 31/45
45.83% Branches 11/24
87.5% Functions 7/8
68.89% Lines 31/45
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   38× 38×   39× 39× 39×     39× 39×               28×   39× 39× 39× 39× 37×   39× 18×   39×                 39×           39×                           34× 34×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-base", "../base/util"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_base_2, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BooleanEditCell = (function () {
        function BooleanEditCell(parent) {
            this.activeClasses = ['e-selectionbackground', 'e-active'];
            this.parent = parent;
        }
        BooleanEditCell.prototype.create = function (args) {
            var col = args.column;
            var classNames = 'e-field e-boolcell';
            Iif (col.type === 'checkbox') {
                classNames = 'e-field e-boolcell e-edit-checkselect';
            }
            var complexFieldName = util_1.getComplexFieldID(args.column.field);
            return ej2_base_1.createElement('input', {
                className: classNames, attrs: {
                    type: 'checkbox', value: args.value, 'e-mappinguid': col.uid,
                    id: this.parent.element.id + complexFieldName,
                    name: complexFieldName
                }
            });
        };
        BooleanEditCell.prototype.read = function (element) {
            return element.checked;
        };
        BooleanEditCell.prototype.write = function (args) {
            var selectChkBox;
            var chkState;
            var isAddRow = args.requestType === 'add' || args.row.classList.contains('e-addedrow');
            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(args.rowData[args.column.field].toString().toLowerCase());
            }
            Iif (!ej2_base_1.isNullOrUndefined(selectChkBox)) {
                this.editType = this.parent.editSettings.mode;
                this.editRow = args.row;
                if (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.querySelectorAll('.e-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,
                change: this.checkBoxChange.bind(this)
            }, args.column.edit.params));
            this.obj.appendTo(args.element);
        };
        BooleanEditCell.prototype.checkBoxChange = function (args) {
            if (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.querySelectorAll('.e-rowcell')), add].concat(this.activeClasses));
            }
        };
        BooleanEditCell.prototype.destroy = function () {
            Eif (this.obj) {
                this.obj.destroy();
            }
        };
        return BooleanEditCell;
    }());
    exports.BooleanEditCell = BooleanEditCell;
});