all files / schedule/renderer/ month.js

99.03% Statements 513/518
92.67% Branches 278/300
98.41% Functions 62/63
99.02% Lines 505/510
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720          931× 931× 931× 931× 931× 931× 931×   469× 469× 469×   469× 469× 469× 469×     216× 216× 216×   95× 95× 95× 95× 95× 95× 95×   95× 95× 51×     354×   596× 596× 596× 596× 596× 596× 566×   596× 596× 596× 596× 129× 129×     467× 467×   596× 596× 265× 265× 99×   265× 265× 167× 167×     98×         331×   596×   498×   498× 498× 153×       345×   498× 331×     320× 320× 257×   320× 15×       15× 15×     291× 291× 291× 34× 34×   34×                 257×   291× 291×   295× 295× 295× 295× 2027× 14031× 2027× 13×   2027×   295×   415× 99×   316×   478× 478× 478× 478× 478× 13× 13×     478× 12×   478×   478× 478× 478× 478× 478× 478× 478× 478× 478×   478× 478× 270×           6470× 6470× 6470× 6073×     481× 481× 481× 481× 481× 481×   294× 15×     291× 34×   291× 291× 15×   291× 291× 291×   291× 291× 291× 228×     63× 63× 63×   291× 291× 291× 291×   291× 291×   505× 15× 15× 15× 15× 15× 15×   15× 75× 75× 75×   15×     481× 481× 481× 481× 481× 230× 230× 230×   481× 481× 481× 589× 589× 589× 9175× 9175×   589×   481× 481×   9175× 9175× 9175× 2538× 2538×   9175× 458×   9175× 5992× 5992× 5992× 124× 124× 124× 124× 124× 124× 124×       5868× 5868× 5868× 5868× 5868×     5868× 5868×   5992×   9175× 9175× 9175×   295×     295× 295× 13138×       13138× 1561×   13138×   295×   295× 20× 71× 2485× 71× 71× 355× 355× 2485× 2485×           10033× 275×   275× 275× 275× 1461× 1461× 1461× 9968× 9968× 9968× 410× 410× 410× 410× 1115× 135× 10× 10×     400× 1095× 1095× 695×   1095×       9558×   9958×   1461× 1461× 9968× 9968×       295×   13138× 1700×   13138× 233×   13138×   10862×   12760×   478× 478× 478× 478× 187×   478× 478×       478× 478× 478× 478×   497× 497× 497× 497× 497× 497× 497× 2442×   121×   2321× 2321× 36599× 36599×   2321×   497×   36599× 36599× 23461×   36599× 36599× 36599× 5561× 5561×   36599× 26491×   36599× 32×   36599× 36599× 36599× 22888×   22888×   36599× 36599× 530× 530× 530× 530× 530× 530×   36599× 36599× 36599×   36599× 23461×   13138× 13138× 210× 210× 210× 210× 210× 210×     12928×     12928×   13138× 13138× 10862× 10862× 10862× 10862×     641× 641×   641× 641×   605× 36× 36×   36×     569× 569× 569×     314× 314× 187× 187× 187×     127×   486× 486× 486× 486× 486× 17212× 16304×     908× 618×     17212× 17212×       486× 478×   486× 482×   486×   53×         47×     503×   503×   191×   469× 466× 466× 466× 466×       466× 466× 23× 23× 20×     20×           443× 443×     478× 478×   75× 75×         75× 75× 75× 75×   282× 282× 282×     14757×     37195×   1056× 561×   495× 469× 156× 156×   469× 469× 96×   469× 57×   469×          
/* 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", "./view-base", "../event-renderer/month", "../base/util", "../base/constant", "../base/css-constant"], function (require, exports, ej2_base_1, view_base_1, month_1, util, event, cls) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Month = (function (_super) {
        __extends(Month, _super);
        function Month(parent) {
            var _this = _super.call(this, parent) || this;
            _this.dayNameFormat = 'wide';
            _this.viewClass = 'e-month-view';
            _this.isInverseTableSelect = false;
            _this.monthEvent = null;
            _this.monthDates = {};
            return _this;
        }
        Month.prototype.addEventListener = function () {
            this.parent.on(event.scrollUiUpdate, this.onScrollUIUpdate, this);
            this.parent.on(event.dataReady, this.onDataReady, this);
            this.parent.on(event.cellClick, this.onCellClick, this);
        };
        Month.prototype.removeEventListener = function () {
            Eif (this.parent) {
                this.parent.off(event.scrollUiUpdate, this.onScrollUIUpdate);
                this.parent.off(event.dataReady, this.onDataReady);
                this.parent.off(event.cellClick, this.onCellClick);
            }
        };
        Month.prototype.onDataReady = function (args) {
            this.monthEvent = new month_1.MonthEvent(this.parent);
            this.monthEvent.renderAppointments();
            this.parent.notify(event.eventsLoaded, {});
        };
        Month.prototype.onCellClick = function (event) { };
        Month.prototype.onContentScroll = function (e) {
            this.parent.removeNewEventElement();
            this.parent.notify(event.virtualScroll, e);
            this.scrollTopPanel(e.target);
            this.scrollLeftPanel(e.target);
            this.parent.uiStateValues.top = e.target.scrollTop;
            this.parent.uiStateValues.left = e.target.scrollLeft;
            this.setPersistence();
        };
        Month.prototype.scrollLeftPanel = function (target) {
            var leftPanel = this.getLeftPanelElement();
            if (leftPanel) {
                leftPanel.scrollTop = target.scrollTop;
            }
        };
        Month.prototype.getLeftPanelElement = function () {
            return this.element.querySelector('.' + cls.WEEK_NUMBER_WRAPPER_CLASS);
        };
        Month.prototype.onScrollUIUpdate = function (args) {
            var headerHeight = this.getHeaderBarHeight();
            var header = this.getDatesHeaderElement();
            var content = this.getContentAreaElement();
            var height = this.parent.element.offsetHeight - headerHeight - header.offsetHeight;
            var leftPanel = this.getLeftPanelElement();
            if (this.parent.height !== 'auto') {
                this.setContentHeight(content, leftPanel, height);
            }
            var scrollBarWidth = util.getScrollBarWidth();
            header.firstElementChild.style[args.cssProperties.rtlBorder] = '';
            header.style[args.cssProperties.rtlPadding] = '';
            if (content.offsetWidth - content.clientWidth > 0) {
                header.firstElementChild.style[args.cssProperties.border] = scrollBarWidth > 0 ? '1px' : '0px';
                header.style[args.cssProperties.padding] = scrollBarWidth > 0 ? scrollBarWidth - 1 + 'px' : '0px';
            }
            else {
                header.firstElementChild.style[args.cssProperties.border] = '';
                header.style[args.cssProperties.padding] = '';
            }
            this.setColWidth(content);
            if (args.scrollPosition || !args.isPreventScrollUpdate && this.parent.currentView === 'TimelineMonth') {
                var top_1 = this.parent.currentView === 'TimelineMonth' ? this.parent.uiStateValues.top : args.scrollPosition.top;
                if (leftPanel) {
                    leftPanel.scrollTop = top_1;
                }
                content.scrollTop = top_1;
                if (this.parent.uiStateValues.isInitial) {
                    this.scrollToSelectedDate();
                    this.parent.uiStateValues.isInitial = false;
                }
                else {
                    content.scrollLeft = this.parent.currentView === 'TimelineMonth' ? this.parent.uiStateValues.left :
                        args.scrollPosition.left;
                }
            }
            else {
                this.scrollToSelectedDate();
            }
            this.retainScrollPosition();
        };
        Month.prototype.scrollToSelectedDate = function () {
            var headerCell = this.element.querySelector('.' + cls.HEADER_CELLS_CLASS + '[data-date="'
                + this.parent.selectedDate.getTime().toString() + '"]');
            var content = this.getContentAreaElement();
            if (!ej2_base_1.isNullOrUndefined(headerCell)) {
                content.scrollLeft = !this.parent.enableRtl ?
                    headerCell.offsetLeft : -(this.parent.getContentTable().offsetWidth - headerCell.offsetLeft - headerCell.offsetWidth);
            }
            else {
                content.scrollLeft = 0;
            }
            if (content.scrollLeft === 0 && this.parent.uiStateValues.isInitial) {
                this.parent.uiStateValues.left = 0;
            }
        };
        Month.prototype.setContentHeight = function (content, leftPanelElement, height) {
            content.style.height = 'auto';
            if (this.parent.currentView === 'Month') {
                content.style.height = ej2_base_1.formatUnit(height);
            }
            if (leftPanelElement) {
                if (this.parent.currentView === 'MonthAgenda') {
                    height = (this.parent.activeViewOptions.interval > 1) ?
                        this.getContentAreaElement().firstElementChild.offsetHeight :
                        this.element.querySelector('.' + cls.CONTENT_TABLE_CLASS).offsetHeight;
                }
                leftPanelElement.style.height = 'auto';
                leftPanelElement.style.height = ej2_base_1.formatUnit(height - this.getScrollXIndent(content));
            }
        };
        Month.prototype.generateColumnLevels = function () {
            var colLevels = [];
            var level = this.getDateSlots(this.renderDates, this.parent.activeViewOptions.workDays);
            if (this.parent.activeViewOptions.group.resources.length > 0) {
                colLevels = this.parent.resourceBase.generateResourceLevels(level);
                if (this.parent.currentView === 'MonthAgenda') {
                    colLevels = [level];
                }
                if (this.parent.uiStateValues.isGroupAdaptive && this.parent.resourceBase.lastResourceLevel.length > 0) {
                    var resourceLevel = this.parent.resourceBase.lastResourceLevel[this.parent.uiStateValues.groupIndex];
                    var levels_1 = this.getDateSlots(resourceLevel.renderDates, resourceLevel.workDays);
                    Iif (this.parent.activeViewOptions.group.byDate && this.parent.activeViewOptions.group.hideNonWorkingDays) {
                        var index = levels_1.findIndex(function (x, index) {
                            return index !== 0 && x.date.getDay() === levels_1[0].date.getDay();
                        });
                        levels_1 = index > -1 ? levels_1.slice(0, index) : levels_1;
                    }
                    colLevels = [levels_1];
                }
            }
            else {
                colLevels.push(level);
            }
            this.colLevels = colLevels;
            return colLevels;
        };
        Month.prototype.getDateSlots = function (renderDates, workDays) {
            var count = this.parent.activeViewOptions.showWeekend ? util.WEEK_LENGTH : workDays.length;
            var dateSlots = [];
            var isCurrentMonth = this.isCurrentMonth(this.parent.selectedDate);
            for (var col = 0; col < count; col++) {
                var classList = [cls.HEADER_CELLS_CLASS];
                var currentDateIndex = renderDates.slice(0, count).map(function (date) { return date.getDay(); });
                if (isCurrentMonth && currentDateIndex.indexOf(this.parent.currentTimezoneDate.getDay()) === col) {
                    classList.push(cls.CURRENT_DAY_CLASS);
                }
                dateSlots.push({ date: renderDates[parseInt(col.toString(), 10)], type: 'monthDay', className: classList, colSpan: 1, workDays: workDays });
            }
            return dateSlots;
        };
        Month.prototype.getDayNameFormat = function () {
            if (this.parent.isAdaptive || this.parent.activeViewOptions.group.resources.length > 0) {
                return 'abbreviated';
            }
            return 'wide';
        };
        Month.prototype.renderLayout = function (type) {
            this.dayNameFormat = this.getDayNameFormat();
            this.setPanel(ej2_base_1.createElement('div', { className: cls.TABLE_WRAP_CLASS }));
            var clsList = [this.viewClass];
            clsList.push(type);
            if (this.parent.activeViewOptions.group.byDate) {
                clsList.push('e-by-date');
                if (this.parent.currentView !== 'Month') {
                    this.parent.activeViewOptions.group.hideNonWorkingDays = false;
                }
            }
            if (this.parent.activeViewOptions.allowVirtualScrolling && !this.parent.uiStateValues.isGroupAdaptive) {
                clsList.push(cls.VIRTUAL_SCROLL_CLASS);
            }
            if (this.parent.rowAutoHeight && this.parent.eventSettings.ignoreWhitespace) {
                clsList.push(cls.IGNORE_WHITESPACE);
            }
            ej2_base_1.addClass([this.element], clsList);
            this.renderPanel(type);
            this.element.appendChild(this.createTableLayout(cls.OUTER_TABLE_CLASS));
            this.element.querySelector('table').setAttribute('role', 'presentation');
            this.colLevels = this.generateColumnLevels();
            this.renderHeader();
            this.renderContent();
            var target = (this.parent.currentView === 'MonthAgenda') ? this.parent.activeView.getPanel() : this.parent.element;
            if (this.parent.uiStateValues.isGroupAdaptive && !target.querySelector('.' + cls.RESOURCE_TOOLBAR_CONTAINER)) {
                this.renderResourceMobileLayout();
            }
            this.parent.notify(event.contentReady, {});
            if (this.parent.uiStateValues.isCustomMonth) {
                this.parent.uiStateValues.isCustomMonth = false;
            }
        };
        Month.prototype.refreshHeader = function () {
            ej2_base_1.remove(this.element.querySelector('tbody tr'));
            this.renderHeader();
            this.parent.notify(event.contentReady, {});
            var dateHeader = this.element.querySelector('.' + cls.DATE_HEADER_WRAP_CLASS);
            var contentWrapper = this.element.querySelector('.' + cls.CONTENT_WRAP_CLASS);
            Eif (dateHeader) {
                dateHeader.scrollLeft = this.parent.uiStateValues.left;
            }
            Eif (contentWrapper) {
                contentWrapper.scrollLeft = this.parent.uiStateValues.left;
            }
        };
        Month.prototype.wireCellEvents = function (element) {
            ej2_base_1.EventHandler.add(element, 'mousedown', this.parent.workCellAction.cellMouseDown, this.parent.workCellAction);
            ej2_base_1.EventHandler.add(element, 'click', this.parent.workCellAction.cellClick, this.parent.workCellAction);
            if (!this.parent.isAdaptive) {
                ej2_base_1.EventHandler.add(element, 'dblclick', this.parent.workCellAction.cellDblClick, this.parent.workCellAction);
            }
        };
        Month.prototype.renderHeader = function () {
            var tr = ej2_base_1.createElement('tr');
            this.renderLeftIndent(tr);
            var dateTd = ej2_base_1.createElement('td');
            dateTd.appendChild(this.renderDatesHeader());
            tr.appendChild(dateTd);
            ej2_base_1.prepend([tr], this.element.querySelector('tbody'));
        };
        Month.prototype.renderLeftIndent = function (tr) {
            if (this.parent.activeViewOptions.showWeekNumber) {
                tr.appendChild(ej2_base_1.createElement('td', { className: 'e-left-indent' }));
            }
        };
        Month.prototype.renderContent = function () {
            if (this.parent.activeViewOptions.group.resources.length > 0) {
                this.parent.resourceBase.renderedResources = ej2_base_1.extend([], this.parent.resourceBase.lastResourceLevel, null, true);
            }
            var tr = ej2_base_1.createElement('tr');
            if (this.parent.activeViewOptions.showWeekNumber) {
                tr.appendChild(this.renderWeekNumberContent());
            }
            var workTd = ej2_base_1.createElement('td');
            var levels = this.colLevels.slice(0);
            if (this.parent.virtualScrollModule) {
                this.resetColLevels();
            }
            var wrap = ej2_base_1.createElement('div', { className: cls.CONTENT_WRAP_CLASS });
            var contentArea = this.renderContentArea();
            if (this.parent.currentView === 'Month') {
                wrap.appendChild(contentArea);
            }
            else {
                var monthAgendaWrapper = ej2_base_1.createElement('div', { className: cls.TABLE_CONTAINER_CLASS });
                monthAgendaWrapper.appendChild(contentArea);
                wrap.appendChild(monthAgendaWrapper);
            }
            ej2_base_1.EventHandler.add(wrap, 'scroll', this.onContentScroll, this);
            workTd.appendChild(wrap);
            tr.appendChild(workTd);
            if (this.parent.virtualScrollModule) {
                this.colLevels = levels;
                this.parent.virtualScrollModule.renderVirtualTrack(wrap);
            }
            this.element.querySelector('tbody').appendChild(tr);
            this.renderAppointmentContainer();
        };
        Month.prototype.renderWeekNumberContent = function () {
            var dateCol = this.renderDates.map(function (date) { return new Date(+date); });
            var td = ej2_base_1.createElement('td');
            var contentWrapper = ej2_base_1.createElement('div', { className: cls.WEEK_NUMBER_WRAPPER_CLASS });
            td.appendChild(contentWrapper);
            var contentWrapTable = this.createTableLayout();
            contentWrapper.appendChild(contentWrapTable);
            var noOfDays = this.parent.activeViewOptions.showWeekend ? util.WEEK_LENGTH :
                this.parent.activeViewOptions.workDays.length;
            for (var i = 0, length_1 = (this.renderDates.length / noOfDays); i < length_1; i++) {
                var dates = dateCol.splice(0, noOfDays);
                var weekNumber = this.parent.getWeekNumberContent(dates);
                contentWrapTable.querySelector('tbody').appendChild(this.createWeekNumberElement(weekNumber));
            }
            return td;
        };
        Month.prototype.renderAppointmentContainer = function () {
        };
        Month.prototype.renderDatesHeader = function () {
            var container = ej2_base_1.createElement('div', { className: cls.DATE_HEADER_CONTAINER_CLASS });
            var wrap = ej2_base_1.createElement('div', { className: cls.DATE_HEADER_WRAP_CLASS });
            container.appendChild(wrap);
            var table = this.createTableLayout();
            if (this.parent.currentView === 'Month') {
                var thead = ej2_base_1.createElement('thead');
                thead.appendChild(ej2_base_1.createElement('tr'));
                ej2_base_1.prepend([thead], table);
            }
            this.createColGroup(table, this.colLevels[this.colLevels.length - 1]);
            var trEle = ej2_base_1.createElement('tr');
            for (var i = 0; i < this.colLevels.length; i++) {
                var level = this.colLevels[parseInt(i.toString(), 10)];
                var ntr = trEle.cloneNode();
                for (var j = 0; j < level.length; j++) {
                    var td = level[parseInt(j.toString(), 10)];
                    ntr.appendChild(this.createHeaderCell(td));
                }
                table.querySelector('tbody').appendChild(ntr);
            }
            wrap.appendChild(table);
            return container;
        };
        Month.prototype.createHeaderCell = function (td) {
            var tdEle = ej2_base_1.createElement('td');
            this.addAttributes(td, tdEle);
            if (td.type === 'monthDay') {
                var ele = ej2_base_1.createElement('span', { innerHTML: util.capitalizeFirstWord(this.parent.getDayNames(this.dayNameFormat)[td.date.getDay()], 'single') });
                tdEle.appendChild(ele);
            }
            if (td.type === 'resourceHeader') {
                this.setResourceHeaderContent(tdEle, td);
            }
            if (td.type === 'dateHeader') {
                ej2_base_1.addClass([tdEle], cls.DATE_HEADER_CLASS);
                tdEle.setAttribute('data-date', td.date.getTime().toString());
                if (this.parent.activeViewOptions.dateHeaderTemplate) {
                    var cellArgs = { date: td.date, type: td.type };
                    var elementId = this.parent.element.id + '_';
                    var viewName = this.parent.activeViewOptions.dateHeaderTemplateName;
                    var templateId = elementId + viewName + 'dateHeaderTemplate';
                    var dateTemplate = [].slice.call(this.parent.getDateHeaderTemplate()(cellArgs, this.parent, 'dateHeaderTemplate', templateId, false, undefined, undefined, this.parent.root));
                    Eif (dateTemplate && dateTemplate.length) {
                        ej2_base_1.append(dateTemplate, tdEle);
                    }
                }
                else {
                    var ele = ej2_base_1.createElement('span', { className: cls.NAVIGATE_CLASS });
                    var skeleton = 'full';
                    var title = this.parent.globalize.formatDate(td.date, { skeleton: skeleton, calendar: this.parent.getCalendarMode() });
                    ele.setAttribute('title', util.capitalizeFirstWord(title, 'multiple'));
                    var innerText = (this.parent.calendarUtil.isMonthStart(td.date) && !this.isCurrentDate(td.date) && !this.parent.isAdaptive) ?
                        this.parent.globalize.formatDate(td.date, { format: 'MMM d', calendar: this.parent.getCalendarMode() }) :
                        this.parent.globalize.formatDate(td.date, { skeleton: 'd', calendar: this.parent.getCalendarMode() });
                    ele.innerHTML = util.capitalizeFirstWord(innerText, 'single');
                    tdEle.appendChild(ele);
                }
                this.wireCellEvents(tdEle);
            }
            var args = { elementType: td.type, element: tdEle, date: td.date, groupIndex: td.groupIndex };
            this.parent.trigger(event.renderCell, args);
            return tdEle;
        };
        Month.prototype.getContentSlots = function () {
            Iif (!(this.colLevels[this.colLevels.length - 1] && this.colLevels[this.colLevels.length - 1][0])) {
                return [];
            }
            var slotDatas = [];
            var prepareSlots = function (rowIndex, renderDate, resData, classList) {
                var data = {
                    date: new Date(+renderDate), groupIndex: resData.groupIndex, workDays: resData.workDays,
                    type: 'monthCells', className: classList || [cls.WORK_CELLS_CLASS]
                };
                if (!slotDatas[parseInt(rowIndex.toString(), 10)]) {
                    slotDatas[parseInt(rowIndex.toString(), 10)] = [];
                }
                slotDatas[parseInt(rowIndex.toString(), 10)].push(data);
            };
            var includeResource = this.parent.currentView !== 'MonthAgenda' &&
                this.parent.activeViewOptions.group.resources.length > 0;
            if (includeResource && !this.parent.uiStateValues.isGroupAdaptive && !this.parent.activeViewOptions.group.byDate) {
                for (var _i = 0, _a = this.colLevels[this.colLevels.length - 2]; _i < _a.length; _i++) {
                    var res = _a[_i];
                    var dates = res.renderDates.map(function (date) { return new Date(+date); });
                    var count = this.parent.activeViewOptions.showWeekend ? util.WEEK_LENGTH : res.workDays.length;
                    for (var i = 0; i < (res.renderDates.length / count); i++) {
                        var colDates = dates.splice(0, count);
                        for (var _b = 0, colDates_1 = colDates; _b < colDates_1.length; _b++) {
                            var colDate = colDates_1[_b];
                            prepareSlots(i, colDate, res);
                        }
                    }
                }
            }
            else {
                var dates = this.renderDates.map(function (date) { return new Date(+date); });
                var count = this.parent.activeViewOptions.showWeekend ? util.WEEK_LENGTH :
                    this.parent.activeViewOptions.workDays.length;
                var level = this.colLevels.slice(0, 1)[0];
                var startIndex = this.renderDates.map(Number).indexOf(+level[0].date);
                for (var i = 0; i < (this.renderDates.length / count); i++) {
                    var colDates = dates.splice(0, count);
                    var k = startIndex;
                    var _loop_1 = function (j) {
                        var colDate = colDates[parseInt(k.toString(), 10)];
                        k++;
                        if (includeResource) {
                            var lastRow = this_1.colLevels[(this_1.colLevels.length - 1)];
                            var rowCount = lastRow.length / count;
                            var resourcesTd = lastRow.slice(0, rowCount);
                            if (this_1.parent.activeViewOptions.group.hideNonWorkingDays) {
                                resourcesTd = lastRow.filter(function (x) { return x.date.getDay() === colDate.getDay(); });
                                if (resourcesTd.length === 0) {
                                    j = j - 1;
                                    return out_j_1 = j, "continue";
                                }
                            }
                            for (var resIndex = 0; resIndex < resourcesTd.length; resIndex++) {
                                var clsList = void 0;
                                if (resIndex !== 0) {
                                    clsList = [cls.WORK_CELLS_CLASS, cls.DISABLE_DATE];
                                }
                                prepareSlots(i, colDate, resourcesTd[parseInt(resIndex.toString(), 10)], clsList);
                            }
                        }
                        else {
                            prepareSlots(i, colDate, this_1.colLevels[this_1.colLevels.length - 1][0]);
                        }
                        out_j_1 = j;
                    };
                    var this_1 = this, out_j_1;
                    for (var j = startIndex; j < (this.colLevels[0].length + startIndex) && j < colDates.length; j++) {
                        _loop_1(j);
                        j = out_j_1;
                    }
                }
            }
            return slotDatas;
        };
        Month.prototype.updateClassList = function (data) {
            if (!this.isCustomMonth() && this.isOtherMonth(data.date)) {
                data.className.push(cls.OTHERMONTH_CLASS);
            }
            if (!this.parent.isMinMaxDate(data.date)) {
                data.className.push(cls.DISABLE_DATES);
            }
            this.updateSelectedCellClass(data);
        };
        Month.prototype.updateSelectedCellClass = function (data) {
            return;
        };
        Month.prototype.isOtherMonth = function (date) {
            return date.getTime() < this.monthDates.start.getTime() || date.getTime() > this.monthDates.end.getTime();
        };
        Month.prototype.renderContentArea = function () {
            var tbl = this.createTableLayout(cls.CONTENT_TABLE_CLASS);
            this.setAriaAttributes(tbl);
            this.addAutoHeightClass(tbl);
            if (this.parent.currentView === 'TimelineMonth') {
                this.createColGroup(tbl, this.colLevels[this.colLevels.length - 1]);
            }
            var monthDate = new Date(this.parent.selectedDate.getTime());
            this.monthDates = {
                start: this.parent.calendarUtil.firstDateOfMonth(monthDate),
                end: this.parent.calendarUtil.lastDateOfMonth(util.addMonths(monthDate, this.parent.activeViewOptions.interval - 1))
            };
            var tBody = tbl.querySelector('tbody');
            ej2_base_1.append(this.getContentRows(), tBody);
            this.wireCellEvents(tBody);
            return tbl;
        };
        Month.prototype.getContentRows = function () {
            var trows = [];
            var tr = ej2_base_1.createElement('tr');
            var td = ej2_base_1.createElement('td', { attrs: { 'aria-selected': 'false' } });
            var slotDatas = this.getContentSlots();
            var isTimeline = this.parent.currentView === 'TimelineMonth';
            var existingGroupIndices = isTimeline ? this.getGroupIndices() : [];
            for (var row = 0; row < slotDatas.length; row++) {
                if (existingGroupIndices.length > 0 &&
                    existingGroupIndices.indexOf(slotDatas[parseInt(row.toString(), 10)][0].groupIndex) > -1) {
                    continue;
                }
                var ntr = tr.cloneNode();
                for (var col = 0; col < slotDatas[parseInt(row.toString(), 10)].length; col++) {
                    var ntd = this.createContentTd(slotDatas[parseInt(row.toString(), 10)][parseInt(col.toString(), 10)], td);
                    ntr.appendChild(ntd);
                }
                trows.push(ntr);
            }
            return trows;
        };
        Month.prototype.createContentTd = function (data, td) {
            var ntd = td.cloneNode();
            if (data.colSpan) {
                ntd.setAttribute('colspan', data.colSpan.toString());
            }
            this.updateClassList(data);
            var type = data.type;
            if (data.className.indexOf(cls.RESOURCE_PARENT_CLASS) !== -1) {
                data.className.push(cls.RESOURCE_GROUP_CELLS_CLASS);
                type = 'resourceGroupCells';
            }
            if (this.parent.workHours.highlight && this.isWorkDay(data.date, data.workDays)) {
                data.className.push(cls.WORKDAY_CLASS);
            }
            if (this.isCurrentDate(data.date)) {
                data.className.push(cls.CURRENTDATE_CLASS);
            }
            ej2_base_1.addClass([ntd], data.className);
            ntd.setAttribute('data-date', data.date.getTime().toString());
            if (!ej2_base_1.isNullOrUndefined(data.groupIndex) || this.parent.uiStateValues.isGroupAdaptive) {
                var groupIndex = this.parent.uiStateValues.isGroupAdaptive ? this.parent.uiStateValues.groupIndex :
                    data.groupIndex;
                ntd.setAttribute('data-group-index', '' + groupIndex);
            }
            this.renderDateHeaderElement(data, ntd);
            if (this.parent.activeViewOptions.cellTemplate) {
                var args_1 = { date: data.date, type: type, groupIndex: data.groupIndex };
                var scheduleId = this.parent.element.id + '_';
                var viewName = this.parent.activeViewOptions.cellTemplateName;
                var templateId = scheduleId + viewName + 'cellTemplate';
                var cellTemplate = [].slice.call(this.parent.getCellTemplate()(args_1, this.parent, 'cellTemplate', templateId, false, undefined, undefined, this.parent.root));
                ej2_base_1.append(cellTemplate, ntd);
            }
            var args = { elementType: type, element: ntd, date: data.date, groupIndex: data.groupIndex };
            this.parent.trigger(event.renderCell, args);
            return ntd;
        };
        Month.prototype.renderDateHeaderElement = function (data, ntd) {
            if (this.parent.currentView === 'TimelineMonth') {
                return;
            }
            var dateHeader = ej2_base_1.createElement('div', { className: cls.DATE_HEADER_CLASS });
            if (this.parent.activeViewOptions.cellHeaderTemplate) {
                var args = { date: data.date, type: data.type, groupIndex: data.groupIndex };
                var scheduleId = this.parent.element.id + '_';
                var viewName = this.parent.activeViewOptions.cellHeaderTemplateName;
                var templateId = scheduleId + viewName + 'cellHeaderTemplate';
                var cellHeaderTemplate = [].slice.call(this.parent.getCellHeaderTemplate()(args, this.parent, 'cellHeaderTemplate', templateId, false, undefined, undefined, this.parent.root));
                ej2_base_1.append(cellHeaderTemplate, dateHeader);
            }
            else {
                var innerText = (this.parent.calendarUtil.isMonthStart(data.date) && !this.isCurrentDate(data.date) && !this.parent.isAdaptive) ?
                    this.parent.globalize.formatDate(data.date, { format: 'MMM d', calendar: this.parent.getCalendarMode() }) :
                    this.parent.globalize.formatDate(data.date, { skeleton: 'd', calendar: this.parent.getCalendarMode() });
                dateHeader.innerHTML = util.capitalizeFirstWord(innerText, 'single');
            }
            ntd.appendChild(dateHeader);
            if (this.getModuleName() === 'month') {
                ej2_base_1.addClass([dateHeader], cls.NAVIGATE_CLASS);
                var skeleton = 'full';
                var announcementText = this.parent.globalize.formatDate(data.date, { skeleton: skeleton, calendar: this.parent.getCalendarMode() });
                ntd.setAttribute('aria-label', announcementText);
            }
        };
        Month.prototype.getMonthStart = function (currentDate) {
            var useDisplayDate = this.parent.currentView === 'Month' && !ej2_base_1.isNullOrUndefined(this.parent.activeViewOptions.displayDate) && (this.parent.uiStateValues.isCustomMonth || this.isCustomRange());
            var date = useDisplayDate ? this.parent.activeViewOptions.displayDate : !(this.parent.uiStateValues.isCustomMonth ||
                this.isCustomRange()) && this.isCustomMonth() ? currentDate : this.parent.calendarUtil.firstDateOfMonth(currentDate);
            var monthStart = util.getWeekFirstDate(date, this.parent.activeViewOptions.firstDayOfWeek);
            return new Date(monthStart.getFullYear(), monthStart.getMonth(), monthStart.getDate());
        };
        Month.prototype.getMonthEnd = function (currentDate) {
            if (this.isCustomMonth()) {
                var start = this.getMonthStart(currentDate);
                var numberOfDays = util.WEEK_LENGTH * (this.parent.activeViewOptions.numberOfWeeks > 0 ?
                    this.parent.activeViewOptions.numberOfWeeks : util.DEFAULT_WEEKS);
                return util.addDays(start, (numberOfDays - 1));
            }
            else {
                var endDate = util.addMonths(currentDate, this.parent.activeViewOptions.interval - 1);
                var lastWeekOfMonth = util.getWeekFirstDate(this.parent.calendarUtil.lastDateOfMonth(endDate), this.parent.activeViewOptions.firstDayOfWeek);
                return util.addDays(lastWeekOfMonth, util.WEEK_LENGTH - 1);
            }
        };
        Month.prototype.isCustomRange = function () {
            var dates = this.parent.getCurrentViewDates();
            if (dates && dates.length > 0) {
                var selectedTime = util.resetTime(this.parent.selectedDate).getTime();
                var weekFirstDate = util.getWeekFirstDate(dates[dates.length - 1], this.parent.activeViewOptions.firstDayOfWeek);
                return !(selectedTime >= util.getWeekFirstDate(dates[0], this.parent.activeViewOptions.firstDayOfWeek).getTime() &&
                    selectedTime <= util.addDays(weekFirstDate, 6).getTime());
            }
            return false;
        };
        Month.prototype.getRenderDates = function (workDays) {
            var renderDates = [];
            var currentDate = util.resetTime(this.parent.selectedDate);
            var start = this.getMonthStart(currentDate);
            var monthEnd = this.getMonthEnd(currentDate);
            do {
                if (this.parent.activeViewOptions.showWeekend) {
                    renderDates.push(start);
                }
                else {
                    if (this.isWorkDay(start, workDays)) {
                        renderDates.push(start);
                    }
                }
                start = util.addDays(start, 1);
                Iif (start.getHours() > 0) {
                    start = util.resetTime(start);
                }
            } while (start.getTime() <= monthEnd.getTime());
            if (!workDays) {
                this.renderDates = renderDates;
            }
            if (this.parent.headerModule) {
                this.parent.headerModule.previousNextIconHandler();
            }
            return renderDates;
        };
        Month.prototype.getNextPreviousDate = function (type) {
            if (this.isCustomMonth()) {
                var dates = this.parent.getCurrentViewDates();
                var date = util.getWeekFirstDate(type === 'next' ? dates[dates.length - 1]
                    : dates[0], this.parent.activeViewOptions.firstDayOfWeek);
                return util.addDays(date, type === 'next' ? util.WEEK_LENGTH : -(this.parent.activeViewOptions.numberOfWeeks > 0 ?
                    this.parent.activeViewOptions.numberOfWeeks : util.DEFAULT_WEEKS) * util.WEEK_LENGTH);
            }
            else {
                return util.addMonths(this.parent.selectedDate, ((type === 'next' ? 1 : -1) * this.parent.activeViewOptions.interval));
            }
        };
        Month.prototype.getStartDate = function () {
            return this.getMonthStart(this.parent.selectedDate);
        };
        Month.prototype.getEndDate = function () {
            return this.getMonthEnd(this.parent.selectedDate);
        };
        Month.prototype.getEndDateFromStartDate = function (start) {
            return util.addDays(new Date(start.getTime()), 1);
        };
        Month.prototype.getDateRangeText = function () {
            if (this.parent.isAdaptive || ej2_base_1.isNullOrUndefined(this.parent.activeViewOptions.dateFormat)) {
                var startDate = this.parent.selectedDate;
                var endDate = void 0;
                var updateCustomRange = false;
                if (this.isCustomMonth()) {
                    var dates = this.parent.getCurrentViewDates();
                    updateCustomRange = dates[0].getMonth() !== dates[dates.length - 1].getMonth() ||
                        dates[0].getFullYear() !== dates[dates.length - 1].getFullYear();
                    Eif (updateCustomRange) {
                        startDate = dates[0];
                        endDate = dates[dates.length - 1];
                    }
                }
                var isUpdateDateRange = (this.parent.currentView !== 'Month' || !this.isCustomMonth());
                if (this.parent.activeViewOptions.interval > 1 && isUpdateDateRange || updateCustomRange) {
                    endDate = endDate ? endDate : util.addMonths(util.lastDateOfMonth(startDate), this.parent.activeViewOptions.interval - 1);
                    if (startDate.getFullYear() === endDate.getFullYear()) {
                        var monthNames = (this.parent.globalize.formatDate(startDate, { format: 'MMMM', calendar: this.parent.getCalendarMode() })) + ' - ' +
                            (this.parent.globalize.formatDate(endDate, { format: 'MMMM ', calendar: this.parent.getCalendarMode() })) +
                            this.parent.globalize.formatDate(endDate, { skeleton: 'y', calendar: this.parent.getCalendarMode() });
                        return util.capitalizeFirstWord(monthNames, 'single');
                    }
                    var text = (this.parent.globalize.formatDate(startDate, { format: 'MMMM', calendar: this.parent.getCalendarMode() })) + ' ' +
                        startDate.getFullYear() + ' - ' +
                        this.parent.globalize.formatDate(endDate, { format: 'MMMM ', calendar: this.parent.getCalendarMode() }) +
                        this.parent.globalize.formatDate(endDate, { skeleton: 'y', calendar: this.parent.getCalendarMode() });
                    return util.capitalizeFirstWord(text, 'single');
                }
                var format = (this.parent.activeViewOptions.dateFormat) ? this.parent.activeViewOptions.dateFormat : 'MMMM y';
                return util.capitalizeFirstWord(this.parent.globalize.formatDate(startDate, { format: format, calendar: this.parent.getCalendarMode() }), 'single');
            }
            return this.formatDateRange(this.parent.selectedDate);
        };
        Month.prototype.getLabelText = function (view) {
            var viewStr = view.charAt(0).toLowerCase() + view.substring(1);
            return this.formatViewLabel(viewStr, this.getStartDate(), this.getEndDate());
        };
        Month.prototype.createWeekNumberElement = function (text) {
            var tr = ej2_base_1.createElement('tr');
            var td = ej2_base_1.createElement('td', {
                className: cls.WEEK_NUMBER_CLASS,
                attrs: { 'title': (text ? this.parent.localeObj.getConstant('week') + ' ' + text : '') },
                innerHTML: (text || '')
            });
            tr.appendChild(td);
            var args = { elementType: 'weekNumberCell', element: td };
            this.parent.trigger(event.renderCell, args);
            return tr;
        };
        Month.prototype.unWireEvents = function () {
            var contentScrollableEle = this.element.querySelector('.' + cls.CONTENT_WRAP_CLASS);
            Eif (contentScrollableEle) {
                ej2_base_1.EventHandler.remove(contentScrollableEle, 'scroll', this.onContentScroll);
            }
        };
        Month.prototype.isCustomMonth = function () {
            return this.parent.currentView === 'Month' &&
                (!ej2_base_1.isNullOrUndefined(this.parent.activeViewOptions.displayDate) || this.parent.activeViewOptions.numberOfWeeks > 0);
        };
        Month.prototype.getModuleName = function () {
            return 'month';
        };
        Month.prototype.destroy = function () {
            if (!this.parent || this.parent && this.parent.isDestroyed) {
                return;
            }
            if (this.element) {
                if (this.monthEvent) {
                    this.monthEvent.destroy();
                    this.monthEvent = null;
                }
                this.unWireEvents();
                if (this.parent.resourceBase) {
                    this.parent.resourceBase.destroy();
                }
                if (this.parent.scheduleTouchModule) {
                    this.parent.scheduleTouchModule.resetValues();
                }
                _super.prototype.destroy.call(this);
            }
        };
        return Month;
    }(view_base_1.ViewBase));
    exports.Month = Month;
});