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

Add date_picker form field type to FormBuilder and use it where possible

Benjamin Bädorf1a3203495043
diff --git a/app/views/announcements/edit.html.erb b/app/views/announcements/edit.html.erb
index 84bf1e11490..012037a6637 100644
--- a/app/views/announcements/edit.html.erb
+++ b/app/views/announcements/edit.html.erb
@@ -16,20 +16,7 @@
with_text_formatting: true %>
</div>
<div class="form--field">
- <label
- class="form--label"
- title="<%= t('announcements.show_until') %>"
- for="announcements_show_until"
- ><%= t('announcements.show_until') %></label>
- <div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- inputs: {
- value: @announcement.show_until,
- id: "announcement_show_until",
- name: "announcement[show_until]"
- }
- %>
- </div>
+ <%= f.date_picker :show_until, label: t('announcements.show_until') %>
</div>
<div class="form--field">
<%= f.check_box :active, label: t(:label_active) %>
diff --git a/app/views/versions/_form.html.erb b/app/views/versions/_form.html.erb
index b0bf3c2b1cf..1d95890a388 100644
--- a/app/views/versions/_form.html.erb
+++ b/app/views/versions/_form.html.erb
@@ -63,13 +63,7 @@ See COPYRIGHT and LICENSE files for more details.
for="version_start_date"
><%= t(:start_date) %></label>
<div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- inputs: {
- value: version.start_date,
- id: "version_start_date",
- name: "version[start_date]"
- }
- %>
+ <%= f.date_picker :start_date %>
</div>
</div>
@@ -79,13 +73,7 @@ See COPYRIGHT and LICENSE files for more details.
for="version_effective_date"
><%= t(:effective_date) %></label>
<div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- inputs: {
- value: version.effective_date,
- id: "version_effective_date",
- name: "version[effective_date]"
- }
- %>
+ <%= f.date_picker :effective_date %>
</div>
</div>
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 6d986c8da1b..06ecbc89f2d 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -34,6 +34,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
include ActionView::Helpers::AssetTagHelper
include ERB::Util
include TextFormattingHelper
+ include AngularHelper
def self.tag_with_label_method(selector, &)
->(field, options = {}, *args) do
@@ -82,13 +83,26 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
super
end
- def date_field(field, value, options = {})
- angular_component_tag 'op-single-date-picker',
- class: 'date costs-date-picker',
- inputs: {
- id: field_id(field),
- name: field_name(field)
- }
+ def date_picker(field, options = {})
+ merge_required_attributes(options[:required], options)
+ options[:visible_overflow] = true;
+
+ input_options, label_options = extract_from options
+
+ if field_has_errors?(field)
+ input_options[:class] << ' -error'
+ end
+
+ label = label_for_field(field, label_options)
+ input = angular_component_tag 'op-single-date-picker',
+ class: options[:class],
+ inputs: {
+ value: @object.public_send(field),
+ id: field_id(field),
+ name: field_name(field)
+ }
+
+ (label + container_wrap_field(input, :date_picker, options))
end
def radio_button(field, value, options = {}, *args)
@@ -197,7 +211,8 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
if options[:no_label]
field_html
else
- content_tag(:span, field_html, class: options[:no_class] ? '' : 'form--field-container')
+ classes = options[:visible_overflow] ? '-visible-overflow' : ''
+ content_tag(:span, field_html, class: options[:no_class] ? classes : classes + ' form--field-container')
end
end
diff --git a/modules/backlogs/app/views/rb_sprints/_sprint.html.erb b/modules/backlogs/app/views/rb_sprints/_sprint.html.erb
index 01e96f660a5..2c485741ae1 100644
--- a/modules/backlogs/app/views/rb_sprints/_sprint.html.erb
+++ b/modules/backlogs/app/views/rb_sprints/_sprint.html.erb
@@ -53,16 +53,14 @@ See COPYRIGHT and LICENSE files for more details.
value: sprint.effective_date,
id: "effective_date_#{sprint.id}",
name: :effective_date
- }
- %>
+ } %>
<%= angular_component_tag "op-single-date-picker",
class: "start_date editor",
inputs: {
value: sprint.start_date,
id: "start_date_#{sprint.id}",
name: :start_date
- }
- %>
+ } %>
<%= text_field_tag :name,
sprint.name,
class: 'name editor' %>
diff --git a/modules/budgets/app/views/budgets/_form.html.erb b/modules/budgets/app/views/budgets/_form.html.erb
index 7cc911adb14..33e891c5bf2 100644
--- a/modules/budgets/app/views/budgets/_form.html.erb
+++ b/modules/budgets/app/views/budgets/_form.html.erb
@@ -40,15 +40,7 @@ See COPYRIGHT and LICENSE files for more details.
resource: resource %>
</div>
<div class="form--field">
- <label class="form--label" for='budget_fixed_date'><%= WorkPackage.human_attribute_name(:fixed_date) %></label>
- <div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- inputs: {
- value: @budget.fixed_date,
- id: "budget_fixed_date",
- name: "budget[fixed_date]"
- }
- %>
+ <%= f.date_picker :fixed_date %>
</div>
<%= render partial: 'budgets/subform/material_budget_subform' %>
diff --git a/modules/costs/app/views/cost_types/_rate.html.erb b/modules/costs/app/views/cost_types/_rate.html.erb
index a9ca7d635af..584edba1718 100644
--- a/modules/costs/app/views/cost_types/_rate.html.erb
+++ b/modules/costs/app/views/cost_types/_rate.html.erb
@@ -46,24 +46,14 @@ See COPYRIGHT and LICENSE files for more details.
<% unless error_messages.blank? %>
<tr><td colspan="3"><%= error_messages %></td></tr>
<% end %>
-<%= fields_for prefix, rate do |rate_form| %>
+<%= fields_for prefix, rate, builder: TabularFormBuilder do |rate_form| %>
<tr class="subform-row <%= classes %>" id="<%= id_prefix %>">
<td class="-no-ellipsis">
<label class="hidden-for-sighted" for="<%= "#{id_prefix}_valid_from" %>"><%= Rate.human_attribute_name(:valid_from) %></label>
- <!--
- <%= rate_form.date_field :valid_from,
+ <%= rate_form.date_picker :valid_from,
class: 'date costs-date-picker',
- index: id_or_index,
+ no_label: true,
required: templated ? false : true %>
- -->
- <%= angular_component_tag 'op-single-date-picker',
- class: 'date costs-date-picker',
- inputs: {
- value: @fixed_date,
- id: "#{id_prefix}_valid_from",
- name: "cost_type[new_rate_attributes[0][valid_from]"
- }
- %>
</td>
<td class="currency">
<span class="inline-label">
@@ -74,6 +64,7 @@ See COPYRIGHT and LICENSE files for more details.
inputmode: :decimal,
placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),
value: rate.rate ? rate.rate.round(2) : "",
+ no_label: true,
required: templated ? false : true %>
<span class="form-label">
<%= Setting.plugin_costs['costs_currency'] %>
diff --git a/modules/costs/app/views/costlog/edit.html.erb b/modules/costs/app/views/costlog/edit.html.erb
index f6bb639b2ac..14d92384fcf 100644
--- a/modules/costs/app/views/costlog/edit.html.erb
+++ b/modules/costs/app/views/costlog/edit.html.erb
@@ -60,22 +60,10 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
</div>
<div class="form--field -required">
- <label
- class="form--label"
- for="cost_entry_spent_on"
- title="<%= t(:label_date) %>"
- ><%= t(:label_date) %></label>
- <div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- class: 'remote-field--input',
- inputs: {
- value: h("#{@cost_entry.spent_on.to_s}"),
- required: true,
- id: "cost_entry_spent_on",
- name: "cost_entry[spent_on]"
- }
- %>
- </div>
+ <%= f.date_picker :spent_on,
+ required: true,
+ class: 'remote-field--input',
+ data: { :'remote-field-key' => 'fixed_date' } %>
<label for="cost_entry_spent_on" class="hidden-for-sighted"><%= t(:label_date) %> <%= t(:text_hint_date_format) %></label>
</div>
<% if User.current.allowed_to? :log_costs, @project %>
diff --git a/modules/costs/app/views/hourly_rates/_rate.html.erb b/modules/costs/app/views/hourly_rates/_rate.html.erb
index 5f5831acfe2..a33665a4fde 100644
--- a/modules/costs/app/views/hourly_rates/_rate.html.erb
+++ b/modules/costs/app/views/hourly_rates/_rate.html.erb
@@ -39,14 +39,13 @@ See COPYRIGHT and LICENSE files for more details.
classes += " subform-row-template" if templated
-%>
-<%= fields_for prefix, rate do |rate_form| %>
+<%= fields_for prefix, rate, builder: TabularFormBuilder do |rate_form| %>
<tr class="subform-row <%= classes %>" id="<%= id_prefix %>">
<td>
<label class="hidden-for-sighted" for="<%= "#{id_prefix}_valid_from" %>"><%= Rate.human_attribute_name(:valid_from) %></label>
- <%= rate_form.text_field :valid_from,
- class: 'date costs-date-picker -augmented-datepicker',
- index: id_or_index,
- required: true %>
+ <%= rate_form.date_picker :valid_from,
+ class: 'date costs-date-picker',
+ no_label: true %>
</td>
<td class="currency">
<span class="inline-label">
diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb
index 1cab5be4dda..3cb68e3d558 100644
--- a/modules/meeting/app/views/meetings/_form.html.erb
+++ b/modules/meeting/app/views/meetings/_form.html.erb
@@ -47,12 +47,10 @@ See COPYRIGHT and LICENSE files for more details.
</label>
<div class="form--field-container -visible-overflow">
- <%= angular_component_tag 'op-single-date-picker',
- inputs: {
- required: true,
- id: "meeting-form-start-date",
- name: "meeting[start_date]"
- }
+ <%= f.date_picker :start_date,
+ id: 'meeting-form-start-date',
+ required: true,
+ no_label: true,
%>
<label for="meeting-form-start-time" class="hidden-for-sighted">
<%= Meeting.human_attribute_name(:start_time) %>