@syncfusion/ej2-gantt
Version:
Essential JS 2 Gantt Component
10 lines • 1.18 MB
JavaScript
/*!
* filename: ej2-gantt.min.js
* version : 29.1.35
* Copyright Syncfusion Inc. 2001 - 2024. All rights reserved.
* Use of this code is subject to the terms of our license.
* A copy of the current license can be obtained at any time by e-mailing
* licensing@syncfusion.com. Any infringement will be prosecuted under
* applicable laws.
*/
this.ej=this.ej||{},this.ej.gantt=function(e,t,i,r,a,n,s,o,l,d,h,p,u,c,g){"use strict";function f(e,t,i){for(var r=e;r&&(i?r.id!==t:!r.classList.contains(t));)r=r.parentElement;return r}function m(e){return t.isNullOrUndefined(e.startDate)&&t.isNullOrUndefined(e.endDate)&&t.isNullOrUndefined(e.duration)?null:!(t.isNullOrUndefined(e.startDate)||t.isNullOrUndefined(e.endDate)||t.isNullOrUndefined(e.duration))}function y(e){return!(!e.dataSource||e.dataSource instanceof r.DataManager||!("result"in e.dataSource))}function D(e){for(var t={},i=0,r=Object.keys(e);i<r.length;i++){var a=r[i];t[e[a]]=a}return t}function v(e){return!t.isNullOrUndefined(e)&&"object"==typeof e&&0===Object.keys(e).length}function k(e){var t=e.getFullYear(),i=e.getMonth(),r=e.getDate(),a=e.getHours(),n=e.getMinutes(),s=e.getSeconds(),o=e.getMilliseconds();return Date.UTC(t,i,r,a,n,s,o)}function w(e){if(e instanceof r.DataManager){var t=e.adaptor;return t instanceof r.ODataAdaptor||t instanceof r.ODataV4Adaptor||t instanceof r.WebApiAdaptor||t instanceof r.WebMethodAdaptor||t instanceof r.CacheAdaptor||t instanceof r.RemoteSaveAdaptor||t instanceof r.UrlAdaptor}return!1}function b(e,i,r,a){if(r){for(var n=void 0,s=0;s<e.length;s++)n=o=i?e[parseInt(s.toString(),10)].taskData:t.extend({},e[parseInt(s.toString(),10)].taskData,{},!0);return n}for(var n=[],s=0;s<e.length;s++){!t.isNullOrUndefined(a)&&a.timezone&&T(e[s],a);var o=i?e[parseInt(s.toString(),10)].taskData:t.extend({},e[parseInt(s.toString(),10)].taskData,{},!0);n.push(o)}return n}function T(e,i){return e&&!t.isNullOrUndefined(e.ganttProperties)&&(e.taskData[i.taskFields.startDate]=i.dateValidationModule.remove(e.ganttProperties.startDate,i.timezone),null!==i.taskFields.endDate&&(e.taskData[i.taskFields.endDate]=i.dateValidationModule.remove(e.ganttProperties.endDate,i.timezone)),(i.taskFields.baselineEndDate||i.taskFields.baselineStartDate)&&(e.taskData[i.taskFields.baselineStartDate]=i.dateValidationModule.remove(e.ganttProperties.baselineStartDate,i.timezone),e.taskData[i.taskFields.baselineEndDate]=i.dateValidationModule.remove(e.ganttProperties.baselineEndDate,i.timezone))),null}function P(e,t){for(var i,r=0;r<t.length;r++)i=new RegExp("\\{"+r+"\\}","gm"),e=e.replace(i,t[r].toString());return e}function S(e,i,r,a){for(var n=-1,s=0;s<r.length;s++)if(t.getValue(i,r[s])===t.getValue(i,e)&&t.isNullOrUndefined(a)||!t.isNullOrUndefined(a)&&t.getValue(i,r[s])===t.getValue(i,e)&&t.getValue(a,r[s])===t.getValue(a,e)){n=s;break}return n}function C(e){return 76*e/92}function R(e){return 92*e/76}function M(){return x++}var x=0,O=function(){function e(e){this.fromSegments=!1,this.mondayTimeRangeLength=0,this.tuesdayTimeRangeLength=0,this.wednesdayTimeRangeLength=0,this.thursdayTimeRangeLength=0,this.fridayTimeRangeLength=0,this.saturdayTimeRangeLength=0,this.sundayTimeRangeLength=0,this.parent=e}return e.prototype.isValidateNonWorkDays=function(e){return!t.isNullOrUndefined(e)&&e.isAutoSchedule&&(!this.parent.includeWeekend||this.parent.totalHolidayDates.length>0)||t.isNullOrUndefined(e)&&(!this.parent.includeWeekend||this.parent.totalHolidayDates.length>0)},e.prototype.checkStartDate=function(e,i,r,a){if(t.isNullOrUndefined(e))return null;var n=new Date(e.getTime()),s=this.parent.getCurrentDayStartTime(n),o=this.parent.getCurrentDayEndTime(n),l=new Date(e.getTime()),d=this.getSecondsInDecimal(l);if(r=t.isNullOrUndefined(r)?!t.isNullOrUndefined(i)&&i.isMilestone:r,d<s&&(!r||a))this.setTime(s,l);else if(d<s&&r)this.setTime(s,l);else if(d===o&&(!i||!r)||d>o)l.setDate(l.getDate()+1),s=this.parent.getCurrentDayStartTime(l),this.setTime(s,l);else if(d>s&&d<o){var h=this.parent.workingTimeRanges;this.parent.weekWorkingTime.length>0&&(h=this.parent.getWorkingRange(l));for(var p=0;p<h.length;p++){var u=h[p];if(d>=u.to&&h[p+1]&&d<h[p+1].from){(d!==u.to||i&&r)&&d===u.to||this.setTime(h[p+1].from,l);break}}}var c;if(!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping)return new Date(l.getTime());do{c=new Date(l.getTime());var g=this.parent.totalHolidayDates.length;if(this.isValidateNonWorkDays(i)){s=this.parent.getCurrentDayStartTime(c),i&&(o=this.parent.getCurrentDayEndTime(i.endDate?i.isAutoSchedule?i.endDate:i.autoEndDate:c));var f=!r||a?s:o;if(!this.parent.includeWeekend){var m=new Date(l.getTime());l=this.getNextWorkingDay(l),f=this.parent.getCurrentDayStartTime(l),m.getTime()===l.getTime()||r||this.setTime(f,l)}for(var y=0;y<g;y++){var D=this.getDateFromFormat(new Date(this.parent.totalHolidayDates[y])),v=new Date(D.getTime());D.setHours(0,0,0,0),v.setHours(23,59,59,59),l.getTime()>=D.getTime()&&l.getTime()<v.getTime()&&(l.setDate(l.getDate()+1),f=this.parent.getCurrentDayStartTime(l),this.setTime(f,l))}}}while(c.getTime()!==l.getTime());return new Date(l.getTime())},e.prototype.checkEndDate=function(e,i,r){if(t.isNullOrUndefined(e))return null;var a,n;if(this.parent.weekWorkingTime.length>0){var s=e;(!this.parent.includeWeekend&&i&&i.isAutoSchedule||this.parent.editModule&&this.parent.editModule.taskbarEditModule&&this.parent.editModule.taskbarEditModule.taskBarEditRecord&&!this.parent.editModule.taskbarEditModule.taskBarEditRecord.ganttProperties.isAutoSchedule)&&(s=this.getNextWorkingDay(e)),a=this.parent.getStartTime(s),n=this.parent.getEndTime(s)}else a=this.parent.defaultStartTime,n=this.parent.defaultEndTime;var o=new Date(e.getTime()),l=this.getSecondsInDecimal(o);if(l>n)this.setTime(n,o);else if(l<=a&&!r){var d=this.parent.taskFields;this.parent.editModule&&this.parent.editModule.editedRecord&&!this.parent.editModule.editedRecord[d.startDate]&&this.parent.editModule.editedRecord[d.endDate]?o.setDate(o.getDate()):o.setDate(o.getDate()-1),n=this.parent.getCurrentDayEndTime(o),this.setTime(n,o)}else if(l>a&&l<n)for(var h=0;h<this.parent.workingTimeRanges.length;h++)if(l>this.parent.workingTimeRanges[h].to&&this.parent.workingTimeRanges[h+1]&&l<=this.parent.workingTimeRanges[h+1].from){this.setTime(this.parent.workingTimeRanges[h].to,o);break}var p;if(!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping)return t.isNullOrUndefined(o)||(n=this.parent.getCurrentDayEndTime(e),this.setTime(n,o)),new Date(o.getTime());do{p=new Date(o.getTime());var u=this.parent.totalHolidayDates.length;if(this.isValidateNonWorkDays(i)){if(!this.parent.includeWeekend){var c=new Date(o.getTime());o=this.getPreviousWorkingDay(o),n=this.parent.getCurrentDayEndTime(o),c.getTime()!==o.getTime()&&this.setTime(n,o)}for(var g=0;g<u;g++){var f=this.getDateFromFormat(new Date(this.parent.totalHolidayDates[g])),m=new Date(f.getTime()),y=new Date(o.getTime());y.setMinutes(o.getMilliseconds()-2),f.setHours(0,0,0,0),m.setHours(23,59,59,59),(o.getTime()>=f.getTime()&&o.getTime()<m.getTime()||y.getTime()>=f.getTime()&&y.getTime()<m.getTime())&&(o.setDate(o.getDate()-1),n=this.parent.getCurrentDayEndTime(o),o.getTime()===f.getTime()&&86400===n&&0===this.getSecondsInDecimal(o)||this.setTime(n,o))}}}while(p.getTime()!==o.getTime());return new Date(o.getTime())},e.prototype.checkBaselineStartDate=function(e,i){if(t.isNullOrUndefined(e))return null;var r=this.parent.getCurrentDayStartTime(e),a=this.parent.getCurrentDayEndTime(i&&i.endDate?i.isAutoSchedule?i.endDate:i.autoEndDate:e),n=new Date(e.getTime()),s=this.getSecondsInDecimal(n);if(s<r)this.setTime(r,n);else if(s>a)n.setDate(n.getDate()+1),r=this.parent.weekWorkingTime.length>0?this.parent.getStartTime(n):this.parent.defaultStartTime,this.setTime(r,n);else if(s>r&&s<a)for(var o=0;o<this.parent.workingTimeRanges.length;o++)if(s>this.parent.workingTimeRanges[o].to&&this.parent.workingTimeRanges[o+1]&&s<this.parent.workingTimeRanges[o+1].from){this.setTime(this.parent.workingTimeRanges[o+1].from,n);break}return n},e.prototype.checkBaselineEndDate=function(e,i){if(t.isNullOrUndefined(e))return null;var r=this.parent.getCurrentDayEndTime(e),a=this.parent.getCurrentDayStartTime(i&&i.startDate?i.isAutoSchedule?i.startDate:i.autoStartDate:e),n=new Date(e.getTime()),s=this.getSecondsInDecimal(n);if(s>r)this.setTime(r,n);else if(s<a&&!t.isNullOrUndefined(i)&&!i.isMilestone)n.setDate(n.getDate()-1),r=this.parent.getCurrentDayEndTime(n),this.setTime(r,n);else if(s>a&&s<r)for(var o=0;o<this.parent.workingTimeRanges.length;o++)if(s>this.parent.workingTimeRanges[o].to&&this.parent.workingTimeRanges[o+1]&&s<=this.parent.workingTimeRanges[o+1].from){this.setTime(this.parent.workingTimeRanges[o].to,n);break}return i&&i.baselineStartDate&&n&&i.baselineStartDate.getTime()>n.getTime()&&n.setDate(n.getDate()+1),n},e.prototype.calculateStartDate=function(e){var i=e.ganttProperties,r=null;t.isNullOrUndefined(i.endDate)||t.isNullOrUndefined(i.duration)||(r=this.getStartDate(i.endDate,i.duration,i.durationUnit,i)),this.parent.setRecordValue("startDate",r,i,!0),this.parent.taskFields.startDate&&this.parent.dataOperation.updateMappingData(e,"startDate")},e.prototype.calculateEndDate=function(e){var i,r,a=e.ganttProperties,n=null;if(t.isNullOrUndefined(a.startDate))n=e[this.parent.taskFields.endDate],t.isNullOrUndefined(n)||(r=this.parent.getCurrentDayEndTime(n),this.setTime(r,n)),this.parent.setRecordValue("endDate",n,a,!0);else{if(!t.isNullOrUndefined(a.endDate)&&t.isNullOrUndefined(a.duration)&&(1===this.compareDates(a.startDate,a.endDate)&&(this.parent.setRecordValue("startDate",new Date(a.endDate.getTime()),a,!0),i=this.parent.getCurrentDayStartTime(a.isAutoSchedule?a.autoStartDate:a.startDate),r=this.parent.getCurrentDayEndTime(a.isAutoSchedule?a.autoEndDate:a.endDate),this.setTime(i,a.startDate)),this.calculateDuration(e)),!t.isNullOrUndefined(a.duration)){var s=!t.isNullOrUndefined(a.segments)&&a.segments.length>1?this.totalDuration(a.segments):a.duration;n=this.getEndDate(a.startDate,s,a.durationUnit,a,!1)}this.parent.setRecordValue("endDate",n,a,!0)}this.parent.taskFields.endDate&&this.parent.dataOperation.updateMappingData(e,"endDate")},e.prototype.totalDuration=function(e){for(var t=0,i=0;i<e.length;i++)t+=e[i].duration+e[i].offsetDuration;return t},e.prototype.calculateDuration=function(e){var i,r=e.ganttProperties;i=!t.isNullOrUndefined(r.segments)&&r.segments.length>0&&!t.isNullOrUndefined(this.parent.editModule.taskbarEditModule)?this.parent.editModule.taskbarEditModule.sumOfDuration(r.segments):t.isNullOrUndefined(this.parent.taskFields.milestone)||t.isNullOrUndefined(r.startDate)||t.isNullOrUndefined(r.endDate)||r.startDate.getTime()!==r.endDate.getTime()||!1!==e.taskData[this.parent.taskFields.milestone]?this.getDuration(r.startDate,r.endDate,r.durationUnit,r.isAutoSchedule,r.isMilestone):1,this.parent.setRecordValue("duration",i,r,!0);var a=this.parent.columnByField[this.parent.columnMapping.duration];if(!(t.isNullOrUndefined(this.parent.editModule)||t.isNullOrUndefined(this.parent.editModule.cellEditModule)||this.parent.editModule.cellEditModule.isCellEdit||t.isNullOrUndefined(a))){if(!t.isNullOrUndefined(a.edit)&&!t.isNullOrUndefined(a.edit.read)){var n=this.parent.editModule.dialogModule.dialog;if(!t.isNullOrUndefined(n)){var s=n.querySelector("#"+this.parent.element.id+"Duration").ej2_instances[0];t.isNullOrUndefined(s)||s.value===i.toString()||(s.value=i.toString(),s.dataBind())}}this.parent.taskFields.duration&&(this.parent.dataOperation.updateMappingData(e,"duration"),this.parent.taskFields.durationUnit&&this.parent.dataOperation.updateMappingData(e,"durationUnit"))}},e.prototype.getNonworkingTime=function(e,i,r,a){a=!!t.isNullOrUndefined(a)||a;var n=this.parent.includeWeekend||!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping||!r?0:this.getWeekendCount(e,i),s=this.getNumberOfSeconds(e,i,a),o=!r||!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping?0:this.getHolidaysCount(e,i),l=(s-86400*n-86400*o)/86400,d=this.getNonWorkingSecondsOnDate(e,i,r);return(this.parent.weekWorkingTime.length>0?this.nonWorkingSeconds(e,i,r,l):l*(86400-this.parent.secondsPerDay))+86400*n+86400*o+d},e.prototype.nonWorkingSeconds=function(e,i,r,a,n){var s=e.getTime()>i.getTime()?new Date(i.getTime()):new Date(e.getTime()),o=e.getTime()>i.getTime()?new Date(e.getTime()):new Date(i.getTime()),l=0,d=0;if(n){var h=this.parent.getCurrentDayStartTime(s),p=this.parent.getCurrentDayEndTime(s);s.getHours()<p/3600&&s.getHours()>=h/3600||s.setDate(s.getDate()+1)}else s.setDate(s.getDate()+1),s.setHours(0,0,0,0),o.setHours(0,0,0,0);if(!(a>0||t.isNullOrUndefined(a)))return 0;for(;n&&s.getTime()<=o.getTime()||!n&&s.getTime()<o.getTime();){if(r){if(this.isOnHolidayOrWeekEnd(s,!0))do{s.setDate(s.getDate()+1)}while(this.isOnHolidayOrWeekEnd(s,!0));this.parent.includeWeekend||this.getNextWorkingDay(s)}if(s.getTime()<=o.getTime()){d++;var u=this.parent.getSecondsPerDay(s);if(l+=n?u:86400-u,s.setDate(s.getDate()+1),r){if(this.isOnHolidayOrWeekEnd(s,!0))do{s.setDate(s.getDate()+1)}while(this.isOnHolidayOrWeekEnd(s,!0));this.parent.includeWeekend||this.getNextWorkingDay(s)}}}return n&&(l>0?l/=d:l=this.parent.secondsPerDay),l},e.prototype.getDuration=function(e,i,r,a,n,s){if(t.isNullOrUndefined(e)||t.isNullOrUndefined(i))return null;s=!!t.isNullOrUndefined(s)||s;var o,l=0,d=this.getTimeDifference(e,i,s)/1e3-this.getNonworkingTime(e,i,a,s);return o=this.parent.weekWorkingTime.length>0?this.nonWorkingSeconds(e,i,a,void 0,!0):this.parent.secondsPerDay,l=n&&this.parent.getFormatedDate(e)===this.parent.getFormatedDate(i)?0:r&&"day"!==r?"minute"===r?d/60:d/3600:d/o,parseFloat(l.toString())},e.prototype.getDurationAsSeconds=function(e,t,i){var r;return r=this.parent.weekWorkingTime.length>0?this.parent.getSecondsPerDay(i):this.parent.secondsPerDay,t&&"day"!==t.toLocaleLowerCase()?"hour"===t.toLocaleLowerCase()?3600*e:60*e:r*e},e.prototype.getEndDate=function(e,t,i,r,a){var n,s=new Date(e.getTime()),o=new Date(e.getTime()),l=new Date(e.getTime());n=this.parent.weekWorkingTime.length>0&&(!i||"day"===i.toLocaleLowerCase())?this.calculateSecondDuration(t,l,n,e,!0):this.getDurationAsSeconds(t,i,e);for(;n>0;)o.setSeconds(o.getSeconds()+n),(n-=n-this.getNonworkingTime(s,o,r.isAutoSchedule,!0))>0&&(o=this.checkStartDate(o,r,a)),s=new Date(o.getTime());return o},e.prototype.getStartDate=function(e,t,i,r,a){var n,s=new Date(e.getTime()),o=new Date(e.getTime()),l=new Date(s.getTime());n=this.parent.weekWorkingTime.length>0?this.calculateSecondDuration(t,l,n,s,!1):this.getDurationAsSeconds(t,i,s);for(;n>0;)o.setSeconds(o.getSeconds()-n),(n-=n-this.getNonworkingTime(o,s,r.isAutoSchedule,!0))>0&&(s=this.checkEndDate(o,r)),s=new Date(o.getTime());if(a&&r.isMilestone){o.setDate(o.getDate()-1);var d=this.parent.getCurrentDayEndTime(r.endDate?r.isAutoSchedule?r.endDate:r.autoEndDate:o);this.parent.dateValidationModule.setTime(d,o),o=this.parent.dateValidationModule.checkStartDate(o,r,!0)}return o},e.prototype.calculateSecondDuration=function(e,t,i,r,a){if(e<1)i=this.parent.getSecondsPerDay(t)*e;else{i=0;var n=e,s=this.parent.getCurrentDayStartTime(t),o=this.parent.getCurrentDayEndTime(t);for(t.getHours()<o/3600&&t.getHours()>s/3600||!this.fromSegments||(a?t.setDate(t.getDate()+1):t.setDate(t.getDate()-1));n>0;){if(this.isOnHolidayOrWeekEnd(t,!0))do{a?t.setDate(t.getDate()+1):t.setDate(t.getDate()-1)}while(this.isOnHolidayOrWeekEnd(t,!0));this.parent.includeWeekend||(t=a?this.getNextWorkingDay(t):this.getPreviousWorkingDay(t));var l=this.parent.getSecondsPerDay(t),d=0;if(this.getSecondsInDecimal(r)!==this.parent.getStartTime(r)&&!Number.isInteger(n)){var h=e.toString().split(".");l*=d=parseFloat("."+h[1]),n-=d}n<1&&(l*=n),i+=l,a?t.setDate(t.getDate()+1):t.setDate(t.getDate()-1),d||n--}}return i},e.prototype.getProjectStartDate=function(e,i){if(!t.isNullOrUndefined(this.parent.cloneProjectStartDate)){"string"==typeof this.parent.cloneProjectStartDate&&(this.parent.cloneProjectStartDate=this.getDateFromFormat(this.parent.cloneProjectStartDate));o=this.checkStartDate(this.parent.cloneProjectStartDate);return this.parent.cloneProjectStartDate=o,new Date(o.getTime())}if(t.isNullOrUndefined(this.parent.projectStartDate)){if(t.isNullOrUndefined(i))return null;var r=this.parent.flatData,a=void 0;r.length>0?a=r[0].ganttProperties.startDate:(a=new Date).setHours(0,0,0,0);for(var n=1;n<r.length;n++){var s=r[n].ganttProperties.startDate;t.isNullOrUndefined(s)||-1!==this.compareDates(s,a)||(a=s)}this.parent.cloneProjectStartDate=this.checkStartDate(a,e)}else{var o=this.getDateFromFormat(this.parent.projectStartDate);this.parent.cloneProjectStartDate=this.checkStartDate(o)}return new Date(this.parent.cloneProjectStartDate.getTime())},e.prototype.getValidStartDate=function(e,i){var r=null,a=i?e.autoStartDate:e.startDate,n=i?e.autoEndDate:e.endDate,s=!e.isAutoSchedule&&e.autoDuration?e.autoDuration:e.duration;if(t.isNullOrUndefined(a))if(t.isNullOrUndefined(n)){if(!t.isNullOrUndefined(s)){var o=this.parent.getTaskByUniqueID(e.uniqueID);if(this.parent.allowUnscheduledTasks&&o&&o.parentItem&&t.isNullOrUndefined(a)&&t.isNullOrUndefined(n)){for(var l=this.parent.getParentTask(o.parentItem);l&&!l.ganttProperties.startDate;)l=this.parent.getParentTask(l.parentItem);r=l&&l.ganttProperties.startDate?l.ganttProperties.startDate:this.parent.cloneProjectStartDate}else r=this.getProjectStartDate(e)}}else{r=new Date(n.getTime());var d=this.parent.getCurrentDayStartTime(r);this.setTime(d,r)}else r=new Date(a.getTime());return r},e.prototype.getValidEndDate=function(e,i){var r=null,a=i?e.autoStartDate:e.startDate,n=i?e.autoEndDate:e.endDate,s=i?e.autoDuration:e.duration;if(t.isNullOrUndefined(n))if(t.isNullOrUndefined(a)){if(!t.isNullOrUndefined(s)){var o=this.getValidStartDate(e);o&&(r=this.getEndDate(o,s,e.durationUnit,e,!1))}}else if(e.isMilestone)r=this.checkStartDate(a);else{r=new Date(a.getTime());var l=this.parent.getCurrentDayEndTime(n||r);this.setTime(l,r)}else r=new Date(n.getTime());return r},e.prototype.getWorkingTime=function(e,i,r,a,n,s,o,l){if(!t.isNullOrUndefined(i.from)&&!t.isNullOrUndefined(i.to)){r.setHours(0,0,0,0);var d=new Date(r.getTime());r.setTime(r.getTime()+36e5*i.from);var h=new Date(r.getTime());if(24===i.to){d.setTime(d.getTime()+864e5)}else d.setTime(d.getTime()+36e5*i.to);var p=new Date(d.getTime()),u=p.getTime()-h.getTime(),c=this.getSecondsInDecimal(h),g=this.getSecondsInDecimal(p);0===g&&(g=86400),a+=u/1e3,0===n&&(this.parent.defaultStartTime=c,this.parent.weekWorkingTime.length>0&&this.assignStartTime(e,c)),n!==this[e.toLowerCase()+"TimeRangeLength"]-1&&""!==e||(this.parent.defaultEndTime=g,this.parent.weekWorkingTime.length>0&&this.assignEndTime(e,g)),n>0?""===e?(s.push(s[s.length-1]+c-o[n-1].to),o[n-1].to<c&&l.push({from:o[n-1].to,to:c,isWorking:!1,interval:c-o[n-1].to})):(this.parent[e.toLowerCase()+"NonWorkingHours"].push(this.parent[e.toLowerCase()+"NonWorkingHours"][this.parent[e.toLowerCase()+"NonWorkingHours"].length-1]+c-this.parent[e.toLowerCase()+"NonWorkingTimeRanges"][n-1].to),this.parent[e.toLowerCase()+"WorkingTimeRanges"][n-1].to<c&&this.parent[e.toLowerCase()+"NonWorkingTimeRanges"].push({from:this.parent[e.toLowerCase()+"WorkingTimeRanges"][n-1].to,to:c,isWorking:!1,interval:c-this.parent[e.toLowerCase()+"WorkingTimeRanges"][n-1].to})):""===e?(s.push(0),l.push({from:0,to:c,isWorking:!1,interval:c})):(this.parent[e.toLowerCase()+"NonWorkingHours"].push(0),this.parent[e.toLowerCase()+"NonWorkingTimeRanges"].push({from:0,to:c,isWorking:!1,interval:c})),""===e?(o.push({from:c,to:g}),l.push({from:c,to:g,isWorking:!0,interval:g-c})):(this.parent[e.toLowerCase()+"WorkingTimeRanges"].push({from:c,to:g}),this.parent[e.toLowerCase()+"NonWorkingTimeRanges"].push({from:c,to:g,isWorking:!0,interval:g-c}))}return a},e.prototype.assignStartTime=function(e,t){switch(e){case"Monday":this.parent.mondayDefaultStartTime=t;break;case"Tuesday":this.parent.tuesdayDefaultStartTime=t;break;case"Wednesday":this.parent.wednesdayDefaultStartTime=t;break;case"Thursday":this.parent.thursdayDefaultStartTime=t;break;case"Friday":this.parent.fridayDefaultStartTime=t;break;case"Saturday":this.parent.saturdayDefaultStartTime=t;break;case"Sunday":this.parent.sundayDefaultStartTime=t}},e.prototype.assignEndTime=function(e,t){switch(e){case"Monday":this.parent.mondayDefaultEndTime=t;break;case"Tuesday":this.parent.tuesdayDefaultEndTime=t;break;case"Wednesday":this.parent.wednesdayDefaultEndTime=t;break;case"Thursday":this.parent.thursdayDefaultEndTime=t;break;case"Friday":this.parent.fridayDefaultEndTime=t;break;case"Saturday":this.parent.saturdayDefaultEndTime=t;break;case"Sunday":this.parent.sundayDefaultEndTime=t}},e.prototype.calculateWeekWorkTime=function(e,t,i,r,a,n,s){for(var o=0,l=0;l<t.length;l++){var d=t[l];o+=this.getWorkingTime(e,d,i,r,l,a,n,s)}return this.parent[e.toLowerCase()+"DefaultStartTime"]/3600!=24&&this.parent[e.toLowerCase()+"NonWorkingTimeRanges"].push({from:this.parent[e.toLowerCase()+"DefaultEndTime"],to:86400,isWorking:!1,interval:86400-this.parent[e.toLowerCase()+"DefaultEndTime"]}),o},e.prototype.getSecondsPerDay=function(){var e=0,i=new Date("10/11/2018");this.parent.nonWorkingHours=[];var r=this.parent.nonWorkingHours;this.parent.workingTimeRanges=[],this.parent.workingTimeRanges=[];var a=this.parent.workingTimeRanges;this.parent.nonWorkingTimeRanges=[];for(var n=this.parent.nonWorkingTimeRanges,s=0,o=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];s<o.length;s++)this[(y=o[s]).toLowerCase()+"TimeRangeLength"]=this.parent.dayWorkingTime.length;if(this.parent.weekWorkingTime.length>0){for(var l=0;l<this.parent.weekWorkingTime.length;l++)this[this.parent.weekWorkingTime[l].dayOfWeek.toLowerCase()+"TimeRangeLength"]=this.parent.weekWorkingTime[l].timeRange.length;for(var d=this.parent.weekWorkingTime,h=this.parent.dayWorkingTime,p=0,u=d;p<u.length;p++){var c=u[p];if(c.timeRange&&c.timeRange.length>0){var g=this.calculateWeekWorkTime(c.dayOfWeek,c.timeRange,i,e,r,a,n);this.parent[c.dayOfWeek.toLowerCase()+"Seconds"]=g}}for(var f=0,m=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];f<m.length;f++){var y=m[f],D=this.parent[y.toLowerCase()+"DefaultStartTime"];if(t.isNullOrUndefined(D)){var v=this.calculateWeekWorkTime(y,h,i,e,r,a,n);this.parent[y.toLowerCase()+"Seconds"]=v}}}for(var k=this.parent.dayWorkingTime,w=k.length,b=0,T=0;T<w;T++){var P=k[T];b+=this.getWorkingTime("",P,i,e,T,r,a,n)}return this.parent.defaultEndTime/3600!=24&&n.push({from:this.parent.defaultEndTime,to:86400,isWorking:!1,interval:86400-this.parent.defaultEndTime}),e=b},e.prototype.getDurationValue=function(e,i){var r=null,a=null;if("string"==typeof e){var n=e.match(/(\d*\.*\d+|.+$)/g);if(n&&n.length<=2){a=parseFloat(n[0].toString().trim());var s=n[1]?n[1].toString().trim().toLowerCase():null;-1!==t.getValue("minute",this.parent.durationUnitEditText).indexOf(s)?r="minute":-1!==t.getValue("hour",this.parent.durationUnitEditText).indexOf(s)?r="hour":-1!==t.getValue("day",this.parent.durationUnitEditText).indexOf(s)&&(r="day")}}else a=e,r=null;return{duration:a,durationUnit:r}},e.prototype.getNextWorkingDay=function(e){var t=e.getDay();return-1!==this.parent.nonWorkingDayIndex.indexOf(t)?(e.setDate(e.getDate()+1),e=this.getNextWorkingDay(e)):e},e.prototype.getWeekendCount=function(e,t){var i=0,r=new Date(e.getTime()),a=new Date(t.getTime());for(r.setHours(0,0,0,0),r.setDate(r.getDate()+1),a.setHours(0,0,0,0);r.getTime()<a.getTime();)-1!==this.parent.nonWorkingDayIndex.indexOf(r.getDay())&&(i+=1),r.setDate(r.getDate()+1);return i},e.prototype.getNumberOfSeconds=function(e,t,i){var r=new Date(e.getTime()),a=new Date(t.getTime()),n=0;return r.setDate(r.getDate()+1),r.setHours(0,0,0,0),a.setHours(0,0,0,0),r.getTime()<a.getTime()&&(n=this.getTimeDifference(r,a,i)/1e3),n%86400!=0&&(n=n-n%86400+86400),n},e.prototype.getHolidaysCount=function(e,t){var i=0,r=this.parent.totalHolidayDates,a=new Date(e.getTime()),n=new Date(t.getTime());if(a.setDate(a.getDate()+1),a.setHours(0,0,0,0),n.setHours(0,0,0,0),a.getTime()<n.getTime())for(var s=0;s<r.length;s++){var o=this.getDateFromFormat(new Date(r[s]));a.getTime()<=o.getTime()&&n.getTime()>o.getTime()&&(!this.parent.includeWeekend&&-1===this.parent.nonWorkingDayIndex.indexOf(o.getDay())||this.parent.includeWeekend)&&(i+=1)}return i},e.prototype.getHolidayDates=function(){for(var e=this.parent.holidays,i=[],r=0;r<e.length;r++){var a=this.getDateFromFormat(e[r].from),n=this.getDateFromFormat(e[r].to);if(!t.isNullOrUndefined(a)||!t.isNullOrUndefined(n))if(t.isNullOrUndefined(a)||t.isNullOrUndefined(n)){var s=a||n;s.setHours(0,0,0,0),-1===i.indexOf(s.getTime())&&i.push(s.getTime())}else for(;a<=n;)a.setHours(0,0,0,0),-1===i.indexOf(a.getTime())&&i.push(a.getTime()),a.setDate(a.getDate()+1)}return i},e.prototype.isOnHolidayOrWeekEnd=function(e,i){if(i=t.isNullOrUndefined(i)?this.parent.includeWeekend:i,this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping||(i=!0),!i&&-1!==this.parent.nonWorkingDayIndex.indexOf(e.getDay()))return!0;for(var r=this.parent.totalHolidayDates,a=0;a<r.length;a++){var n=this.getDateFromFormat(new Date(r[a])),s=new Date(n.getTime());if(n.setHours(0,0,0,0),s.setHours(23,59,59,59),e.getTime()>=n.getTime()&&e.getTime()<s.getTime())return!0}return!1},e.prototype.getNonWorkingSecondsOnDate=function(e,i,r){var a,n,s=this.getSecondsInDecimal(e),o=this.getSecondsInDecimal(i),l=-1,d=-1,h=0,p=!(!r||!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping)&&this.isOnHolidayOrWeekEnd(e,null),u=!(!r||!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping)&&this.isOnHolidayOrWeekEnd(i,null);if(this.parent.weekWorkingTime.length>0){a=this.parent.getNonWorkingRange(e);for(g=0;g<a.length;g++)s>=(c=a[g]).from&&s<=c.to&&(l=g);n=this.parent.getNonWorkingRange(i);for(g=0;g<n.length;g++)o>=(c=n[g]).from&&o<=c.to&&(d=g)}else{a=this.parent.nonWorkingTimeRanges,n=this.parent.nonWorkingTimeRanges;for(g=0;g<a.length;g++){var c=a[g];s>=c.from&&s<=c.to&&(l=g),o>=c.from&&o<=c.to&&(d=g)}}if(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()){if(p)h+=86400-s;else for(g=l;g<a.length;g++)t.isNullOrUndefined(a[g])||a[g].isWorking||(h+=g===l?a[g].to-s:a[g].interval);if(u)h+=o;else for(g=0;g<=d;g++)n[g].isWorking||(h+=g===d?o-n[g].from:n[g].interval)}else if(l!==d)if(u)h+=o-s;else for(var g=l;g<=d;g++)t.isNullOrUndefined(a[g])||a[g].isWorking||(h+=g===l?a[g].to-s:g===d?o-a[g].from:a[g].interval);else u?h+=o-s:a[l].isWorking||(h=o-s);return h},e.prototype.getPreviousWorkingDay=function(e){var t=e.getDay(),i=0===t?6:t-1,r=this.parent.getCurrentDayEndTime(e);return-1!==this.parent.nonWorkingDayIndex.indexOf(t)||-1!==this.parent.nonWorkingDayIndex.indexOf(i)&&86400===r&&0===this.getSecondsInDecimal(e)?(e.setDate(e.getDate()-1),-1!==this.parent.nonWorkingDayIndex.indexOf(e.getDay())&&(e=this.getPreviousWorkingDay(e)),e):e},e.prototype.getNonWorkingDayIndex=function(){var e=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],t=e.length;0===this.parent.workWeek.length&&(this.parent.workWeek=["Monday","Tuesday","Wednesday","Thursday","Friday"]);for(var i=this.parent.workWeek.slice(),r=i.length,a=0;a<r;a++)i[a]=i[a].toLowerCase();this.parent.nonWorkingDayIndex=[];for(a=0;a<t;a++)-1===i.indexOf(e[a])&&this.parent.nonWorkingDayIndex.push(a)},e.prototype.setTime=function(e,t){var i=e/3600,r=(e-3600*(i=parseInt(i,10)))/60,a=e-3600*i-60*(r=parseInt(r,10));t.setHours(i,r,a)},e.prototype.getTimeDifference=function(e,t,i){var r=new Date(e.getTime()),a=new Date(t.getTime());return i&&this.updateDateWithTimeZone(r,a),a.getTime()-r.getTime()},e.prototype.updateDateWithTimeZone=function(e,t){var i,r,a=e.getTimezoneOffset(),n=t.getTimezoneOffset();if(a!==n){var s=new Date((new Date).getFullYear(),0,1).getTimezoneOffset();if(s!==a?(r=e,i=a):s!==n&&(r=t,i=n),s<0){o=s-i;r.setTime(r.getTime()+60*o*1e3)}else if(s>=0){var o=i-s;r.setTime(r.getTime()-60*o*1e3)}}},e.prototype.getSecondsInDecimal=function(e){return 60*e.getHours()*60+60*e.getMinutes()+e.getSeconds()+e.getMilliseconds()/1e3},e.prototype.offset=function(e,t){var i=e.getTimezoneOffset();try{var r=new Date(e.toLocaleString("en-US",{timeZone:t}));return isNaN(r.getTime())?0:(e.getTime()-r.getTime())/6e4+i}catch(e){return 0}},e.prototype.remove=function(e,i){return t.isNullOrUndefined(e)||(e=this.reverse(e,i,e.getTimezoneOffset())),e},e.prototype.reverse=function(e,t,i){"string"==typeof t&&(t=this.offset(e,t)),"string"==typeof i&&(i=this.offset(e,i));var r=e.getTimezoneOffset(),a=(e=new Date(e.getTime()+6e4*(t-i))).getTimezoneOffset();return new Date(e.getTime()+6e4*(a-r))},e.prototype.convert=function(e,t){var i=e.getTimezoneOffset(),r=this.offset(e,t);"string"==typeof i&&(i=this.offset(e,i)),"string"==typeof r&&(r=this.offset(e,r));var a=e.getTimezoneOffset(),n=(e=new Date(e.getTime()+6e4*(i-r))).getTimezoneOffset();return new Date(e.getTime()+6e4*(n-a))},e.prototype.getDateFromFormat=function(e,i){var r;if(t.isNullOrUndefined(e))return null;if(e instanceof Date)r=new Date(e.getTime());else{var a=this.parent.globalize.parseDate(e,{format:this.parent.getDateFormat(),type:"dateTime"});r=t.isNullOrUndefined(a)&&!isNaN(new Date(e).getTime())?new Date(e):a}return!t.isNullOrUndefined(this.parent.timezone)&&i?this.convert(r,this.parent.timezone):r},e.prototype.compareDates=function(e,i){return t.isNullOrUndefined(e)||t.isNullOrUndefined(i)?!t.isNullOrUndefined(e)&&t.isNullOrUndefined(i)?1:t.isNullOrUndefined(e)&&!t.isNullOrUndefined(i)?-1:null:e.getTime()>i.getTime()?1:e.getTime()<i.getTime()?-1:0},e.prototype.getDurationString=function(e,i){var r="";if(!t.isNullOrUndefined(e)&&(r+=parseFloat(e.toFixed(2))+" ",!t.isNullOrUndefined(i))){var a=1!==e;"day"===i?r+=a?this.parent.localeObj.getConstant("days"):this.parent.localeObj.getConstant("day"):"hour"===i?r+=a?this.parent.localeObj.getConstant("hours"):this.parent.localeObj.getConstant("hour"):"minute"===i&&(r+=a?this.parent.localeObj.getConstant("minutes"):this.parent.localeObj.getConstant("minute"))}return r},e.prototype.getWorkString=function(e,i){var r="";if(!t.isNullOrUndefined(e)&&(r+=parseFloat(e).toFixed(2)+" ",!t.isNullOrUndefined(i))){var a=1!==e;"day"===i?r+=a?this.parent.localeObj.getConstant("days"):this.parent.localeObj.getConstant("day"):"hour"===i?r+=a?this.parent.localeObj.getConstant("hours"):this.parent.localeObj.getConstant("hour"):"minute"===i&&(r+=a?this.parent.localeObj.getConstant("minutes"):this.parent.localeObj.getConstant("minute"))}return r},e.prototype.calculateProjectDatesForValidatedTasks=function(e){var i=this,r="string"==typeof this.parent.projectStartDate?new Date(this.parent.projectStartDate):this.parent.projectStartDate,a="string"==typeof this.parent.projectEndDate?new Date(this.parent.projectEndDate):this.parent.projectEndDate,n=null,s=null,o=t.getValue("dataOperation.dataArray",this.parent);if(r&&a||!o||0!==o.length){if(o.length>0){var l=o.slice().sort(function(e,t){return new Date(e[i.parent.taskFields.startDate]).getTime()-new Date(t[i.parent.taskFields.startDate]).getTime()}),d=o.slice().sort(function(e,t){return new Date(t[i.parent.taskFields.endDate]).getTime()-new Date(e[i.parent.taskFields.endDate]).getTime()});n=l[0][this.parent.taskFields.startDate],s=d[d.length-1][this.parent.taskFields.endDate]}}else n=this.getDateFromFormat(new Date),s=this.getDateFromFormat(new Date(n.getTime()));this.parent.cloneProjectStartDate=r?new Date(r.getTime()):"string"==typeof n?new Date(n):n,this.parent.cloneProjectEndDate=a?new Date(a.getTime()):"string"==typeof s?new Date(s):s},e.prototype.calculateProjectDates=function(e){var i=this;if(this.parent.isLoad&&this.parent.enablePersistence&&this.parent.cloneProjectStartDate&&this.parent.cloneProjectEndDate)return this.parent.cloneProjectStartDate=this.getDateFromFormat(this.parent.cloneProjectStartDate),void(this.parent.cloneProjectEndDate=this.getDateFromFormat(this.parent.cloneProjectEndDate));var r="string"==typeof this.parent.projectStartDate?new Date(this.parent.projectStartDate):this.parent.projectStartDate,a="string"==typeof this.parent.projectEndDate?new Date(this.parent.projectEndDate):this.parent.projectEndDate,n=this.parent.timelineModule.isZooming&&this.parent.cloneProjectStartDate?this.getDateFromFormat(this.parent.cloneProjectStartDate):this.getDateFromFormat(r),s=this.parent.timelineModule.isZooming&&this.parent.cloneProjectEndDate?this.getDateFromFormat(this.parent.cloneProjectEndDate):this.getDateFromFormat(a),o=null,l=null,d=this.parent.flatData,h=this.parent.currentViewData,p=[],u=function(e){t.isNullOrUndefined(e)||p.push(e)},c=function(e){e.length>0&&(e.sort(function(e,t){return e.getTime()-t.getTime()}),o=new Date(e[0].getTime()),l=e.length>1?new Date(e[e.length-1].getTime()):null)};if((!n||!s)&&d.length>0||e||this.parent.timelineModule.isZoomToFit){(h.length>0&&this.parent.timelineModule.isZoomToFit&&this.parent.treeGrid.filterModule&&this.parent.treeGrid.filterModule.filteredResult.length>0?h:d).forEach(function(e){p=[];var r,a,n=e.ganttProperties;t.isNullOrUndefined(n.startDate)&&t.isNullOrUndefined(n.endDate)?(r=null,a=null):(r=i.getValidStartDate(n),a=i.getValidEndDate(n)),u(o),u(l),u(r),u(a),i.parent.renderBaseline&&!i.parent.timelineModule.isZoomToFit&&(u(n.baselineStartDate),u(n.baselineEndDate)),n.indicators&&n.indicators.length>0&&!i.parent.timelineModule.isZoomToFit&&n.indicators.forEach(function(e){u(i.getDateFromFormat(e.date))}),c(p)}),p=[],u(o),u(l),this.parent.eventMarkers.length>0&&!this.parent.timelineModule.isZoomToFit&&this.parent.eventMarkers.forEach(function(e,t){u(i.getDateFromFormat(e.day))}),this.parent.totalHolidayDates.length>0&&!this.parent.timelineModule.isZoomToFit&&this.parent.totalHolidayDates.forEach(function(e,t){u(new Date(e))}),c(p),o&&l||(o?o=t.isNullOrUndefined(o)?this.getDateFromFormat(new Date):o:(o=t.isNullOrUndefined(o)?this.getDateFromFormat(new Date):o).setHours(0,0,0,0),(l=this.getDateFromFormat(new Date(o.getTime()))).setDate(l.getDate()+20))}else n&&s||0!==d.length||(o=this.getDateFromFormat(new Date),l=this.getDateFromFormat(new Date(o.getTime())));e?(t.setValue("minStartDate",o,e),t.setValue("maxEndDate",l,e)):(this.prevProjectStartDate=this.parent.cloneProjectStartDate,this.parent.cloneProjectStartDate=o?this.parent.timelineModule.isZoomToFit?o:t.isNullOrUndefined(n)?o:new Date(n.getTime()):new Date(n.getTime()),this.parent.cloneProjectEndDate=l?this.parent.timelineModule.isZoomToFit?l:t.isNullOrUndefined(s)?l:new Date(s.getTime()):new Date(s.getTime())),this.parent.isProjectDateUpdated=!0},e.prototype.splitTasksDuration=function(e){var t=0,i=e[0].startDate,r=e[e.length-1].endDate;return"Hour"===this.parent.timelineModule.bottomTier?t+=Math.ceil(this.getTimeDifference(i,r)/36e5):"Minutes"===this.parent.timelineModule.bottomTier?t+=Math.ceil(this.getTimeDifference(i,r)/6e4):t+=Math.ceil(this.getTimeDifference(i,r)/864e5),t},e}(),I=function(){var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(t,i)};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}(),E=function(e){function i(t){var i=e.call(this,t)||this;return i.customSegmentProperties=[],i.isBaseline=!1,i.isDurationValueUpdated=!1,i.uid=0,i.recordIndex=0,i.taskIds=[],i.hierarchyData=[],i.addEventListener(),i}return I(i,e),i.prototype.addEventListener=function(){this.parent.on("beforeDataManipulate",this.checkDataBinding.bind(this))},i.prototype.checkDataBinding=function(e){var i=this;if(e&&(this.parent.flatData=[],this.parent.currentViewData=[],this.parent.updatedRecords=[],this.dataArray=[],this.taskIds=[],this.parent.ids=[],this.recordIndex=0,this.hierarchyData=[],this.parent.predecessorsCollection=[],this.parent.treeGrid.parentData=[],this.parent.taskIds=[]),t.isNullOrUndefined(this.parent.dataSource))this.parent.dataSource=[],this.parent.processTimeline(),this.parent.renderGantt(e);else if(this.parent.dataSource instanceof r.DataManager)this.initDataSource(e);else{if(this.parent.dataSource instanceof Object&&y(this.parent)){var a=t.getValue("result",this.parent.dataSource);this.dataArray=a}else this.dataArray=this.parent.dataSource;this.processTimeline(),this.cloneDataSource(),this.parent.renderGantt(e),this.parent.flatData.map(function(e){i.parent.chartRowsModule.updateSegment(e.ganttProperties.segments,e.ganttProperties.taskId)})}this.parent.flatData.map(function(e){i.parent.chartRowsModule.updateSegment(e.ganttProperties.segments,e.ganttProperties.taskId)})},i.prototype.processTimeline=function(){this.parent.processTimeline(),this.parent.enableValidation||(this.parent.dataOperation.calculateProjectDatesForValidatedTasks(),this.parent.timelineModule.validateTimelineProp())},i.prototype.initDataSource=function(e){var t=this,i=this.parent.query instanceof r.Query?this.parent.query:new r.Query;i.requiresCount();var a=this.parent.dataSource;this.parent.loadChildOnDemand&&this.parent.taskFields.hasChildMapping?(this.processTimeline(),this.parent.renderGantt(e)):a.executeQuery(i).then(function(i){t.dataArray=i.result,t.processTimeline(),(!t.parent.loadChildOnDemand||t.parent.loadChildOnDemand&&!t.parent.taskFields.hasChildMapping)&&t.cloneDataSource(),t.parent.renderGantt(e)}).catch(function(i){t.parent.processTimeline(),t.parent.renderGantt(e),t.parent.trigger("actionFailure",{error:i})})},i.prototype.constructDataSource=function(e){for(var i,a=new r.DataManager(e).executeLocal((new r.Query).group(this.parent.taskFields.parentID)),n=[],s=0;s<a.length;s++){var o=a[s];!t.isNullOrUndefined(o.key)&&(i=this.taskIds.indexOf(o.key.toString()))>-1&&!t.isNullOrUndefined(o.key)?e[i][this.parent.taskFields.child]=o.items:-1!==i&&n.push.apply(n,o.items)}this.hierarchyData=this.dataReorder(e,n)},i.prototype.cloneDataSource=function(){var e=this.parent.taskFields.id,i=this.parent.taskFields.parentID,a=[];if(t.isNullOrUndefined(e)||t.isNullOrUndefined(i))a=this.dataArray;else{for(var n=[],s=0;s<this.dataArray.length;s++){var o=this.dataArray[s];o.parentItem&&delete o.parentItem,n.push(t.extend({},{},o,!0)),t.isNullOrUndefined(o[e])||this.taskIds.push(o[e].toString())}this.parent.taskFields.child||this.parent.setProperties({taskFields:{child:"Children"}},!0),this.constructDataSource(n),a=this.hierarchyData}if(this.parent.taskFields.segmentId&&(this.segmentCollection=new r.DataManager(this.parent.segmentData).executeLocal((new r.Query).group(this.parent.taskFields.segmentId)),this.parent.taskFields.segments||(this.parent.taskFields.segments="Segments")),"ProjectView"!==this.parent.viewType){var l=t.extend([],[],this.parent.resources,!0),d=[];if(this.constructResourceViewDataSource(l,a,d),d.length>0){var h={},p=this.parent.resourceFields.name||"resourceName";h[this.parent.resourceFields.id]=0,h[p]=this.parent.localeObj.getConstant("unassignedTask"),h[this.parent.taskFields.child]=d,l.push(h)}a=l}this.prepareDataSource(a)},i.prototype.constructResourceViewDataSource=function(e,t,i){for(var r=this,a=0;a<t.length;a++)!function(a){var n=t[a],s=null!==r.parent.taskFields.child?r.parent.taskFields.child:r.parent.taskFields.child="Children",o=n&&n[r.parent.taskFields.resourceInfo],l=r.parent.resourceFields.id;if(n[s]&&0!==n[s].length||!o||!o.length)(!n[s]||n[s]&&0===n[s].length)&&i.push(n);else if("string"==typeof o){r.isResourceString=!0;for(var d=o,h=0;h<e.length;h++)if(e[h][r.parent.resourceFields.name].toString()===d.toString()){e[h][s]?e[h][s].push(n):e[h][s]=[n];break}}else o.forEach(function(t){for(var i="object"==typeof t?t[l]:t,r=0;r<e.length;r++)if(e[r][l].toString()===i.toString()){e[r][s]?e[r][s].push(n):e[r][s]=[n];break}});n[r.parent.taskFields.child]&&n[r.parent.taskFields.child].length&&r.constructResourceViewDataSource(e,n[r.parent.taskFields.child],i)}(a)},i.prototype.prepareDataSource=function(e){this.prepareRecordCollection(e,0),this.parent.initialLoadData=t.extend({},{},this.parent.flatData,!0),(!this.parent.autoCalculateDateScheduling||this.parent.isLoad&&this.parent.treeGrid.loadChildOnDemand&&this.parent.taskFields.hasChildMapping)&&(this.parent.dataMap=this.parent.flatData.reduce(function(e,t){return e.set(t.uniqueID,t),e},new Map)),"ResourceView"===this.parent.viewType&&this.calculateSharedTaskUniqueIds(),this.parent.taskFields.dependency&&this.parent.predecessorModule&&this.parent.predecessorModule.ensurePredecessorCollection()},i.prototype.calculateSharedTaskUniqueIds=function(){for(var e=this,t=0;t<this.parent.getTaskIds().length;t++)!function(t){var i=[];if(i[0]=e.parent.getTaskIds()[t][0],i[1]=e.parent.getTaskIds()[t].slice(1),"R"!==i[0]){var r=[],a=[];e.parent.flatData.filter(function(e){e.ganttProperties.taskId.toString()===i[1]&&0!==e.level&&(a.push(e.ganttProperties.rowUniqueID),r.push(e))});for(var n=0;n<r.length;n++)r[n].ganttProperties.sharedTaskUniqueIds=a}}(t)},i.prototype.prepareRecordCollection=function(e,i,r){for(var a=this,n=e.length,s=this,o=0;o<n;o++)!function(n){var o=e[n];if(!t.isNullOrUndefined(s.parent.taskFields.segmentId)){var l=s.segmentCollection.filter(function(e){return e.key===o[a.parent.taskFields.id]});l.length>0&&(o[s.parent.taskFields.segments]=l[0].items)}s.parent.taskFields.hasChildMapping&&o.parentUniqueID&&(r=s.parent.getTaskByUniqueID(o.parentUniqueID));var d=s.createRecord(o,i,r,!0);(!s.parent.enableValidation||!s.parent.autoCalculateDateScheduling||s.parent.isLoad&&s.parent.treeGrid.loadChildOnDemand&&s.parent.taskFields.hasChildMapping)&&s.updateTaskLeftWidth(d),d.index=s.recordIndex++,s.parent.ids[d.index]=d.ganttProperties.rowUniqueID,s.parent.flatData.push(d),s.parent.setTaskIds(d);var h=o[s.parent.taskFields.child]||o.taskData&&o.taskData[s.parent.taskFields.child];if("ResourceView"===s.parent.viewType&&t.isNullOrUndefined(h)&&t.isNullOrUndefined(d.parentItem)&&0===d.level){var p=d.ganttProperties,u=d;s.parent.setRecordValue(p.isAutoSchedule?"startDate":"autoStartDate",null,u.ganttProperties,!0),s.parent.setRecordValue(p.isAutoSchedule?"endDate":"autoEndDate",null,u.ganttProperties,!0);var c=u.ganttProperties;s.parent.setRecordValue("isMilestone",!1,c,!0),c.isAutoSchedule&&s.calculateDuration(u),s.updateWorkWithDuration(u);var g=c.work;s.parent.setRecordValue("work",g,c,!0),s.parent.setRecordValue("taskType","FixedDuration",c,!0),t.isNullOrUndefined(s.parent.taskFields.type)||s.updateMappingData(u,"type"),s.parent.setRecordValue("progress",Math.floor(0),c,!0),s.parent.setRecordValue("totalProgress",0,c,!0),s.parent.setRecordValue("totalDuration",0,c,!0),c.isAutoSchedule||(s.parent.setRecordValue("autoDuration",s.calculateAutoDuration(c),c,!0),s.updateAutoWidthLeft(u)),s.parent.allowParentDependency||s.resetDependency(u),s.updateWidthLeft(u),s.updateTaskData(u)}s.parent.taskFields.hasChildMapping&&(r=null),!t.isNullOrUndefined(h)&&h.length>0&&s.prepareRecordCollection(h,d.level+1,d)}(o)},i.prototype.addCustomFieldValue=function(e,t){var i=this.parent.ganttColumns,r=i.length;if(r)for(var a=0;a<r;a++)void 0===t[i[a].field]&&this.parent.setRecordValue(i[a].field,e[i[a].field],t)},i.prototype.getGanttUid=function(e){return e+this.uid++},i.prototype.createRecord=function(e,i,r,a){var n=this.parent.taskFields,s=this.parent.resourceFields,o=e[n.progress],l=null,d=null,h=e[n.notes];o=100<(o=o&&parseFloat(o.toString())?parseFloat(o.toString()):0)?100:o;var p=e[n.dependency],u=this.getDateFromFormat(e[n.baselineStartDate],!0),c=this.getDateFromFormat(e[n.baselineEndDate],!0),g={},f={},m="Auto"===this.parent.taskMode||"Manual"!==this.parent.taskMode&&!0!==e[n.manual];this.parent.setRecordValue("ganttProperties",f,g),e.ganttProperties&&e.ganttProperties.predecessor&&e.ganttProperties.predecessor.length>0&&this.parent.undoRedoModule&&this.parent.undoRedoModule.isUndoRedoPerformed&&this.parent.setRecordValue("predecessor",e.ganttProperties.predecessor,f,!0),t.isNullOrUndefined(e[n.id])?t.isNullOrUndefined(e[s.id])||(l=e[s.id],d=t.isNullOrUndefined(e[s.name])&&"Unassigned Task"===e.resourceName?e.resourceName:e[s.name],this.addTaskData(g,e,!1)):(l=e[n.id],d=e[n.name],!!(this.parent.loadChildOnDemand&&n.hasChildMapping&&e.taskData)?g.taskData=e.taskData:e.taskData&&e.ganttProperties?this.addTaskData(g,e.taskData,a):this.addTaskData(g,e,a)),this.parent.setRecordValue("taskId",l,f,!0),this.parent.setRecordValue("taskName",d,f,!0),this.parent&&n.parentID&&this.parent.setRecordValue("parentId",e[n.parentID],f,!0),this.addCustomFieldValue(e,g),this.parent.setRecordValue("isAutoSchedule",m,f,!0),!this.parent.undoRedoModule||this.parent.undoRedoModule&&!this.parent.undoRedoModule.isUndoRedoPerformed?this.parent.setRecordValue("resourceInfo",this.setResourceInfo(e),f,!0):e.ganttProperties&&this.parent.setRecordValue("resourceInfo",e.ganttProperties.resourceInfo,f,!0),this.parent.setRecordValue("isMilestone",!1,f,!0),this.parent.setRecordValue("indicators",e[n.indicators],f,!0),this.updateResourceName(g),!t.isNullOrUndefined(e[n.child])&&e[n.child].length>0||e.taskData&&e.taskData[n.child]&&e.taskData[n.child].length>0?(this.parent.setRecordValue("hasChildRecords",!0,g),this.parent.setRecordValue("isMilestone",!1,f,!0),this.parent.allowParentDependency||this.resetDependency(g)):this.parent.loadChildOnDemand&&n.hasChildMapping&&g.taskData[n.hasChildMapping]?this.parent.setRecordValue("hasChildRecords",!0,g):this.parent.setRecordValue("hasChildRecords",!1,g),this.calculateScheduledValues(g,e,a),this.parent.setRecordValue("baselineStartDate",this.checkBaselineStartDate(u,f),f,!0);var D;D=this.parent.weekWorkingTime.length>0&&c?this.parent.getEndTime(c):this.parent.defaultEndTime,c&&0===c.getHours()&&86400!==D&&this.setTime(D,c),(f.baselineStartDate&&c&&f.baselineStartDate.getTime()>c.getTime()||!t.isNullOrUndefined(f.baselineStartDate)&&!t.isNullOrUndefined(f.startDate)&&f.baselineStartDate.getTime()===f.startDate.getTime()&&!t.isNullOrUndefined(c)&&!t.isNullOrUndefined(f.endDate)&&c.toLocaleDateString()===f.endDate.toLocaleDateString()&&f.isMilestone)&&(c=f.baselineStartDate),this.parent.setRecordValue("baselineEndDate",this.checkBaselineEndDate(c,f),f,!0),this.parent.setRecordValue("progress",o,f,!0),this.parent.setRecordValue("totalProgress",o,f,!0),e.ganttProperties&&e.ganttProperties.predecessorsName&&this.parent.undoRedoModule&&this.parent.undoRedoModule.isUndoRedoPerformed?this.parent.setRecordValue("predecessorsName",e.ganttProperties.predecessorsName,f,!0):this.parent.setRecordValue("predecessorsName",p,f,!0),this.parent.setRecordValue("notes",h,f,!0),this.parent.setRecordValue("cssClass",e[n.cssClass],f,!0),this.parent.setRecordValue("parentItem",this.getCloneParent(r),g),this.parent.loadChildOnDemand&&n.hasChildMapping&&this.parent.currentViewData.length>0&&this.parent.setRecordValue("parentItem",g.parentItem,this.parent.currentViewData[this.taskIds.indexOf(e[n.id].toString())]);var v=g.parentItem?g.parentItem.uniqueID:null;if(this.parent.setRecordValue("parentUniqueID",v,g),"ResourceView"!==this.parent.viewType||t.isNullOrUndefined(n.parentID)||t.isNullOrUndefined(g.parentItem)||this.parent.setRecordValue("parentId",g.parentItem.taskId,f,!0),this.parent.setRecordValue("level",i,g),e.ganttProperties&&this.parent.undoRedoModule&&this.parent.undoRedoModule.isUndoRedoPerformed?this.parent.setRecordValue("uniqueID",e.uniqueID,g):this.parent.loadChildOnDemand&&n.hasChildMapping&&e.uniqueID?this.parent.setRecordValue("uniqueID",e.uniqueID,g):this.parent.setRecordValue("uniqueID",this.getGanttUid(this.parent.element.id+"_data_"),g),this.parent.setRecordValue("uniqueID",g.uniqueID,f,!0),this.parent.setRecordValue("childRecords",[],g),this.parent.dataSource instanceof Object&&y(this.parent)&&!t.isNullOrUndefined(n.child)&&this.parent.setRecordValue(n.child,[],g),g.hasChildRecords&&(this.parent.setRecordValue("autoStartDate",g.ganttProperties.startDate,f),this.parent.setRecordValue("autoEndDate",g.ganttProperties.endDate,f),this.parent.setRecordValue("autoDuration",g.ganttProperties.duration,f)),this.parent.setRecordValue("expanded",!g.hasChildRecords||!this.parent.collapseAllParentTasks,g),this.updateExpandStateMappingValue(g,e),a||(this.parent.setRecordValue("width",this.calculateWidth(g),f,!0),this.parent.setRecordValue("left",this.calculateLeft(f,g),f,!0),this.parent.setRecordValue("progressWidth",this.getProgressWidth(f.width,o),f,!0),f.baselineEndDate&&f.baselineStartDate&&(this.parent.setRecordValue("baselineLeft",this.calculateBaselineLeft(f),f,!0),this.parent.setRecordValue("baselineWidth",this.calculateBaselineWidth(f),f,!0))),t.isNullOrUndefined(n.work)&&this.updateWorkWithDuration(g),t.isNullOrUndefined(n.manual)||this.parent.dataOperation.updateMappingData(g,"manual"),this.updateTaskData(g),p&&this.parent.predecessorsCollection.push(g),t.isNullOrUndefined(r)||(r.childRecords.push(g),this.parent.dataSource instanceof Object&&y(this.parent)&&!t.isNullOrUndefined(this.parent.taskFields.child)&&r[this.parent.taskFields.child].push(g.taskData)),"ProjectView"===this.parent.viewType)this.parent.setRecordValue("rowUniqueID",f.taskId.toString(),f,!0);else{var k=g.uniqueID.replace(this.parent.element.id+"_data_","");this.parent.setRecordValue("rowUniqueID",k,g),this.parent.setRecordValue("rowUniqueID",k,f,!0),this.parent.setRecordValue("sharedTaskUniqueIds",[],f,!0)}return this.parent.allowUnscheduledTasks&&g.ganttProperties.startDa