mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
Status form update #2623
This commit is contained in:
parent
bed27ce940
commit
9b9e1a3068
3 changed files with 31 additions and 32 deletions
|
@ -16,9 +16,9 @@ class Admin::DomainsController < AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
add_prefix_to_statuses
|
||||
dp = add_prefix_to_statuses
|
||||
|
||||
if @domain.update(domain_params)
|
||||
if @domain.update(dp)
|
||||
flash[:notice] = I18n.t('domain_updated')
|
||||
redirect_to [:admin, @domain]
|
||||
else
|
||||
|
@ -53,21 +53,24 @@ class Admin::DomainsController < AdminController
|
|||
end
|
||||
|
||||
def domain_params
|
||||
params.require(:domain).permit(
|
||||
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
||||
)
|
||||
if params[:domain]
|
||||
params.require(:domain).permit({ statuses: [] })
|
||||
else
|
||||
{statuses: []}
|
||||
end
|
||||
end
|
||||
|
||||
def build_associations
|
||||
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||
@server_statuses = @domain.domain_statuses.select(&:server_status?)
|
||||
@server_statuses << @domain.domain_statuses.build if @server_statuses.empty?
|
||||
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@server_statuses = [nil] if @server_statuses.empty?
|
||||
end
|
||||
|
||||
def add_prefix_to_statuses
|
||||
domain_params[:domain_statuses_attributes].each do |_k, hash|
|
||||
hash[:value] = hash[:value].prepend('server') if hash[:value].present?
|
||||
end
|
||||
dp = domain_params
|
||||
dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? }
|
||||
dp[:statuses].reject! { |x| x.blank? }
|
||||
dp
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
#domain-statuses
|
||||
= f.fields_for :domain_statuses, @server_statuses do |status_fields|
|
||||
- @server_statuses.each do |x|
|
||||
.panel.panel-default
|
||||
.panel-heading.clearfix
|
||||
.pull-left= t(:status)
|
||||
.pull-right
|
||||
= link_to(t(:add_another), '#', class: 'btn btn-primary btn-xs add-domain-status')
|
||||
= link_to(t(:delete), '#', class: 'btn btn-danger btn-xs destroy')
|
||||
= link_to(t(:delete), '#', class: 'btn btn-danger btn-xs destroy-status')
|
||||
.panel-body
|
||||
.errors
|
||||
= render 'shared/errors', object: status_fields.object
|
||||
- if status_fields.object.errors.any?
|
||||
%hr
|
||||
.form-group
|
||||
= status_fields.label :value, class: 'col-md-2 control-label'
|
||||
= f.label 'status', class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= status_fields.select :value, options_for_select(DomainStatus.statuses_for_admin, status_fields.object.value.try(:sub, 'server', '')), {include_blank: true}, {class: 'form-control'}
|
||||
= select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x.try(:sub, 'server', '')), include_blank: true, class: 'form-control'
|
||||
.form-group
|
||||
= status_fields.label :description, class: 'col-md-2 control-label'
|
||||
= label_tag t(:description), nil, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= status_fields.text_field :description, class: 'form-control', autocomplete: 'off'
|
||||
= text_field_tag :description, nil, class: 'form-control', autocomplete: 'off'
|
||||
|
||||
:coffee
|
||||
$("#domain-statuses").nestedAttributes
|
||||
bindAddTo: $(".add-domain-status")
|
||||
afterAdd: (item) ->
|
||||
item.find(".errors").html ""
|
||||
|
||||
$('.destroy-status').on 'click', (e) ->
|
||||
e.preventDefault()
|
||||
if $('.panel').length > 1
|
||||
$(this).parents('.panel').remove()
|
||||
else
|
||||
$(this).parents('.panel').find('select').val('')
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
- panel_class = @domain.errors.messages[:domain_statuses] ? 'panel-danger' : 'panel-default'
|
||||
#domain_statuses.panel{class: panel_class}
|
||||
#domain_statuses.panel.panel-default
|
||||
.panel-heading.clearfix
|
||||
= t(:statuses)
|
||||
.table-responsive
|
||||
|
@ -9,12 +8,7 @@
|
|||
%th{class: 'col-xs-6'}= t(:status)
|
||||
%th{class: 'col-xs-6'}= t(:description)
|
||||
%tbody
|
||||
- @domain.domain_statuses.each do |x|
|
||||
- @domain.statuses.each do |x|
|
||||
%tr
|
||||
%td= x.value
|
||||
%td= x.description
|
||||
- if @domain.errors.messages[:domain_statuses]
|
||||
%tfoot
|
||||
- @domain.errors.messages[:domain_statuses].each do |x|
|
||||
%tr
|
||||
%td{colspan: 4}= x
|
||||
%td= x
|
||||
%td
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue