acts_as_list automatic numbering

48 views
Skip to first unread message

Ronny Hanssen

unread,
Dec 4, 2011, 4:33:24 PM12/4/11
to hobo...@googlegroups.com
Hi all,

I have a model set up with acts-as-list, where the items in the list are movable using drag-and-drop. So far so good. However, this specific list should be numbered. So, the quick-minded suggest adding the position to the card. Well, that's all dandy, but drag-n-dropping the items does not update the cards themselves. So, I could write a javascript that updates these numbers on every drag-n-drop operation. But, that seems overkill when exchanging the collection UL with an OL would do the trick.

But, what is the "slickest" way to change the collection? I know I can change the child-collection from the automatic generated show-page for the list. Would that be the best approach you think?

Regards,
Ronny

Bryan Larsen

unread,
Dec 6, 2011, 2:57:45 PM12/6/11
to hobo...@googlegroups.com
That seems like a simple request and something that should be easy to
do, but isn't.

IMO, the best solution is to cut and paste the collection definition
from rapid_generics.dryml into your application.dryml, and then change
the 'ul' into an 'ol'. This won't any other part of your application
until you update your CSS since the Hobo theme hides list markers
anyways.

For that reason we should consider making the same change in Hobo
itself for everybody.

Another option would be:

<def tag="collection" attrs="list-tag">
<% list_tag ||= 'ul' %>
<call-tag tag="&list_tag" class="collection #{collection_name
:dasherize => true}" merge-attrs unless="empty?">
<li param="item" class="#{scope.even_odd} #{model_id_class}"
repeat="&select_viewable">
<do param="default"><card param/></do>
</li>
</call-tag>
<empty-collection-message param="empty-message"/>
</def>

which would allow you to do:

<collection: list-tag='ol'> in your page. However, I think the first
option I mentioned is best. Does anybody have any objections to
changing the collection list tag to 'ol'?

Bryan

> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/Z_3Vzpj_HRcJ.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

Ronny Hanssen

unread,
Dec 8, 2011, 9:57:47 AM12/8/11
to hobo...@googlegroups.com
Thanks Bryan. The de-facto standard in the internet HTML development community seems to have ended up on using ul, strangely enough also even when order is important...

In most cases (i.e menulists, record collections, etc.) the items are ordered.

With that in mind I'd be happy with being changed to ol. Maybe implement your last suggestion with
<def tag="collection" attrs="list-tag">
  <% list_tag ||= 'ol' %>
...

... in order to "revert" the change for those that really need it...

How about in addition also making the collection tag polymorphic? That would make it easy to override the collection tag definition by model.

Ronny

Bryan Larsen

unread,
Dec 8, 2011, 10:06:03 AM12/8/11
to hobo...@googlegroups.com
> How about in addition also making the collection tag polymorphic? That would
> make it easy to override the collection tag definition by model.
>

That wouldn't do much good -- the only two things that are ever passed
to a collection are plain old lists and ActiveRecord finders. The
list itself can contain many different types of objects: the
live-search is a good example of that in action.

Bryan

Ronny Hanssen

unread,
Dec 22, 2011, 7:28:47 AM12/22/11
to hobo...@googlegroups.com
Ah. Yes, you are right. Didn't think about the fact that the collections can be multi-typed.

I then suggest that the ul is turned into a ol, with the option to override it, using a "list-tag" parameter.

Any objections to that idea?


~Ronny

Bryan Larsen

unread,
Dec 22, 2011, 12:51:31 PM12/22/11
to hobo...@googlegroups.com
OK, here's the new definition. Something very similar will end up in
Hobo 1.4, but here it is for those who want it early.

Besides the update discussed, it has been updated to work better with
non-ActiveRecord arrays.

Bryan

<!-- Repeats the body of the tag inside a `<ul>` list with one item
for each object in the collection (`this`). If no body is given,
renders a `<card>` inside the `<li>`.
Automatically adds 'even' and 'odd' CSS classes.
`empty-collection-message` is called from this tag.   To suppress you
can use the `without-empty-message` pseudo-attribute:
    <collection without-empty-message/>
If your collection is an ActiveRecord result set (and in Hobo it most
likely is), the best way to customize the empty message is via
translations.   Example: for product models, the key to customize
would be `products.collection.empty_message`.
If your collection is a generic array, empty-collection-message
doesn't work.   `<collection>` also sets the last_if flag, so you can
use the `<else>` tag to display a message:
    <collection with="&[]"/>    <else>No items.</else>
### Attributes
- list-tag:  set to 'ol' if you prefer that over 'ul'. --><def


tag="collection" attrs="list-tag">  <% list_tag ||= 'ul' %>  <call-tag
tag="&list_tag" class="collection #{collection_name :dasherize =>
true}" merge-attrs unless="empty?">    <li param="item"
class="#{scope.even_odd} #{model_id_class}" repeat="&select_viewable">
    <do param="default"><card param/></do>    </li>  </call-tag>

<empty-collection-message param="empty-message"/>  <if/><%# set
last-if so <else/> works %></def>
<!-- Renders a message such as "No products to display". If the
collection (`this`) is empty, `style="display:none"` is added. This
means the message is still present and can be revealed with JavaScript
if all items in the collection are removed via ajax remove buttons.
--><def tag="empty-collection-message">  <unless
test="&this._?.member_class.nil?">    <div
class="empty-collection-message" style="#{'display:none' if
!this.empty?}" param="default">      <ht
key="#{this.member_class.name.underscore}.collection.empty_message">
    No <collection-name/> to display      </ht>    </div>
</unless></def>

> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/hobousers/-/T3ypw4DMVVsJ.

Bryan Larsen

unread,
Dec 22, 2011, 12:53:57 PM12/22/11
to Hobo Users
Arg, I've successully posted tags using gmail before, I don't know why
it failed this time. Trying again.

Ronny Hanssen

unread,
Dec 22, 2011, 7:20:57 PM12/22/11
to hobo...@googlegroups.com
Good. Thanks :)

kevinpfromnm

unread,
Dec 23, 2011, 12:17:10 PM12/23/11
to hobo...@googlegroups.com
Seeing that brings to mind a suggestion for the taglibs.  Now that internationalization is the preferred way to customize text, would make sense to have a list of translation keys used in each tag (along with the already existing parameters and attributes).

Bryan Larsen

unread,
Dec 23, 2011, 12:21:43 PM12/23/11
to hobo...@googlegroups.com
Good point. I've been adding the major ones ad-hoc to the
documentation as I update tags, but a systematic listing of all
translation tags would be very useful.

Is there anybody who would like to volunteer to do this? Expertise is
not required, so it's a great way to get yourself into the list of
people who have patches accepted into Hobo. :)

cheers,
Bryan

> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/hobousers/-/-W4_Uo15YHQJ.

Reply all
Reply to author
Forward
0 new messages