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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

292<br />

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

});<br />

// Sets the action for the form submission<br />

var action = $(event.target).attr("name") || "edit_event";<br />

// Loads the editing form <strong>and</strong> displays it<br />

$.ajax({<br />

type: "POST",<br />

url: processFile,<br />

data: "action="+action,<br />

success: function(data){<br />

// Hides the form<br />

var form = $(data).hide(),<br />

// Make sure the modal window exists<br />

modal = fx.initModal();<br />

// Call the boxin function to create<br />

// the modal overlay <strong>and</strong> fade it in<br />

fx.boxin(null, modal);<br />

// Load the form into the window,<br />

// fades in the content, <strong>and</strong> adds<br />

// a class to the form<br />

form<br />

.appendTo(modal)<br />

.addClass("edit-form")<br />

.fadeIn("slow");<br />

},<br />

error: function(msg){<br />

alert(msg);<br />

}<br />

});<br />

Storing the Event ID if One Exists<br />

Next, the event ID needs to be extracted, assuming it’s available. To find this value, use the event.target<br />

property again, but this time look for the sibling element with the name, event_id, <strong>and</strong> then store the<br />

value of this in a variable called id.<br />

You add this to the event h<strong>and</strong>ler using the following bold code:<br />

// Displays the edit form as a modal window<br />

$(".admin-options form,.admin").live("click", function(event){<br />

// Prevents the form from submitting<br />

event.preventDefault();<br />

// Sets the action for the form submission<br />

var action = $(event.target).attr("name") || "edit_event",<br />

// Saves the value of the event_id input

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

Saved successfully!

Ooh no, something went wrong!