diff --git a/app/controllers/meeting_contents_controller.rb b/app/controllers/meeting_contents_controller.rb index 4077ee1d13..65c805a517 100644 --- a/app/controllers/meeting_contents_controller.rb +++ b/app/controllers/meeting_contents_controller.rb @@ -21,6 +21,7 @@ class MeetingContentsController < ApplicationController include PaginationHelper + include OpenProject::Concerns::Preview menu_item :meetings @@ -93,15 +94,10 @@ class MeetingContentsController < ApplicationController redirect_back_or_default :controller => '/meetings', :action => 'show', :id => @meeting end - def preview - (render_403; return) unless @content.editable? - @text = params[:text] - render :partial => 'common/preview' - end - def default_breadcrumb MeetingsController.new.send(:default_breadcrumb) end + private def find_meeting @@ -111,4 +107,13 @@ class MeetingContentsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def parse_preview_data + text = { } + + text = { WikiContent.human_attribute_name(:content) => params[@content_type][:text] } if @content.editable? + + return text, [], @content + end + end diff --git a/app/controllers/meeting_minutes_controller.rb b/app/controllers/meeting_minutes_controller.rb index 5897b3a724..e5f8a682b2 100644 --- a/app/controllers/meeting_minutes_controller.rb +++ b/app/controllers/meeting_minutes_controller.rb @@ -28,4 +28,4 @@ class MeetingMinutesController < MeetingContentsController @content = @meeting.minutes || @meeting.build_minutes @content_type = "meeting_minutes" end -end \ No newline at end of file +end diff --git a/app/views/meeting_contents/_form.html.erb b/app/views/meeting_contents/_form.html.erb index 2ead6b20f9..17a64437ff 100644 --- a/app/views/meeting_contents/_form.html.erb +++ b/app/views/meeting_contents/_form.html.erb @@ -27,17 +27,12 @@ See doc/COPYRIGHT.md for more details. <%= f.hidden_field :lock_version %>


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

<%= submit_tag l(:button_save) %> -<%= link_to_remote l(:label_preview), - {:url => {:controller => '/' + content_type.pluralize, :action => 'preview', :meeting_id => content.meeting}, - :method => :post, - :update => "#{content_type}_preview", - :with => "'text=' + encodeURIComponent($('#{content_type}_text').value)", - :complete => "Element.scrollTo('#{content_type}_preview')" - }, :accesskey => accesskey(:preview) %> | +<% path = send("preview_#{content_type}_path", content.meeting) %> +<%= preview_link path, "#{content_type}_form", { class: 'preview' } %> <%= link_to l(:button_cancel), "#", :onclick => "$$('.show-#{content_type}').invoke('show'); $$('.edit-#{content_type}').invoke('hide'); return false;" %>

<%= wikitoolbar_for "#{content_type}_text" %> <% end %> -
+
<%= render :partial => 'shared/meeting_header' %> diff --git a/spec/controllers/meeting_agendas_controller_spec.rb b/spec/controllers/meeting_agendas_controller_spec.rb new file mode 100644 index 0000000000..5ba365c8a4 --- /dev/null +++ b/spec/controllers/meeting_agendas_controller_spec.rb @@ -0,0 +1,41 @@ +#-- copyright +# OpenProject Meeting Plugin +# +# Copyright (C) 2011-2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See doc/COPYRIGHT.md for more details. +#++ + +require File.dirname(__FILE__) + '/../spec_helper' + +describe MeetingAgendasController do + let(:meeting) { FactoryGirl.create(:meeting) } + let(:user) { FactoryGirl.create(:admin) } + + before { User.stub(:current).and_return(user) } + + describe 'preview' do + let(:text) { "Meeting agenda content" } + + it_behaves_like 'valid preview' do + let(:preview_texts) { [text] } + let(:preview_params) { { meeting_id: meeting.id, meeting_agenda: { text: text } } } + end + + it_behaves_like 'authorizes object access' do + let(:preview_params) { { meeting_id: meeting.id, meeting_agenda: { } } } + end + end +end diff --git a/spec/controllers/meeting_minutes_controller_spec.rb b/spec/controllers/meeting_minutes_controller_spec.rb new file mode 100644 index 0000000000..67876dbf7d --- /dev/null +++ b/spec/controllers/meeting_minutes_controller_spec.rb @@ -0,0 +1,43 @@ +#-- copyright +# OpenProject Meeting Plugin +# +# Copyright (C) 2011-2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See doc/COPYRIGHT.md for more details. +#++ + +require File.dirname(__FILE__) + '/../spec_helper' + +describe MeetingMinutesController do + let(:meeting) { FactoryGirl.create(:meeting) } + let(:user) { FactoryGirl.create(:admin) } + + before { User.stub(:current).and_return(user) } + + describe 'preview' do + let(:text) { "Meeting minutes content" } + + before { MeetingMinutes.any_instance.stub(:editable?).and_return(true) } + + it_behaves_like 'valid preview' do + let(:preview_texts) { [text] } + let(:preview_params) { { meeting_id: meeting.id, meeting_minutes: { text: text } } } + end + + it_behaves_like 'authorizes object access' do + let(:preview_params) { { meeting_id: meeting.id, meeting_minutes: { } } } + end + end +end diff --git a/spec/routing/previews_routing_spec.rb b/spec/routing/previews_routing_spec.rb new file mode 100644 index 0000000000..37986099dd --- /dev/null +++ b/spec/routing/previews_routing_spec.rb @@ -0,0 +1,43 @@ +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require 'spec_helper' + +describe 'preview' do + it "should connect POST /meetings/:meeting_id/agenda/preview to meeting_agendas#preview" do + expect(post("/meetings/1/agenda/preview")).to route_to(controller: 'meeting_agendas', + meeting_id: '1', + action: 'preview') + end + + it "should connect POST /meetings/:meeting_id/agenda/preview to meeting_minutes#preview" do + expect(post("/meetings/1/minutes/preview")).to route_to(controller: 'meeting_minutes', + meeting_id: '1', + action: 'preview') + end +end