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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/zena/use/action.rb', line 144

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

/oo



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

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

#logout_pathObject



173
174
175
176
177
178
179
# File 'lib/zena/use/action.rb', line 173

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



67
68
69
70
71
# File 'lib/zena/use/action.rb', line 67

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



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

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/zena/use/action.rb', line 84

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



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/zena/use/action.rb', line 125

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/zena/use/action.rb', line 103

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