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
47
48
49
50
51
# 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|

        klass = model.constantize
        klass_resource = klass.name.tableize

        admin_items_path = { :controller => "admin/#{klass_resource}" }
        new_admin_item_path = { :controller => "admin/#{klass_resource}", :action => 'new'}

        html << <<-HTML
<tr class="#{cycle('even', 'odd')}">
<td>#{link_to klass.typus_human_name.pluralize, admin_items_path}<br /><small>#{klass.typus_description}</small></td>
<td class="right"><small>
#{link_to _("Add"), new_admin_item_path if @current_user.can_perform?(klass, 'create')}
</small></td>
</tr>
        HTML

      end

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

    end

  end

end

#display_flash_message(message = flash) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/typus_helper.rb', line 161

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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/typus_helper.rb', line 122

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



182
183
184
185
186
187
188
189
190
191
192
# File 'app/helpers/typus_helper.rb', line 182

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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/helpers/typus_helper.rb', line 144

def (user = @current_user)

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

  message = _("Are you sure you want to sign out and end your session?")

  <<-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, { :confirm => message } }</li>
</ul>
  HTML

end

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



115
116
117
118
119
120
# File 'app/helpers/typus_helper.rb', line 115

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.



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
87
88
89
90
91
# File 'app/helpers/typus_helper.rb', line 56

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/typus_helper.rb', line 93

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



174
175
176
177
178
179
180
# File 'app/helpers/typus_helper.rb', line 174

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