all files / renderer/ nonworking-day.js

95.17% Statements 138/145
86.73% Branches 98/113
100% Functions 11/11
95.17% Lines 138/145
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   529× 529× 529× 529× 529×   728× 521×     521× 26×   521×     633× 118× 118× 101×     101×   101×   118×   515×         118× 118× 118× 118× 118× 118× 94×   118× 118× 236× 216× 216× 216× 216× 216×   20× 14× 14×     236×   236× 236× 236×     236× 236×     236× 236× 236× 230×   236× 236× 199×   236×   118×   629× 610× 610× 512×     512× 26× 26×   512×   610×   19×             610× 610×     610×     610×   610× 610× 610× 610× 610× 68733× 19425× 19425× 19425× 602× 602× 602× 602× 602× 602×   19425× 19425× 19425× 19425× 19425× 19425× 18823×             18823×                 602×   19425× 19425×     19425×   68733× 68733×   610×   119× 119× 119× 119× 92×   119×   119× 119× 119× 233×     647× 647× 119× 119×   647× 620×                  
define(["require", "exports", "@syncfusion/ej2-base", "../base/css-constants", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, cls, ej2_base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var NonWorkingDay = (function () {
        function NonWorkingDay(gantt) {
            this.weekendWidthUpdated = false;
            this.parent = gantt;
            this.nonworkingContainer = null;
            this.holidayContainer = null;
            this.weekendContainer = null;
        }
        NonWorkingDay.prototype.createNonworkingContainer = function () {
            if (!this.parent.ganttChartModule.chartBodyContent.contains(this.nonworkingContainer)) {
                this.nonworkingContainer = ej2_base_1.createElement('div', {
                    className: cls.nonworkingContainer
                });
                if (this.parent.enableTimelineVirtualization) {
                    this.nonworkingContainer.style.height = '100%';
                }
                this.parent.ganttChartModule.chartBodyContent.insertBefore(this.nonworkingContainer, this.parent.ganttChartModule.chartBodyContent.lastChild);
            }
        };
        NonWorkingDay.prototype.renderHolidays = function () {
            if (this.parent.holidays && this.parent.holidays.length > 0) {
                this.createNonworkingContainer();
                if (!this.nonworkingContainer.contains(this.holidayContainer)) {
                    this.holidayContainer = ej2_base_1.createElement('div', {
                        className: cls.holidayContainer
                    });
                    if (this.parent.enableTimelineVirtualization) {
                        this.holidayContainer.style.height = '100%';
                        this.holidayContainer.style.zIndex = '-1';
                    }
                    this.nonworkingContainer.appendChild(this.holidayContainer);
                }
                this.holidayContainer.innerHTML = this.getHolidaysElement().innerHTML;
            }
            else if (this.holidayContainer && this.holidayContainer.parentNode) {
                ej2_base_1.remove(this.holidayContainer);
                Iif (this.nonworkingContainer && this.nonworkingContainer.childNodes.length === 0) {
                    ej2_base_1.remove(this.nonworkingContainer);
                }
            }
        };
        NonWorkingDay.prototype.getHolidaysElement = function () {
            var fromDate;
            var toDate;
            var container = ej2_base_1.createElement('div');
            var height = this.parent.contentHeight;
            var toolbarHeight = 0;
            if (!ej2_base_2.isNullOrUndefined(this.parent.toolbarModule) && !ej2_base_2.isNullOrUndefined(this.parent.toolbarModule.element)) {
                toolbarHeight = this.parent.toolbarModule.element.offsetHeight;
            }
            var viewportHeight = this.parent.ganttHeight - toolbarHeight - this.parent.ganttChartModule.chartTimelineContainer.offsetHeight;
            for (var i = 0; i < this.parent.holidays.length; i++) {
                if (this.parent.holidays[i].from && this.parent.holidays[i].to) {
                    fromDate = this.parent.dateValidationModule.getDateFromFormat(this.parent.holidays[i].from);
                    toDate = this.parent.dateValidationModule.getDateFromFormat(this.parent.holidays[i].to);
                    toDate.setDate(toDate.getDate() + 1);
                    fromDate.setHours(0, 0, 0, 0);
                    toDate.setHours(0, 0, 0, 0);
                }
                else if (this.parent.holidays[i].from) {
                    fromDate = this.parent.dateValidationModule.getDateFromFormat(this.parent.holidays[i].from);
                    fromDate.setHours(0, 0, 0, 0);
                }
                else Eif (this.parent.holidays[i].to) {
                    fromDate = this.parent.dateValidationModule.getDateFromFormat(this.parent.holidays[i].to);
                    fromDate.setHours(0, 0, 0, 0);
                }
                var width = (this.parent.holidays[i].from && this.parent.holidays[i].to) ?
                    this.parent.dataOperation.getTaskWidth(fromDate, toDate) : this.parent.perDayWidth;
                var left = this.parent.dataOperation.getTaskLeft(fromDate, false, true);
                var align = this.parent.enableRtl ? "right:" + left + "px;" : "left:" + left + "px;";
                var holidayDiv = ej2_base_1.createElement('div', {
                    className: cls.holidayElement, styles: align + " width:" + width + "px; height:100%;"
                });
                var spanTop = (viewportHeight < height) ? viewportHeight / 2 : height / 2;
                var spanElement = ej2_base_1.createElement('span', {
                    className: cls.holidayLabel, styles: "top:" + spanTop + "px;left:" + (width / 2) + "px;"
                });
                var property = this.parent.disableHtmlEncode ? 'textContent' : 'innerHTML';
                spanElement[property] = this.parent.holidays[i].label ? this.parent.holidays[i].label : '';
                if (this.parent.enableHtmlSanitizer && typeof (spanElement[property]) === 'string') {
                    spanElement[property] = ej2_base_1.SanitizeHtmlHelper.sanitize(spanElement[property]);
                }
                holidayDiv.appendChild(spanElement);
                if (this.parent.holidays[i].cssClass) {
                    holidayDiv.classList.add(this.parent.holidays[i].cssClass);
                }
                container.appendChild(holidayDiv);
            }
            return container;
        };
        NonWorkingDay.prototype.renderWeekends = function () {
            if (this.parent.highlightWeekends) {
                this.createNonworkingContainer();
                if (!this.nonworkingContainer.contains(this.weekendContainer)) {
                    this.weekendContainer = ej2_base_1.createElement('div', {
                        className: cls.weekendContainer
                    });
                    if (this.parent.enableTimelineVirtualization) {
                        this.weekendContainer.style.height = '100%';
                        this.weekendContainer.style.zIndex = '-1';
                    }
                    this.nonworkingContainer.appendChild(this.weekendContainer);
                }
                this.weekendContainer.innerHTML = this.getWeekendElements().innerHTML;
            }
            else Iif (this.weekendContainer) {
                ej2_base_1.remove(this.weekendContainer);
                if (this.nonworkingContainer && this.nonworkingContainer.childNodes.length === 0) {
                    ej2_base_1.remove(this.nonworkingContainer);
                }
            }
        };
        NonWorkingDay.prototype.getWeekendElements = function () {
            var container = ej2_base_1.createElement('div');
            var leftValueForStartDate = (this.parent.enableTimelineVirtualization &&
                this.parent.ganttChartModule.scrollObject.element.scrollLeft !== 0)
                ? this.parent.ganttChartModule.scrollObject.getTimelineLeft() : null;
            var startDate = (this.parent.enableTimelineVirtualization && !ej2_base_2.isNullOrUndefined(leftValueForStartDate))
                ? new Date((this.parent.timelineModule['dateByLeftValue'](leftValueForStartDate)).getTime()) :
                new Date(this.parent.timelineModule.timelineStartDate.getTime());
            var endDate = this.parent.enableTimelineVirtualization ? new Date((this.parent.timelineModule.weekendEndDate).getTime()) :
                new Date(this.parent.timelineModule.timelineEndDate.getTime());
            var nonWorkingIndex = this.parent.nonWorkingDayIndex;
            var isFirstCell = true;
            var isFirstExecution = true;
            this.weekendWidthUpdated = false;
            do {
                if (nonWorkingIndex.indexOf(startDate.getDay()) !== -1) {
                    var left = this.parent.dataOperation.getTaskLeft(startDate, false, true);
                    var width = this.parent.perDayWidth;
                    if (isFirstCell) {
                        var start = new Date(startDate.getTime());
                        var tempEnd = new Date(start.getTime());
                        tempEnd.setDate(tempEnd.getDate() + 1);
                        tempEnd.setHours(0, 0, 0, 0);
                        width = this.parent.dataOperation.getTaskWidth(start, tempEnd);
                        isFirstCell = false;
                    }
                    var sDate = new Date(startDate);
                    var dubDate = new Date(startDate);
                    sDate.setDate(sDate.getDate() + 1);
                    var sDateOffset = sDate.getTimezoneOffset();
                    var dubDateOffset = dubDate.getTimezoneOffset();
                    if (!isFirstExecution) {
                        var isHourTimeline = (this.parent.timelineModule.bottomTier === 'Hour' &&
                            this.parent.timelineModule.customTimelineSettings.bottomTier.count === 1) ||
                            (this.parent.timelineModule.topTier === 'Hour' &&
                                this.parent.timelineModule.customTimelineSettings.topTier.count === 1 &&
                                this.parent.timelineModule.bottomTier === 'Minutes' &&
                                (this.parent.timelineModule.customTimelineSettings.bottomTier.count === 30 ||
                                    this.parent.timelineModule.customTimelineSettings.bottomTier.count === 15));
                        Iif (sDateOffset !== this.parent.timelineModule.timelineStartDate.getTimezoneOffset() &&
                            !this.weekendWidthUpdated) {
                            if (isHourTimeline && sDateOffset < dubDateOffset) {
                                width = width - (this.parent.perDayWidth / 24);
                                this.weekendWidthUpdated = true;
                            }
                        }
                    }
                    else {
                        isFirstExecution = false;
                    }
                    var align = this.parent.enableRtl ? "right:" + left + "px;" : "left:" + left + "px;";
                    var weekendDiv = ej2_base_1.createElement('div', {
                        className: cls.weekend, styles: align + " width:" + width + "px;height:100%;"
                    });
                    container.appendChild(weekendDiv);
                }
                startDate.setDate(startDate.getDate() + 1);
                startDate.setHours(0, 0, 0, 0);
            } while (startDate < endDate);
            return container;
        };
        NonWorkingDay.prototype.updateHolidayLabelHeight = function () {
            var height = this.parent.getContentHeight();
            var gantttable = document.getElementById(this.parent.element.id);
            var toolbarHeight = 0;
            if (!ej2_base_2.isNullOrUndefined(this.parent.toolbarModule) && !ej2_base_2.isNullOrUndefined(this.parent.toolbarModule.element)) {
                toolbarHeight = this.parent.toolbarModule.element.offsetHeight;
            }
            var viewportHeight = (this.parent.height === 'auto') ? gantttable.offsetHeight - toolbarHeight - this.parent.ganttChartModule.chartTimelineContainer.offsetHeight :
                this.parent.ganttHeight - toolbarHeight - this.parent.ganttChartModule.chartTimelineContainer.offsetHeight;
            var top = (viewportHeight < height) ? viewportHeight / 2 : height / 2;
            var labels = this.holidayContainer.querySelectorAll('.' + cls.holidayLabel);
            for (var i = 0; i < labels.length; i++) {
                labels[i].style.top = ej2_base_1.formatUnit(top);
            }
        };
        NonWorkingDay.prototype.updateContainerHeight = function () {
            var height = this.parent.getContentHeight();
            if (this.holidayContainer) {
                this.holidayContainer.style.height = ej2_base_1.formatUnit(height);
                this.updateHolidayLabelHeight();
            }
            if (this.weekendContainer) {
                this.weekendContainer.style.height = ej2_base_1.formatUnit(height);
            }
        };
        NonWorkingDay.prototype.removeContainers = function () {
            if (this.holidayContainer) {
                ej2_base_1.remove(this.holidayContainer);
            }
            if (this.weekendContainer) {
                ej2_base_1.remove(this.weekendContainer);
            }
            Eif (this.nonworkingContainer) {
                ej2_base_1.remove(this.nonworkingContainer);
            }
        };
        return NonWorkingDay;
    }());
    exports.NonWorkingDay = NonWorkingDay;
});