Type.registerNamespace("Telerik.Sitefinity.Modules.Events.Web.UI.Public"); var calendarViewWindowManager = null; //This script is used to disable the initial loading of appointments & resources when the RadScheduler loads. //Removing this will result in a double call to the service. function OnClientAppointmentsPopulating(sender, args) { var loaded = jQuery(sender).data("loaded"); if (!loaded) { args.set_cancel(true); } } function OnClientResourcesPopulating(sender, args) { var loaded = jQuery(sender).data("loaded"); if (!loaded) { jQuery(sender).data("loaded", true); args.set_cancel(true); } } Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView = function (element) { Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView.initializeBase(this, [element]); this._providerName = null; this._uiCulture = null; this._allowCreateEvents = null; this._allowChangeCalendarView = null; this._isDesignMode = null; this._scheduler = null; this._windowManager = null; this._calendarEventEditDialog = null; this._calendarEventAddDialogUrl = null; this._calendarEventAddDialog = null; this._viewEventDialog = null; this._addEventDialog = null; this._editEventDialog = null; this._createEventButton = null; this._calendarsCheckBoxList = null; this._createCalendarSection = null; this._onCreateEventButtonClickDeledate = null; this._onSchedulerTimeSlotClickDelegate = null; this._onSchedulerAppointmentClickDelegate = null; this._onSchedulerAppointmentsPopulatingDelegate = null; this._onSchedulerAppointmentDoubleClickDelegate = null; this._onSchedulerAppointmentDataBoundDelegate = null; this._onSchedulerRequestSuccessDelegate = null; this._onCalendarCreatedDelegate = null; this._onCalendarSelectDelegate = null; this._onCalendarsCheckBoxListDataBoundDelegate = null; this._addEventDialogPageLoadDelegate = null; this._addEventDialogShowDelegate = null; this._addEventDialogCloseDelegate = null; this._calendarEventAddDialogCloseDelegate = null; this._editEventDialogPageLoadDelegate = null; this._editEventDialogCloseDelegate = null; this._calendarEventEditDialogCloseDelegate = null; this._onSchedulerAppointmentMoveStart = null; this._onSchedulerAppointmentMoveEnd = null; this._onSchedulerAppointmentResizeStart = null; this._onSchedulerAppointmentResizeEnd = null; this._filterExpression = null; this._sortExpression = null; this._calendarsFilter = null; this._startDST = null; this._endDST = null; } Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView.prototype = { initialize: function () { Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView.callBaseMethod(this, 'initialize'); this._addEventDialogPageLoadDelegate = Function.createDelegate(this, this._addEventDialogPageLoadHandler); this._addEventDialogShowDelegate = Function.createDelegate(this, this._addEventDialogShowHandler); this._addEventDialogCloseDelegate = Function.createDelegate(this, this._addEventDialogCloseHandler); this._calendarEventAddDialogCloseDelegate = Function.createDelegate(this, this._calendarEventAddDialogCloseHandler); this._editEventDialogPageLoadDelegate = Function.createDelegate(this, this._editEventDialogPageLoadHandler); this._editEventDialogCloseDelegate = Function.createDelegate(this, this._editEventDialogCloseHandler); this._calendarEventEditDialogCloseDelegate = Function.createDelegate(this, this._calendarEventEditDialogCloseHandler); this._onSchedulerTimeSlotClickDelegate = Function.createDelegate(this, this._onSchedulerTimeSlotClickHandler); this._onSchedulerAppointmentClickDelegate = Function.createDelegate(this, this._onSchedulerAppointmentClickHandler); this._onCreateEventButtonClickDeledate = Function.createDelegate(this, this._onCreateEventButtonClickHandler); this._onSchedulerAppointmentsPopulatingDelegate = Function.createDelegate(this, this._onSchedulerAppointmentsPopulatingHandler); this._onSchedulerRequestSuccessDelegate = Function.createDelegate(this, this._onSchedulerRequestSuccessHandler); this._onCalendarCreatedDelegate = Function.createDelegate(this, this._onCalendarCreatedHandler); this._onCalendarSelectDelegate = Function.createDelegate(this, this._onCalendarSelectHandler); this._onCalendarsDataBoundDelegate = Function.createDelegate(this, this._onCalendarsDataBoundHandler); this.get_scheduler().add_timeSlotClick(this._onSchedulerTimeSlotClickDelegate); this.get_scheduler().add_appointmentClick(this._onSchedulerAppointmentClickDelegate); this.get_scheduler().add_appointmentsPopulating(this._onSchedulerAppointmentsPopulatingDelegate); this._onSchedulerAppointmentDataBoundDelegate = Function.createDelegate(this, this._onSchedulerAppointmentDataBoundHandler); this.get_scheduler().add_appointmentDataBound(this._onSchedulerAppointmentDataBoundDelegate); this.get_scheduler().add_requestSuccess(this._onSchedulerRequestSuccessDelegate); if (this.get_createEventButton()) $addHandler(this.get_createEventButton(), 'click', this._onCreateEventButtonClickDeledate); if (this.get_createCalendarSection()) this.get_createCalendarSection().add_onCalendarCreated(this._onCalendarCreatedDelegate); this.get_calendarsCheckBoxList().add_onCalendarSelectCommand(this._onCalendarSelectDelegate); this.get_calendarsCheckBoxList().add_onDataBound(this._onCalendarsDataBoundDelegate); this.get_addEventDialog().add_pageLoad(this._addEventDialogPageLoadDelegate); this.get_addEventDialog().add_show(this._addEventDialogShowDelegate); this.get_addEventDialog().add_close(this._addEventDialogCloseDelegate); this.get_calendarEventAddDialog().add_close(this._calendarEventAddDialogCloseDelegate); this.get_editEventDialog().add_pageLoad(this._editEventDialogPageLoadDelegate); this.get_editEventDialog().add_close(this._editEventDialogCloseDelegate); this.get_calendarEventEditDialog().add_close(this._calendarEventEditDialogCloseDelegate); this.get_scheduler()._eventMap.addHandlerForClassName("click", "rsArrowRight", this.get_scheduler()._onNextSchedulerDayClick); this.get_scheduler()._eventMap.addHandlerForClassName("click", "rsArrowLeft", this.get_scheduler()._onPreviousSchedulerDayClick); this.get_scheduler()._eventMap.addHandlerForClassName("click", "rsArrowBottom", this.get_scheduler()._onNextSchedulerDayClick); this.get_scheduler()._eventMap.addHandlerForClassName("click", "rsArrowTop", this.get_scheduler()._onPreviousSchedulerDayClick); if (window.top.GetDialogManager) { var dialogManager = window.top.GetDialogManager(); if (dialogManager) { dialogManager.blacklistWindow(this.get_calendarEventAddDialog()); dialogManager.blacklistWindow(this.get_calendarEventEditDialog()); dialogManager.blacklistWindow(this.get_addEventDialog()); dialogManager.blacklistWindow(this.get_editEventDialog()); } } this.get_calendarsCheckBoxList().set_calendarsFilter(this.get_calendarsFilter()); this.get_calendarsCheckBoxList().bind(); if (!this.get_allowChangeCalendarView()) { //There is no property or event to prevent view changing so we override the method. this.get_scheduler().set_selectedView = function (value) { }; } this._onSchedulerAppointmentMoveStart = Function.createDelegate(this, this._onSchedulerAppointmentMoveStartHandler); this._onSchedulerAppointmentResizeStart = Function.createDelegate(this, this._onSchedulerAppointmentResizeStartHandler); this.get_scheduler().add_appointmentMoveStart(this._onSchedulerAppointmentMoveStart); this.get_scheduler().add_appointmentResizeStart(this._onSchedulerAppointmentResizeStart); }, dispose: function () { if (this._onSchedulerAppointmentClickDelegate) { if (this.get_scheduler()) { this.get_scheduler().remove_appointmentClick(this._onSchedulerAppointmentClickDelegate); } delete this._onSchedulerAppointmentClickDelegate; } if (this._onSchedulerTimeSlotClickDelegate) { if (this.get_scheduler()) { this.get_scheduler().remove_timeSlotClick(this._onSchedulerTimeSlotClickDelegate); } delete this._onSchedulerTimeSlotClickDelegate; } if (this._onCreateEventButtonClickDeledate) { if (this.get_createEventButton()) { $removeHandler(this.get_createEventButton(), 'click', this._onCreateEventButtonClickDeledate); } delete this._onCreateEventButtonClickDeledate; } if (this._onCalendarsListItemChoiceFieldValueChangedDelegate) { if (this.get_calendarsListChoiceField()) { this.get_calendarsListChoiceField().remove_valueChanged(this._onCalendarsListItemChoiceFieldValueChangedDelegate); } delete this._onCalendarsListItemChoiceFieldValueChangedDelegate; } if (this._onCalendarCreatedDelegate) { if (this.get_createCalendarSection()) { this.get_createCalendarSection().remove_onCalendarCreated(this._onCalendarCreatedDelegate); } delete this._onCalendarCreatedDelegate; } if (this._onCalendarSelectDelegate) { if (this.get_calendarsCheckBoxList()) { this.get_calendarsCheckBoxList().remove_onCalendarSelectCommand(this._onCalendarSelectDelegate); } delete this._onCalendarSelectDelegate; } if (this._onCalendarsDataBoundDelegate) { if (this.get_calendarsCheckBoxList()) { this.get_calendarsCheckBoxList().remove_onDataBound(this._onCalendarsDataBoundDelegate); } delete this._onCalendarsDataBoundDelegate; } if (this._addEventDialogShowDelegate) { if (this.get_addEventDialog()) { this.get_addEventDialog().remove_show(this._addEventDialogShowDelegate); } delete this._addEventDialogShowDelegate; } if (this._addEventDialogPageLoadDelegate) { if (this.get_addEventDialog()) { this.get_addEventDialog().remove_pageLoad(this._addEventDialogPageLoadDelegate); } delete this._addEventDialogPageLoadDelegate; } if (this._addEventDialogShowDelegate) { if (this.get_addEventDialog()) { this.get_addEventDialog().remove_show(this._addEventDialogShowDelegate); } delete this._addEventDialogShowDelegate; } if (this._addEventDialogCloseDelegate) { if (this.get_addEventDialog()) { this.get_addEventDialog().remove_close(this._addEventDialogCloseDelegate); } delete this._addEventDialogCloseDelegate; } if (this._calendarEventAddDialogCloseDelegate) { if (this.get_calendarEventAddDialog()) { this.get_calendarEventAddDialog().remove_close(this._calendarEventAddDialogCloseDelegate); } delete this._calendarEventAddDialogCloseDelegate; } if (this._editEventDialogPageLoadDelegate) { if (this.get_editEventDialog()) { this.get_editEventDialog().remove_pageLoad(this._editEventDialogPageLoadDelegate); } delete this._editEventDialogPageLoadDelegate; } if (this._editEventDialogCloseDelegate) { if (this.get_editEventDialog()) { this.get_editEventDialog().remove_close(this._editEventDialogCloseDelegate); } delete this._editEventDialogCloseDelegate; } if (this._calendarEventEditDialogCloseDelegate) { if (this.get_calendarEventEditDialog()) { this.get_calendarEventEditDialog().remove_close(this._calendarEventEditDialogCloseDelegate); } delete this._calendarEventEditDialogCloseDelegate; } if (this._onSchedulerAppointmentDataBoundDelegate) { if (this.get_scheduler()) { this.get_scheduler().remove_appointmentDataBound(this._onSchedulerAppointmentDataBoundDelegate); } delete this._onSchedulerAppointmentDataBoundDelegate; } if (this._onSchedulerRequestSuccessDelegate) { if (this.get_scheduler()) { this.get_scheduler().remove_requestSuccess(this._onSchedulerRequestSuccessDelegate); } delete this._onSchedulerRequestSuccessDelegate; } if (this._onSchedulerAppointmentMoveStart) { if (this.get_scheduler()) { this.get_scheduler().remove_appointmentMoveStart(this._onSchedulerAppointmentMoveStart); } delete this._onSchedulerAppointmentMoveStart; } if (this._onSchedulerAppointmentResizeStart) { if (this.get_scheduler()) { this.get_scheduler().remove_appointmentResizeStart(this._onSchedulerAppointmentResizeStart); } delete this._onSchedulerAppointmentResizeStart; } Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView.callBaseMethod(this, 'dispose'); }, // ------------------------------------------------- Event Handlers ------------------------------------------------ // _onSchedulerAppointmentDataBoundHandler: function (sender, args) { var calendarColor = this._getAttributeValueByKey(args.get_data().Attributes, "CalendarColor"); args.get_data()["IsEditable"] = this._getAttributeValueByKey(args.get_data().Attributes, "IsEditable"); var allDay = this._getAttributeValueByKey(args.get_data().Attributes, "AllDay"); if (calendarColor) { args.get_appointment().set_backColor(calendarColor); } var appointment = args.get_appointment(); var appSub = appointment.get_subject(); if (appSub) { appointment.set_subject(appSub.htmlEncode ? appSub.htmlEncode() : appSub); } var start = appointment.get_start(); var newStart = new Date(start); var end = appointment.get_end(); var newEnd = new Date(end); }, _onSchedulerTimeSlotClickHandler: function (sender, args) { if (this.get_allowCreateEvents()) { var startTime = args.get_targetSlot().get_startTime(); var isAllDay; if (args.get_targetSlot().get_isAllDay()) { isAllDay = "True"; } else { isAllDay = "False"; } var url = String.format(this.get_calendarEventAddDialogUrl(), isAllDay, encodeURIComponent(startTime)); this.get_calendarEventAddDialog().set_navigateUrl(url); this.get_calendarEventAddDialog().show(); } }, _onSchedulerAppointmentClickHandler: function (sender, args) { if (!this.get_viewEventDialog()._kendoWindow.wrapper.hasClass("sfcalendarEventPreviewWrp")) this.get_viewEventDialog()._kendoWindow.wrapper.addClass("sfcalendarEventPreviewWrp") var top = jQuery(args.get_appointment()._domElement).offset().top; var left = jQuery(args.get_appointment()._domElement).offset().left; this.get_viewEventDialog().show(args.get_appointment(), this.get_providerName(), this.get_uiCulture(), top, left); }, _onSchedulerAppointmentsPopulatingHandler: function (sender, args) { args.get_schedulerInfo().CalendarIds = this.get_calendarsCheckBoxList().get_selectedValues(); args.get_schedulerInfo().UiCulture = this.get_uiCulture(); args.get_schedulerInfo().ProviderName = this.get_providerName(); args.get_schedulerInfo().FilterExpression = this.get_filterExpression(); args.get_schedulerInfo().SortExpression = this.get_sortExpression(); args.get_schedulerInfo().TimeZoneId = GetUserPreferences().get_timeZoneId(); }, _onSchedulerRequestSuccessHandler: function (sender, args) { this.set_startDST(args.get_result().StartDST); this.set_endDST(args.get_result().EndDST); }, _onSchedulerAppointmentMoveStartHandler: function (sender, args) { this._allowMove(args); }, _onSchedulerAppointmentResizeStartHandler: function (sender, args) { this._allowResize(args); }, _allowMove: function (args) { this._allowEdit(args); }, _allowResize: function (args) { this._allowEdit(args); }, _allowEdit: function (args) { if (args.get_appointment().get_recurrenceState() != 0 || args.get_appointment().get_attributes().getAttribute("IsEditable") == "False") { args.set_cancel(true); } else { args.set_cancel(false); } }, _onCreateEventButtonClickHandler: function (sender, args) { if (this.get_allowCreateEvents()) { var url = String.format(this.get_calendarEventAddDialogUrl(), "false", ""); this.get_calendarEventAddDialog().set_navigateUrl(url); this.get_calendarEventAddDialog().show(); } }, _onCalendarCreatedHandler: function (sender, args) { this.get_calendarsCheckBoxList().bind(); this.get_createCalendarSection().hideSection(); }, _onCalendarSelectHandler: function (sender, args) { this.get_scheduler().rebind(); }, _onCalendarsDataBoundHandler: function (sender, args) { if (!this.get_isDesignMode()) { this.get_scheduler().rebind(); } }, _addEventDialogPageLoadHandler: function (sender, args) { if (!$telerik.isChrome) { this._addEventDialogShowHandler(sender, args); } else { var that = this; window.setTimeout(function () { that._addEventDialogShowHandler(sender, args) }, 0); } }, _addEventDialogShowHandler: function (sender, args) { var framehandle = this.get_addEventDialog().get_contentFrame().contentWindow; if (framehandle && framehandle.createDialog) { var commandName = "create"; var params = { IsEditable: true }; var that = this; var dummyItemsList = { getBinder: function () { return { get_provider: function () { return [that.get_providerName()] } } } }; var commandArgs = this.get_uiCulture() ? { language: this.get_uiCulture() } : null; framehandle.createDialog(commandName, null, dummyItemsList, this.get_addEventDialog(), params, null, commandArgs); this.get_calendarEventAddDialog().close(); } }, _addEventDialogCloseHandler: function (sender, args) { this.get_scheduler().rebind(); }, _calendarEventAddDialogCloseHandler: function (sender, args) { if (args.get_argument() && args.get_argument() == "rebind") { this.get_scheduler().rebind(); } }, _editEventDialogPageLoadHandler: function (sender, args) { var framehandle = this.get_editEventDialog().get_contentFrame().contentWindow; if (framehandle && framehandle.createDialog) { var commandName = "edit"; var dataItem = { Id: this.get_calendarEventEditDialog().AjaxDialog.get_eventId() }; var params = { IsEditable: true, parentId: this.get_calendarEventEditDialog().AjaxDialog.get_event().ParentId }; var that = this; var dummyItemsList = { getBinder: function () { return { get_provider: function () { return [that.get_providerName()] } } } }; var key = { Id: dataItem.Id }; var commandArgs = this.get_uiCulture() ? { language: this.get_uiCulture() } : null; framehandle.createDialog(commandName, dataItem, dummyItemsList, this.get_editEventDialog(), params, key, commandArgs); this.get_calendarEventEditDialog().close(); } }, _editEventDialogCloseHandler: function (sender, args) { this.get_scheduler().rebind(); }, _calendarEventEditDialogCloseHandler: function (sender, args) { if (args.get_argument() && args.get_argument() == "rebind") { this.get_scheduler().rebind(); } }, // ------------------------------------------------- Private Methods ----------------------------------------------- // _getAttributeValueByKey: function (attributes, key) { for (var i in attributes) { if (attributes[i].Key == key) { return attributes[i].Value; } } return null; }, // ------------------------------------------------- Properties ---------------------------------------------------- // set_providerName: function (value) { this._providerName = value; }, get_providerName: function () { return this._providerName; }, set_scheduler: function (value) { this._scheduler = value; }, get_scheduler: function () { return this._scheduler; }, set_windowManager: function (value) { this._windowManager = value; calendarViewWindowManager = value; }, get_windowManager: function () { return this._windowManager; }, set_calendarEventAddDialog: function (value) { this._calendarEventAddDialog = value; }, get_calendarEventAddDialog: function () { return this._calendarEventAddDialog; }, set_calendarEventAddDialogUrl: function (value) { this._calendarEventAddDialogUrl = value; }, get_calendarEventAddDialogUrl: function () { return this._calendarEventAddDialogUrl; }, set_calendarEventEditDialog: function (value) { this._calendarEventEditDialog = value; }, get_calendarEventEditDialog: function () { return this._calendarEventEditDialog; }, get_viewEventDialog: function () { return this._viewEventDialog; }, set_viewEventDialog: function (value) { this._viewEventDialog = value; }, set_addEventDialog: function (value) { this._addEventDialog = value; }, get_addEventDialog: function () { return this._addEventDialog; }, set_editEventDialog: function (value) { this._editEventDialog = value; }, get_editEventDialog: function () { return this._editEventDialog; }, get_createEventButton: function () { return this._createEventButton; }, set_createEventButton: function (value) { this._createEventButton = value; }, get_calendarsCheckBoxList: function () { return this._calendarsCheckBoxList; }, set_calendarsCheckBoxList: function (value) { this._calendarsCheckBoxList = value; }, get_createCalendarSection: function () { return this._createCalendarSection; }, set_createCalendarSection: function (value) { this._createCalendarSection = value; }, get_uiCulture: function () { return this._uiCulture; }, set_uiCulture: function (value) { this._uiCulture = value; }, get_allowCreateEvents: function () { return this._allowCreateEvents; }, set_allowCreateEvents: function (value) { this._allowCreateEvents = value; }, get_filterExpression: function () { return this._filterExpression; }, set_filterExpression: function (value) { this._filterExpression = value }, get_sortExpression: function () { return this._sortExpression; }, set_sortExpression: function (value) { this._sortExpression = value }, get_isDesignMode: function () { return this._isDesignMode; }, set_isDesignMode: function (value) { this._isDesignMode = value }, get_allowChangeCalendarView: function () { return this._allowChangeCalendarView; }, set_allowChangeCalendarView: function (value) { this._allowChangeCalendarView = value; }, get_calendarsFilter: function () { return this._calendarsFilter; }, set_calendarsFilter: function (value) { this._calendarsFilter = value; }, get_startDST: function () { return this._startDST; }, set_startDST: function (value) { this._startDST = value; }, get_endDST: function () { return this._endDST; }, set_endDST: function (value) { this._endDST = value; } } Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView.registerClass("Telerik.Sitefinity.Modules.Events.Web.UI.Public.CalendarView", Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.ViewBase);