Sha256: 9f36e38876492861637634359989789a9528e57fa1056bb4e8a793dd97bf56dc

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

$(document).ready(function(){
	// UJS Destroy
    $("a.destroy").click(function(){
        var result = confirm("Are you sure you want to delete this?");
        if (result) {
			try {
				var id = $(this).attr("id");
				// Parent ID is determined from link ID. Example: post_3_link (link ID) yields post_3 (parent ID).
				var endIndex = id.lastIndexOf('_');
				if (endIndex > 1) {
					var parent_id = '#' + id.slice(0, endIndex);
					$(parent_id).animate({backgroundColor: "#FF0000"}, 500);
					$(parent_id).fadeOut(500);
				} else {
					throw "Invalid ID";
				}
				// Finally, call the destroy action.
	            $.post($(this).attr("href"), "_method=delete");
			} catch (e) {
				alert("Error: " + e + ". Check that parent ID is defined and/or the link ID includes parent ID as part of the link ID.");
			}
        }
		// Ensure the default event does not fire.
		return false;
    });
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aeonscope-btech_rest-0.4.1 rails_generators/rest_setup/templates/public/javascripts/rest.js