diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 4d10cdb08..9c495ef11 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -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 diff --git a/app/models/domain.rb b/app/models/domain.rb index 1f371bfd0..3dde9681d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -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? diff --git a/app/models/domain_status.rb b/app/models/domain_status.rb index f27f0bb71..b33b5446c 100644 --- a/app/models/domain_status.rb +++ b/app/models/domain_status.rb @@ -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 diff --git a/app/views/admin/domains/form_partials/_statuses.haml b/app/views/admin/domains/form_partials/_statuses.haml index 94ba87ef8..52b9282ef 100644 --- a/app/views/admin/domains/form_partials/_statuses.haml +++ b/app/views/admin/domains/form_partials/_statuses.haml @@ -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")