Skip to content

Commit

Permalink
Fixed using column name (introspection) in forms. Cleanup textarea.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 16, 2011
1 parent 8b1c2c6 commit 9e16495
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,30 @@ def form_hidden_fields(opts)
end

def r_textarea
@params = @markup.params.merge(@params)
res = make_textarea(params)
extract_label(res, @params[:name])
html_attributes, attribute = get_input_params()
erb_attr = html_attributes.delete(:erb_attr)
value = html_attributes.delete(:value)

return parser_error('Missing name.') unless attribute || html_attributes[:name]

@markup.tag = 'textarea'
@markup.set_dyn_params(html_attributes)

unless value
if @blocks == [] || @blocks == ['']
if @context[:in_add]
value = ''
else
value = attribute ? "<%= #{node_attribute(attribute)} %>" : ""
end
else
value = expand_with
end
end

res = @markup.wrap(value)

extract_label(res, attribute || erb_attr)
end

# <r:select name='klass' root_class='...'/>
Expand All @@ -397,6 +418,7 @@ def r_textarea
# TODO: optimization (avoid loading full AR to only use [id, name])
def r_select
html_attributes, attribute = get_input_params()
erb_attr = html_attributes.delete(:erb_attr)
# TEMPORARY HACK UNTIL WE FIX get_input_params to return a single hash with
# {:html => { prepared html attributes }, :raw => {:value => '..', :name => '..', :param => '..'}}
if param = @params[:param]
Expand Down Expand Up @@ -445,12 +467,13 @@ def r_select
parser_error("missing 'nodes', 'root_class' or 'values'")
end

extract_label(res, attribute)
extract_label(res, attribute || erb_attr)
end


def r_input
html_attributes, attribute = get_input_params()
erb_attr = html_attributes.delete(:erb_attr)
# TODO: get attribute type from get_input_params
res = case @params[:type]
when 'select' # FIXME: why is this only for classes ?
Expand Down Expand Up @@ -487,13 +510,12 @@ def r_input
@markup.set_param(:type, @params[:type] || 'text')

checked = html_attributes.delete(:checked)

@markup.set_dyn_params(html_attributes)
@markup.append_attribute checked if checked
wrap('')
end

extract_label(res, attribute || html_attributes[:name])
extract_label(res, attribute || erb_attr)
end

# <r:checkbox role='collaborator_for' values='projects' in='site'/>"
Expand Down Expand Up @@ -633,6 +655,7 @@ def get_input_params(params = @params)
# end
#end
elsif node.will_be?(Column)
res[:erb_attr] = "<%= #{node}.name %>"
res[:name] = "node[<%= #{node}.name %>]"
res[:value] = "<%= fquote #{node(Node)}.prop[#{node}.name] %>"
end
Expand Down Expand Up @@ -754,31 +777,6 @@ def get_options_for_select
end
end


# Transform a 'zazen' tag into a textarea input field.
def make_textarea(params)
return parser_error("missing 'name'") unless name = params[:name]
if name =~ /\A([\w_]+)\[(.*?)\]/
attribute = $2
else
attribute = name
name = "#{node.form_name}[#{attribute}]"
end
return '' if attribute == 'parent_id' # set with 'r_form'

if @blocks == [] || @blocks == ['']
if @context[:in_add]
value = ''
else
value = attribute ? "<%= #{node_attribute(attribute)} %>" : ""
end
else
value = expand_with
end
html_id = node.dom_prefix ? " id='#{node.dom_prefix}_#{attribute}'" : ''
"<textarea#{html_id} name='#{name}'>#{value}</textarea>"
end

# Return the default field that will receive focus on form display.
def default_focus_field
if (input_fields = descendants('input')) != []
Expand Down

0 comments on commit 9e16495

Please sign in to comment.