Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate event after Ajax post
    primarykey
    data
    text
    <p>I'm trying to update an event after an ajax post to change the title of the event and give it a class so I can change its color. I would also like to tell if an event from my JSON source is approved, and if so, changed its color. I have commented my code below:</p> <p>Upated code:</p> <pre><code>$(document).ready(function () { var liveDate = new Date(); var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var calendar = $('#calendar').fullCalendar({ disableDragging: true, header: { left: 'prev,next today', center: 'title', right: 'year' }, eventClick: function (calEvent, jsEvent, view, eventid) { var eventid = calEvent.id; var start = calEvent.start; var end = calEvent.end; var fullname = calEvent.fullname; var fancyContent = ('&lt;div class="header"&gt;approve booking for ' + eventid + calEvent.title + '&lt;a href="#" class="approve" id="' + eventid + '"&gt;yes&lt;/a&gt;&lt;a href="#" class="approve"&gt;no&lt;/a&gt;&lt;/div&gt;'); $.fancybox({ content: fancyContent }); var getid = $('.approve').attr('id'); // approve function $('.approve').click(function (calEvent, jsEvent, view, getid) { var getid = $('.approve').attr('id'); if ($(this).html() == "yes") { // AJAX post to insert into DB $.post("ajax.php", { action: 'approve', eventid: getid, color: 'green' }, function (data) { var fancyContent = ('&lt;div class="header"&gt;&lt;p&gt;' + data.msge + '&lt;/p&gt;&lt;/div&gt;'); $.fancybox({ content: fancyContent }); }, "json"); // attemping to add class to event to change color, this does not work $('#calendar').fullCalendar('clientEvents', calEvent).addClass('fc-event-updated'); // trying to get id from last updated event so I can change it but this also does not work var eventObject = $('#calendar').fullCalendar('clientEvents', eventid); if (eventObject != null) { eventObject.title = fullname + ' approved'; eventObject.color = 'green'; $('#calendar').fullCalendar('updateEvent', eventObject); } } else { // close fancybox $.fancybox.close(); } // end of if }); // end of approve click }, selectable: true, selectHelper: true, select: function (start, end, allDay, approved, title) { // disable booking dates in the past if (liveDate &gt; start) { var fancyContent = ('&lt;div class="header"&gt;Canot book dates in the past&lt;/div&gt;'); $.fancybox({ content: fancyContent }); return false; } else { // get user to confirm selection var fancyContent = ('&lt;div class="header"&gt;Book the following days off&lt;/div&gt;Start Time: &lt;/b&gt;&lt;/label&gt;' + $.fullCalendar.formatDate(start, "yyyy-MM-dd") + '&lt;br&gt;' + '&lt;label&gt;&lt;b&gt;End Time: &lt;/b&gt;&lt;/label&gt;' + $.fullCalendar.formatDate(end, "yyyy-MM-dd") + '&lt;br&gt;' + '&lt;label&gt;&lt;a href="#" class="button"&gt;yes&lt;/a&gt;&lt;a class="button" href="#"&gt;no&lt;/a&gt;&lt;/div&gt;'); $.fancybox({ content: fancyContent }); $('.button').click(function () { if ($(this).html() == "yes") { // ajax to insert into DB $.post("ajax.php", { start: $.fullCalendar.formatDate(start, "yyyy-MM-dd"), end: $.fullCalendar.formatDate(end, "yyyy-MM-dd"), action: 'add', userid: userid }, function (data) { // render event an insert id generated from query calendar.fullCalendar('renderEvent', { id: data, title: fullname + 'pending approval', start: start, end: end, className: 'unapproved' }, false // make the event "stick" ); }, "json"); // close fancybox $.fancybox.close(); } else { // close fancybox $.fancybox.close(); } // end of if }); //if ajax post successful then show booking on page - not sure how to get value from previous fancybox } // end liveDate &gt; start else calendar.fullCalendar('unselect'); }, editable: true, eventSources: [ // event sources from json { url: 'json-events.php', type: 'POST', error: function (data) { alert('there was an error while fetching events!' + data.msge); }, // if event is approved = 1 then change color and title of event. This does not work success: function (data) { var event = data.approved; if (data.approved == "1") { var title = title + "approved"; var className = "approved"; } else { var title = title + "awaiting approval"; var className = "unapproved"; } } } ] }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload