Module: Gluttonberg::Helpers::FormBuilder

Includes:
ActionView::Helpers
Defined in:
lib/gluttonberg/helpers/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#asset_browser(field_name, opts = {}) ⇒ Object

Assets



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gluttonberg/helpers/form_builder.rb', line 63

def asset_browser( field_name , opts = {} )
  opts[:asset_id] = asset_id = self.object.send(field_name.to_s)
  filter = opts[:filter] || "all"


  opts[:id] = "#{field_name}_#{asset_id}" if opts[:id].blank?
  asset = if asset_id.blank?
    nil
  else
    Gluttonberg::Asset.where(:id => asset_id).first
  end
  locals = {
    :opts => opts,
    :asset => asset,
    :field_name => field_name,
    :form => self
  }
  _render("/gluttonberg/admin/asset_library/shared/asset_browser", locals)
end

#asset_tag(asset, thumbnail_type = nil) ⇒ Object



83
84
85
86
87
88
# File 'lib/gluttonberg/helpers/form_builder.rb', line 83

def asset_tag(asset , thumbnail_type = nil)
  unless asset.blank?
    path = thumbnail_type.blank? ? asset.url : asset.url_for(thumbnail_type)
    tag(:img , :class => asset.name , :alt => asset.name , :src => path)
  end
end

#clear_asset(field_name, opts = {}) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/gluttonberg/helpers/form_builder.rb', line 90

def clear_asset( field_name , opts = {} )
  asset_id = self.object.send(field_name.to_s)
  opts[:id] = "#{field_name}_#{asset_id}" if opts[:id].blank?
  view = ActionView::Base.new(ActionController::Base.view_paths)
  view.extend ApplicationHelper
  view.clear_asset_tag(field_name, opts)
end

#datetime_field(field_name, date_field_html_opts = {}, time_field_html_opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gluttonberg/helpers/form_builder.rb', line 30

def datetime_field(field_name,date_field_html_opts = {},time_field_html_opts = {})
  date_field_html_opts["data-datepicker"] = "bsdatepicker"
  unique_field_name = "#{field_name}_#{Gluttonberg::Member.generateRandomString}"
  date_field_html_opts[:onblur] = "checkDateFormat(this,'.#{unique_field_name}_error');combine_datetime('#{unique_field_name}');"

  date_field_html_opts[:class] = "" if date_field_html_opts[:class].blank?
  date_field_html_opts[:class] += " small span2 datefield"

  time_field_html_opts[:class] = "" if time_field_html_opts[:class].blank?
  time_field_html_opts[:class] += " small span2 timefield"

  time_field_html_opts[:onblur] = "checkTimeFormat(this,'.#{unique_field_name}_error');combine_datetime('#{unique_field_name}');"

  date = time = ""

  unless self.object.send(field_name).blank?
    date = self.object.send(field_name).strftime("%d/%m/%Y")
    time = self.object.send(field_name).strftime("%I:%M %p")
  end

  _render "/gluttonberg/admin/shared/datetime_field", {
    :date_field_html_opts => date_field_html_opts,
    :time_field_html_opts => time_field_html_opts,
    :date => date,
    :time => time,
    :form => self,
    :unique_field_name => unique_field_name,
    :field_name => field_name
  }
end

#publisable_dropdownObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gluttonberg/helpers/form_builder.rb', line 5

def publisable_dropdown
  ActiveSupport::Deprecation.warn "f.publisable_dropdown is deprecated and will be removed in Gluttonberg 4.0, use submit_and_publish_controls(form, object, can_publish, schedule_field=true, revisions=true, opts={}) instead."
  object = self.object
  val = object.state
  if val == "not_ready"
    val = "ready"
  end
  @@workflow_states = [  ['Published' , "published" ] ,[ 'Draft' , 'ready' ] , [ "Archived" , 'archived' ]  ]
  object.published_at = Time.zone.now if object.published_at.blank?
  html = "<fieldset id='publish_meta'><div class='publishing_block' > "
  html += select( :state, options_for_select(@@workflow_states , val), {} , :class => "publishing_state" )
  html += datetime_field("published_at")
  html += "</div></fieldset>"

  html.html_safe
end

#publishing_schedule(schedule_field) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/gluttonberg/helpers/form_builder.rb', line 22

def publishing_schedule(schedule_field)
  object = self.object
  object.published_at = Time.zone.now if object.published_at.blank?
  html = ""
  html += schedule_field ? datetime_field("published_at") : hidden_field("published_at")
  html.html_safe
end