Class: SiteAnnouncementsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/site_announcements_controller.rb

Instance Method Summary collapse

Instance Method Details

#check_manage_announcementsObject



112
113
114
115
116
117
# File 'app/controllers/site_announcements_controller.rb', line 112

def check_manage_announcements    
  if !can_manage_announcements?
    flash[:error] = "Admin rights required"
    redirect_to root_url
  end
end

#createObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/site_announcements_controller.rb', line 65

def create
  @site_announcement=SiteAnnouncement.new(params[:site_announcement])
  @site_announcement.announcer = current_person

  respond_to do |format|
    if @site_announcement.save
      flash[:notice] = 'The Announcement was successfully announced.'
      format.html { redirect_to(@site_announcement) }
      format.xml  { render :xml => @site_announcement, :status => :created, :location => @site_announcement }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @site_announcement.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/site_announcements_controller.rb', line 32

def destroy 
  @site_announcement=SiteAnnouncement.find(params[:id])
  
  respond_to do |format|
    if @site_announcement.destroy
      flash[:notice]="Announcement destroyed"
      format.html {redirect_to site_announcements_path}
    else        
      flash[:error]="There was a problem destroying the announcement"        
      format.html { render :action=>:edit }
    end
  end
end

#editObject



81
82
83
# File 'app/controllers/site_announcements_controller.rb', line 81

def edit
  @site_announcement=SiteAnnouncement.find(params[:id])
end

#feedObject



6
7
8
9
10
11
12
13
# File 'app/controllers/site_announcements_controller.rb', line 6

def feed
  limit=params[:limit]
  limit||=10
  @site_announcements=SiteAnnouncement.feed_announcements :limit=>limit
  respond_to do |format|
    format.atom
  end
end

#indexObject



104
105
106
107
108
109
110
# File 'app/controllers/site_announcements_controller.rb', line 104

def index
  if params[:feed_only]
    @site_announcements=SiteAnnouncement.feed_announcements(:limit=>1000)
  else
    @site_announcements=SiteAnnouncement.order("created_at DESC")
  end
end

#newObject



61
62
63
# File 'app/controllers/site_announcements_controller.rb', line 61

def new
  @site_announcement=SiteAnnouncement.new
end

#notification_settingsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/site_announcements_controller.rb', line 46

def notification_settings

  @info=NotifieeInfo.find_by_unique_key(params[:key])
  
  respond_to do |format|
    if @info.nil?
      flash[:error]="Invalid Key"
      format.html{ redirect_to root_url }
    else
      format.html
    end
  end
  
end

#showObject



100
101
102
# File 'app/controllers/site_announcements_controller.rb', line 100

def show
  @site_announcement=SiteAnnouncement.find(params[:id])
end

#updateObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/site_announcements_controller.rb', line 85

def update
  @site_announcement=SiteAnnouncement.find(params[:id])
  
  respond_to do |format|
    if @site_announcement.update_attributes(params[:site_announcement])
      flash[:notice] = 'Announcement was successfully updated.'
      format.html { redirect_to(@site_announcement) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @site_announcement.errors, :status => :unprocessable_entity }
    end
  end
end

#update_notification_settingsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/site_announcements_controller.rb', line 15

def update_notification_settings
  receive_notifications = params[:receive_notifications]
  receive_notifications ||= false
  @info = NotifieeInfo.find_by_unique_key(params[:key])
  @info.receive_notifications = receive_notifications unless @info.nil?
  respond_to do |format|
    if @info && @info.save
      flash[:notice]="Email announcement setting updated. You will now #{"not " if !@info.receive_notifications?}receive notification emails."
      format.html { redirect_to(root_url) }
    else
      flash[:error]="Unable to update your settings"
      flash[:error]+=", the key presented wasn't recognised."
      format.html { render :action => :notification_settings}
    end
  end
end