diff --git a/app/controllers/meeting_contents_controller.rb b/app/controllers/meeting_contents_controller.rb index d946919e29..253fae7674 100644 --- a/app/controllers/meeting_contents_controller.rb +++ b/app/controllers/meeting_contents_controller.rb @@ -4,6 +4,7 @@ class MeetingContentsController < ApplicationController menu_item :meetings helper :wiki + helper :meeting_contents before_filter :find_meeting, :find_content before_filter :authorize diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index cef2671d97..903808811c 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -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 diff --git a/app/helpers/meeting_contents_helper.rb b/app/helpers/meeting_contents_helper.rb index 07483a0ff1..755d3e84bf 100644 --- a/app/helpers/meeting_contents_helper.rb +++ b/app/helpers/meeting_contents_helper.rb @@ -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 \ No newline at end of file diff --git a/app/views/meeting_contents/_form.html.erb b/app/views/meeting_contents/_form.html.erb index 3fd9f9d8b5..9623598e93 100644 --- a/app/views/meeting_contents/_form.html.erb +++ b/app/views/meeting_contents/_form.html.erb @@ -3,7 +3,7 @@

<%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %>


<%= f.text_field :comment, :size => 120 %>

-

<%= 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;" %>

+

<%= submit_tag l(:button_save) %> <%= link_to l(:button_cancel), "#", :onclick => "$$('.show-#{content_type}').invoke('show'); $$('.edit-#{content_type}').invoke('hide'); return false;" %>

<%= wikitoolbar_for "#{content_type}_text" %> <% end %> diff --git a/app/views/meeting_contents/_show.html.erb b/app/views/meeting_contents/_show.html.erb index a3134e1c48..3d32ede167 100644 --- a/app/views/meeting_contents/_show.html.erb +++ b/app/views/meeting_contents/_show.html.erb @@ -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? -%>
- <%= 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 %>

<%=l :"label_#{content_type}" %>

- <% if authorize_for(content_type.pluralize, 'update') && content.editable? -%> -
> + <% if can_edit_meeting_content?(content, content_type) -%> +
> <%= render(:partial => "meeting_contents/form", :locals => {:content => content, :content_type => content_type}) %>
<% end -%> - <% if !(!content.new_record? && content.text.present? && !content.text.empty?) -%> -

><%= l(:label_no_data) %>

- <% else -%> -
+ <% if saved_meeting_content_text_present?(content) -%> +
<%= textilizable(content.text) %>
+ <% else -%> +

<%= l(:label_no_data) %>

<% end -%> + <%= javascript_tag(show_meeting_content_editor?(content, content_type) ? "$$('.show-#{content_type}').invoke('hide');" : "$$('.edit-#{content_type}').invoke('hide');") %>
<% content_for :header_tags do %>