From d3e06e4c94bc5d5f4b4d024fa753b0136fbb77c3 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Sun, 17 Jun 2012 14:05:05 +0300 Subject: [PATCH] close #108 Domain NS records deletion issue --- app/controllers/ns_controller.rb | 16 +++++++++++++--- app/views/ns/destroy.js.erb | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/views/ns/destroy.js.erb diff --git a/app/controllers/ns_controller.rb b/app/controllers/ns_controller.rb index 603bc91..80fdd04 100644 --- a/app/controllers/ns_controller.rb +++ b/app/controllers/ns_controller.rb @@ -36,9 +36,19 @@ class NsController < ApplicationController end def do_destroy - super - if successful? && nested_parent_record.ns_records.count == 0 - flash[:warning] = "All NS records deleted, no other nameservers are associated with this domain!" + if nested_parent_record.ns_records.count > 1 + @record ||= destroy_find_record + begin + self.successful = @record.destroy + rescue Exception => ex + flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) + self.successful = false + logger.debug ex.message + logger.debug ex.backtrace.join("\n") + end + else + self.successful = false + flash[:error] = "Cannot delete it, the domain must have at least one nameserver!" end end end \ No newline at end of file diff --git a/app/views/ns/destroy.js.erb b/app/views/ns/destroy.js.erb new file mode 100644 index 0000000..9dfc6be --- /dev/null +++ b/app/views/ns/destroy.js.erb @@ -0,0 +1,29 @@ +<%# show errors in nested %> +<% messages_id ||= nested? ? "as_domains-#{nested.parent_id}-records-messages" : active_scaffold_messages_id -%> + +<% if controller.send(:successful?) %> + <% if render_parent? %> + <% if render_parent_action == :row %> + <%# TODO: That s not working with delete.... %> + <% current_id = controller_id(params[:eid] || params[:parent_sti]) -%> + ActiveScaffold.delete_record_row('<%= element_row_id(:controller_id => current_id, :action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); + <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)}, :formats => [:js] %> + <% elsif render_parent_action == :index %> + <% if controller.respond_to?(:render_component_into_view) %> + <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> + <% else %> + ActiveScaffold.reload('<%= url_for render_parent_options %>'); + <% end %> + <% end %> + <% elsif (active_scaffold_config.delete.refresh_list) %> + <%= render :partial => 'refresh_list' %> + <% else %> + <% row_id = "as_domains-#{nested.parent_id}-records-list-#{params[:id]}-row" %> + ActiveScaffold.delete_record_row('<%= row_id %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); + <%= render :partial => 'update_calculations', :formats => [:js] %> + <% end %> +<% elsif flash[:error].blank? %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> +<% end %> +<%= render :partial => 'update_messages', :locals => {:messages_id => messages_id} %>