Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created edit functionality #1002

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 2 additions & 82 deletions app/views/account/calculators/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,83 +1,3 @@
<div id="calculators-edit" class="container">
<%= simple_form_for @calculator, url: { action: 'update' }, wrapper: :horizontal_form, html: { novalidate: false } do |f| %>
<div class="form-group row">
<div class="my-auto col-4 has-float-label">
<%= f.input :name, class: 'form-control', required: true %>
</div>
<div class="my-auto col-4 has-float-label">
<%= f.input :preferable, class: 'form-control' %>
</div>
</div>

<h4 class="mt-5"><%= t('.add_new_field_label') %></h4>

<div class="form-group row">
<div class="col-6">
<%= select_tag :kind,
options_from_collection_for_select(Field.kinds.keys, :itself, :capitalize),
id: 'calculator_fields_kind',
prompt: t('.form.select_field_kind_label'),
class: 'custom-select',
data: { 'fields-list' => { form: [NamedValue.name, Select.name],
parameter: [Value.name, RangeField.name, Select.name, Calculation.name],
result: [Calculation.name] } } %>
</div>
<div class="col-4">
<%= select_tag :type, '', id: 'calculator_fields_type',
prompt: t('.form.select_field_type_label'),
class: 'custom-select',
disabled: true %>
</div>
<div class="col-2">
<%= link_to t('buttons.create'), '#',
class: 'btn btn-success text-white disabled',
id: 'add-calculator-field',
data: { url: new_account_calculator_field_path(calculator_slug: @calculator) } %>
</div>
</div>

<div class="my-5">
<h4 class="mb-2"><%= t('.form.form_label') %></h4>
<div class="form-group row" data-kind='form' data-selector-letter='F' data-last-selector='<%= extract_max_selector(@form_fields) %>'>
<% if @form_fields.any? %>
<%= f.fields_for :fields, @form_fields do |ff| %>
<%= render 'account/calculators/fields/form', f: ff %>
<% end %>
<% else %>
<p class="my-3 ms-3 text-black-50" data-empty-text=true><%= t('.form.no_fields_yet_label') %></p>
<% end %>
</div>

<h4 class="mb-2"><%= t('.form.parameters_label') %></h4>
<div class="form-group row" data-kind='parameter' data-selector-letter='P' data-last-selector='<%= extract_max_selector(@parameter_fields) %>'>
<% if @parameter_fields.any? %>
<%= f.fields_for :fields, @parameter_fields do |ff| %>
<%= render 'account/calculators/fields/form', f: ff %>
<% end %>
<% else %>
<p class="my-3 ms-3 text-black-50" data-empty-text=true><%= t('.form.no_fields_yet_label') %></p>
<% end %>
</div>

<h4 class="mb-2"><%= t('.form.results_label') %></h4>
<div class="form-group row" data-kind='result' data-selector-letter='R' data-last-selector='<%= extract_max_selector(@result_fields) %>'>
<% if @result_fields.any? %>
<%= f.fields_for :fields, @result_fields do |ff| %>
<%= render 'account/calculators/fields/form', f: ff %>
<% end %>
<% else %>
<p class="my-3 ms-3 text-black-50" data-empty-text=true><%= t('.form.no_fields_yet_label') %></p>
<% end %>
</div>
</div>

<div class="my-4 row">
<div class="col-12 d-flex justify-content-end button-group">
<%= f.button :submit, t('.form.update_calculator_button'), class: 'btn btn-green me-2' %>
<%= link_to account_calculators_path, class: 'btn btn-danger d-flex align-items-center justify-content-center' do %>
<span class="me-1"><%= t('buttons.cancel') %></span>
<% end %>
</div>
</div>
<% end %>
<div class="container">
<%= render "account/calculators/partials/form", calculator: @calculator %>
</div>
2 changes: 1 addition & 1 deletion app/views/account/calculators/partials/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for(@calculator, url: account_calculators_path) do |f| %>
<%= simple_form_for(calculator, url: polymorphic_path([:account, calculator], locale: I18n.locale)) do |f| %>
<div class="form-group row">
<div class="my-auto col-12 has-float-label">
<fieldset class="bordered">
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ en:
no_fields_yet_label: "No fields yet"
update_calculator_button: "Update calculator"
new:
create_calculator_button: "Create calculator"
create_calculator_button: "Save calculator"
cancel_button: "Сancel"
prohibited_to_update: " prevent the calculator from updating"
prohibited_to_save: " перешкоджають збереженню калькулятора"
Expand Down Expand Up @@ -473,7 +473,7 @@ en:
no_fields_yet_label: "No fields yet"
update_calculator_button: "Update calculator"
new:
create_calculator_button: "Create calculator"
create_calculator_button: "Save calculator"
feature_flags:
submit_button: "Save"
new_calculator_design:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/uk/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ uk:
no_fields_yet_label: "Полів поки нема"
update_calculator_button: "Оновити калькулятор"
new:
create_calculator_button: "Створити калькулятор"
create_calculator_button: "Зберегти калькулятор"
cancel_button: "Скасувати"
prohibited_to_update: " перешкоджають оновленню калькулятора"
prohibited_to_save: " перешкоджають збереженню калькулятора"
Expand Down
Loading