all files / pager/ pager-message.js

100% Statements 44/44
100% Branches 22/22
100% Functions 10/10
100% Lines 44/44
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   491×   479× 479× 479× 479× 479× 479×   1683× 1683×   1683×     1683×               3382× 3382× 3382× 10146× 10146× 10134×     12×     3382×   10146× 10146× 10134×     12×          
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PagerMessage = (function () {
        function PagerMessage(pagerModule) {
            this.pagerModule = pagerModule;
        }
        PagerMessage.prototype.render = function () {
            var div = ej2_base_1.createElement('div', { className: 'e-parentmsgbar' });
            this.pageNoMsgElem = ej2_base_1.createElement('span', { className: 'e-pagenomsg', styles: 'textalign:right' });
            this.pageCountMsgElem = ej2_base_1.createElement('span', { className: 'e-pagecountmsg', styles: 'textalign:right' });
            ej2_base_1.append([this.pageNoMsgElem, this.pageCountMsgElem], div);
            this.pagerModule.element.appendChild(div);
            this.refresh();
        };
        PagerMessage.prototype.refresh = function () {
            var pagerObj = this.pagerModule;
            this.pageNoMsgElem.textContent = this.format(pagerObj.getLocalizedLabel('currentPageInfo'), [pagerObj.totalRecordsCount === 0 ? 0 :
                    pagerObj.currentPage, pagerObj.totalPages || 0, pagerObj.totalRecordsCount || 0]) + ' ';
            this.pageCountMsgElem.textContent = this.format(pagerObj.getLocalizedLabel(pagerObj.totalRecordsCount <= 1 ? 'totalItemInfo' : 'totalItemsInfo'), [pagerObj.totalRecordsCount || 0, pagerObj.totalRecordsCount ? (pagerObj.pageSize * (pagerObj.currentPage - 1)) + 1 : 0,
                pagerObj.pageSize * pagerObj.currentPage > pagerObj.totalRecordsCount ? pagerObj.totalRecordsCount :
                    pagerObj.pageSize * pagerObj.currentPage]);
            this.pageNoMsgElem.parentElement.classList.remove('e-hide');
        };
        PagerMessage.prototype.hideMessage = function () {
            if (this.pageNoMsgElem) {
                this.pageNoMsgElem.style.display = 'none';
            }
            if (this.pageCountMsgElem) {
                this.pageCountMsgElem.style.display = 'none';
            }
        };
        PagerMessage.prototype.showMessage = function () {
            if (!this.pageNoMsgElem) {
                this.render();
            }
            this.pageNoMsgElem.style.display = '';
            this.pageCountMsgElem.style.display = '';
        };
        PagerMessage.prototype.destroy = function () {
        };
        PagerMessage.prototype.format = function (str, args) {
            var regx;
            var regExp = RegExp;
            for (var i = 0; i < args.length; i++) {
                regx = new regExp('\\{' + (i) + '\\}', 'gm');
                if (this.isValidLocale(this.pagerModule.locale)) {
                    str = str.replace(regx, args[parseInt(i.toString(), 10)].toLocaleString(this.pagerModule.locale));
                }
                else {
                    str = str.replace(regx, args[parseInt(i.toString(), 10)].toString());
                }
            }
            return str;
        };
        PagerMessage.prototype.isValidLocale = function (locale) {
            try {
                new Intl.NumberFormat(locale);
                return true;
            }
            catch (e) {
                return false;
            }
        };
        return PagerMessage;
    }());
    exports.PagerMessage = PagerMessage;
});