Module: ActionView::Helpers::FormTagHelper

Defined in:
lib/prime/rails/form_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#p_button_tag(content_or_options = nil, options = nil, &block) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/prime/rails/form_tag_helper.rb', line 96

def p_button_tag(content_or_options = nil, options = nil, &block)       
  options = content_or_options if block_given? && content_or_options.is_a?(Hash)
  options ||= {}
  options = options.stringify_keys

  if disable_with = options.delete("disable_with")
    message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \
              "Use 'data: { disable_with: \'Text\' }' instead."
    ActiveSupport::Deprecation.warn message

    options["data-disable-with"] = disable_with
  end

  if confirm = options.delete("confirm")
    message = ":confirm option is deprecated and will be removed from Rails 4.1. " \
              "Use 'data: { confirm: \'Text\' }' instead'."
    ActiveSupport::Deprecation.warn message

    options["data-confirm"] = confirm
  end

  options.reverse_merge! 'name' => 'button', 'type' => 'submit'
  
  clientid = sanitize_to_id(options["id"])

  if options['ajax']
      options['onclick'] = ''  if !options.has_key?('onclick') 
  	options['onclick'] += "PrimeFaces.ab({source: '#{clientid}'});return false;" 
  end
      
  output =  :button, content_or_options || 'Button', options, &block
          
  widgetvar = options.has_key?("widgetVar") ? options["widgetVar"] : "widget_"+clientid         
  
  options_ui = options
  options_ui = options_ui.merge(:id => clientid )                         
  options_ui = options_ui.to_json        
  
  script = '$(function() {'
  script += "PrimeFaces.cw('Button','#{widgetvar}',#{options_ui})"
  script += '});'         
  output += p_javascript_tag(script, "id" => clientid+"_s")                                             
end

#p_check_box_tag(name, value = "1", checked = false, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/prime/rails/form_tag_helper.rb', line 46

def p_check_box_tag(name, value = "1", checked = false, options = {})
  html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
  html_options["checked"] = "checked" if checked
  output = tag :input, html_options
  
  clientid = sanitize_to_id(name)
  widgetvar = options.has_key?("widgetVar") ? options["widgetVar"] : "widget_"+clientid         
  
  options_ui = options
  options_ui = options_ui.merge(:id => clientid )                         
  options_ui = options_ui.to_json        
  
  script = '$(function() {'
  script += "PrimeFaces.cw('CheckBox','#{widgetvar}',#{options_ui})"
  script += '});'         
  output += p_javascript_tag(script, "id" => clientid+"_s")         
  
end

#p_password_field_tag(name = "password", value = nil, options = {}) ⇒ Object



65
66
67
# File 'lib/prime/rails/form_tag_helper.rb', line 65

def p_password_field_tag(name = "password", value = nil, options = {})
  p_text_field_tag(name, value, options.update("type" => "password"))
end

#p_select_tag(name, option_tags = nil, options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/prime/rails/form_tag_helper.rb', line 69

def p_select_tag(name, option_tags = nil, options = {})
  option_tags ||= ""
  html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name

  if options.delete(:include_blank)
    option_tags = (:option, '', :value => '').safe_concat(option_tags)
  end

  if prompt = options.delete(:prompt)
    option_tags = (:option, prompt, :value => '').safe_concat(option_tags)
  end

  output =  :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
  
  clientid = sanitize_to_id(name)
  widgetvar = options.has_key?("widgetVar") ? options["widgetVar"] : "widget_"+clientid         
  
  options_ui = options
  options_ui = options_ui.merge(:id => clientid )                         
  options_ui = options_ui.to_json        
  
  script = '$(function() {'
  script += "PrimeFaces.cw('Dropdown','#{widgetvar}',#{options_ui})"
  script += '});'         
  output += p_javascript_tag(script, "id" => clientid+"_s")         
end

#p_text_area_tag(name, content = nil, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/prime/rails/form_tag_helper.rb', line 22

def p_text_area_tag(name, content = nil, options = {})        
  options = options.stringify_keys
  clientid = sanitize_to_id(name)
  widgetvar = options.has_key?("widgetVar") ? options["widgetVar"] : "widget_"+clientid        

  if size = options.delete("size")
    options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
  end

  escape = options.delete("escape") { true }
  content = ERB::Util.html_escape(content) if escape        

  output =  :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)                
  
  options_ui = options
  options_ui = options_ui.merge(:id => clientid )                         
  options_ui = options_ui.to_json        
  
  script = '$(function() {'
  script += "PrimeFaces.cw('InputTextarea','#{widgetvar}',#{options_ui})"
  script += '});'         
  output += p_javascript_tag(script, "id" => clientid+"_s")        
end

#p_text_field_tag(name, value = nil, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/prime/rails/form_tag_helper.rb', line 2

def p_text_field_tag(name, value = nil, options = {})
  options = options.stringify_keys
  clientid = sanitize_to_id(name)
  widgetvar = options.has_key?("widgetVar") ? options["widgetVar"] : "widget_"+clientid
  output = tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)

  widgetclass = "InputText"
  widgetclass = "Password" if options['type'] == 'password'
  
  options_ui = options
  options_ui = options_ui.merge(:id => clientid )                         
  options_ui = options_ui.to_json            
  
  script = '$(function() {'
  script += "PrimeFaces.cw('#{widgetclass}','#{widgetvar}',#{options_ui})"
  script += '});'         
  output += p_javascript_tag(script, "id" => clientid+"_s")
                 
end