Skip to content

Commit

Permalink
Added support for 'attr' in select with root_class (to get kpath).
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 16, 2011
1 parent 804ac75 commit 55bfb16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ def classes_for_form(opts={})

kpath_len = base_kpath.size

attribute = opts[:class_attr] || 'name'

VirtualClass.all_classes(base_kpath, opts[:without]).map do |vclass|
if vclass.create_group_id.nil? || group_ids.include?(vclass.create_group_id)
# white spaces are insecable spaces (not ' ')
a, b = vclass.kpath, vclass.name
[('  ' * (a.size - kpath_len)) + b, b]
[('  ' * (a.size - kpath_len)) + b, vclass[attribute]]
else
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def r_select
class_opts = ''
class_opts << ", :without => #{@params[:without].inspect}" if @params[:without]
# do not use 'selected' if the node is not new
"#{select_tag}<%= options_for_select(Node.classes_for_form(:class => #{klass.inspect}#{class_opts}), (#{node}.new_record? ? #{selected} : #{node}.klass)) %></select>"
"#{select_tag}<%= options_for_select(Node.classes_for_form(:class => #{klass.inspect}#{class_opts}, :class_attr => #{(@params[:attr] || 'name').inspect}), (#{node}.new_record? ? #{selected} : #{node}.klass)) %></select>"
elsif @params[:type] == 'time_zone'
# <r:select name='d_tz' type='time_zone'/>
"#{select_tag}<%= options_for_select(TZInfo::Timezone.all_identifiers, #{selected}) %></select>"
Expand Down
4 changes: 4 additions & 0 deletions test/integration/zafu_compiler/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ select_class_new_node:
src: "<r:pages><r:each/><r:add/><r:form><select name='klass' root_class='Note' selected='Post'/></r:form>"
res: "/<select.*name=.node\[klass\].*Note.*Letter.*Post. selected=.selected./"

select_class_kpath:
src: "<r:select param='k' root_class='Note' attr='kpath'/>"
res: "/<select.*name=.k.*NN.*Note.*NNL.*Letter.*NNP.*Post/"

select_nodes:
src: "<r:form><select nodes='images in site' name='foo'></select></r:form>"
res: "/name='node\[foo\]'><option value=\"\" selected=\"selected\"></option>\n<option value=\"40\">Autumn Tree</option>\n<option value=\"30\">bird</option>/"
Expand Down

0 comments on commit 55bfb16

Please sign in to comment.