(function(){"use strict";var t=['<div class="u8-visitplanningnewsuggestionspopup u8-padding-l">','<div id="validationsummary" class="u8-visitplanningnewsuggestionspopup-validationsummary u8-margin-bottom" style="display:none"></div>','<table cellspacing="0" cellpadding="2">',"<tr>",'<td class="label"><div class="u8-label">{{text TXT_VisitPlanning_10}}</div></td>','<td class="input">{{DateInput({id: $data.get("id") + "_startDateInput", bindings: "#startDate" })}}</td>','<td class="label"><div class="u8-label">{{text TXT_VisitPlanning_11}}</div></td>','<td class="input">{{DateInput({id: $data.get("id") + "_endDateInput", bindings: "#endDate" })}}</td>',"</tr>","<tr>",'<td class="label"><div class="u8-label">{{text TXT_VisitPlanning_12}}</div></td>','<td class="input">{{ComboBox({id: $data.get("id") + "_startLocation", bindings: "#startLocation;#startLocations=>@items" })}}</td>','<td class="label"><div class="u8-label">{{text TXT_VisitPlanning_13}}</div></td>','<td class="input">{{ComboBox({id: $data.get("id") + "_overnightLocation", bindings: "#overnightLocation;#startLocations=>@items;#overnightComboDisabled==>disabled" })}}</td>',"</tr>","</table>",'<div class="userinfo">${$data.get("userInfo")}</div>','<div class="u8-buttons">','{{Button({ textId:"TXT_VisitPlanning_6", command:"CreateSuggestions", bindings: "#denyCreate==>disabled" })}}&nbsp;','{{Button({ textId: "TXT_button_text_0", command:"Cancel" })}}',"</div>","</div>"].join("");u8.Crm.Widgets.VisitPlanningNewSuggestionsPopup=function(t,e){$.extend(this,u8.Crm.Widgets.VisitPlanningNewSuggestionsPopup.defaults,e);this.WidgetContainer();this.id=u8.Base.Dom.uniqueId();this.element=t;this.rep=this.model.get("rep");$assert(this.rep,"Failed to create new suggestions because no rep is available.");this.bind()};u8.Crm.Widgets.VisitPlanningNewSuggestionsPopup.defaults={popup:{title:"TXT_VisitPlanning_3",sizing:"fit",allowResize:false,autoShow:false,position:"left-middle",showArrow:true,allowMaximize:false}};u8.Crm.Widgets.VisitPlanningNewSuggestionsPopup.makeClass({name:"VisitPlanningNewSuggestionsPopup",deriveFrom:u8.Base.Widgets.WidgetContainer,events:["Close"]});$.extend(u8.Crm.Widgets.VisitPlanningNewSuggestionsPopup.prototype,{open:function(){Function.chain(this._using,this._createModel,this._openPopup,this._createView).call(this)},dispose:function(){if(this._isDisposed){return}this.unbind();if(this._model){this._model.dispose();this._model=null}this.WidgetContainer_dispose()},_using:function(t){u8.using({texts:["VisitPlanning","button_text"]},t)},_createModel:function(t){var e=this.model,i=e.get("date")||e.get("defaultSuggestionStart")||new Date,s=e.get("defaultSuggestionDuration")||1,a=e.get("customerFilterSet");this._model=new u8.Base.Model({properties:{id:this.id,startDate:i,endDate:i.clone().addDays(n(s)-1),startLocation:0,overnightLocation:0,overnightComboDisabled:true,denyCreate:false,startLocations:[{key:0,text:$t("TXT_VisitPlanning_7")},{key:1,text:$t("TXT_VisitPlanning_8")},{key:2,text:$t("TXT_VisitPlanning_9")}],userInfo:a&&a.name?"TXT_VisitPlanning_5".format({selectedRep:this.rep.name,filterSet:a.name}):"TXT_VisitPlanning_30".format({selectedRep:this.rep.name})},onPropertyChange:this._onPropertyChange.bind(this)});t()},_openPopup:function(t){var e=$.extend({},this.popup,{alignTo:this.element,parent:this,onCreate:t,onClose:this._onPopupClose.bind(this)});this._popup=new u8.Base.Widgets.Popup("<div></div>",e);this._popup.open()},_createView:function(){var e=this;var i=this._popup;i.getContent().utml({template:t,itemOptions:{parent:i,context:this._model},data:this._model},function(){u8.tools.ready(i.children,function(){i.autoSizeAndPosition().show()});e._validationManager=u8.Base.ValidationManager.addToWidget(i,{elWindow:i.getWindow(),summarySelector:".u8-visitplanningnewsuggestionspopup-validationsummary"})})},_notify:function(t){if(!t){this._validationManager.removeMessage(this.id)}else{this._validationManager.write(t,this.id)}},_onPopupClose:function(t,e){this.raise("Close",e);this.dispose()},_onPropertyChange:function(t,e){var i=e.propertyName,n=e.value,s=this._model;if(i=="startDate"){s.set("endDate",n)}else if(i=="endDate"){var a=s.get("startDate"),o=Date.diffDays(n,a);s.set("overnightComboDisabled",o<=0);var d=undefined;if(o>31){d=$t("TXT_VisitPlanning_20")}else if(o<0){d=$t("TXT_VisitPlanning_28")}this._notify(d);s.set("denyCreate",o<0||o>31)}},"Command.CreateSuggestions":function(){var t=this._model;this._popup.close({newSuggestionOptions:{repId:this.rep.repId,startTime:e(t.get("startDate")),endTime:i(t.get("endDate")),startLocation:t.get("startLocation"),overnightLocation:t.get("overnightComboDisabled")?undefined:t.get("overnightLocation")}})},"Command.Cancel":function(){this._popup.close({cancel:true})}});function e(t){var e=new Date;if(Date.dateEquals(t,e)){return e}else{return t.clone().stripTime()}}function i(t){return t.clone().addDays(1).stripTime()}function n(t){return Math.min(Math.max(t,1),31)}})();