Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Replace meeting script with stimulus controller

ulfertsd04b18f263af
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 8d7466d1753..94925ce4628 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -41,11 +41,12 @@ module AttachmentsHelper
#
# Within ckeditor-augmented-textarea-form, this attachment list is added automatically
# when a resource is added.
- def list_attachments(resource)
+ def list_attachments(resource, options = {})
content_tag 'op-attachments',
'',
'data-resource': resource.to_json,
'data-allow-uploading': false,
- 'data-destroy-immediately': true
+ 'data-destroy-immediately': true,
+ **options
end
end
diff --git a/app/views/roles/_form.html.erb b/app/views/roles/_form.html.erb
index 392fa0344a2..bcabb9606b1 100644
--- a/app/views/roles/_form.html.erb
+++ b/app/views/roles/_form.html.erb
@@ -56,15 +56,18 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
</div>
- <div data-admin-roles-target="memberAttributes">
+ <div data-admin-roles-target="memberAttributes"
+ hidden>
<%= render partial: "member_attributes", locals: { f: f, role: role, roles: roles&.select {|r| !r.is_a?(GlobalRole)} }%>
</div>
- <div data-admin-roles-target="globalPermissions">
+ <div data-admin-roles-target="globalPermissions"
+ hidden>
<%= render partial: "permissions",
locals: { permissions: grouped_setable_permissions(GlobalRole.new), role: role, show_global_role: true }%>
</div>
- <div data-admin-roles-target="memberPermissions">
+ <div data-admin-roles-target="memberPermissions"
+ hidden>
<%= render partial: "permissions",
locals: { permissions: grouped_setable_permissions(role), role: role, show_global_role: false }%>
</div>
diff --git a/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js b/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js
deleted file mode 100644
index ba6a77dd82f..00000000000
--- a/frontend/src/app/core/augmenting/dynamic-scripts/meeting.js
+++ /dev/null
@@ -1,26 +0,0 @@
-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);
-
- jQuery('.meeting_content ~ attachments').toggle(!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);
- window.OpenProject.pageWasEdited = false;
-
- return false;
- });
-});
diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-content.controller.ts b/frontend/src/stimulus/controllers/dynamic/meeting-content.controller.ts
new file mode 100644
index 00000000000..53c7ccb8cb9
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/meeting-content.controller.ts
@@ -0,0 +1,82 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 the OpenProject GmbH
+ *
+ * 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 COPYRIGHT and LICENSE files for more details.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class MeetingContentController extends Controller {
+ static targets = [
+ 'renderedText',
+ 'editor',
+ 'attachments',
+ 'editButton',
+ ];
+
+ initialize() {
+ // This should have been achieved by the `data-loader-edit-state-value` attribute, but for unknown reasons
+ // this does not apply the value to the variable. Doing it manually for now.
+ const rawInitialValue = this.element.getAttribute('data-loader-edit-state-value');
+
+ if (rawInitialValue === 'true') {
+ this.editStateValue = true;
+ } else if (rawInitialValue === 'false') {
+ this.editStateValue = false;
+ }
+ }
+
+ static values = {
+ editState: { type: Boolean, default: false },
+ };
+
+ declare editStateValue:boolean;
+
+ declare readonly renderedTextTarget:HTMLElement;
+
+ declare readonly editorTarget:HTMLElement;
+
+ declare readonly attachmentsTarget:HTMLElement;
+
+ declare readonly editButtonTarget:HTMLLinkElement;
+
+ enableEditState() {
+ this.editStateValue = true;
+ }
+
+ cancelEditState() {
+ this.editStateValue = false;
+ window.OpenProject.pageWasEdited = false;
+ }
+
+ editStateValueChanged() {
+ this.renderedTextTarget.hidden = this.editStateValue;
+ this.attachmentsTarget.hidden = this.editStateValue;
+ this.editorTarget.hidden = !this.editStateValue;
+ this.editButtonTarget.classList.toggle('-active', this.editStateValue);
+ }
+}
diff --git a/modules/meeting/app/helpers/meeting_contents_helper.rb b/modules/meeting/app/helpers/meeting_contents_helper.rb
index 9f0bee99dbe..9d9eb4498b3 100644
--- a/modules/meeting/app/helpers/meeting_contents_helper.rb
+++ b/modules/meeting/app/helpers/meeting_contents_helper.rb
@@ -106,7 +106,10 @@ module MeetingContentsHelper
content_tag :li, '', class: 'toolbar-item' do
link_to '',
class: 'button button--edit-agenda',
- data: { 'content-type': content_type },
+ data: {
+ action: 'meeting-content#enableEditState',
+ 'meeting-content-target': 'editButton'
+ },
accesskey: accesskey(:edit) do
text_with_icon(I18n.t(:label_edit), 'icon-edit')
end
diff --git a/modules/meeting/app/views/meeting_contents/_form.html.erb b/modules/meeting/app/views/meeting_contents/_form.html.erb
index 40ce71936fc..0412006b1fe 100644
--- a/modules/meeting/app/views/meeting_contents/_form.html.erb
+++ b/modules/meeting/app/views/meeting_contents/_form.html.erb
@@ -49,5 +49,10 @@ See COPYRIGHT and LICENSE files for more details.
<p><%= f.text_field :journal_notes, label: :comments %></p>
<p><%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark button--save-agenda' %>
- <%= link_to t(:button_cancel), "#", data: { 'content-type': content_type }, class: 'button -with-icon icon-cancel button--cancel-agenda' %>
+ <%= link_to t(:button_cancel),
+ "#",
+ data: {
+ action: 'meeting-content#cancelEditState'
+ },
+ class: 'button -with-icon icon-cancel button--cancel-agenda' %>
<% end %>
diff --git a/modules/meeting/app/views/meeting_contents/_show.html.erb b/modules/meeting/app/views/meeting_contents/_show.html.erb
index cc1f7caa61d..bd2e6d5de1a 100644
--- a/modules/meeting/app/views/meeting_contents/_show.html.erb
+++ b/modules/meeting/app/views/meeting_contents/_show.html.erb
@@ -32,10 +32,10 @@ See COPYRIGHT and LICENSE files for more details.
content, content_type = tab[:content], tab[:content_type] if tab && tab.present?
-%>
-<div class="meeting_content
- <%= content_type %>"
+<div data-controller="meeting-content"
data-application-target="dynamic"
- data-controller="meetings">
+ data-loader-edit-state-value="<%= show_meeting_content_editor?(content, content_type) %>"
+>
<div>
<%= toolbar title: t(:"label_#{content_type}") do %>
<%=raw meeting_content_context_menu content, content_type %>
@@ -43,18 +43,16 @@ See COPYRIGHT and LICENSE files for more details.
</div>
<% 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 data-meeting-content-target="editor"
+ hidden>
+ <%= render(:partial => "meeting_contents/form", :locals => {:content => content, :content_type => content_type}) %>
</div>
<% end -%>
+<div data-meeting-content-target="renderedText"
+ hidden>
<% if saved_meeting_content_text_present?(content) -%>
- <div id="<%= content_type %>-text"
- style="<%= 'display: none' if show_meeting_content_editor?(content, content_type) %>"
- class="wiki show-<%= content_type %> op-uc-container"
- data>
+ <div class="wiki op-uc-container">
<%= format_text(content.text, :object => @meeting) %>
</div>
<% else -%>
@@ -63,7 +61,11 @@ See COPYRIGHT and LICENSE files for more details.
</div>
<%# We cannot render attachments for journaled content %>
-<% unless local_assigns[:journaled_version] %>
- <% resource = ::API::V3::MeetingContents::MeetingContentRepresenter.new(content, current_user: current_user, embed_links: true) %>
- <%= list_attachments(resource) %>
-<% end %>
+ <% unless local_assigns[:journaled_version] %>
+ <% resource = ::API::V3::MeetingContents::MeetingContentRepresenter.new(content, current_user: current_user, embed_links: true) %>
+ <%= list_attachments(resource,
+ data: {
+ 'meeting-content-target': "attachments"
+ }) %>
+ <% end %>
+</div>
diff --git a/modules/meeting/app/views/meeting_contents/history.html.erb b/modules/meeting/app/views/meeting_contents/history.html.erb
index 8cf69b092ce..a57bac2c6ee 100644
--- a/modules/meeting/app/views/meeting_contents/history.html.erb
+++ b/modules/meeting/app/views/meeting_contents/history.html.erb
@@ -34,10 +34,6 @@ See COPYRIGHT and LICENSE files for more details.
<h3><%= t(:label_history) %></h3>
-<% content_for :header_tags do %>
- <meta name="required_script" content="meeting" />
-<% end %>
-
<%= form_tag({:action => "diff"}, :method => :get) do %>
<div class="generic-table--container"
data-application-target="dynamic"
diff --git a/modules/meeting/app/views/meetings/_meeting_header.html.erb b/modules/meeting/app/views/meetings/_meeting_header.html.erb
deleted file mode 100644
index 5c129f4d2c1..00000000000
--- a/modules/meeting/app/views/meetings/_meeting_header.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<% content_for :header_tags do %>
- <meta name="required_script" content="meeting" />
-<% end %>
\ No newline at end of file
diff --git a/modules/meeting/app/views/meetings/show.html.erb b/modules/meeting/app/views/meetings/show.html.erb
index f2ce6b39a21..6624b5c8bda 100644
--- a/modules/meeting/app/views/meetings/show.html.erb
+++ b/modules/meeting/app/views/meetings/show.html.erb
@@ -27,8 +27,6 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render partial: 'meetings/meeting_header' %>
-
<% html_title "#{t(:label_meeting)}: #{@meeting.title}" %>
<%= toolbar title: t(:label_meeting),
link_to: link_to(@meeting),