mirror of
https://github.com/redmine/redmine.git
synced 2025-11-14 17:26:06 +01:00
tables and forms redesign,
added form builder for several views git-svn-id: http://redmine.rubyforge.org/svn/trunk@21 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -104,4 +104,47 @@ module ApplicationHelper
|
||||
def lang_options_for_select
|
||||
(GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
|
||||
end
|
||||
|
||||
def label_tag_for(name, option_tags = nil, options = {})
|
||||
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
||||
content_tag("label", label_text)
|
||||
end
|
||||
|
||||
def labelled_tabular_form_for(name, object, options, &proc)
|
||||
options[:html] ||= {}
|
||||
options[:html].store :class, "tabular"
|
||||
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
|
||||
end
|
||||
end
|
||||
|
||||
class TabularFormBuilder < ActionView::Helpers::FormBuilder
|
||||
include GLoc
|
||||
|
||||
def initialize(object_name, object, template, options, proc)
|
||||
set_language_if_valid options.delete(:lang)
|
||||
@object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
|
||||
end
|
||||
|
||||
(field_helpers - %w(radio_button) + %w(date_select)).each do |selector|
|
||||
src = <<-END_SRC
|
||||
def #{selector}(field, options = {})
|
||||
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
||||
label = @template.content_tag("label", label_text,
|
||||
:class => (@object.errors[field] ? "error" : nil),
|
||||
:for => (@object_name.to_s + "_" + field.to_s))
|
||||
label + super
|
||||
end
|
||||
END_SRC
|
||||
class_eval src, __FILE__, __LINE__
|
||||
end
|
||||
|
||||
def select(field, choices, options = {})
|
||||
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
||||
label = @template.content_tag("label", label_text,
|
||||
:class => (@object.errors[field] ? "error" : nil),
|
||||
:for => (@object_name.to_s + "_" + field.to_s))
|
||||
label + super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user