Class: KirguduBase::OldFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, GuiHelper
Defined in:
app/helpers/kirgudu_base/old_form_builder.rb

Instance Method Summary collapse

Methods included from GuiHelper

#autocomplete_field_tag, #autocomplete_with_id_tag, #chosen_select_tag, #control_tag, #date_picker_tag, #file_input_tag, get_value_for_control, html_options_add_class, html_options_prepare_commons, html_options_set_ids, #left_menu_item_disabled, #left_menu_item_divider, #left_menu_item_link, #left_menu_item_title, #link_to_cart_add, #link_to_cart_remove, #link_to_delete, #link_to_edit, #link_to_entry, #link_to_leftmenu, #link_to_mass, #link_to_nav, #link_to_new, #link_to_paged, #link_to_property, #link_to_search, #link_to_show, #link_to_unless_current_entry, #password_field_tag, #select_tag, #switcher_tag, #text_area_tag, #text_field_tag

Instance Method Details

#autocomplete_field(label, *args) ⇒ Object



82
83
84
85
86
87
88
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 82

def autocomplete_field(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")
end

#autocomplete_with_id(label, text_value, path, options = {}) ⇒ Object



91
92
93
94
95
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
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 91

def autocomplete_with_id(label, text_value, path, options = {})
  options ||= {}

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")

  options[:id] = "#{@object_name}_#{label}"
  options[:name] = "#{@object_name}[#{label}]"
  options[:property_name] = label

  if options[:parent]
    options[:parent_control_id] = "#{@object_name}_#{options[:parent]}"
    options[:parent] = nil
  end

  if options[:onchange]

    onchange_actions = []

    if options[:onchange].is_a?(Hash)
      onchange_actions.push(options[:onchange])
    elsif options[:onchange].is_a?(Array)
      options[:onchange].each do |a|
        onchange_actions.push(a)
      end
    end

    onchange_actions.each do |o|
      o[:property_control] = "#{@object_name}_#{o[:property]}"
    end

    options[:onchange] = onchange_actions
  end

  autocomplete_with_id_tag(@object[label], text_value, path, options)
end

#choose_image(label, thumb_url, *args) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 245

def choose_image(label, thumb_url, *args)
  options = args.extract_options!


  image_options = Hash.new
  image_options[:src] = thumb_url
  image_options[:id] = "#{@object_name}_#{label}_selected_image"
  image_options[:style] ='display: none' unless @object[label]

  control_html = @template.('img', '', image_options) + '<br/>'.html_safe

  select_image_options = Hash.new
  select_image_options[:href] = "javascript:showImageSelectDialog('##{@object_name}_#{label}_imagesModal'); return false;"

  control_html += @template.('a', select_image_options) do
    "Select Image"
  end

  hidden_options = Hash.new
  hidden_options[:type] = 'hidden'
  hidden_options[:id] ="#{@object_name}_#{label}"
  hidden_options[:name] = "#{@object_name}[#{label}]"
  hidden_options[:value] = @object[label].to_s if @object[label]

  control_html += @template.('input', '', hidden_options)

  control_html
end

#chosen_select(label, choices, *args) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 200

def chosen_select(label, choices, *args)

  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present?
  options[:class] = classes.join(' ')

  options[:id] = "#{@object_name}_#{label}"
  options[:name] = "#{@object_name}[#{label}]"
  options[:value] = @object[label]
  options[:property_name] = label


  if options[:onchange]
    onchange_actions = []
    if options[:onchange].is_a?(Hash)
      onchange_actions.push(options[:onchange])
    elsif options[:onchange].is_a?(Array)
      options[:onchange].each do |a|
        onchange_actions.push(a)
      end
    end

    onchange_actions.each do |o|
      o[:property_control] = "#{@object_name}_#{o[:property]}"

      if o[:source] && o[:source].is_a?(Hash)
        o[:source] = Rails.application.routes.url_helpers.url_for(o[:source])
      end
    end

    options[:onchange] = onchange_actions
  end

  if options[:parent]
    options[:parent_value] = @object[options[:parent]]
  end


  chosen_select_tag(choices, options)

end

#color_picker(label, *args) ⇒ Object



186
187
188
189
190
191
192
193
194
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 186

def color_picker(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("color-picker") if !classes.include?("color-picker")
  options[:class] = classes.join(" ")

  text_field(label, args)
end

#date_picker(label, *args) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 130

def date_picker(label, *args)
  options = args.extract_options!

  #raise options.to_json

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present?
  options[:class] = classes.join(' ')

  options[:id] = "#{@object_name}_#{label}"
  options[:name] = "#{@object_name}[#{label}]"
  options[:value] = @object[label]

  date_picker_tag(options)
end

#elastic_textarea(label, *args) ⇒ Object

def date_picker_with_icon(label, *args)

options = args.extract_options! classes = Array.new classes.push (“row-fluid”) classes.push (“input-append”) classes.push (“date”) classes.push (“error”) if @object.errors.present? options.merge!(class: classes.join(“ ”)) options.merge!(id: “datepicker_#@object_name_##label”) options.merge!(“data-date” => @object.instance_values) options.merge!(“data-date-format” => “dd-mm-yyyy”)

result = @template.content_tag(“div”, options) do text_field(label, class: ‘row-fluid’) + @template.content_tag(‘span’, class: ‘add-on’) do @template.content_tag(‘i’, class: ‘icon-th’) do end end end js=“<script type="text/javascript">

   $(document).ready(function(){
     $('#datepicker_#{@object_name}_#{label}').datepicker();
    });
</script>"

result + js.html_safe

end



175
176
177
178
179
180
181
182
183
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 175

def elastic_textarea(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("autogrow") if !classes.include?("autogrow")
  options[:class] = classes.join(" ")

  text_area(label, options)
end

#error_label(label, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 10

def error_label(label, *args)
  options = args.extract_options!
  options.merge!(class: "error", generated: "true", style: "display: block")
  errors_in_html = ""
  if @object.errors[label].present?
    @object.errors[label].each do |error_message|
      errors_in_html += @template.("label", error_message.capitalize.html_safe, options)
    end
  end
  errors_in_html.html_safe
end

#label(label, *args) ⇒ Object



26
27
28
29
30
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 26

def label(label, *args)
  @template.("label", *args) do
    @object.class.human_attribute_name(label)
  end
end

#label_with_hint(label, hint, *args) ⇒ Object



22
23
24
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 22

def label_with_hint(label, hint, *args)
  @template.("label", (@object.class.human_attribute_name(label) + @template.("span", hint, class: 'help-block')).html_safe, *args)
end

#masked_fieldObject



196
197
198
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 196

def masked_field

end

#password_field(label, *args) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 72

def password_field(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")

  super(label, options)
end

#radio_group(label, values, *args) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 275

def radio_group(label, values, *args)
  control_html = ""
  values.each do |value_pair|
    control_html +=
      @template.('label', class: "radio") do
        @template.('div', class: "radio") do
          @template.('span', class: '') do
            @template.tag('input', type: 'radio', name: "#{@object_name}[#{label}]", id: "#{@object_name}_#{label}", value: value_pair[1], style: 'opacity: 0;')
          end
        end +
          value_pair[0]
      end
  end
  control_html.html_safe
end

#switcher(label, *args) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 292

def switcher(label, *args)
  options = args.extract_options!
  options ||= {}
  options.stringify_keys!

  value_off = options['value-off'] || "0"
  value_on = options['value-on'] || "1"

  off_input_options = {type: "radio", name: "#{@object_name}[#{label}]", id: "#{@object_name}-#{label}-off", value: value_off}
  on_input_options = {type: "radio", name: "#{@object_name}[#{label}]", id: "#{@object_name}-#{label}-on", value: value_on}

  if @object[label] == true
    on_input_options['checked'] = true
  else
    off_input_options['checked'] = true
  end

  toggle_options = {}

  toggle_options[:class] = "toggle" + (@object[label] == value_on ? ' on' : ' off')
  toggle_options[:class] = "toggle on"


  control_html =
    @template.('div', class: "row-fluid") do
      @template.('div', class: "pull-left") do
        @template.('label', class: 'radio off') do
          @template.tag('input', off_input_options)

        end +
          @template.('label', class: 'radio on') do
            @template.tag('input', on_input_options)
          end +
          @template.('div', toggle_options) do
            @template.('div', class: "yes") do
              options['label-on'] || 'ON'
            end +
              @template.('div', class: "switch") do
              end +
              @template.('div', class: "no") do
                options['label-off'] || 'OFF'
              end
          end
      end
    end
  control_html
end

#text_area(label, *args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 59

def text_area(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")

  options.merge!(rows: '5') unless options.include?(:rows)

  super(label, options)
end

#text_edit(label, *args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 46

def text_edit(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")

  options[:id] = "#{@object_name}_#{label}"
  options[:name] = "#{@object_name}[#{label}]"

  edit_tag(@object[label], options)
end

#text_field(label, *args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/kirgudu_base/old_form_builder.rb', line 33

def text_field(label, *args)
  options = args.extract_options!

  classes = options[:class] ? options[:class].to_s.split(' ') : []
  classes.push ("error") if @object.errors[label].present? && !classes.include?("error")
  options[:class] = classes.join(" ")

  options[:id] = "#{@object_name}_#{label}"
  options[:name] = "#{@object_name}[#{label}]"

  super(label, options)
end