Skip to content

Commit

Permalink
Working on the editing of existing records.
Browse files Browse the repository at this point in the history
  • Loading branch information
keegan committed Jul 9, 2008
1 parent 2fe1eb0 commit b49da3e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 26 deletions.
16 changes: 7 additions & 9 deletions app/controllers/records_controller.rb
@@ -1,38 +1,36 @@
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
end
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
end
end

def destroy
@record = @zone.records.find( params[:id] )
@record = Record.find( params[:id] )
@record.destroy
redirect_to zone_path( @zone )
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/edit.html.haml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/new.html.haml
Expand Up @@ -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 &nbsp;
#record-form-div
Expand Down
9 changes: 9 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions app/views/templates/_record_template.html.haml
Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions 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
Expand All @@ -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}')"
28 changes: 19 additions & 9 deletions app/views/zones/show.html.haml
Expand Up @@ -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
&nbsp;
= image_tag 'database_edit.png'
= link_to prototip_info_icon('database_edit.png', 'zone-edit'), edit_zone_path( @zone )

#domain-name.padded
%table.grid
Expand All @@ -23,7 +23,7 @@
%h2.underline
SOA Record
&nbsp;
= image_tag 'database_edit.png'
= prototip_info_icon('database_edit.png', 'soa-record-edit')
%table.grid
%tr
%td Primary name server
Expand All @@ -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
Expand All @@ -63,4 +63,14 @@
%td{ :colspan => "6" } &nbsp;
%tr
%td{ :colspan => "6" }
= image_tag 'database_add.png'
= 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();
}
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -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'
Expand Down

0 comments on commit b49da3e

Please sign in to comment.