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> <p><strong>Line Items</strong></p>
<table class="list line-items-table"> <table class="list line-items-table">
@@ -9,26 +11,30 @@
<th>Description</th> <th>Description</th>
<th style="width:120px;">Quantity</th> <th style="width:120px;">Quantity</th>
<th style="width:150px;">Unit Price</th> <th style="width:150px;">Unit Price</th>
<th style="width:80px;"></th> <% unless readonly %>
<th style="width:80px;"></th>
<% end %>
</tr> </tr>
</thead> </thead>
<tbody data-nested-form-container> <tbody <%= 'data-nested-form-container' unless readonly %>>
<%= f.fields_for :line_items do |item_form| %> <%= 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 %> <% end %>
</tbody> </tbody>
</table> </table>
<template data-nested-form-template> <% unless readonly %>
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %> <template data-nested-form-template>
<%= render "line_items/line_item_fields", f: item_form %> <%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
<% end %> <%= render "line_items/line_item_fields", f: item_form, readonly: false %>
</template> <% end %>
</template>
<p> <p>
<button type="button" class="icon icon-add" data-nested-form-add> <button type="button" class="icon icon-add" data-nested-form-add>
Add Line Item Add Line Item
</button> </button>
</p> </p>
<% end %>
</div> </div>

View File

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