Languages

Fsharp
ActionScript
xBase
Clean
GPSS
PureBasic
Sieve
Erlang
JOVIAL
Mercury
Linda
DataFlex
PostScript
FoxPro2
VFP
Cobol
Prolog
Jython
Awk
VisualBasic
JavaScript
Matlab
ASP
Haskell
Csharp
D
Smalltalk
Nemerle
Pixilang
Java
SQL
Python
ObjectPascal
Ruby
Perl
Pascal
Assembler
PHP
C
Functions  Add function  Users  Registration  Enter   About  ASCII Table  Our helpers

Ruby-on-Rails


1 Ruby on Rails with Ajax: Modifying the Slide Show

2 Drag and Drop Everything (Almost Everything) continued

3 Adding a Dropped Photo

4 Filtering by Category

Ruby on Rails with Ajax: Modifying the Slide Show



(Page 1 of 4 )

In this conclusion to a two-part article, you_ll learn how to drag and drop slides in our example slideshow to modify it, and how to filter by category. This article is excerpted from chapter six of the book Ruby on Rails: Up and Running, written by Bruce A. Tate and Curt Hibbs (O_Reilly, 2006; ISBN: 0596101325). Copyright © 2006 O_Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O_Reilly Media.

Drag and Drop Everything (Almost Everything) 

We have already displayed a list of thumbnails of all photos that are in the slideshow and enabled the user to drag them around to rearrange their order in the slideshow. Now let_s add a second list of thumbnails, showing all photos that are not being used in the slideshow.

We_ll let the user add a photo to the slideshow by dragging it from the list of unused photos and dropping it onto the slideshow thumbnails. Similarly, we can enable the user to remove photos from the slideshow by dragging its thumbnail from the slideshow and dropping on the unused photos list. Finally, we_ll allow the user to filter the unused photos list by category.

As you might expect, we can accomplish all that in a very small amount of code. We will add a mere 58 lines of Ruby code to the models and controllers, 47 lines to the view templates, and 16 lines to our CSS stylesheet! Figure 6-4 gives you a preview of how this is going to look when we_re done.


Figure 6-4.  Preview of drag-and-drop slideshow editing

Let_s start by updating the slideshow_s edit template. Edit photos/app/views/slideshows/edit.rhtml to look like this:

  <h1>Editing slideshow</h1>

  <div id=_slideshow-contents_>
    <p style=_text-align: center;_><b>Slideshow Photos</b></p>
   
<div id=_slideshow-thumbs_>
     
<%= render :partial => _show_slides_draggable_ %>
    </div>
  </div>

  <div id=_slideshow-photo-picker_>
    <p style=_text-align: center;_><b>Unused Photos</b></p>
   
<div id=_slideshow-photos_>
      <%= render :partial => _photo_picker_ %>
    </div>
  </div>

  <div id=_slideshow-attributes_>
    <p><%= link_to _Play this Slideshow_, :action => _show_, :id => @slideshow %></p>
   
<div style=_border: thin solid; padding-left: 1em;_>
     
<p style=_text-align: center;_><b>Attributes</b></p>
     
<%= start_form_tag :action => _update_, :id => @slideshow %>
        <%= render :partial => _form_ %>
       
<%= submit_tag _Save Attributes_ %>
      <%= end_form_tag %>
    </div>
   
<p>
      <b>Hint:</b> Drag and drop photos between the
      two lists to add and remove photos from the
      slideshow. Drag photos within the slideshow to
      rearrange their order.
    </p>
 
</div>

  <%= drop_receiving_element("slideshow-contents",
            :update => "slideshow-thumbs",
            :url => {:action => "add_photo" },
            :accept => "photos",
            :droponempty => "true",
            :loading => visual_effect(:fade),
            :complete => visual_effect(:highlight, _sortable_thumbs_)
            ) %>

This file has been almost entirely rewritten, so there are no marked-as-changed lines. You can see that I have laid out this edit page into three sections:

  <div id=_slideshow-contents_> . . . </div>
  <div id=_slideshow-photo-picker_> . . . </div>
  <div id=_slideshow-attributes_> . . . </div>

Only the slideshow-photo-picker is new. It shows the list of unused photos that can be added to the slideshow. We will set up the CSS stylesheet to display these sections side-by-side as you saw them in Figure 6-4.

slideshow-contents is rendered by the partial template show_slides_draggable,
slideshow-photo-picker is rendered by the partial template photo_picker, and slideshow-attributes is mostly rendered by the form partial template that was generated from the scaffolding. I say "mostly" because I added a few things inline around the rendering of form.


1 2 3 4
"Stocky Dragon" Dinosaur Terrorized Late Cretaceous Europe

Photo of the fossilized hindlimb of Balaur bondoc.

Paleontologists have discovered that a close relative of Velociraptor hunted the dwarfed inhabitants of Late Cretaceous Europe, an island landscape largely isolated from nearby continents.

While island animals tend to be smaller and more primitive than their continental cousins, the theropod Balaur bondoc was as large as its relatives on other parts of the globe, and demonstrated advanced adaptations including fused bones and two terrifyingly large claws on each hind ...

More at http://www.nsf.gov/news/news_summ.jsp?cntn_id=117592&WT.mc_id=USNSF_51&WT.mc_ev=click


This is an NSF News item.

PycckaR
BepcuR


Articles
Articles


Library
Library


Downloads
Downloads

Google Chrome Golf 6
 © Internet, books, teachers and Rudevich Alexander brains.