Module: Admin::DocumentsHelper

Defined in:
app/helpers/admin/documents_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_bread_crumb(document, root = true) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/admin/documents_helper.rb', line 50

def admin_bread_crumb(document, root = true)
  result = ''
  if root
    result << '<ul class="bread_crumb">'
    result << "<li><a href='#{admin_documents_path}'>Dashboard</a></li>"
  end
  if document
    result << admin_bread_crumb(document.parent, false) if document.parent
    unless document.new_record? # no title yet
      result << '<li>'
      result << (root ? (document.title || document.permalink) : link_to(document.permalink.titleize, admin_document_path(document.id)))
      result << '</li>'
    end
  end
  result << '</ul>' if root
  result
end

#admin_cancel_document_path(document) ⇒ Object



68
69
70
71
72
73
74
# File 'app/helpers/admin/documents_helper.rb', line 68

def admin_cancel_document_path(document)
  if document.parent
    admin_document_path(document.parent.id)
  else
    admin_dashboard_path
  end
end

#form_partialObject

Find the correct form partial for @document



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/admin/documents_helper.rb', line 34

def form_partial
  root = 'admin/documents'
  choices = ["_#{@document.meta_definition.label_path.gsub('/', '_')}_form.html.erb", "_#{@document.label}_form.html.erb"]
  
  self.view_paths.each do | view_path |      
    choices.each do | choice |
      target = File.join(view_path, root, choice)
      logger.debug 'FORM: ' + target
      if File.exists? target
        return File.join(root, choice).gsub('/_', '/')
      end
    end
  end
  "admin/documents/form"    
end

#per_page_optionsObject

Returns options Array for ‘per_page’ select



21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/admin/documents_helper.rb', line 21

def per_page_options
  options = [1, 5, 10, 20, 50, 100]
  result = []
  options.each do | o |
    k = o.to_s
    v = o
    k = k + ' (Default)' if o == Settings.documents.per_page
    result << [k, v]
  end
  result
end

#sort_by_optionsObject

returns options Array for ‘sort_by’ select



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/admin/documents_helper.rb', line 4

def sort_by_options
  options = { 'Date DESC' => 'published_at DESC',
              'Date ASC'  => 'published_at ASC',
              'Title'     => 'title',
              'Manually'  => 'position ASC'
      }
  
  result = []        
  options.each do |k,v|
    k = k + ' (Default)' if v == Settings.documents._sort_by
    result << [k,v]
  end
 
  result.sort       
end