Module: TypusHelper

Included in:
Admin::MasterHelper
Defined in:
app/helpers/typus_helper.rb

Instance Method Summary collapse

Instance Method Details

#applicationsObject

Applications list on the dashboard



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/typus_helper.rb', line 6

def applications

  returning(String.new) do |html|

    Typus.applications.each do |app|

      available = Typus.application(app).map do |resource|
                    resource if @current_user.resources.include?(resource)
                  end
      next if available.compact.empty?

      html << <<-HTML
<table class="typus">
<tr>
<th colspan="2">#{app}</th>
</tr>
      HTML

      available.compact.each do |model|
        description = Typus.module_description(model)
        admin_items_path = { :controller => "admin/#{model.tableize}" }
        new_admin_item_path = { :controller => "admin/#{model.tableize}", :action => 'new'}
        html << <<-HTML
<tr class="#{cycle('even', 'odd')}">
<td>#{link_to model.constantize.typus_human_name.pluralize, admin_items_path}<br /><small>#{description}</small></td>
<td class="right"><small>
#{link_to _("Add"), new_admin_item_path if @current_user.can_perform?(model, 'create')}
</small></td>
</tr>
        HTML
      end

      html << <<-HTML
</table>
      HTML

    end

  end

end

#display_flash_message(message = flash) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/helpers/typus_helper.rb', line 154

def display_flash_message(message = flash)

  return if message.empty?
  flash_type = message.keys.first

  <<-HTML
<div id="flash" class="#{flash_type}">
<p>#{message[flash_type]}</p>
</div>
  HTML

end

#headerObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/helpers/typus_helper.rb', line 117

def header

  links = []
  links << "<li>#{link_to_unless_current _("Dashboard"), admin_dashboard_path}</li>"

  Typus.models_on_header.each do |model|
    links << "<li>#{link_to_unless_current model.constantize.typus_human_name.pluralize, :controller => "/admin/#{model.tableize}"}</li>"
  end

  if ActionController::Routing::Routes.named_routes.routes.keys.include?(:root)
    links << "<li>#{link_to _("View site"), root_path, :target => 'blank'}</li>"
  end

  <<-HTML
<h1>#{Typus::Configuration.options[:app_name]}</h1>
<ul>
#{links.join("\n")}
</ul>
  HTML

end

#locales(uri = admin_set_locale_path) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
# File 'app/helpers/typus_helper.rb', line 175

def locales(uri = admin_set_locale_path)

  return unless Typus.locales.many?

  locale_links = Typus.locales.map { |l| "<a href=\"#{uri}?locale=#{l.last}\">#{l.first.downcase}</a>" }

  <<-HTML
<p>#{_("Set language to")} #{locale_links.join(', ')}.</p>
  HTML

end

#login_info(user = @current_user) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/helpers/typus_helper.rb', line 139

def (user = @current_user)

  admin_edit_typus_user_path = { :controller => "admin/#{Typus::Configuration.options[:user_class_name].tableize}", 
                                 :action => 'edit', 
                                 :id => user.id }

  <<-HTML
<ul>
<li>#{_("Logged as")} #{link_to user.name, admin_edit_typus_user_path, :title => "#{user.email} (#{user.role})"}</li>
<li>#{link_to _("Sign out"), admin_sign_out_path }</li>
</ul>
  HTML

end

#page_title(action = params[:action]) ⇒ Object



110
111
112
113
114
115
# File 'app/helpers/typus_helper.rb', line 110

def page_title(action = params[:action])
  crumbs = [ ]
  crumbs << @resource[:class].typus_human_name.pluralize if @resource
  crumbs << _(action.humanize) unless %w( index ).include?(action)
  return "#{Typus::Configuration.options[:app_name]} - " + crumbs.compact.map { |x| x }.join(' &rsaquo; ')
end

#resourcesObject

Resources (wich are not models) on the dashboard.



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
84
85
86
# File 'app/helpers/typus_helper.rb', line 51

def resources

  available = Typus.resources.map do |resource|
                resource if @current_user.resources.include?(resource)
              end
  return if available.compact.empty?

  returning(String.new) do |html|

    html << <<-HTML
<table class="typus">
<tr>
<th colspan="2">#{_("Resources")}</th>
</tr>
    HTML

    available.compact.each do |resource|

      resource_path = { :controller => "admin/#{resource.underscore}" }

      html << <<-HTML
<tr class="#{cycle('even', 'odd')}">
<td>#{link_to _(resource.humanize), resource_path}</td>
<td align="right" style="vertical-align: bottom;"></td>
</tr>
      HTML

    end

    html << <<-HTML
</table>
    HTML

  end

end

#typus_block(*args) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/helpers/typus_helper.rb', line 88

def typus_block(*args)

  options = args.extract_options!

  partials_path = "admin/#{options[:location]}"
  resources_partials_path = 'admin/resources'

  partials = ActionController::Base.view_paths.map do |view_path|
    Dir["#{view_path.path}/#{partials_path}/*"].map { |f| File.basename(f, '.html.erb') }
  end.flatten
  resources_partials = Dir["#{Rails.root}/app/views/#{resources_partials_path}/*"].map { |f| File.basename(f, '.html.erb') }

  partial = "_#{options[:partial]}"

  path = if partials.include?(partial) then partials_path
         elsif resources_partials.include?(partial) then resources_partials_path
         end

  render :partial => "#{path}/#{options[:partial]}" if path

end

#typus_message(message, html_class = 'notice') ⇒ Object



167
168
169
170
171
172
173
# File 'app/helpers/typus_helper.rb', line 167

def typus_message(message, html_class = 'notice')
  <<-HTML
<div id="flash" class="#{html_class}">
<p>#{message}</p>
</div>
  HTML
end