Module: Zena::Use::Action::Common

Included in:
ControllerMethods, ViewMethods, ZafuMethods
Defined in:
lib/zena/use/action.rb

Instance Method Summary collapse

Instance Method Details

This method renders an action link without using Rails actions so that we can feed it with erb from Zafu.



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
# File 'lib/zena/use/action.rb', line 10

def node_action_link(action, node_zip, opts={})
  text  = opts[:text].blank? ? _("btn_#{action}") : opts[:text]
  title = opts[:title] || _("btn_title_#{action}")
  query = []
  if params = opts[:params]
    params.each do |k,v|
      query << "#{k}=#{v}"
    end
  end

  if %w{edit drive add_doc}.include?(action)
    case action
    when 'edit'
      url = "/nodes/#{node_zip}/versions/0/edit"
    when 'drive'
      url = "/nodes/#{node_zip}/edit"
    when 'add_doc'
      url = "/documents/new"
      query << "parent_id=#{node_zip}"
    end
    id  = win_id(node_zip, action)

    url = query.empty? ? url : "#{url}?#{query.join('&')}"
    tag = "<a href='#{url}' target='_blank' title='#{title}' onclick=\"Zena.open_window('#{url}', '#{id}', event);return false;\">"
  else
    query = query.empty? ? '' : "?#{query.join('&')}"
    tag  = "<a href='/nodes/#{node_zip}/versions/0/#{action}#{query}' onclick='Zena.m(this, \"put\");return false;' title ='#{title}'>"
  end
  "#{tag}#{text}</a>"
end

#win_id(node_zip, action) ⇒ Object



5
6
7
# File 'lib/zena/use/action.rb', line 5

def win_id(node_zip, action)
  "#{current_site.host.gsub('.', '_')}_#{node_zip}_#{action}"
end