January 15th, 2009 by Andrea Franz
Some people in the past had problems using the Gallery extension on Dreamhost. I didn’t try Dreamhost but someone from the Radiant list solved that problem following these instructions. Check it out if you are on Dreamhost too.
March 27th, 2008 by Andrea Franz
Some weeks ago Casper Fabricius sent me a patch for the Radiant Newsletter extension. He added a statistics system to track how many times sent emails are opened. I have finally found the time to apply it and make a commit to my repository. Thank you very very much for your work Casper! I’ll write an article about this extension as soon as possible.
December 17th, 2007 by Andrea Franz
I love to use prototype and scriptaculous to create Rich Internet Application, and I love all the built-in effects and libraries of script.aculo.us.
Today I was working with Sortable.create to provide a simple way to reorder images inside a gallery. I started using the same code used in the SortableListsDemo page of the official wiki. Each time the list is updated, the serialized list is sent to the server. The server receives the list and updates all the images positions. It’s pretty simple and works fine, but the problem is that the server executes a query for each image in the gallery. This means that if I have 100 images, 100 queries will be run. It’s a hell for my server! The best way to improve this action is to send to the server more detailed information, such as the dragged image, the old position and the new position. In this way I can execute only 2 queries for each movement. To do that I wrote a simple javascript class called LiteSortable that acts like the Sortable.create method. It receives the same parameters, and the same callbacks: onUpdate, onChange. The only change is that these 2 callbacks will receive more information about the movement, and I can improve the previous client side code with:
function sort(list, element, id, old_position, new_position) {
new Ajax.Request('/admin/gallery_item/sort/', {
evalScripts:true,
parameters: {
id: id,
old_position: old_position,
new_position: new_position
}
});
}
document.observe('dom:loaded', function() {
new LiteSortable('list', {
onUpdate: sort
});
});
And the server code become like the following:
def sort
old_position, new_position = params[:old_position].to_i, params[:new_position].to_i
@item = GalleryItem.find(:first, :conditions => ["id = ? AND position = ?", params[:id], old_position])
if @item
x, y, z = old_position < new_position ? ["-", "<", ">"] : ["+", ">", "<"]
GalleryItem.update_all("position = (position #{x} 1)", ["parent_id IS NULL AND gallery_id = ? AND position #{y}= ? AND position #{z}= ?", @item.gallery_id, new_position, old_position])
@item.update_attribute('position', new_position)
else
@error = true
end
end
If @error is true, it means that the dragged image it’s been deleted or moved by somone else.
If you want to use LiteSortable you can check out the entire project with:
svn co http://dev.gravityblast.com/svn/projects/js/LiteSortable/
…or save download the lite_sortable.js file from here.
Filed under: Development,
Javascript,
RIA,
Rails,
Ruby |
Comments Off