A small follow up, I wanted a nicely nested reusable tree-select-one for
assigning a single record of one model in a belongs_to relation to a
tree-structured model.
So I modified (and simplified kicking out most of the options) the
select-one tag like this:
<def attrs='include-none' tag='tree-select-one'><%
>
> options =
> this_field_reflection.klass.*sort_by_ancestry*(this_field_reflection.klass.all)
>
>> *{|a, b| a.position <=> b.position}*
>
> select_options = options.map { |x| [(*" " * x.depth
>> + "‣ " +* name(:with => x, :no_wrapper => true))*.html_safe*,
>
> x.id] }
>
> attributes = add_classes(attributes, "input", "belongs_to",
>> type_and_field)
>
> -%>
>
>
>> <select name='#{param_name_for_this(true)}'
>> merge-attrs='&attributes.except :name'>
>
> <%= options_for_select(select_options, this ? this.id : "") %>
>
> </select>
>
> </def>
>
>
The modification is mainly two ideas combined:
- Using Ancestry's capabilty of creating a properly sorted array using the
sort_by_ancestry method
- Indenting the items with a formatting
It looks like this
<https://lh3.googleusercontent.com/-M4EjKg5xmWM/VE4jqPCsXZI/AAAAAAAAAVQ/KLBVYvD_xxo/s1600/tree-select-one.png>
and is called like this:
<extend tag="form" for="ContentElement">
>
> <old-form merge>
>
> <field-list: fields=" ... attributes as usual ... , *folder*" param>
>
> *<folder-view:>*
>
> *<tree-select-one />*
>
> * </folder-view:>*
>
> </field-list:>
>
> </old-form>
>>
> </extend>
>
>
Ciao,
Stefan
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.