Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.85 KB | None | 0 0
  1. events: "../ajax/fullcalendar/response.php?view=1",
  2.  
  3. $.post( "getevents2.php",
  4. {'getEvents': 1},
  5. function(data) {
  6. var array = JSON.parse(data);
  7. for(i = 0; i < array.length; i++) {
  8. $('#calendar').fullCalendar( 'renderEvent', {
  9. title: 'Sometitle',
  10. start: days[array[i]['day']]+'T'+array[i]['start_time'], // here we are setting needed date from array 'days' by day's name which we got from database
  11. end: days[array[i]['day']]+'T'+array[i]['end_time'] // here's the same
  12. } );
  13. }
  14. }
  15. );
  16.  
  17. //Custom
  18. //De momento esta funcion no se usa, asi que, sigue usando fecha completa en lugar de solo 7 dias, asi que en teoria, los eventos desapareceran cuando avance el tiempo
  19. Date.prototype.getDaysOfCurrentWeek = function(start)
  20. {
  21. // Array of all days of week
  22. var days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  23.  
  24. // Calculates date of first day of current week
  25. start = start || 0;
  26. var today = new Date(this.setHours(0, 0, 0, 0));
  27. var day = today.getDay() - start;
  28. var date = today.getDate() - day;
  29.  
  30. // Then we are calculating all dates of current week and then reformat them into ISOO
  31. var daysOfWeek = new Object();
  32. for(i = 0; i < 8; i++) {
  33. tmp = new Date(today.setDate(date+i));
  34. daysOfWeek[days[i]] = tmp.getFullYear()+'-'+(tmp.getMonth()+1)+'-'+tmp.getDate();
  35. }
  36.  
  37. return daysOfWeek;
  38. }
  39. //Ends Custom
  40.  
  41. var days = new Date().getDaysOfCurrentWeek(); // gets array like ('nameOfDay' => 0000-00-00)
  42. $(document).ready(function(){
  43.  
  44.  
  45. var currentMousePos = {
  46. x: -1,
  47. y: -1
  48. };
  49. jQuery(document).on("mousemove", function (event) {
  50. currentMousePos.x = event.pageX;
  51. currentMousePos.y = event.pageY;
  52. });
  53.  
  54.  
  55. /* initialize the external events
  56. -----------------------------------------------------------------*/
  57. $('#external-events .external-event').each(function() {
  58.  
  59. // store data so the calendar knows to render an event upon drop
  60. $(this).data('event', {
  61. title: $.trim($(this).text()), // use the element's text as the event title
  62. color: $.trim($(this).data("color")),
  63. stick: true // maintain when user navigates (see docs on the renderEvent method)
  64. });
  65.  
  66. // make the event draggable using jQuery UI
  67. $(this).draggable({
  68. zIndex: 999,
  69. revert: true, // will cause the event to go back to its
  70. revertDuration: 0 // original position after the drag
  71. });
  72.  
  73. });
  74. ////////////////
  75.  
  76. var calendar = $('#calendar').fullCalendar({
  77. header:{
  78. left: 'prev,next today',
  79. center: 'title',
  80. right: 'month,agendaWeek,agendaDay'
  81. },
  82.  
  83. defaultView: 'agendaWeek', //agendaWeek
  84. editable: true,
  85. selectable: true,
  86. allDaySlot: false,
  87. //Custom
  88. // allDaySlot: false, //repetido
  89. hiddenDays: [0], //Ocultar Domingo
  90. columnFormat: 'dddd',
  91. minTime: '07:00:00',
  92. maxTime: '22:00:00',
  93. slotDuration: "00:50:00", //Cada 54 minutos
  94. slotLabelInterval: 50,
  95. //slotMinutes: 54,
  96. slotLabelFormat: 'h(:mm)a',
  97. header: true, //lo cambie a false para esconderlo y cuando lo devolvi a true ya no aparecio el encabezado
  98.  
  99.  
  100.  
  101. droppable: true,
  102. //Ends Custom
  103.  
  104.  
  105. events: "../ajax/fullcalendar/response.php?view=1", //De las lineas 87 a 101, no funciono, descomentar 102
  106.  
  107.  
  108.  
  109. eventClick: function(event, jsEvent, view) {
  110. endtime = $.fullCalendar.moment(event.end).format('h:mm');
  111. starttime = $.fullCalendar.moment(event.start).format('dddd, MMMM Do YYYY, h:mm');
  112. var mywhen = starttime + ' - ' + endtime;
  113. $('#modalTitle').html(event.title);
  114. $('#modalWhen').text(mywhen);
  115. $('#eventID').val(event.id);
  116. $('#calendarModal').modal();
  117. },
  118.  
  119. //header and other values
  120. select: function(start, end, jsEvent) {
  121. endtime = $.fullCalendar.moment(end).format('h:mm');
  122. starttime = $.fullCalendar.moment(start).format('dddd, MMMM Do YYYY, h:mm');
  123. var mywhen = starttime + ' - ' + endtime;
  124. start = moment(start).format();
  125. end = moment(end).format();
  126. $('#createEventModal #startTime').val(start);
  127. $('#createEventModal #endTime').val(end);
  128. $('#createEventModal #when').text(mywhen);
  129. $('#createEventModal').modal('toggle');
  130. },
  131.  
  132.  
  133.  
  134.  
  135. //custom
  136. eventReceive: function(event){
  137. var title = event.title;
  138. var color = event.color;
  139. $.ajax({
  140. url: '../ajax/fullcalendar/response.php',
  141. data: 'action=add&title='+title+'&start='+moment(event.start).format()+'&end='+moment(event.end).format()+'&color='+color,
  142. type: 'POST',
  143. dataType: 'json',
  144. success: function(response){
  145. event.id = response.eventid;
  146. $('#calendar').fullCalendar('updateEvent',event);
  147.  
  148. },
  149. error: function(e){
  150. console.log(e.responseText);
  151.  
  152. }
  153. });
  154. $('#calendar').fullCalendar('updateEvent',event);
  155.  
  156.  
  157. console.log(event);
  158.  
  159. },
  160. //custom
  161.  
  162.  
  163. eventDrop: function(event, delta){
  164. $.ajax({
  165. url: '../ajax/fullcalendar/response.php',
  166. data: 'action=update&title='+event.title+'&start='+moment(event.start).format()+'&end='+moment(event.end).format()+'&id='+event.id ,
  167. type: "POST",
  168. success: function(json) {
  169. //alert(json);
  170. }
  171. });
  172. },
  173. eventResize: function(event) {
  174. $.ajax({
  175. url: '../ajax/fullcalendar/response.php',
  176. data: 'action=update&title='+event.title+'&start='+moment(event.start).format()+'&end='+moment(event.end).format()+'&id='+event.id,
  177. type: "POST",
  178. success: function(json) {
  179. //alert(json);
  180. }
  181. });
  182. },
  183.  
  184. //custom
  185. eventDragStop: function (event, jsEvent, ui, view) {
  186. if (isElemOverDiv()) {
  187. var eventID = $('#eventID').val();
  188. var con = confirm('&iquest;Estas seguro de eliminar este evento permanentemente?');
  189. if(con == true) {
  190. $.ajax({
  191. url: '../ajax/fullcalendar/response.php',
  192. data: 'action=delete&id='+event.id,
  193. type: 'POST',
  194. dataType: 'json',
  195. success: function(response){
  196. console.log(response);
  197. // if(response.status == 'success'){
  198. //$('#calendar').fullCalendar('removeEvents');
  199. //$("#calendar").fullCalendar('removeEvents',+eventID);
  200. // $("#calendar").fullCalendar('removeEvents',+response.idEvent);
  201. //getFreshEvents();
  202.  
  203. if(response == 1)
  204. //$("#calendar").fullCalendar('removeEvents',eventID);
  205. $("#calendar").fullCalendar('removeEvents',event.id);
  206. else
  207. return false;
  208.  
  209.  
  210. $('#calendar').fullCalendar( 'refetchEvents' );
  211. // }
  212. },
  213. error: function(e){
  214. alert('Error processing your request: '+e.responseText);
  215. }
  216. });
  217. }
  218. }
  219. }
  220. //custom
  221.  
  222. });
  223.  
  224.  
  225.  
  226. $('#submitButton').on('click', function(e){
  227. // We don't want this to act as a link so cancel the link action
  228. e.preventDefault();
  229. doSubmit();
  230. });
  231.  
  232. $('#deleteButton').on('click', function(e){
  233. // We don't want this to act as a link so cancel the link action
  234. e.preventDefault();
  235. doDelete();
  236. });
  237.  
  238. function doDelete(){
  239. $("#calendarModal").modal('hide');
  240. var eventID = $('#eventID').val();
  241. $.ajax({
  242. url: '../ajax/fullcalendar/response.php',
  243. data: 'action=delete&id='+eventID,
  244. type: "POST",
  245. success: function(json) {
  246. if(json == 1)
  247. $("#calendar").fullCalendar('removeEvents',eventID);
  248. else
  249. return false;
  250.  
  251.  
  252. }
  253. });
  254. }
  255. function doSubmit(){
  256. $("#createEventModal").modal('hide');
  257. var title = $('#title').val();
  258. var startTime = $('#startTime').val();
  259. var endTime = $('#endTime').val();
  260. var color = $('#color').val();
  261.  
  262. $.ajax({
  263. url: '../ajax/fullcalendar/response.php',
  264. // data: 'action=add&title='+title+'&start_time='+startTime+'&end_time='+endTime, //start='+startTime+'&end='+endTime, //Si no regreso a como estaba devuelve 1970
  265. data: 'action=add&title='+title+'&start='+startTime+'&end='+endTime+'&color='+color, //Si no regreso a como estaba devuelve 1970
  266. type: "POST",
  267. success: function(json) {
  268.  
  269.  
  270. $("#calendar").fullCalendar('renderEvent',
  271. {
  272. id: json.id,
  273. title: title,
  274. start: startTime,
  275. end: endTime,
  276. color: color,
  277. //start: days[array[i]['day']]+'T'+array[i]['start_time'], // here we are setting needed date from array 'days' by day's name which we got from database
  278. //end: days[array[i]['day']]+'T'+array[i]['end_time'] // here's the same
  279. },
  280.  
  281. true);
  282.  
  283. //alert(json);
  284.  
  285. }
  286. });
  287.  
  288.  
  289. }
  290.  
  291.  
  292.  
  293.  
  294. function getFreshEvents(){
  295. $.ajax({
  296. url: '../ajax/fullcalendar/response.php',
  297. type: 'POST', // Send post data
  298. data: 'view=1',
  299. async: false,
  300. success: function(s){
  301. freshevents = s;
  302. }
  303. });
  304. $('#calendar').fullCalendar('addEventSource', s.parse(freshevents));
  305. }
  306.  
  307. function isElemOverDiv() {
  308. var trashEl = jQuery('#trash');
  309.  
  310. var ofs = trashEl.offset();
  311.  
  312. var x1 = ofs.left;
  313. var x2 = ofs.left + trashEl.outerWidth(true);
  314. var y1 = ofs.top;
  315. var y2 = ofs.top + trashEl.outerHeight(true);
  316.  
  317. if (currentMousePos.x >= x1 && currentMousePos.x <= x2 &&
  318. currentMousePos.y >= y1 && currentMousePos.y <= y2) {
  319. return true;
  320. }
  321. return false;
  322. }
  323.  
  324. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement