main.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. /**
  3. * @ngdoc function
  4. * @name angularBootstrapCalendarApp.controller:MainCtrl
  5. * @description
  6. * # MainCtrl
  7. * Controller of the angularBootstrapCalendarApp
  8. */
  9. angular.module('mwl.calendar')
  10. .controller('MainCtrl', function ($scope, $modal, moment) {
  11. var currentYear = moment().year();
  12. var currentMonth = moment().month();
  13. $scope.events = [
  14. {
  15. title: 'Event 1',
  16. type: 'warning',
  17. starts_at: new Date(currentYear,currentMonth,25,8,30),
  18. ends_at: new Date(currentYear,currentMonth,25,9,30)
  19. },
  20. {
  21. title: 'Event 2',
  22. type: 'info',
  23. starts_at: new Date(currentYear,currentMonth,19,7,30),
  24. ends_at: new Date(currentYear,currentMonth,25,9,30)
  25. },
  26. {
  27. title: 'This is a really long event title',
  28. type: 'important',
  29. starts_at: new Date(currentYear,currentMonth,25,6,30),
  30. ends_at: new Date(currentYear,currentMonth,25,6,60)
  31. },
  32. ];
  33. $scope.calendarView = 'month';
  34. $scope.calendarDay = new Date();
  35. function showModal(action, event) {
  36. $modal.open({
  37. templateUrl: 'modalContent.html',
  38. controller: function($scope, $modalInstance) {
  39. $scope.$modalInstance = $modalInstance;
  40. $scope.action = action;
  41. $scope.event = event;
  42. }
  43. });
  44. }
  45. $scope.eventClicked = function(event) {
  46. showModal('Clicked', event);
  47. };
  48. $scope.eventEdited = function(event) {
  49. showModal('Edited', event);
  50. };
  51. $scope.eventDeleted = function(event) {
  52. showModal('Deleted', event);
  53. };
  54. $scope.setCalendarToToday = function() {
  55. $scope.calendarDay = new Date();
  56. };
  57. $scope.toggle = function($event, field, event) {
  58. $event.preventDefault();
  59. $event.stopPropagation();
  60. event[field] = !event[field];
  61. };
  62. });