var corpServices=angular.module("diversus.feature.events.services",["ngResource"]),calendarModule,eventDetailModule,eventListingModule,eventsUpdateModule,iCalModule,rsvpFormModule;(function(){var t="/api/",i="/sessionapi/",n=function(n,r,u,f,e){var o=t;return e&&(o=i),["$resource",function(t){return f?t(jsWebApi.ensureSitecoreContext(o+n),r,jsWebApi.antiForgeryRequest(u)):t(jsWebApi.ensureSitecoreContext(o+n),r,jsWebApi.anonymousRequest(u))}]};corpServices.factory("EventListingService",n("EventListing/:id",{id:"@id"},!0,!1,!1));corpServices.factory("CalendarListService",n("CalendarList/:id",{id:"@id"},!0,!1,!1));corpServices.factory("EventOptionsService",n("CalendarEventOptions/:id",{id:"@id"},!0,!1,!1));corpServices.factory("FeaturedEventService",n("FeaturedEvent/:id",{id:"@id"},!0,!1,!1));corpServices.factory("EventsSearchService",n("EventsSearch/:id",{id:"@id"},!0,!1,!0));corpServices.factory("EventsSearchSuggestionsService",n("EventsSearchSuggestions/:id",{id:"@id"},!0,!1,!1));corpServices.factory("RsvpService",n("SendRsvp/:id",{id:"@id"},!1,!1,!1));corpServices.factory("EventUpdateService",n("EventUpdate/:id",{id:"@id"},!1,!1,!1))})();calendarModule=angular.module("diversus.feature.events.calendarModule",["ngRoute","ngSanitize"]);calendarModule.controller("CalendarCtrl",["$scope","$controller","$timeout","CalendarListService","EventListingService",function(n,t,i,r,u){n.populateCalendarsList=function(t){n.data.calendars=[];n.callWebApiService(r,{id:t}).then(function(t){return n.HandleResponseErrors(t),n.data.calendars=t.EventsCalendars,!0},function(){n.onSubmitFail()})};n.populateEventsForCalendar=function(t){n.callWebApiService(u,{Id:n.itemId,Categories:n.data.Categories,DateFrom:n.dateFrom,DateTo:n.dateTo,WhatsOnFeaturedOnly:!1,WhatsOnOnly:!1,ExcludeMultipleRecurringDates:!1,CurrentPage:0,PageSize:0,DisabledAccess:n.data.DisabledAccess}).then(function(i){var u,r,f;for(n.HandleResponseErrors(i),n.InitialLoad&&(n.data.EventCategories=i.EventCategories),u=[],n.data.eventAmount=i.CalendarEvents.length,r=0;r<i.CalendarEvents.length;r++)f={title:i.CalendarEvents[r].EventName,start:jsDates.parseDateToCalendarDateFromJson(i.CalendarEvents[r].EventStartDate,!0),end:jsDates.parseDateToCalendarDateFromJson(i.CalendarEvents[r].EventEndDate,!0),url:i.CalendarEvents[r].EventUrl,allDay:i.CalendarEvents[r].AllDayEvent,color:i.CalendarEvents[r].EventBackgroundColour,textColor:i.CalendarEvents[r].EventTextColour,image:i.CalendarEvents[r].ThumbnailUrl,location:i.CalendarEvents[r].EventLocation},u.push(f);return $("#calendar").fullCalendar("removeEventSource",n.data.events),n.data.events=[],n.data.events=u,$("#calendar").fullCalendar("addEventSource",n.data.events),t&&(n.InitialLoad=!1),!0},function(){n.onSubmitFail()})};n.CalClass=function(){return n.InitialLoad?"Hide":""};n.DateChange=function(){var i,t;for(n.submitAttempted=!0,n.populateEventsForCalendar(!1),n.filtered=!1,i=jQuery(".catFilter :input"),t=0;t<i.length;t++)if(i[t].checked==!0){n.filtered=!0;break}};n.init=function(i){n.InitialLoad=!0;n.itemId=i;angular.extend(this,t("BaseCtrl",{$scope:n}));n.data.EventCategories=[];n.data.Categories=[];n.filtered=!1;$("#calendar").fullCalendar({eventSources:[],timeFormat:"h(:mm)a",eventClick:function(n){if(n.url)return window.location.replace(n.url),!1},header:{left:"prev,title,next",center:"",right:"today agendaDay agendaWeek month"}});n.dateFrom=jsDates.getDefaultDatepickerFromDate();n.dateTo=jsDates.getDefaultDatepickerToDate();n.dateTo.setFullYear((new Date).getFullYear()+3);n.dateFrom.setFullYear((new Date).getFullYear()-2);n.populateCalendarsList(i);n.selectedCalendar=i.replace("{","").replace("}","").toLowerCase();n.populateEventsForCalendar(!0)}}]);calendarModule.controller("EventsHomeCtrl",["$scope","$controller","$timeout","CalendarListService","EventListingService",function(n,t,i,r,u){n.populateCalendarsList=function(t){n.data.calendars=[];n.callWebApiService(r,{id:t}).then(function(t){return n.HandleResponseErrors(t),n.data.calendars=t.EventsCalendars,!0},function(){n.onSubmitFail()})};n.populateEventsForCalendar=function(t,i){n.callWebApiService(u,{Id:n.itemId,Categories:n.data.Categories,DateFrom:n.dateFrom,DateTo:n.dateTo,WhatsOnFeaturedOnly:t,WhatsOnOnly:i,ExcludeMultipleRecurringDates:!0,CurrentPage:n.Page,PageSize:n.PageSize,DisabledAccess:n.data.DisabledAccess}).then(function(r){var u,f;for(n.HandleResponseErrors(r),n.InitialLoad&&(n.data.EventCategories=r.EventCategories),n.data.eventAmount=r.CalendarEvents.length,u=0;u<r.CalendarEvents.length;u++)if(f={title:r.CalendarEvents[u].EventName,start:jsDates.parseDateToCalendarDateFromJson(r.CalendarEvents[u].EventStartDate,!0),end:jsDates.parseDateToCalendarDateFromJson(r.CalendarEvents[u].EventEndDate,!0),url:r.CalendarEvents[u].EventUrl,allDay:r.CalendarEvents[u].AllDayEvent,color:r.CalendarEvents[u].EventBackgroundColour,textColor:r.CalendarEvents[u].EventTextColour,image:r.CalendarEvents[u].ThumbnailUrl,location:r.CalendarEvents[u].EventLocation},i){n.data.WhatsOnEvents.push(f);continue}else if(t){n.data.FeaturedEvents.push(f);continue}else{n.data.WhatsOnEvents.push(f);continue}return n.TotalEventsCount=r.TotalItems,n.ShowMoreButton=r.TotalItems==n.data.WhatsOnEvents.length?!1:!0,n.InitialLoad=!1,!0},function(){n.onSubmitFail()})};n.FilterCategories=function(){n.filterForm.$valid&&(n.data.WhatsOnEvents=[],n.Page=0,n.populateEventsForCalendar(!1,!1))};n.ShowMore=function(){n.Page=n.Page+1;n.populateEventsForCalendar(!1,!1)};n.DateChange=function(){var i,t;for(n.submitAttempted=!0,n.filtered=!1,i=jQuery(".catFilter :input"),t=0;t<i.length;t++)if(i[t].checked==!0){n.filtered=!0;break}n.filterForm.$valid&&(n.data.WhatsOnEvents=[],n.Page=0,n.populateEventsForCalendar(!1,!1))};n.openFrom=function(){n.fromStatus.opened=!0};n.openTo=function(){n.toStatus.opened=!0};n.init=function(i){angular.extend(this,t("BaseCtrl",{$scope:n}));n.InitialLoad=!0;n.data.EventCategories=[];n.itemId=i;n.data.WhatsOnEvents=[];n.data.FeaturedEvents=[];n.data.Categories=[];n.PageSize=3;n.filtered=!1;n.DisabledAccess=!1;n.populateCalendarsList(i);n.selectedCalendar=i.replace("{","").replace("}","").toLowerCase();n.dateFrom=jsDates.getDefaultDatepickerFromDate();n.dateTo=jsDates.getDefaultDatepickerToDate();n.dateTo.setFullYear((new Date).getFullYear()+1);n.minDate=new Date;n.dateOptions={formatYear:"yy",startingDay:1,showWeeks:!1};n.fromStatus={opened:!1};n.toStatus={opened:!1};n.submitAttempted=!1;n.Page=0;n.ShowMoreButton=!1;n.populateEventsForCalendar(!1,!1)}}]);calendarModule.controller("UpcomingMiniCtrl",["$scope","$controller","$timeout","EventListingService",function(n,t,i,r){n.populateEventsForCalendar=function(){n.callWebApiService(r,{Id:n.Id,Categories:n.Categories,MaxEvents:n.MaxEvents,DateFrom:n.dateFrom,DateTo:n.dateTo,WhatsOnFeaturedOnly:!1,WhatsOnOnly:!1,ExcludeMultipleRecurringDates:!0,CurrentPage:n.Page,PageSize:n.PageSize}).then(function(t){var r,i,u;for(n.HandleResponseErrors(t),r=[],i=0;i<t.CalendarEvents.length;i++)u={title:t.CalendarEvents[i].EventName,start:jsDates.parseDateToCalendarDateFromJson(t.CalendarEvents[i].EventStartDate,!0),end:jsDates.parseDateToCalendarDateFromJson(t.CalendarEvents[i].EventEndDate,!0),url:t.CalendarEvents[i].EventUrl,allDay:t.CalendarEvents[i].AllDayEvent,color:t.CalendarEvents[i].EventBackgroundColour,textColor:t.CalendarEvents[i].EventTextColour,image:t.CalendarEvents[i].ThumbnailUrl,location:t.CalendarEvents[i].EventLocation},r.push(u);return n.Upcoming=r,!0},function(){n.onSubmitFail()})};n.init=function(i,r,u,f){angular.extend(this,t("BaseCtrl",{$scope:n}));n.Categories=i.split("|");n.MaxEvents=r;n.RightCol=u;n.Id=f;n.PageSize=6;n.Page=0;n.dateFrom=jsDates.getDefaultDatepickerFromDate();n.dateTo=jsDates.getDefaultDatepickerToDate();n.dateTo.setFullYear((new Date).getFullYear()+1);n.populateEventsForCalendar()}}]);eventDetailModule=angular.module("diversus.feature.events.eventDetailModule",["ngRoute","ngSanitize"]);eventDetailModule.controller("EventDetailCtrl",["$scope","$controller","EventOptionsService",function(n,t,i){n.populateEventOptions=function(){n.data.eventOptions={};n.callWebApiService(i,{id:n.itemId}).then(function(t){return n.HandleResponseErrors(t),n.data.eventOptions=t,!0},function(){n.onSubmitFail()})};n.DownloadICal=function(){window.open("/api/iCal/"+n.itemId,"_blank","")};n.init=function(i){angular.extend(this,t("BaseCtrl",{$scope:n}));n.itemId=i;n.populateEventOptions()};n.IsOnHour=function(n){var t=new Date(n);return t.getMinutes()==0?!0:!1}}]);eventListingModule=angular.module("diversus.feature.events.eventListingModule",["ngRoute","ngSanitize"]);eventListingModule.controller("FeaturedEventCtrl",["$scope","$controller","FeaturedEventService",function(n,t,i){n.populateEvents=function(t){n.data.Events={};n.callWebApiService(i,{eventCount:t}).then(function(t){return n.HandleResponseErrors(t),n.data.Events=t.CalendarEvents,!0},function(){n.onSubmitFail()})};n.init=function(i){angular.extend(this,t("BaseCtrl",{$scope:n}));n.populateEvents(i)}}]);eventsUpdateModule=angular.module("diversus.feature.events.updatectrlModule",["ngRoute","ngSanitize"]);eventsUpdateModule.controller("EventUpdateCtrl",["$scope","$controller","$q","EventUpdateService","FinderCategoryListService","FinderLocationService",function(n,t,i,r,u,f){n.dto={GoogleMapsLocationUrl:""};n.state={success:!1,loading:!0};n.valid={map:!0};n.$watch("dto.GoogleMapsLocationUrl",function(){var t=n.dto.GoogleMapsLocationUrl,i,r,u,f;if(t!=null){if(!t.match(/^https:\/\/www\.google\.com\.au\/maps\//g)){n.valid.map=!1;return}if(n.valid.map=!0,i=t.match(/(\-)?\d+\.\d+\!4d(\-)?\d+\.\d+/),i)r=i[0].split(","),n.dto.Latitude=r[0],n.dto.Longitude=r[1];else{n.valid.map=!1;return}if(t.match(/^https:\/\/www\.google\.com\.au\/maps\/place\//g)){if(u=t.match(/\/place\/[^@]+\/@/),!u){n.valid.map=!1;return}f=decodeURIComponent(u[0].split("/")[2].replace(/\+/g,"%20"));n.dto.LocationName=f}}});var e=function(n){return Object.keys(n).forEach(function(t){n[t]&&typeof n[t]=="object"||(n[t]===""||n[t]===null)&&delete n[t]}),n},o=function(n,t){var r=i.defer(),u=function(n){r.resolve(n)},f=function(n){r.reject(n)};return e(t),n.post(t,u,f),r.promise};n.submit=function(){if(n.dto.Recaptcha=grecaptcha.getResponse(),!n.dto.Recaptcha){n.ModelState={"cfi.Captcha":["Fill in the CAPTCHA to submit the form"]};return}n.ModelState=null;n.state.loading=!0;o(r,n.dto).then(function(){return n.state.loading=!1,n.state.success=!0,!0},function(t){n.onSubmitFail();t.status===400&&(n.ModelState=typeof t.data.ModelState!="undefined"?t.data.ModelState:{"cfi.Email":[t.data.Message]});grecaptcha.reset();n.state.loading=!1})};n.init=function(i){angular.extend(this,t("BaseCtrl",{$scope:n}));n.callWebApiService(u,{id:"{EC9741EF-1A5A-4F2A-839C-AAC09771305F}"}).then(function(t){return n.categories=t.CategoryFacets,!0},function(){n.onSubmitFail()});n.callWebApiService(f,{id:"{E950CE1A-423F-41F5-8BC3-1A33CF18D86B}"}).then(function(t){return n.locations=t.Locations,!0},function(){n.onSubmitFail()});n.callWebApiService(r,{id:i}).then(function(t){return n.dto=t,n.state.loading=!1,!0},function(){n.onSubmitFail();n.state.loading=!1})}}]);iCalModule=angular.module("diversus.feature.events.iCalModule",["ngRoute","ngSanitize"]);iCalModule.controller("ICalCtrl",["$scope","$controller",function(n,t){n.DownloadICal=function(){window.open("/api/iCal/"+n.itemId,"_blank","")};n.init=function(i){angular.extend(this,t("BaseCtrl",{$scope:n}));n.itemId=i}}]);rsvpFormModule=angular.module("diversus.feature.events.rsvpFormModule",["ngRoute","ngSanitize"]);rsvpFormModule.controller("RsvpFormCtrl",["$scope","$controller","EventOptionsService","RsvpService",function(n,t,i,r){n.getEventOptions=function(){n.data.eventOptions={};n.callWebApiService(i,{id:n.EventId}).then(function(t){return n.HandleResponseErrors(t),t.HasResponseErrors||(n.ShowForm=!0),!0},function(){n.onSubmitFail()})};n.Submit=function(){n.submitAttempted=!0;n.RsvpForm.$valid&&n.callWebApiService(r,{EventId:n.EventId,Name:n.Name,Comments:n.Comments,Attending:n.Attending}).then(function(t){return n.HandleResponseErrors(t),t.HasResponseErrors||(n.FormSent=!0),!0},function(){n.onSubmitFail()})};n.init=function(){angular.extend(this,t("BaseCtrl",{$scope:n}));n.ShowForm=!1;n.Attending=1;n.EventId="";n.FormSent=!1;var i=jsCommon.getUrlParameter("EventId");i==!1?i=null:(n.EventId=i.replace("+"," "),n.getEventOptions())}}])