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

97.56% Statements 80/82
85.94% Branches 55/64
100% Functions 17/17
97.47% Lines 77/79
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130          91× 91× 91× 91× 91×   76× 76× 76× 76× 76× 31× 31× 58×         76×                         76×         76× 76× 76× 76×         76× 76× 76× 76× 76× 76× 76× 76×   72×   71× 71× 71× 71×   76×                   48× 48×           48×            
/* 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-dropdowns", "@syncfusion/ej2-data", "../base/util", "../base/util", "./edit-cell-base", "../base/string-literals", "../base/constant"], function (require, exports, ej2_base_1, ej2_dropdowns_1, ej2_data_1, util_1, util_2, edit_cell_base_1, literals, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DropDownEditCell = (function (_super) {
        __extends(DropDownEditCell, _super);
        function DropDownEditCell(parent) {
            var _this = _super.call(this) || this;
            _this.parent = parent;
            _this.flag = false;
            _this.removeEventHandler = _this.removeEventListener;
            return _this;
        }
        DropDownEditCell.prototype.write = function (args) {
            var isInline = this.parent.editSettings.mode !== 'Dialog';
            this.column = args.column;
            var pred = new ej2_data_1.Predicate(args.column.field, 'notequal', null, true, false);
            var params = {};
            if (args.column.edit.params) {
                var keys = Object.keys(args.column.edit.params);
                for (var i = 0; i < keys.length; i++) {
                    params[keys[parseInt(i.toString(), 10)]] = keys[parseInt(i.toString(), 10)] === 'query' ?
                        args.column.edit.params[keys[parseInt(i.toString(), 10)]].clone() :
                        args.column.edit.params[keys[parseInt(i.toString(), 10)]];
                }
            }
            this.obj = new ej2_dropdowns_1.DropDownList(ej2_base_1.extend({
                dataSource: this.parent.dataSource instanceof ej2_data_1.DataManager ?
                    this.parent.dataSource : new ej2_data_1.DataManager(this.parent.dataSource),
                query: new ej2_data_1.Query().where(pred).select(args.column.field), enabled: util_1.isEditable(args.column, args.requestType, args.element),
                fields: { value: args.column.field },
                value: util_1.getObject(args.column.field, args.rowData),
                enableRtl: this.parent.enableRtl,
                placeholder: isInline ? '' : args.column.headerText, popupHeight: '200px',
                floatLabelType: isInline ? 'Never' : 'Always',
                sortOrder: 'Ascending',
                cssClass: this.parent.cssClass ? this.parent.cssClass : null,
                close: this.dropDownClose.bind(this)
            }, params));
            if (this.parent.enableVirtualization) {
                if (params.dataSource) {
                    this.obj.dataSource = params.dataSource;
                }
                else {
                    this.obj.dataSource = args.column.isForeignColumn() ? [args.foreignKeyData[0]] : [args.rowData];
                }
            }
            this.addEventListener();
            this.obj.query.params = this.parent.query.params;
            this.obj.appendTo(args.element);
            args.element.setAttribute('name', util_1.getComplexFieldID(args.column.field));
        };
        DropDownEditCell.prototype.dropDownClose = function (args) {
            Iif (args.event && args.event.action === 'escape') {
                this.parent.editModule.editCellDialogClose = true;
            }
        };
        DropDownEditCell.prototype.addEventListener = function () {
            this.ddCreated = this.dropdownCreated.bind(this);
            this.ddOpen = this.dropDownOpen.bind(this);
            this.ddBeforeOpen = this.dropdownBeforeOpen.bind(this);
            this.ddComplete = this.ddActionComplete.bind(this);
            this.obj.addEventListener(literals.create, this.ddCreated);
            this.obj.addEventListener(literals['open'], this.ddOpen);
            this.obj.addEventListener(literals.beforeOpen, this.ddBeforeOpen);
            this.obj.addEventListener(events.actionComplete, this.ddComplete);
        };
        DropDownEditCell.prototype.removeEventListener = function () {
            if (this.obj.isDestroyed) {
                return;
            }
            this.obj.removeEventListener(literals.create, this.ddCreated);
            this.obj.removeEventListener(literals['open'], this.ddOpen);
            this.obj.removeEventListener(literals.beforeOpen, this.ddBeforeOpen);
            this.obj.removeEventListener(events.actionComplete, this.ddComplete);
        };
        DropDownEditCell.prototype.dropdownCreated = function (e) {
            this.flag = true;
        };
        DropDownEditCell.prototype.dropdownBeforeOpen = function () {
            if (this.parent.enableVirtualization) {
                if (this.column.edit.params && this.column.edit.params.dataSource) {
                    this.obj.dataSource = this.column.edit.params.dataSource;
                }
                else {
                    this.obj.dataSource = !this.column.isForeignColumn() ? (this.parent.dataSource instanceof ej2_data_1.DataManager ?
                        this.parent.dataSource : new ej2_data_1.DataManager(this.parent.dataSource))
                        : this.column.dataSource instanceof ej2_data_1.DataManager ?
                            this.column.dataSource : new ej2_data_1.DataManager(this.column.dataSource);
                }
            }
        };
        DropDownEditCell.prototype.ddActionComplete = function (e) {
            e.result = ej2_data_1.DataUtil.distinct(e.result, this.obj.fields.value, true);
            if (this.flag && this.column.dataSource && !(this.column.edit.params &&
                this.column.edit.params.ddEditedData)) {
                Iif ('result' in this.column.dataSource) {
                    this.column.dataSource.result = e.result;
                }
                else Eif (this.column.dataSource instanceof ej2_data_1.DataManager) {
                    this.column.dataSource.dataSource.json = e.result;
                }
            }
            this.flag = false;
        };
        DropDownEditCell.prototype.dropDownOpen = function (args) {
            var dlgElement = util_2.parentsUntil(this.obj.element, 'e-dialog');
            if (this.parent.editSettings.mode === 'Dialog' && !ej2_base_1.isNullOrUndefined(dlgElement)) {
                var dlgObj = ej2_base_1.select('#' + dlgElement.id, document).ej2_instances[0];
                args.popup.element.style.zIndex = (dlgObj.zIndex + 1).toString();
            }
        };
        return DropDownEditCell;
    }(edit_cell_base_1.EditCellBase));
    exports.DropDownEditCell = DropDownEditCell;
});