!function(){var t;t=jQuery,Craft.NewUsersWidget=Garnish.Base.extend({settings:null,data:null,startDate:null,endDate:null,$widget:null,$body:null,init:function(e,a){var r=this;switch(this.setSettings(a),this.$widget=t("#widget"+e),this.$body=this.$widget.find(".body:first"),this.$chartContainer=t('<div class="chart hidden"></div>').appendTo(this.$body),this.$error=t('<div class="error"/>').appendTo(this.$body),this.settings.dateRange){case"d7":this.startDate=Craft.NewUsersWidget.getDateByDays(6),this.endDate=new Date;break;case"d30":this.startDate=Craft.NewUsersWidget.getDateByDays(30),this.endDate=new Date;break;case"lastweek":this.startDate=Craft.NewUsersWidget.getDateByDays(13),this.endDate=Craft.NewUsersWidget.getDateByDays(7);break;case"lastmonth":this.startDate=Craft.NewUsersWidget.getDateByDays(60),this.endDate=Craft.NewUsersWidget.getDateByDays(30)}var s={startDate:Craft.NewUsersWidget.getDateValue(this.startDate),endDate:Craft.NewUsersWidget.getDateValue(this.endDate),userGroupId:this.settings.userGroupId};Craft.postActionRequest("charts/get-new-users-data",s,(function(t,e){if("success"===e&&void 0===t.error){r.$chartContainer.removeClass("hidden"),r.chart=new Craft.charts.Area(r.$chartContainer,{yAxis:{formatter:function(t){return function(e){var a=",.0f";return e!=Math.round(e)&&(a=",.1f"),t.formatLocale.format(a)(e)}}}});var a=new Craft.charts.DataTable(t.dataTable),s={orientation:t.orientation,dataScale:t.scale,formats:t.formats};r.chart.draw(a,s),window.dashboard.grid.on("refreshCols",r.handleGridRefresh.bind(r))}else{var i=Craft.t("A server error occurred.");void 0!==t&&t&&void 0!==t.error&&(i=t.error),r.$error.html(i),r.$error.removeClass("hidden")}})),this.$widget.data("widget").on("destroy",this.destroy.bind(this)),Craft.NewUsersWidget.instances.push(this)},handleGridRefresh:function(){this.chart.resize()},destroy:function(){Craft.NewUsersWidget.instances.splice(t.inArray(this,Craft.NewUsersWidget.instances),1),this.base()}},{instances:[],getDateByDays:function(t){var e=new Date;return e=e.getTime()-86400*t*1e3,new Date(e)},getDateValue:function(t){return Math.floor(t.getTime()/1e3)}})}();
//# sourceMappingURL=NewUsersWidget.js.map