]> git.openstreetmap.org Git - rails.git/blob - app/controllers/redactions_controller.rb
Geocode pre-filled values when the user presses 'Go'.
[rails.git] / app / controllers / redactions_controller.rb
1 class RedactionsController < ApplicationController
2   layout 'site'
3   
4   before_filter :authorize_web
5   before_filter :set_locale
6   before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
7   before_filter :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
8   before_filter :lookup_redaction, :only => [:show, :edit, :update, :destroy]
9   before_filter :check_database_readable
10   before_filter :check_database_writable, :only => [:create, :update, :destroy]
11
12   def index
13     @redactions = Redaction.order(:id)
14   end
15
16   def new
17     @redaction = Redaction.new
18   end
19      
20   def create
21     @redaction = Redaction.new
22     @redaction.user = @user
23     @redaction.title = params[:redaction][:title]
24     @redaction.description = params[:redaction][:description]
25     # note that the description format will default to 'markdown'
26
27     if @redaction.save
28       flash[:notice] = t('redaction.create.flash')
29       redirect_to @redaction
30     else
31       render :action => 'new'
32     end
33   end
34      
35   def show
36   end
37   
38   def edit
39   end
40      
41   def update
42     # note - don't update the user ID
43     @redaction.title = params[:redaction][:title]
44     @redaction.description = params[:redaction][:description]
45
46     if @redaction.save
47       flash[:notice] = t('redaction.update.flash')
48       redirect_to @redaction
49     else
50       render :action => 'edit'
51     end
52   end
53      
54   def destroy
55     unless @redaction.old_nodes.empty? and
56         @redaction.old_ways.empty? and
57         @redaction.old_relations.empty?
58       flash[:error] = t('redaction.destroy.not_empty')
59       redirect_to @redaction
60     else
61       if @redaction.destroy
62         flash[:notice] = t('redaction.destroy.flash')
63         redirect_to :redactions
64       else
65         flash[:error] = t('redaction.destroy.error')
66         redirect_to @redaction
67       end
68     end
69   end
70
71   private
72
73   def lookup_redaction
74     @redaction = Redaction.find(params[:id])
75   end
76 end