Module: Zena::Use::Action::ViewMethods

Includes:
RubyLess, Common
Defined in:
lib/zena/use/action.rb

Instance Method Summary collapse

Methods included from Common

#node_action_link, #win_id

Instance Method Details

#discussion_actions(discussion, opt = {}) ⇒ Object

TODO: test



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/zena/use/action.rb', line 139

def discussion_actions(discussion, opt={})
  opt = {:action=>:all}.merge(opt)
  return '' unless @node.can_drive?
  if opt[:action] == :view
    link_to_function(_('btn_view'), "opener.Zena.discussion_show(#{discussion[:id]}); return false;")
  elsif opt[:action] == :all
    if discussion.open?
      link_to_remote( _("img_open"), :url=>{:controller=>'discussions', :action => 'close' , :id => discussion[:id]}, :title=>_("btn_title_close_discussion")) + "\n"
    else
      link_to_remote( _("img_closed"), :url=>{:controller=>'discussions', :action => 'open', :id => discussion[:id]}, :title=>_("btn_title_open_discussion")) + "\n"
    end +
    if discussion.can_destroy?
      link_to_remote( _("btn_remove"), :url=>{:controller=>'discussions', :action => 'remove', :id => discussion[:id]}, :title=>_("btn_title_destroy_discussion")) + "\n"
    else
      ''
    end
  end
end

#login_pathObject



158
159
160
161
162
163
164
# File 'lib/zena/use/action.rb', line 158

def 
  if params[:controller] == 'nodes'
    zen_path(@node, :prefix => AUTHENTICATED_PREFIX)
  else
    super
  end
end

#logout_pathObject



166
167
168
169
170
171
172
# File 'lib/zena/use/action.rb', line 166

def logout_path
  if params[:controller] == 'nodes' && @node.public?
    super :redirect => zen_path(@node, :prefix => visitor.lang)
  else
    super
  end
end

#next_in_list_i(nb, list) ⇒ Object



62
63
64
65
66
# File 'lib/zena/use/action.rb', line 62

def next_in_list_i(nb, list)
  list = list.to_s.split(',').map(&:to_f)
  nb   = nb.to_f
  list[((list.index(nb) || -1) + 1) % list.size]
end

#next_in_list_s(str, list) ⇒ Object



56
57
58
59
60
# File 'lib/zena/use/action.rb', line 56

def next_in_list_s(str, list)
  list = list.to_s.split(',').map(&:strip)
  str  = str.to_s
  list[((list.index(str) || -1) + 1) % list.size]
end

#node_actions(node, opts = {}) ⇒ Object

Node actions that appear on the web page



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/zena/use/action.rb', line 79

def node_actions(node, opts={})
  actions = (opts[:actions] || 'all').to_s
  actions = 'edit,propose,refuse,publish,drive' if actions == 'all'

  return '' if node.new_record?
  res = actions.split(',').reject do |action|
    !node.can_apply?(action.to_sym)
  end.map do |action|
    node_action_link(action, node.zip, opts)
  end.join(" ")

  if res != ""
    "<span class='actions'>#{res}</span>"
  else
    ""
  end
end

TODO: test



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/zena/use/action.rb', line 120

def version_action_link(action, version)
  if action == 'view'
    # FIXME
    link_to_function(
    _("status_#{version.status}_img"),
    "Zena.version_preview('/nodes/#{version.node.zip}/versions/#{version.number}');", :title => _("status_#{version.status}"))
  else
    if action == 'destroy_version'
      action = 'destroy'
      method = :delete
    else
      method = :put
    end
    link_to_remote( _("btn_#{action}"), :url=>{:controller=>'versions', :action => action, :node_id => version.node[:zip], :id => version.number, :drive=>true}, :title=>_("btn_title_#{action}"), :method => method ) + "\n"
  end
end

#version_actions(version, opts = {}) ⇒ Object

Actions that appear in the drive popup versions list



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/zena/use/action.rb', line 98

def version_actions(version, opts={})
  return "" unless version.kind_of?(Version)
  # 'view' ?
  actions = (opts[:actions] || 'all').to_s
  actions = 'destroy_version,remove,redit,unpublish,propose,refuse,publish' if actions == 'all'

  node = version.node
  node.version = version

  actions.split(',').reject do |action|
    action.strip!
    if action == 'view'
      !node.can_apply?('publish')
    else
      !node.can_apply?(action.to_sym)
    end
  end.map do |action|
    version_action_link(action, version)
  end.join(' ')
end