Merge branch 'refactor_content_context_menu'

pull/6827/head
Felix Schäfer 14 years ago
commit ce51ab381b
  1. 1
      app/controllers/meeting_contents_controller.rb
  2. 3
      app/controllers/meetings_controller.rb
  3. 53
      app/helpers/meeting_contents_helper.rb
  4. 2
      app/views/meeting_contents/_form.html.erb
  5. 21
      app/views/meeting_contents/_show.html.erb

@ -4,6 +4,7 @@ class MeetingContentsController < ApplicationController
menu_item :meetings
helper :wiki
helper :meeting_contents
before_filter :find_meeting, :find_content
before_filter :authorize

@ -7,6 +7,7 @@ class MeetingsController < ApplicationController
before_filter :authorize
helper :watchers
helper :meeting_contents
include WatchersHelper
def index
@ -16,7 +17,7 @@ class MeetingsController < ApplicationController
end
def show
params[:tab] = "minutes" if @meeting.agenda.present? && @meeting.agenda.locked?
params[:tab] ||= "minutes" if @meeting.agenda.present? && @meeting.agenda.locked?
end
def create

@ -1,2 +1,55 @@
module MeetingContentsHelper
def can_edit_meeting_content?(content, content_type)
authorize_for(content_type.pluralize, 'update') && content.editable?
end
def saved_meeting_content_text_present?(content)
!content.new_record? && content.text.present? && !content.text.empty?
end
def show_meeting_content_editor?(content, content_type)
can_edit_meeting_content?(content, content_type) && !saved_meeting_content_text_present?(content)
end
def meeting_content_context_menu(content, content_type)
menu = []
menu << meeting_agenda_toggle_status_link(content, content_type)
menu << meeting_content_edit_link(content_type) if can_edit_meeting_content?(content, content_type)
menu << meeting_content_history_link(content_type, content.meeting)
menu << meeting_content_notify_link(content_type, content.meeting) if saved_meeting_content_text_present?(content)
menu.join(" ")
end
def meeting_agenda_toggle_status_link(content, content_type)
content.meeting.agenda.present? && content.meeting.agenda.locked? ? open_meeting_agenda_link(content_type, content.meeting) : close_meeting_agenda_link(content_type, content.meeting)
end
def close_meeting_agenda_link(content_type, meeting)
case content_type
when "meeting_agenda"
link_to_if_authorized l(:label_meeting_close), {:controller => 'meeting_agendas', :action => 'close', :meeting_id => meeting}, :method => :put, :class => "icon icon-lock show-meeting_agenda"
when "meeting_minutes"
link_to_if_authorized l(:label_meeting_agenda_close), {:controller => 'meeting_agendas', :action => 'close', :meeting_id => meeting}, :method => :put, :class => "icon icon-lock show-meeting_minutes"
end
end
def open_meeting_agenda_link(content_type, meeting)
case content_type
when "meeting_agenda"
link_to_if_authorized l(:label_meeting_open), {:controller => 'meeting_agendas', :action => 'open', :meeting_id => meeting}, :method => :put, :class => 'icon icon-lock show-meeting_agenda', :confirm => l(:text_meeting_agenda_open_are_you_sure)
when "meeting_minutes"
end
end
def meeting_content_edit_link(content_type)
link_to l(:button_edit), "#", :class => "icon icon-edit show-#{content_type}", :accesskey => accesskey(:edit), :onclick => "$$('.edit-#{content_type}').invoke('show'); $$('.show-#{content_type}').invoke('hide'); return false;"
end
def meeting_content_history_link(content_type, meeting)
link_to_if_authorized l(:label_history), {:controller => content_type.pluralize, :action => 'history', :meeting_id => meeting}, :class => "icon icon-history show-#{content_type}"
end
def meeting_content_notify_link(content_type, meeting)
link_to_if_authorized l(:label_notify), {:controller => content_type.pluralize, :action => 'notify', :meeting_id => meeting}, :method => :put, :class => "icon icon-notification show-#{content_type}"
end
end

