all files / pager/ pager-dropdown.js

96.92% Statements 63/65
90% Branches 18/20
100% Functions 12/12
96.92% Lines 63/65
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     155×                                   12× 11× 11×     13×     14× 13×                  
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-dropdowns"], function (require, exports, ej2_base_1, ej2_dropdowns_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PagerDropDown = (function () {
        function PagerDropDown(pagerModule) {
            this.pagerModule = pagerModule;
        }
        PagerDropDown.prototype.getModuleName = function () {
            return 'pagerdropdown';
        };
        PagerDropDown.prototype.render = function () {
            var pagerObj = this.pagerModule;
            this.pagerDropDownDiv = ej2_base_1.createElement('div', { className: 'e-pagesizes' });
            var dropDownDiv = ej2_base_1.createElement('div', { className: 'e-pagerdropdown' });
            var defaultTextDiv = ej2_base_1.createElement('div', { className: 'e-pagerconstant' });
            var input = ej2_base_1.createElement('input', { attrs: { type: 'text', tabindex: '1' } });
            this.pagerCons = ej2_base_1.createElement('span', { className: 'e-constant', innerHTML: this.pagerModule.getLocalizedLabel('pagerDropDown') });
            dropDownDiv.appendChild(input);
            defaultTextDiv.appendChild(this.pagerCons);
            this.pagerDropDownDiv.appendChild(dropDownDiv);
            this.pagerDropDownDiv.appendChild(defaultTextDiv);
            this.pagerModule.element.appendChild(this.pagerDropDownDiv);
            var pageSizesModule = this.pagerModule.pageSizes;
            var pageSizesArray = (pageSizesModule.length ? this.convertValue(pageSizesModule) :
                ['All', '5', '10', '12', '20']);
            var defaultValue = this.pagerModule.pageSize;
            this.dropDownListObject = new ej2_dropdowns_1.DropDownList({
                dataSource: pageSizesArray,
                value: defaultValue.toString(),
                change: this.onChange.bind(this),
                cssClass: 'e-alldrop'
            });
            this.dropDownListObject.appendTo(input);
            if (pageSizesModule.length) {
                this.dropDownListObject.element.value = this.pagerModule.pageSize.toString();
            }
            pagerObj.pageSize = defaultValue;
            pagerObj.dataBind();
            pagerObj.trigger('dropDownChanged', { pageSize: defaultValue });
            this.addEventListener();
        };
        PagerDropDown.prototype.onChange = function (e) {
            if (this.dropDownListObject.value === 'All') {
                this.pagerModule.pageSize = this.pagerModule.totalRecordsCount;
                this.pagerCons.innerHTML = this.pagerModule.getLocalizedLabel('pagerAllDropDown');
                e.value = this.pagerModule.pageSize;
                Iif (document.getElementsByClassName('e-popup-open e-alldrop').length) {
                    document.getElementsByClassName('e-alldrop')[1].style.display = 'none';
                }
            }
            else {
                this.pagerModule.pageSize = parseInt(this.dropDownListObject.value, 10);
                Iif (this.pagerCons.innerHTML !== this.pagerModule.getLocalizedLabel('pagerDropDown')) {
                    this.pagerCons.innerHTML = this.pagerModule.getLocalizedLabel('pagerDropDown');
                }
            }
            this.pagerModule.dataBind();
            this.pagerModule.trigger('dropDownChanged', { pageSize: this.dropDownListObject.value });
        };
        PagerDropDown.prototype.beforeValueChange = function (prop) {
            if (typeof prop.newProp.value === 'number') {
                var val = prop.newProp.value.toString();
                prop.newProp.value = val;
            }
        };
        PagerDropDown.prototype.convertValue = function (pageSizeValue) {
            var item = pageSizeValue;
            for (var i = 0; i < item.length; i++) {
                item[i] = typeof item[i] === 'number' ? item[i].toString() : item[i];
            }
            return item;
        };
        PagerDropDown.prototype.setDropDownValue = function (prop, value) {
            if (this.dropDownListObject) {
                this.dropDownListObject[prop] = value;
            }
        };
        PagerDropDown.prototype.addEventListener = function () {
            this.dropDownListObject.on('beforeValueChange', this.beforeValueChange, this);
        };
        PagerDropDown.prototype.removeEventListener = function () {
            this.dropDownListObject.off('beforeValueChange', this.beforeValueChange);
        };
        PagerDropDown.prototype.destroy = function (args) {
            if (this.dropDownListObject && !this.dropDownListObject.isDestroyed) {
                this.removeEventListener();
                this.dropDownListObject.destroy();
                ej2_base_1.remove(this.pagerDropDownDiv);
            }
        };
        return PagerDropDown;
    }());
    exports.PagerDropDown = PagerDropDown;
});