calendarCtrl.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. /**
  3. * Controller of the angularBootstrapCalendarApp
  4. */
  5. app.controller('CalendarCtrl', ["$scope", "$aside", "moment", "SweetAlert", function ($scope, $aside, moment, SweetAlert) {
  6. var date = new Date();
  7. var d = date.getDate();
  8. var m = date.getMonth();
  9. var y = date.getFullYear();
  10. $scope.events = [
  11. {
  12. title: 'Birthday Party',
  13. type: 'home',
  14. starts_at: new Date(y, m, 5, 19, 0),
  15. ends_at: new Date(y, m, 5, 22, 30)
  16. },
  17. {
  18. title: 'AngularJS Seminar',
  19. type: 'off-site-work',
  20. starts_at: new Date(y, m, 8, 10, 30),
  21. ends_at: new Date(y, m, 9, 18, 30)
  22. },
  23. {
  24. title: 'Event 1',
  25. type: 'job',
  26. starts_at: new Date(y, m, d - 5),
  27. ends_at: new Date(y, m, d - 2)
  28. },
  29. {
  30. title: 'Event 2',
  31. type: 'cancelled',
  32. starts_at: new Date(y, m, d - 3, 16, 0),
  33. ends_at: new Date(y, m, d - 3, 18, 0)
  34. },
  35. {
  36. title: 'This is a really long event title',
  37. type: 'to-do',
  38. starts_at: new Date(y, m, d + 1, 19, 0),
  39. ends_at: new Date(y, m, d + 1, 22, 30)
  40. },
  41. ];
  42. $scope.calendarView = 'month';
  43. $scope.calendarDay = new Date();
  44. function showModal(action, event) {
  45. var modalInstance = $aside.open({
  46. templateUrl: 'calendarEvent.html',
  47. placement: 'right',
  48. size: 'sm',
  49. backdrop: true,
  50. controller: function ($scope, $modalInstance) {
  51. $scope.$modalInstance = $modalInstance;
  52. $scope.action = action;
  53. $scope.event = event;
  54. $scope.cancel = function () {
  55. $modalInstance.dismiss('cancel');
  56. };
  57. $scope.deleteEvent = function () {
  58. $modalInstance.close($scope.event, $scope.event);
  59. };
  60. }
  61. });
  62. modalInstance.result.then(function (selectedEvent, action) {
  63. $scope.eventDeleted(selectedEvent);
  64. });
  65. }
  66. $scope.eventClicked = function (event) {
  67. showModal('Clicked', event);
  68. };
  69. $scope.addEvent = function () {
  70. $scope.events.push({
  71. title: 'New Event',
  72. starts_at: new Date(y, m, d, 10, 0),
  73. ends_at: new Date(y, m, d, 11, 0),
  74. type: 'job'
  75. });
  76. $scope.eventEdited($scope.events[$scope.events.length - 1]);
  77. };
  78. $scope.eventEdited = function (event) {
  79. showModal('Edited', event);
  80. };
  81. $scope.eventDeleted = function (event) {
  82. SweetAlert.swal({
  83. title: "Are you sure?",
  84. text: "Your will not be able to recover this event!",
  85. type: "warning",
  86. showCancelButton: true,
  87. confirmButtonColor: "#DD6B55",
  88. confirmButtonText: "Yes, delete it!",
  89. cancelButtonText: "No, cancel plx!",
  90. closeOnConfirm: false,
  91. closeOnCancel: false
  92. }, function (isConfirm) {
  93. if (isConfirm) {
  94. $scope.events.splice(event.$id, 1);
  95. SweetAlert.swal("Deleted!", "Event has been deleted.", "success");
  96. } else {
  97. SweetAlert.swal("Cancelled", "Event is safe :)", "error");
  98. }
  99. });
  100. };
  101. $scope.setCalendarToToday = function () {
  102. $scope.calendarDay = new Date();
  103. };
  104. $scope.toggle = function ($event, field, event) {
  105. $event.preventDefault();
  106. $event.stopPropagation();
  107. event[field] = !event[field];
  108. };
  109. }]);