02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

{<br />

$id = (int) $_POST['event_id'];<br />

}<br />

else { $id = NULL; }<br />

echo $obj->$use_array['method']($id);<br />

function __autoload($class_name)<br />

{<br />

$filename = '../../../sys/class/class.'<br />

. strtolower($class_name) . '.inc.php';<br />

if ( file_exists($filename) )<br />

{<br />

include_once $filename;<br />

}<br />

}<br />

?><br />

CHAPTER 8 ■ EDITING THE CALENDAR WITH AJAX AND JQUERY<br />

Save this file <strong>and</strong> reload http://localhost/. Next, click the Add a New Event button to bring up the<br />

form in a modal window, <strong>and</strong> then enter a new event with the following information:<br />

• Event Title: Test Event<br />

• Event Start: 2010-01-04 08:00:00<br />

• Event End: 2010-01-04 10:00:00<br />

• Event Description: This is a test description.<br />

Now click the Create a New Event button; the modal window will fade out, <strong>and</strong> the following<br />

message will be logged into the console:<br />

Event saved!<br />

Note that the new event does not appear in the calendar unless the page is refreshed. This may<br />

confuse users, so in the next section you’ll modify the app to add newly created events into the calendar<br />

after a successful save.<br />

Adding Events Without Refreshing<br />

Adding the new events to the calendar is fairly involved; after the event is saved, you need to take the<br />

following steps:<br />

1. Deserialize the form data.<br />

2. Create date objects for both the currently displayed month <strong>and</strong> the new event.<br />

3. Make sure the month <strong>and</strong> year match up for the new event.<br />

273

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!