text: BX.namespace("BX.Tasks.Shared.Form");BX.Tasks.Shared.Form.ProjectPlan=BX.Tasks.Util.Widget.extend({sys:{code:"dateplanmanager"},options:{matchWorkTime:false,companyWorkTime:false},methods:{construct:function(){this.callConstruct(BX.Tasks.Util.Widget);if(typeof this.instances=="undefined"){this.instances={}}this.vars.blockSignal=false;this.vars.matchWorkTime=this.option("matchWorkTime");var t=this.optionP("data");var e=this.optionP("auxData").COMPANY_WORKTIME;this.vars.TIME_UNIT_TYPE_DAY="days";this.vars.TIME_UNIT_TYPE_HOUR="hours";this.vars.TIME_UNIT_TYPE_MINUTE="mins";this.vars.WORKDAY_DURATION=this.getWorkDayDuration();this.vars.unit=t.TASK.DURATION_TYPE||this.vars.TIME_UNIT_TYPE_DAY;var i=null;this.getDeadlinePicker(e);var a=this.getStartDatePlanPicker(e);var n=this.getEndDatePlanPicker(e);var s=0;if(a&&n){var r=a.getTimeStamp();var h=r?new Date(r*1e3):null;var l=n.getTimeStamp();var o=l?new Date(l*1e3):null;if(h&&l&&h<o){s=this.calculateDuration(h,o)/1e3}}this.setDurationSeconds(s);BX.Tasks.Util.bindInstantChange(this.getDurationControl(),this.passCtx(BX.debounce(this.onDurationChange,300,this)));this.bindDelegateControl("duration","keydown",this.preventEnter);this.bindDelegateControl("unit-setter","click",this.passCtx(this.onUnitChange))},getDurationControl:function(){return this.control("duration")},getStartDatePlanPicker:function(t){if(!this.instances.startDatePlanPicker){var e=this.control("start-date-plan");if(BX.type.isElementNode(e)){var i=new BX.Tasks.Util.DatePicker({scope:e,defaultTime:t.HOURS.START});i.bindEvent("change",BX.delegate(this.onStartDatePlanChange,this));this.instances.startDatePlanPicker=i}}return this.instances.startDatePlanPicker},getEndDatePlanPicker:function(t){if(!this.instances.endDatePlanPicker){var e=this.control("end-date-plan");if(BX.type.isElementNode(e)){var i=new BX.Tasks.Util.DatePicker({scope:e,defaultTime:t.HOURS.END});i.bindEvent("change",BX.delegate(this.onEndDatePlanChange,this));this.instances.endDatePlanPicker=i}}return this.instances.endDatePlanPicker},getDeadlinePicker:function(t){if(!this.instances.deadlinePicker){var e=this.control("deadline");if(BX.type.isElementNode(e)){var i=new BX.Tasks.Util.DatePicker({scope:e,defaultTime:t.HOURS.END});i.bindEvent("change",BX.delegate(this.onDeadLineChange,this));this.instances.deadlinePicker=i}}return this.instances.deadlinePicker},onDeadLineChange:function(t){if(this.checkNoWorkDays(this.matchWorkTime())){return}this.solveDeadline(t);this.fireEvent("change-deadline",[this.getDeadlinePicker().getValue()])},onStartDatePlanChange:function(){if(this.checkNoWorkDays(this.matchWorkTime())){return}this.solveTriangle(true,false,false)},onEndDatePlanChange:function(){if(this.checkNoWorkDays(this.matchWorkTime())){return}this.solveTriangle(false,true,false)},preventEnter:function(t){if(BX.Tasks.Util.isEnter(t)){BX.PreventDefault(t);return false}},checkNoWorkDays:function(t){if(!t){return false}var e=true;var i=this.getCalendar();var a=i.weekends;var n=[0,1,2,3,4,5,6];n.forEach(function(t){if(!(t in a)){e=false}});return e},setMatchWorkTime:function(t){this.vars.matchWorkTime=t;if(this.checkNoWorkDays(t)){return}var e=this.getStartDatePlanPicker();var i=this.getEndDatePlanPicker();this.recalculateDuration();if(e&&e.getTimeStamp()!==null){this.solveTriangle(true,false,false)}else if(i&&i.getTimeStamp()!==null){this.solveTriangle(false,true,false)}var a=this.getDeadlinePicker();if(a){this.solveDeadline(a.getTimeStamp())}},matchWorkTime:function(){return this.vars.matchWorkTime},getCalendar:function(){if(this.parent()&&this.parent().instances.calendar){return this.parent().instances.calendar}if(this.instances.calendar==false){this.instances.calendar=new BX.Tasks.Calendar(BX.Tasks.Calendar.adaptSettings(this.option("companyWorkTime")))}return this.instances.calendar},setDeadline:function(t){this.getDeadlinePicker().disableChangeEvent();this.getDeadlinePicker().setTimeStamp(t.getTime()/1e3);this.getDeadlinePicker().enableChangeEvent()},fixDeadline:function(t){var e=this.getCalendar();if(this.matchWorkTime()&&!e.isWorkTime(t)){t=e.getClosestWorkTime(t,true);this.setDeadline(t)}return t},setStartDate:function(t){this.getStartDatePlanPicker().disableChangeEvent();this.getStartDatePlanPicker().setTimeStamp(t.getTime()/1e3);this.getStartDatePlanPicker().enableChangeEvent()},fixStartDate:function(t){var e=this.getCalendar();if(this.matchWorkTime()&&!e.isWorkTime(t)){t=e.getClosestWorkTime(t,true);this.setStartDate(t)}return t},setEndDate:function(t){this.getEndDatePlanPicker().disableChangeEvent();this.getEndDatePlanPicker().setTimeStamp(t.getTime()/1e3);this.getEndDatePlanPicker().enableChangeEvent()},fixEndDate:function(t){var e=this.getCalendar();if(this.matchWorkTime()&&!e.isWorkTime(t)){t=e.getClosestWorkTime(t,false);this.setEndDate(t)}return t},showHintPopup:function(t){if(t){BX.Tasks.Util.hintManager.show(t.control("display"),BX.message("TASKS_TASK_COMPONENT_TEMPLATE_DATE_CORRECTION_TOOLTIP"),null,null,{autoHide:true})}},calculateDuration:function(t,e){if(this.matchWorkTime()){var i=this.getCalendar().calculateDuration(t,e);return i>0?i:e-t}else{return e-t}},calculateStartDate:function(t,e){if(this.matchWorkTime()){return this.getCalendar().calculateStartDate(t,e)}else{return new Date(t.getTime()-e)}},calculateEndDate:function(t,e){if(this.matchWorkTime()){return this.getCalendar().calculateEndDate(t,e)}else{return new Date(t.getTime()+e)}},solveDeadline:function(t){if(t!==null){var e=new Date(t*1e3);var i=this.fixDeadline(e);if(e.getTime()!==i.getTime()){this.showHintPopup(this.getDeadlinePicker())}}},solveTriangle:function(t,e,i){if(this.vars.blockSignal){return}this.vars.blockSignal=true;var a=this.getStartDatePlanPicker().getTimeStamp();var n=a?new Date(a*1e3):null;var s=this.getEndDatePlanPicker().getTimeStamp();var r=s?new Date(s*1e3):null;var h=this.vars.duration;var l=h*1e3;var o=this.getMultiplier(this.vars.TIME_UNIT_TYPE_DAY);var c=o*1e3;if(i){if(h){if(n){n=this.fixStartDate(n);if(!this.isMaxDurationReached(l)){this.setEndDate(this.calculateEndDate(n,l))}}else if(r){r=this.fixEndDate(r);if(!this.isMaxDurationReached(l)){this.setStartDate(this.calculateStartDate(r,l))}}}}else if(t){if(n){var u=this.fixStartDate(n);if(u.getTime()!==n.getTime()){n=u;this.showHintPopup(this.getStartDatePlanPicker())}if(h){if(!this.isMaxDurationReached(l)){this.setEndDate(this.calculateEndDate(n,l))}}else if(r){r=this.fixEndDate(r);if(n<r){l=this.calculateDuration(n,r);h=l/1e3;this.setDurationSeconds(h);this.isMaxDurationReached(l)}else{this.setDurationSeconds(o);this.setEndDate(this.calculateEndDate(n,c))}}}}else if(e){if(r){n=n?this.fixStartDate(n):null;var D=this.fixEndDate(r);if(D.getTime()!==r.getTime()){r=D;this.showHintPopup(this.getEndDatePlanPicker())}if(n){if(n<r){l=this.calculateDuration(n,r);h=l/1e3;this.setDurationSeconds(h);this.isMaxDurationReached(l)}else{this.setDurationSeconds(o);this.setStartDate(this.calculateStartDate(r,c))}}else if(h){this.setDurationSeconds(h);if(!this.isMaxDurationReached(l)){this.setStartDate(this.calculateStartDate(r,l))}}}}this.vars.blockSignal=false},onDurationChange:function(t){if(this.checkNoWorkDays(this.matchWorkTime())){return}this.vars.duration=this.getDuration(this.vars.unit,t.value);this.solveTriangle(false,false,true)},onUnitChange:function(t){if(this.checkNoWorkDays(this.matchWorkTime())){return}var e=BX.data(t,"unit");if(BX.type.isNotEmptyString(e)){this.setDurationUnit(e,true)}},getWorkDayDuration:function(){var t=this.getCalendar().getWorkDayDuration(new Date);return t>0?t/1e3:86400},isMaxDurationReached:function(t){var e=true;if(!isNaN(t)&&t/1e3<this.getMaxDuration()){e=false}this.switchControlMode(this.getDurationControl().parentElement,e);return e},getMaxDuration:function(){return 2147483647},switchControlMode:function(t,e){if(e){BX.addClass(t,"task-field-error")}else{BX.removeClass(t,"task-field-error")}},getMultiplier:function(t){if(t==this.vars.TIME_UNIT_TYPE_DAY){return this.matchWorkTime()?this.vars.WORKDAY_DURATION:86400}if(t==this.vars.TIME_UNIT_TYPE_HOUR){return 3600}if(t==this.vars.TIME_UNIT_TYPE_MINUTE){return 60}return 1},setDurationUnit:function(t,e){this.vars.unit=t;this.dropCSSFlags("mode-unit-selected-*");this.setCSSFlag("mode-unit-selected-"+t);this.control("duration-type-value").value=t;if(e===true){this.vars.duration=this.getDuration(this.vars.unit,this.getDurationControl().value);this.solveTriangle(false,false,true)}},getUnitByDuration:function(t){var e=[this.vars.TIME_UNIT_TYPE_DAY,this.vars.TIME_UNIT_TYPE_HOUR,this.vars.TIME_UNIT_TYPE_MINUTE];for(var i=0;i<e.length;i++){var a=e[i];var n=this.getMultiplier(a);if(t%n===0){return a}}return this.vars.TIME_UNIT_TYPE_MINUTE},setDurationSeconds:function(t){if(isNaN(t)){return}this.vars.duration=t;if(t){var e=this.getUnitByDuration(t);if(e!=this.vars.unit){this.setDurationUnit(e)}}var i=Math.floor(this.vars.duration/this.getMultiplier(this.vars.unit));if(i>0){this.getDurationControl().value=i}},getDuration:function(t,e){e=parseInt(e,10);if(!isNaN(e)&&e>0){return this.getMultiplier(t)*e}return 0},recalculateDuration:function(){this.vars.duration=this.getDuration(this.vars.unit,this.control("duration").value)}}});
  //# sourceMappingURL=projectplan.map.js