diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index bba3617..ddc516d 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -1,16 +1,14 @@ class RecordsController < ApplicationController - before_filter :get_zone - def new - @record = @zone.records.new + @record = Record.new end def create - @record = @zone.records.new( params[:record] ) + @record = Record.new( params[:record] ) @record.zone_id = @zone.id if @record.save - flash[:now] = "Record created!" + flash[:info] = "Record created!" redirect_to zone_path( @zone ) else render :action => :new @@ -18,13 +16,13 @@ def create end def edit - @record = @zone.records.find( params[:id] ) + @record = Record.find( params[:id] ) end def update - @record = @zone.records.find( params[:id] ) + @record = Record.find( params[:id] ) if @record.update_attributes( params[:record] ) - flash[:now] = "Record udpated!" + flash[:info] = "Record udpated!" redirect_to zone_path( @zone ) else render :action => :edit @@ -32,7 +30,7 @@ def update end def destroy - @record = @zone.records.find( params[:id] ) + @record = Record.find( params[:id] ) @record.destroy redirect_to zone_path( @zone ) end diff --git a/app/views/records/edit.html.haml b/app/views/records/edit.html.haml index fd79169..8fde809 100644 --- a/app/views/records/edit.html.haml +++ b/app/views/records/edit.html.haml @@ -2,7 +2,7 @@ %p= "Modifies an existing record for #{@zone.name} by entering relevant data below." -- form_for( [:zone, @record] ) do |f| +- form_for( :record, @record, :url => zone_record_path( @zone ), :html => { :method => :put } ) do |f| = error_messages_for :record #record-form-div %table.grid diff --git a/app/views/records/new.html.haml b/app/views/records/new.html.haml index 8cca9d5..5e3bfd6 100644 --- a/app/views/records/new.html.haml +++ b/app/views/records/new.html.haml @@ -6,7 +6,7 @@ %p= "Create a new record for #{@zone.name} by entering relevant data below." -- form_for([@zone, @record]) do |f| +- form_for( [@zone, @record] ) do |f| = error_messages_for :record %p   #record-form-div diff --git a/app/views/records/update.rjs b/app/views/records/update.rjs new file mode 100644 index 0000000..b1a322c --- /dev/null +++ b/app/views/records/update.rjs @@ -0,0 +1,9 @@ +if @record.errors.empty? + page.remove "show_#{@record.type.downcase}_#{@record.id}", "edit_#{@record.type.downcase}_#{@record.id}" + page.replace "marker_#{@record.type.downcase}_#{@record.id}", :partial => '/zones/record', :object => @record + page.visual_effect(:highlight, "show_#{@record.type.downcase}_#{@record.id}") + page.call 'showflash', 'info', flash[:info] +else + page.replace_html "error_#{@record.type.downcase}_#{@record.id}", error_messages_for(:record_template) + page.call 'showflash', 'error', flash[:error] +end \ No newline at end of file diff --git a/app/views/templates/_record_template.html.haml b/app/views/templates/_record_template.html.haml index 37e8d8d..1fefcd9 100644 --- a/app/views/templates/_record_template.html.haml +++ b/app/views/templates/_record_template.html.haml @@ -63,8 +63,8 @@ %td Minimum %td= f.text_field :minimum, :size => 4 - else - %td= f.text_field :host, :size => 5 - %td= f.text_field :ttl, :size => 4 + %td= f.text_field :host, :size => 3 + %td= f.text_field :ttl, :size => 3 %td= record_template.record_type %td= f.text_field :priority, :size => 1 %td= f.text_field :data, :size => 6 diff --git a/app/views/zones/_record.html.haml b/app/views/zones/_record.html.haml index acd9ab5..fa1d859 100644 --- a/app/views/zones/_record.html.haml +++ b/app/views/zones/_record.html.haml @@ -1,4 +1,11 @@ -%tr +%div{ :style => "display: none;" } + %div{ :id => "record-template-edit-#{record.id}" } + Edit this record's details + %div{ :id => "record-template-delete-#{record.id}" } + Delete this record + +%tr[ record, :marker ] +%tr[ record, :show ] %td = record.host %td @@ -10,5 +17,19 @@ %td = record.data %td - = prototip_info_icon('database_edit.png', 'record-template-edit') - = link_to prototip_info_icon('database_delete.png', 'record-template-delete'), zone_record_path( record.zone, record ), :method => :delete, :confirm => "Are you sure?" + = link_to_function prototip_info_icon('database_edit.png', "record-template-edit-#{record.id}"), "editRecord(#{record.id}, '#{record.type.downcase}')" + = link_to prototip_info_icon('database_delete.png', "record-template-delete-#{record.id}"), zone_record_path( record ), :method => :delete, :confirm => "Are you sure?" + +%tr[ record, :edit ]{ :style => "display: none;" } + - remote_form_for( :record, record, :url => zone_record_path( record ), :html => { :method => :put } ) do |f| + %td= f.text_field :host, :size => 2 + %td= f.text_field :ttl, :size => 3 + %td= record.type + - if record.type.downcase == 'mx' + %td= f.text_field :priority, :size => 2 + - else + %td= record.priority + %td= f.text_field :data, :size => 15 + %td + = image_submit_tag "table_save.png", { :class => 'nb' } + = link_to_function image_tag("cancel.png"), "hideRecord(#{record.id}, '#{record.type.downcase}')" \ No newline at end of file diff --git a/app/views/zones/show.html.haml b/app/views/zones/show.html.haml index 975f2dd..f264780 100644 --- a/app/views/zones/show.html.haml +++ b/app/views/zones/show.html.haml @@ -3,15 +3,15 @@ %div{ :style => "display: none;" } #record-template-new Create a new record for this zone - #record-template-edit - Edit this record's details - #record-template-delete - Delete this record + #soa-record-edit + Edit the SOA record's details + #zone-edit + Edit this zone's details %h1.underline = @zone.name   - = image_tag 'database_edit.png' + = link_to prototip_info_icon('database_edit.png', 'zone-edit'), edit_zone_path( @zone ) #domain-name.padded %table.grid @@ -23,7 +23,7 @@ %h2.underline SOA Record   - = image_tag 'database_edit.png' + = prototip_info_icon('database_edit.png', 'soa-record-edit') %table.grid %tr %td Primary name server @@ -49,8 +49,8 @@ %table.grid %tr %td{ :colspan => "6" } - = link_to prototip_info_icon('database_add.png', 'record-template-new'), new_zone_record_path( @zone ) - = link_to "New record", new_zone_record_path( @zone ) + = link_to prototip_info_icon('database_add.png', 'record-template-new'), new_zone_record_path + = link_to "New record", new_zone_record_path %tr %td.small Hostname %td.small TTL @@ -63,4 +63,14 @@ %td{ :colspan => "6" }   %tr %td{ :colspan => "6" } - = image_tag 'database_add.png' \ No newline at end of file + = image_tag 'database_add.png' + +:javascript + function editRecord(id, type) { + $('show_' + type + '_' + id).hide(); + $('edit_' + type + '_' + id).show(); + } + function hideRecord(id, type) { + $('edit_' + type + '_' + id).hide(); + $('show_' + type + '_' + id).show(); + } \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5d918c1..7a613d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,8 +32,9 @@ map.root :controller => 'zones' # RESTful zones and records - map.resources :zones, :has_many => :records + map.resources :zones map.resources :soa, :controller => 'records' + map.resources :records, :name_prefix => 'zone_' # RESTful templates map.resources :zone_templates, :controller => 'templates'