"use strict"; (function () { 'use strict'; angular.module('changeModule') .directive('calendarMonthView', ['$timeout', '$log', '$locale', '$rootScope', 'events', function ($timeout, $log, $locale, $rootScope, events) { return { restrict: 'E', templateUrl: 'views/change/calendar-month-view.html', require: '^calendar', scope: { id: '@', viewType: '@' }, link: function (scope, element, attrs, calendarCtrl) { var calendar = scope[scope.id], localeCulture = $locale.culture; //if locale is not supported in DayPilot default to 'en-us' localeCulture = !DayPilot.Locale.find(localeCulture) ? 'en-us' : localeCulture; scope.model = calendarCtrl.model; scope.config = { heightSpec: 'Full', theme: 'monthview', cssClassPrefix: 'monthview', weekStarts: 0, viewType: scope.viewType, weeks: 1, sortDirections: ['asc'], locale: localeCulture, showToolTip: true, onBeforeHeaderRender: function (args) { args.header.html = moment(args.header.dayOfWeek, "d").format("dddd"); }, onTimeRangeSelected: function (args) { if (calendar.timeRangeSelectedHandling !== calendarCtrl.handling.select.disabled) { calendar.clearSelection(); scope.model.context.scheduledStartDate = args.start.toDateLocal(); scope.model.context.scheduledEndDate = args.end.toDateLocal(); scope.$apply(); } }, onEventMove: function (args) { if (args.e.resource() !== scope.model.currentRequestResourceId) { args.preventDefault(); } }, onEventMoved: function (args) { scope.model.context.scheduledStartDate = args.newStart.toDateLocal(); scope.model.context.scheduledEndDate = args.newEnd.toDateLocal(); scope.$apply(); }, onEventResize: function (args) { if (args.e.resource() !== scope.model.currentRequestResourceId) { args.preventDefault(); } }, onEventResized: function (args) { scope.model.context.scheduledStartDate = args.newStart.toDateLocal(); scope.model.context.scheduledEndDate = args.newEnd.toDateLocal(); scope.$apply(); }, onEventClicked: calendarCtrl.onEventClicked }; scope.$watch('model.showWeekends', function () { calendar.showWeekend = scope.model.showWeekends; updateMonthView(); }); scope.$watch('model.context.scheduledStartDate', function () { enqueueRescheduleChangeRequest(); }); scope.$watch('model.context.scheduledEndDate', function () { enqueueRescheduleChangeRequest(); }); scope.$watch('model.context', function () { calendarCtrl.updateCalendarHandling(calendar); }, true); scope.$watch('model.collisions', function () { displayCollisions(); }, true); scope.$watch('model.calendarTypes', function () { displayCollisions(); }, true); var off = $rootScope.$on(events.CHANGE_COLLISION_STATUS_CHANGED, function (event, addressedCollisions) { calendarCtrl.applyAddressedCollisions(addressedCollisions); displayCollisions(); }); scope.$on('$destroy', function () { off(); }); function displayCollisions() { calendarCtrl.displayCollisions({ calendar: calendar, resources: scope.config.resources, changeCollisionCss: 'monthview_event_collision', changeNonCollisionCss: 'monthview_event_secondary', outageCollisionCss: 'monthview_event_outage_collision', outageNonCollisionCss: 'monthview_event_outage_secondary', businessEventCollisionCss: 'monthview_event_business_event_collision', businessEventNonCollisionCss: 'monthview_event_business_event_secondary', updateCalendar: updateMonthView }); } function enqueueRescheduleChangeRequest() { $timeout(function () { rescheduleChangeRequest(scope.model.context.scheduledStartDate, scope.model.context.scheduledEndDate); }); } function rescheduleChangeRequest(start, end) { if (calendarCtrl.rescheduleChangeRequest(calendar, start, end)) { updateMonthView(); } } function updateMonthView() { var start = scope.model.context.scheduledStartDate; var end = scope.model.context.scheduledEndDate; $log.log("update month view: start=" + start + ", end=" + end); if (!start) { start = new Date(); } calendar.startDate = new DayPilot.Date(start, true); calendar.update(); } updateMonthView(); } }; } ]); })();