public
Description: OneBody is free, open-source, web-based social networking and online directory software for churches.
Homepage: http://beonebody.com
Clone URL: git://github.com/seven1m/onebody.git
onebody / app / controllers / administration / scheduled_tasks_controller.rb
100644 54 lines (43 sloc) 1.292 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Administration::ScheduledTasksController < ApplicationController
 
  before_filter :only_admins
  
  def index
    @tasks = Site.current.scheduled_tasks.find(:all, :conditions => ["\"interval\" != ?", 'now'])
  end
  
  def new
    @task = Site.current.scheduled_tasks.new
  end
  
  def create
    @task = Site.current.scheduled_tasks.create(params[:scheduled_task])
    unless @task.errors.any?
      flash[:notice] = 'Task saved.'
      redirect_to administration_scheduled_tasks_path
    else
      render :action => 'new'
    end
  end
  
  def edit
    @task = Site.current.scheduled_tasks.find(params[:id])
  end
  
  def update
    @task = Site.current.scheduled_tasks.find(params[:id])
    if @task.update_attributes(params[:scheduled_task])
      flash[:notice] = 'Task saved.'
      redirect_to administration_scheduled_tasks_path
    else
      render :action => 'edit'
    end
  end
  
  def destroy
    @task = Site.current.scheduled_tasks.find(params[:id])
    @task.destroy
    flash[:notice] = 'Task deleted.'
    redirect_to administration_scheduled_tasks_path
  end
  
  private
  
    def only_admins
      unless @logged_in.super_admin?
        render :text => 'You are not authorized.', :layout => true, :status => 401
        return false
      end
    end
  
end