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 subform

Oliver Günther1ea0dc731bfa
diff --git a/frontend/src/global_styles/content/modules/_costs.sass b/frontend/src/global_styles/content/modules/_costs.sass
index 253fb83c25c..9cd1850c0f4 100644
--- a/frontend/src/global_styles/content/modules/_costs.sass
+++ b/frontend/src/global_styles/content/modules/_costs.sass
@@ -32,6 +32,5 @@ table.list.members
.progress-bar .inner-progress.done
background-color: var(--display-red-bgColor-muted)
-.budget-row-template,
-.subform-row-template
+.budget-row-template
display: none
diff --git a/frontend/src/stimulus/controllers/dynamic/subform.controller.ts b/frontend/src/stimulus/controllers/dynamic/subform.controller.ts
new file mode 100644
index 00000000000..342df55f6dc
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/subform.controller.ts
@@ -0,0 +1,69 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 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 SubformController extends Controller {
+ static targets = [
+ 'template',
+ 'table',
+ ];
+
+ declare readonly tableTarget:HTMLTableElement;
+
+ private rowTemplate:HTMLElement;
+
+ connect() {
+ // We can't use a target as we duplicate the "template" without much cleaning up
+ const item = this.element.querySelector('[data-row-target]') as HTMLElement;
+ this.rowTemplate = item;
+ item.remove();
+ }
+
+ deleteRow(evt:Event) {
+ const row = (evt.target as HTMLElement).closest('tr');
+ row?.remove();
+ }
+
+ addRow() {
+ const index = this.itemCount;
+ const newRow = this.rowTemplate.cloneNode(true) as HTMLElement;
+ this.tableTarget.appendChild(newRow);
+ newRow.style.removeProperty('display');
+ newRow.outerHTML = newRow.outerHTML.replace(/INDEX/g, index.toString());
+
+ // Autofocus
+ setTimeout(() => newRow.querySelector<HTMLElement>('input')?.focus(), 10);
+ }
+
+ get itemCount():number {
+ return this.tableTarget.querySelectorAll('tr').length;
+ }
+}
diff --git a/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb b/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb
index 33e437560bf..e4c79c78358 100644
--- a/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb
+++ b/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb
@@ -30,7 +30,10 @@ require "spec_helper"
require_relative "../support//board_index_page"
require_relative "../support/board_page"
-RSpec.describe "Status action board", :js, with_ee: %i[board_view] do
+RSpec.describe "Status action board",
+ :js,
+ :with_cuprite,
+ with_ee: %i[board_view] do
let(:user) do
create(:user,
member_with_roles: { project => role })
diff --git a/modules/budgets/frontend/module/augment/cost-subform.augment.service.ts b/modules/budgets/frontend/module/augment/cost-subform.augment.service.ts
deleted file mode 100644
index 6c93f684f68..00000000000
--- a/modules/budgets/frontend/module/augment/cost-subform.augment.service.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 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 { Injectable } from "@angular/core";
-
-@Injectable()
-export class CostSubformAugmentService {
-
- constructor() {
- jQuery('costs-subform').each((i, match) => {
- const el = jQuery(match);
-
- const container = el.find('.subform-container');
-
- const templateEl = el.find('.subform-row-template');
- templateEl.detach();
- const template = templateEl[0].outerHTML;
- let rowIndex = parseInt(el.attr('item-count')!);
-
- el.on('click', '.delete-row-button,.delete-budget-item', (evt:any) => {
- jQuery(evt.target).closest('.subform-row').remove();
- return false;
- });
-
- // Add new row handler
- el.find('.add-row-button,.wp-inline-create--add-link').click((evt:any) => {
- evt.preventDefault();
- const row = jQuery(template.replace(/INDEX/g, rowIndex.toString()));
- row.show();
- row.removeClass('subform-row-template');
- row.find('input.costs-date-picker').prop('required', true);
- row.find('input[id^="cost_type_new_rate_attributes"]').prop('required', true);
-
- container.append(row);
- rowIndex += 1;
-
- setTimeout(() => container.find('.subform-row:last-child input:first').focus(), 10)
-
- return false;
- });
- });
- }
-}
diff --git a/modules/budgets/frontend/module/main.ts b/modules/budgets/frontend/module/main.ts
index c452a47f065..34c44dbc399 100644
--- a/modules/budgets/frontend/module/main.ts
+++ b/modules/budgets/frontend/module/main.ts
@@ -28,7 +28,6 @@ import { Injector, NgModule } from '@angular/core';
import { OpenProjectPluginContext } from 'core-app/features/plugins/plugin-context';
import { multiInput } from '@openproject/reactivestates';
import { PlannedCostsFormAugment } from 'core-app/features/plugins/linked/budgets/augment/planned-costs-form';
-import { CostSubformAugmentService } from './augment/cost-subform.augment.service';
import { BudgetResource } from './hal/resources/budget-resource';
export function initializeCostsPlugin(injector:Injector) {
@@ -44,8 +43,6 @@ export function initializeCostsPlugin(injector:Injector) {
const { states } = pluginContext.services;
states.add('budgets', multiInput<BudgetResource>());
- // Augment previous cost-subforms
- new CostSubformAugmentService();
PlannedCostsFormAugment.listen();
});
}
diff --git a/modules/costs/app/views/hourly_rates/_rate.html.erb b/modules/costs/app/views/hourly_rates/_rate.html.erb
index 592a3ce6877..fa6f9ab67c9 100644
--- a/modules/costs/app/views/hourly_rates/_rate.html.erb
+++ b/modules/costs/app/views/hourly_rates/_rate.html.erb
@@ -34,12 +34,15 @@ See COPYRIGHT and LICENSE files for more details.
id_or_index = rate.new_record? ? index : rate.id
prefix = "user[#{new_or_existing}_rate_attributes][]"
id_prefix = "user_#{new_or_existing}_rate_attributes_#{id_or_index}"
- classes ||= ""
- classes += " subform-row-template" if templated
-%>
<%= fields_for prefix, rate, builder: TabularFormBuilder do |rate_form| %>
- <tr class="subform-row <%= classes %>" id="<%= id_prefix %>">
+ <%= content_tag(:tr,
+ class: "subform-row",
+ id: id_prefix,
+ data: templated ? { 'row-target': 'true' } : {},
+ style: templated ? 'display: none;' : ''
+ ) do %>
<td>
<label class="hidden-for-sighted" for="<%= "#{id_prefix}_valid_from" %>"><%= Rate.human_attribute_name(:valid_from) %></label>
<%= rate_form.date_picker :valid_from,
@@ -63,9 +66,9 @@ See COPYRIGHT and LICENSE files for more details.
</span>
</td>
<td class="buttons">
- <a href="#" class="delete-row-button no-decoration-on-hover">
+ <a href="#" class="delete-row-button no-decoration-on-hover" data-action="subform#deleteRow">
<%= op_icon('icon-context icon-delete', title: t(:button_delete)) %>
</a>
</td>
- </tr>
+ <% end %>
<% end %>
diff --git a/modules/costs/app/views/hourly_rates/edit.html.erb b/modules/costs/app/views/hourly_rates/edit.html.erb
index fc67aa38ef3..d8a03409a7b 100644
--- a/modules/costs/app/views/hourly_rates/edit.html.erb
+++ b/modules/costs/app/views/hourly_rates/edit.html.erb
@@ -36,8 +36,10 @@ See COPYRIGHT and LICENSE files for more details.
<p><strong><%= t(:label_current_default_rate) %>:</strong> <%= number_to_currency(default_rate.rate)%></p>
<% end %>
-<costs-subform item-count="<%= @rates.count %>">
-<%= labelled_tabular_form_for @user, url: {action: 'update', project_id: @project}, method: :put do |f| %>
+<%= labelled_tabular_form_for @user,
+ url: {action: 'update', project_id: @project},
+ data: { controller: 'subform', 'application-target': 'dynamic' },
+ method: :put do |f| %>
<%= back_url_hidden_field_tag %>
<%= error_messages_for 'user' %>
<%- @rates.each do |rate| -%>
@@ -46,7 +48,7 @@ See COPYRIGHT and LICENSE files for more details.
<%- end -%>
<div class="generic-table--container">
<div class="generic-table--results-container">
- <table class="generic-table rates" width="200px">
+ <table class="generic-table rates">
<colgroup>
<col>
<col>
@@ -75,7 +77,7 @@ See COPYRIGHT and LICENSE files for more details.
<th><div class="generic-table--empty-header"></div></th>
</tr>
</thead>
- <tbody id="rates_body" class="subform-container">
+ <tbody id="rates_body" class="subform-container" data-subform-target="table">
<%= render partial: "hourly_rates/rate", object: HourlyRate.new(valid_from: Date.current), locals: { templated: true } %>
<%- @rates.each_with_index do |rate, index| -%>
<%= render partial: 'rate', object: rate, locals: {index: index} %>
@@ -86,7 +88,7 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</div>
<div class="wp-inline-create-button">
- <a href="#" class="add-row-button wp-inline-create--add-link">
+ <a href="#" class="add-row-button wp-inline-create--add-link" data-action="subform#addRow">
<%= op_icon('icon icon-add') %>
<%= t(:button_add_rate) %>
</a>
@@ -95,4 +97,3 @@ See COPYRIGHT and LICENSE files for more details.
<%= styled_button_tag t(:button_save), class: '-with-icon icon-checkmark' %>
</div>
<% end %>
-</costs-subform>