(function(){u8.Crm.Widgets.ResourceViewHeader=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.ResourceViewHeader.defaults,t));this._isCreated=false;if(!t.model){$error("ResourceViewHeader requires a model!")}this.setModel(t.model);this._create()};u8.Crm.Widgets.ResourceViewHeader.makeClass({name:"ResourceViewHeader",deriveFrom:u8.Base.Widgets.Widget,events:["Create"]});u8.Crm.Widgets.ResourceViewHeader.defaults={headerOptions:{headerGroupName:"Special",headerName:"ResourcePlanHeader"}};$.extend(u8.Crm.Widgets.ResourceViewHeader.prototype,{dispose:function(){if(this._isDisposed){return}this.setModel(null);this.$(this.element).unbind();this.Widget_dispose()},setModel:function(e){if(this._model){this._model.unbind("Update",this.id)}this._model=e;if(this._model){this._model.bind("Update",this._onModelUpdate.bind(this),this.id)}},getModel:function(){return this._model},_create:function(){var e=Function.chain.onDisposedAbort;Function.chain(e,this._load,this._draw.curry(e)).call(this,u8.tools.createdWhenReady.curry(this))},_load:function(e){u8.using({texts:["names_of_months","net_core_texts","net_months_short"],templates:[{name:"u8-resourceView-header",url:"~/crm/ResourceViewHeader.utml.htm"}]},e)},_draw:function(e,t){Function.chain(e,this._createViewModel.async(),this._createView).call(this,t)},_createViewModel:function(){var e={id:this.id+"_header",isDefault:this.isDefault,view:{showButtons:true,showCaption:false,showImage:false,showCollapse:false},context:this._model};this._viewModel={id:this.id,label:this._getRangeLabel(),addActivityButtonOptions:this.showNewButton&&this.showNewButton!==false&&{text:$t("TXT_net_core_texts_7"),command:"ResourceViewNewActivity"},addCampaignButtonOptions:this.showNewCampaignButton&&this.showNewCampaignButton!==false&&{text:$t("TXT_net_core_texts_130"),command:"ResourceViewNewCampaign"},headerOptions:$.extend({},this.headerOptions,e),rangeInputOptions:{value:this._model.getScaleDefinition().value,showValue:false,showBoundaryValues:true,boundaryButtonImages:{left:"u8-img-zoom-out-s",right:"u8-img-zoom-in-s"},showCurrentValue:false,normalizer:{type:"ListNormalizer",options:{items:this.model.getScales().map(function(e){return{value:e.value,text:e.text||""}})}},onValueChange:this._onScaleChange.bind(this),onStopDrag:this._onScaleChange.bind(this)}}},_createView:function(e){this.$(this.element).addClass("u8-resourceviewheader").toggleClass("page",!!this.isDefault).utml({name:"u8-resourceView-header",data:this._viewModel,itemOptions:{parent:this}},e)},_updateRange:function(){if(!this._viewModel){return}this._viewModel.label=this._getRangeLabel();this.$(this.element).find("#"+this._viewModel.id+"_range").text(this._viewModel.label)},_getRangeLabel:function(){var e={monthName:"short-name"};return new u8.Base.DateRange(this._model.range).toDateString(e)},_onModelUpdate:function(e,t){if(this._isDisposed){return}if(t.reason==="range"||t.reason==="days"){this._updateRange()}},_onScaleChange:function(e,t){if(e.dragging){return}var i=e.getValue();this._model.setScale(i)}})})();