@ -3,7 +3,7 @@
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
<p><label for="<%= content_type %>_comment"><%= l(:field_comments) %></label><br /><%= f.text_field :comment, :size => 120 %></p>
<p><%= submit_tag l(:button_save) %> <%= link_to l(:button_cancel), "#", :onclick => "Element.show(\"#{content_type}-text\"); if ($(\"close-#{content_type}-link\")) {Element.show(\"close-#{content_type}-link\")}; Element.hide(\"edit-#{content_type}\"); return false;" %></p>
<p><%= submit_tag l(:button_save) %> <%= link_to l(:button_cancel), "#", :onclick => "$$('.show-#{content_type}').invoke('show'); $$('.edit-#{content_type}').invoke('hide'); return false;" %></p>
<%= wikitoolbar_for "#{content_type}_text" %>
<% end %>

@ -1,25 +1,22 @@
<% content, content_type = tab[:content], tab[:content_type] if defined?(tab) && tab.present? -%>
<%- content, content_type = tab[:content], tab[:content_type] if defined?(tab) && tab.present? -%>
<div class="meeting_content <%= content_type %>">
<div class="contextual">
<%= link_to_if_authorized l(:label_meeting_agenda_close), {:controller => 'meeting_agendas', :action => 'close', :meeting_id => content.meeting}, :method => :put, :class => 'icon icon-lock' if content_type == "meeting_minutes" && !(content.meeting.agenda.present? && content.meeting.agenda.locked?) %>
<%= (content.locked? ? link_to_if_authorized(l(:label_meeting_open), {:controller => content_type.pluralize, :action => 'open', :meeting_id => content.meeting}, :method => :put, :class => 'icon icon-lock', :confirm => l(:text_meeting_agenda_open_are_you_sure)) : link_to_if_authorized(l(:label_meeting_close), {:controller => content_type.pluralize, :action => 'close', :meeting_id => content.meeting}, :method => :put, :class => 'icon icon-lock', :id => "close-#{content_type}-link", :style => (!content.new_record? && content.text.present? && !content.text.empty? ? "" : "display: none;"))) if content_type == "meeting_agenda" %>
<%= link_to l(:button_edit), "#", :class => 'icon icon-edit', :accesskey => accesskey(:edit), :onclick => "Element.show(\"edit-#{content_type}\"); Element.hide(\"#{content_type}-text\"); if ($(\"close-#{content_type}-link\")) {Element.hide(\"close-#{content_type}-link\")}; return false;" if authorize_for(content_type.pluralize, 'update') && content.editable? %>
<%= link_to_if_authorized(l(:label_history), {:controller => content_type.pluralize, :action => 'history', :meeting_id => content.meeting}, :class => 'icon icon-history') %>
<%= link_to_if_authorized(l(:label_notify), {:controller => content_type.pluralize, :action => 'notify', :meeting_id => content.meeting}, :method => :put, :class => 'icon icon-notification') unless content.new_record? || !content.editable? %>
<%= meeting_content_context_menu content, content_type %>
</div>
<h2><%=l :"label_#{content_type}" %></h2>
<% if authorize_for(content_type.pluralize, 'update') && content.editable? -%>
<div id="edit-<%= content_type %>"<%= " style=\"display: none;\"" if !content.new_record? && content.text.present? && !content.text.empty? %>>
<% if can_edit_meeting_content?(content, content_type) -%>
<div id="edit-<%= content_type %>" class="edit-<%= content_type %>"<%= " style=\"display: none;\"" unless show_meeting_content_editor?(content, content_type)%>>
<%= render(:partial => "meeting_contents/form", :locals => {:content => content, :content_type => content_type}) %>
</div>
<% end -%>
<% if !(!content.new_record? && content.text.present? && !content.text.empty?) -%>
<p class="nodata" id="<%= content_type %>-text"<%= " style=\"display: none;\"" if authorize_for(content_type.pluralize, 'update') && content.editable? %>><%= l(:label_no_data) %></p>
<% else -%>
<div class="wiki" id="<%= content_type %>-text">
<% if saved_meeting_content_text_present?(content) -%>
<div id="<%= content_type %>-text" class="wiki show-<%= content_type %>">
<%= textilizable(content.text) %>
</div>
<% else -%>
<p id="<%= content_type %>-text" class="nodata show-<%= content_type %>"><%= l(:label_no_data) %></p>
<% end -%>
<%= javascript_tag(show_meeting_content_editor?(content, content_type) ? "$$('.show-#{content_type}').invoke('hide');" : "$$('.edit-#{content_type}').invoke('hide');") %>
</div>
<% content_for :header_tags do %>

Loading…
Cancel
Save