Refactor status form #2623

This commit is contained in:
Martin Lensment 2015-06-16 16:16:09 +03:00
parent 9b9e1a3068
commit 238b3aa5e0
4 changed files with 7 additions and 6 deletions

View file

@ -22,7 +22,7 @@ class Admin::DomainsController < AdminController
flash[:notice] = I18n.t('domain_updated')
redirect_to [:admin, @domain]
else
@domain.domain_statuses.build if @domain.domain_statuses.empty?
build_associations
flash.now[:alert] = I18n.t('failed_to_update_domain')
render 'edit'
end
@ -64,11 +64,11 @@ class Admin::DomainsController < AdminController
@domain.domain_statuses.build if @domain.domain_statuses.empty?
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
@server_statuses = [nil] if @server_statuses.empty?
@other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) }
end
def add_prefix_to_statuses
dp = domain_params
dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? }
dp[:statuses].reject! { |x| x.blank? }
dp
end

View file

@ -317,7 +317,7 @@ class Domain < ActiveRecord::Base
end
def force_deletable?
domain_statuses.where(value: DomainStatus::FORCE_DELETE).empty?
!statuses.include?(DomainStatus::FORCE_DELETE)
end
def registrant_verification_asked?

View file

@ -124,7 +124,7 @@ class DomainStatus < ActiveRecord::Base
end
def statuses_for_admin
SERVER_STATUSES.map { |x| x.sub('server', '') }
SERVER_STATUSES.map { |x| [x.sub('server', ''), x] }
end
end
end

View file

@ -10,12 +10,13 @@
.form-group
= f.label 'status', class: 'col-md-2 control-label'
.col-md-10
= select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x.try(:sub, 'server', '')), include_blank: true, class: 'form-control'
= select_tag 'domain[statuses][]', options_for_select(DomainStatus.statuses_for_admin, x), include_blank: true, class: 'form-control'
.form-group
= label_tag t(:description), nil, class: 'col-md-2 control-label'
.col-md-10
= text_field_tag :description, nil, class: 'form-control', autocomplete: 'off'
- @other_statuses.each do |x|
= hidden_field_tag 'domain[statuses][]', x, readonly: true
:coffee
$("#domain-statuses").nestedAttributes
bindAddTo: $(".add-domain-status")