mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 18:59:38 +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
|
end
|
||||||
|
|
||||||
def update
|
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')
|
flash[:notice] = I18n.t('domain_updated')
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
else
|
else
|
||||||
|
@ -53,21 +53,24 @@ class Admin::DomainsController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_params
|
def domain_params
|
||||||
params.require(:domain).permit(
|
if params[:domain]
|
||||||
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
params.require(:domain).permit({ statuses: [] })
|
||||||
)
|
else
|
||||||
|
{statuses: []}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_associations
|
def build_associations
|
||||||
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
@server_statuses = @domain.domain_statuses.select(&:server_status?)
|
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||||
@server_statuses << @domain.domain_statuses.build if @server_statuses.empty?
|
@server_statuses = [nil] if @server_statuses.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_prefix_to_statuses
|
def add_prefix_to_statuses
|
||||||
domain_params[:domain_statuses_attributes].each do |_k, hash|
|
dp = domain_params
|
||||||
hash[:value] = hash[:value].prepend('server') if hash[:value].present?
|
dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? }
|
||||||
end
|
dp[:statuses].reject! { |x| x.blank? }
|
||||||
|
dp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,28 @@
|
||||||
#domain-statuses
|
#domain-statuses
|
||||||
= f.fields_for :domain_statuses, @server_statuses do |status_fields|
|
- @server_statuses.each do |x|
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
.panel-heading.clearfix
|
.panel-heading.clearfix
|
||||||
.pull-left= t(:status)
|
.pull-left= t(:status)
|
||||||
.pull-right
|
.pull-right
|
||||||
= link_to(t(:add_another), '#', class: 'btn btn-primary btn-xs add-domain-status')
|
= 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
|
.panel-body
|
||||||
.errors
|
|
||||||
= render 'shared/errors', object: status_fields.object
|
|
||||||
- if status_fields.object.errors.any?
|
|
||||||
%hr
|
|
||||||
.form-group
|
.form-group
|
||||||
= status_fields.label :value, class: 'col-md-2 control-label'
|
= f.label 'status', class: 'col-md-2 control-label'
|
||||||
.col-md-10
|
.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
|
.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
|
.col-md-10
|
||||||
= status_fields.text_field :description, class: 'form-control', autocomplete: 'off'
|
= text_field_tag :description, nil, class: 'form-control', autocomplete: 'off'
|
||||||
|
|
||||||
:coffee
|
:coffee
|
||||||
$("#domain-statuses").nestedAttributes
|
$("#domain-statuses").nestedAttributes
|
||||||
bindAddTo: $(".add-domain-status")
|
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.panel-default
|
||||||
#domain_statuses.panel{class: panel_class}
|
|
||||||
.panel-heading.clearfix
|
.panel-heading.clearfix
|
||||||
= t(:statuses)
|
= t(:statuses)
|
||||||
.table-responsive
|
.table-responsive
|
||||||
|
@ -9,12 +8,7 @@
|
||||||
%th{class: 'col-xs-6'}= t(:status)
|
%th{class: 'col-xs-6'}= t(:status)
|
||||||
%th{class: 'col-xs-6'}= t(:description)
|
%th{class: 'col-xs-6'}= t(:description)
|
||||||
%tbody
|
%tbody
|
||||||
- @domain.domain_statuses.each do |x|
|
- @domain.statuses.each do |x|
|
||||||
%tr
|
%tr
|
||||||
%td= x.value
|
%td= x
|
||||||
%td= x.description
|
%td
|
||||||
- if @domain.errors.messages[:domain_statuses]
|
|
||||||
%tfoot
|
|
||||||
- @domain.errors.messages[:domain_statuses].each do |x|
|
|
||||||
%tr
|
|
||||||
%td{colspan: 4}= x
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue