Make the form read only if issue id closed

This commit is contained in:
2026-03-07 10:49:07 -05:00
parent 9767870db4
commit 03b94d251a
2 changed files with 37 additions and 26 deletions

View File

@@ -1,6 +1,8 @@
<% @issue.line_items.build if @issue.line_items.empty? %>
<% readonly = @issue.status.is_closed? %>
<div class="box tabular" data-nested-form data-wrapper-selector=".line-item">
<% @issue.line_items.build if @issue.line_items.empty? && !readonly %>
<div class="box tabular" <%= 'data-nested-form data-wrapper-selector=".line-item"' unless readonly %>>
<p><strong>Line Items</strong></p>
<table class="list line-items-table">
@@ -9,20 +11,23 @@
<th>Description</th>
<th style="width:120px;">Quantity</th>
<th style="width:150px;">Unit Price</th>
<% unless readonly %>
<th style="width:80px;"></th>
<% end %>
</tr>
</thead>
<tbody data-nested-form-container>
<tbody <%= 'data-nested-form-container' unless readonly %>>
<%= f.fields_for :line_items do |item_form| %>
<%= render "line_items/line_item_fields", f: item_form %>
<%= render "line_items/line_item_fields", f: item_form, readonly: readonly %>
<% end %>
</tbody>
</table>
<% unless readonly %>
<template data-nested-form-template>
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
<%= render "line_items/line_item_fields", f: item_form %>
<%= render "line_items/line_item_fields", f: item_form, readonly: false %>
<% end %>
</template>
@@ -31,4 +36,5 @@
Add Line Item
</button>
</p>
<% end %>
</div>

View File

@@ -1,12 +1,13 @@
<tr class="line-item">
<%= f.hidden_field :id %>
<%= f.hidden_field :_destroy %>
<%= f.hidden_field :_destroy unless readonly %>
<td>
<%= f.text_field :description,
size: 50,
placeholder: "Description",
:no_label => true %>
no_label: true,
disabled: readonly %>
</td>
<td>
@@ -14,16 +15,19 @@
step: 1,
min: 1,
style: "width:90px;",
:no_label => true %>
no_label: true,
disabled: readonly %>
</td>
<td>
<%= f.number_field :unit_price,
step: 0.01,
style: "width:120px;",
:no_label => true %>
no_label: true,
disabled: readonly %>
</td>
<% unless readonly %>
<td style="text-align:center;">
<button type="button"
class="icon-only icon-del"
@@ -31,4 +35,5 @@
data-nested-form-remove>
</button>
</td>
<% end %>
</tr>