Module: Skyline::RefObjectHelper

Defined in:
app/helpers/skyline/ref_object_helper.rb

Instance Method Summary collapse

Instance Method Details

#image_browser(form_builder, field, options = {}) ⇒ Object

options defaults to: form_builder.object.send(field) || form_builder.object.send(“build_#field”) options defaults to: form_builder.dom_id(field)



24
25
26
# File 'app/helpers/skyline/ref_object_helper.rb', line 24

def image_browser(form_builder, field, options = {})
  referable_field_browser(form_builder, field, :image, options)
end


28
29
30
# File 'app/helpers/skyline/ref_object_helper.rb', line 28

def link_browser(form_builder, field, options = {})
  referable_field_browser(form_builder, field, :link, options)
end

#ref_object_css_class(referable) ⇒ Object



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

def ref_object_css_class(referable)
  case referable.andand.class.to_s
  when "Skyline::Page"
    "page"
  when "Skyline::MediaFile"
    "mediaFile #{referable.file_type}"
  else
    "external"
  end    
end

#ref_object_title(referable, default = "") ⇒ Object

Get the title of a ref_object.



3
4
5
6
7
8
# File 'app/helpers/skyline/ref_object_helper.rb', line 3

def ref_object_title(referable,default = "")
  return referable.default_variant_data.andand.navigation_title.to_s if referable.class.to_s == "Skyline::Page"
  return referable.name.to_s if referable.class.to_s == "Skyline::MediaFile"
  return referable.title.to_s if referable.respond_to?(:title)
  default
end

#referable_field_browser(form_builder, field, browser, options = {}) ⇒ Object



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/skyline/ref_object_helper.rb', line 32

def referable_field_browser(form_builder, field, browser, options = {})
  options.reverse_merge! :object => form_builder.object.send(field) || form_builder.object.send("build_#{field}"), 
                         :container => nil,
                         :skip_class => false
                         
  if !options[:container]
    options[:container] = form_builder.dom_id(field)
    css_class = ref_object_css_class(options[:object].referable)
  else
    css_class = ""
  end

  c = []
    
  if options[:object].andand.marked_for_destruction?
    options[:object].referable_type = nil
    options[:object].referable_id = nil
  end
  
  form_builder.fields_for "#{field}_attributes", options[:object] do |linked_form|
    c << linked_form.hidden_field(:id) unless linked_form.object.new_record?    
    c << linked_form.hidden_field(:referable_type, :class => "referable_type")
    c << linked_form.hidden_field(:referable_id, :class => "referable_id")
    c << linked_form.hidden_field(:_destroy, :class => "referable_delete", :value => 0)    
    linked_form.fields_for "referable_attributes", linked_form.object.referable do |referable_form|
      c << hidden_field_tag(referable_form.object_name + "[uri]", referable_form.object.respond_to?(:uri) ? referable_form.object.uri : "", :class => "link_custom_url")
    end

    
    deselect_button = link_to_function(button_text(:delete), "Application.Browser.unlink('#{options[:container]}');", :class => "button small red delete")
    browse_button = link_to_function(button_text(:browse), "Application.Browser.browse#{browser.to_s.camelcase}For('#{options[:container]}');", :class => "button small")
  
    c << ("div", :class => "not-linked") do
      nl = []
      nl << ("span",t(:nothing_selected, :scope => [:browser,browser]), :class => "title")
      nl << browse_button
    end
    
    c << ("div", :class => "linked") do
      l = []
      referable_title = ("span", ref_object_title(linked_form.object.andand.referable) + " ", :id => linked_form.dom_id(:title), :class => "title referable_title")
      l << t(:links_to, :scope => [:browser,browser], :referable_title => referable_title)
      l << deselect_button
      l << "&nbsp;"
      l << browse_button
    end
    
    c = ("div", c.join, :class => "relatesTo #{"linked" if linked_form.object.andand.referable && !linked_form.object.andand.marked_for_destruction?}")
  end

   "div", c, :id => form_builder.dom_id(field), :class => css_class
end