From a47f5f6934935becae1df1b77db6886e9e90be75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 5 Mar 2018 15:36:05 +0100 Subject: [PATCH] Add meeting JS to show/hide edit form --- app/assets/javascripts/meeting/meeting.js | 23 +++++++++++++++++++++++ app/helpers/meeting_contents_helper.rb | 9 +++------ app/views/meeting_contents/_form.html.erb | 8 +------- app/views/meeting_contents/_show.html.erb | 15 +++++++++++---- lib/open_project/meeting/engine.rb | 2 +- 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 app/assets/javascripts/meeting/meeting.js diff --git a/app/assets/javascripts/meeting/meeting.js b/app/assets/javascripts/meeting/meeting.js new file mode 100644 index 0000000000..4fcd305077 --- /dev/null +++ b/app/assets/javascripts/meeting/meeting.js @@ -0,0 +1,23 @@ +jQuery(function($) { + function toggleContentTypeForm(content_type, edit) { + jQuery('.edit-' + content_type).toggle(edit); + jQuery('.show-' + content_type).toggle(!edit); + + jQuery('.button--edit-agenda').toggleClass('-active', edit); + jQuery('.button--edit-agenda').attr('disabled', edit); + } + + $('.button--edit-agenda').click(function() { + var content_type = $(this).data('contentType'); + toggleContentTypeForm(content_type, true); + + return false; + }); + + $('.button--cancel-agenda').click(function() { + var content_type = $(this).data('contentType'); + toggleContentTypeForm(content_type, false); + + return false; + }); +}); \ No newline at end of file diff --git a/app/helpers/meeting_contents_helper.rb b/app/helpers/meeting_contents_helper.rb index 8428d41385..532f79bdad 100644 --- a/app/helpers/meeting_contents_helper.rb +++ b/app/helpers/meeting_contents_helper.rb @@ -92,14 +92,11 @@ module MeetingContentsHelper def meeting_content_edit_link(content_type) content_tag :li, '', class: 'toolbar-item' do + content_tag :button, '', - class: 'button button--edit-agenda', - onclick: "jQuery('.edit-#{content_type}').show(); - jQuery('.show-#{content_type}').hide(); - jQuery('.button--edit-agenda').addClass('-active'); - jQuery('.button--edit-agenda').attr('disabled', true); - return false;" do + data: { 'content-type': content_type }, + class: 'button button--edit-agenda' do link_to l(:button_edit), '', class: 'icon-context icon-edit', diff --git a/app/views/meeting_contents/_form.html.erb b/app/views/meeting_contents/_form.html.erb index ced9207856..cea76d2333 100644 --- a/app/views/meeting_contents/_form.html.erb +++ b/app/views/meeting_contents/_form.html.erb @@ -29,13 +29,7 @@ See doc/COPYRIGHT.md for more details.

<%= styled_button_tag l(:button_save), class: '-highlight -with-icon icon-checkmark' %> <% path = send("preview_#{content_type}_path", content.meeting) %> <%= preview_link path, "#{content_type}_form", { class: 'button preview' } %> -<%= link_to l(:button_cancel), "#", - :onclick => "jQuery('.show-#{content_type}').show(); - jQuery('.edit-#{content_type}').hide(); - jQuery('.button--edit-agenda').removeClass('-active'); - jQuery('.button--edit-agenda').removeAttr('disabled');; - return false;", - class: 'button' %>

+<%= link_to l(:button_cancel), "#", data: { 'content-type': content_type }, class: 'button button--cancel-agenda' %> <%= 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 4699ab9df6..f9a5874144 100644 --- a/app/views/meeting_contents/_show.html.erb +++ b/app/views/meeting_contents/_show.html.erb @@ -23,6 +23,11 @@ See doc/COPYRIGHT.md for more details. tab ||= locals[:tab_contents] if defined? locals content, content_type = tab[:content], tab[:content_type] if tab && tab.present? -%> + +<% content_for :header_tags do %> + <%= javascript_include_tag('meeting/meeting.js') %> +<% end %> +
<%= toolbar title: l(:"label_#{content_type}") do %> @@ -31,20 +36,22 @@ See doc/COPYRIGHT.md for more details.
<% if can_edit_meeting_content?(content, content_type) -%> -
> +
<%= render(:partial => "meeting_contents/form", :locals => {:content => content, :content_type => content_type}) %>
<% end -%> <% if saved_meeting_content_text_present?(content) -%> -
+
<%= format_text(content.text, :object => @meeting) %>
<% else -%> <%= no_results_box %> <% end -%> - - <%= nonced_javascript_tag(show_meeting_content_editor?(content, content_type) ? "jQuery('.show-#{content_type}').hide();" : "jQuery('.edit-#{content_type}').hide();") %>
<%= render :partial => 'shared/meeting_header' %> diff --git a/lib/open_project/meeting/engine.rb b/lib/open_project/meeting/engine.rb index 462e2b7979..68bf043670 100644 --- a/lib/open_project/meeting/engine.rb +++ b/lib/open_project/meeting/engine.rb @@ -68,7 +68,7 @@ module OpenProject::Meeting patch_with_namespace :BasicData, :SettingSeeder initializer 'meeting.precompile_assets' do - Rails.application.config.assets.precompile += %w(meeting/meeting.css) + Rails.application.config.assets.precompile += %w(meeting/meeting.css meeting/meeting.js) end initializer 'meeting.register_hooks' do