From d2bfbfd2810fbee673e43b2515db8bac527b3441 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 16 Mar 2009 20:58:49 +0100 Subject: Refactored Chaos Calendar by wrapping libical and introducing event and occurrence model. More improvements to come. Enables us to create events with reoccurrence and intervals etc. --- app/controllers/events_controller.rb | 85 +++++++++++++++++++++++++++++++ app/controllers/occurrences_controller.rb | 85 +++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 app/controllers/events_controller.rb create mode 100644 app/controllers/occurrences_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb new file mode 100644 index 0000000..c25c73f --- /dev/null +++ b/app/controllers/events_controller.rb @@ -0,0 +1,85 @@ +class EventsController < ApplicationController + # GET /events + # GET /events.xml + def index + @events = Event.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @events } + end + end + + # GET /events/1 + # GET /events/1.xml + def show + @event = Event.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @event } + end + end + + # GET /events/new + # GET /events/new.xml + def new + @event = Event.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @event } + end + end + + # GET /events/1/edit + def edit + @event = Event.find(params[:id]) + end + + # POST /events + # POST /events.xml + def create + @event = Event.new(params[:event]) + + respond_to do |format| + if @event.save + flash[:notice] = 'Event was successfully created.' + format.html { redirect_to(@event) } + format.xml { render :xml => @event, :status => :created, :location => @event } + else + format.html { render :action => "new" } + format.xml { render :xml => @event.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /events/1 + # PUT /events/1.xml + def update + @event = Event.find(params[:id]) + + respond_to do |format| + if @event.update_attributes(params[:event]) + flash[:notice] = 'Event was successfully updated.' + format.html { redirect_to(@event) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @event.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /events/1 + # DELETE /events/1.xml + def destroy + @event = Event.find(params[:id]) + @event.destroy + + respond_to do |format| + format.html { redirect_to(events_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/occurrences_controller.rb b/app/controllers/occurrences_controller.rb new file mode 100644 index 0000000..e3f1cdd --- /dev/null +++ b/app/controllers/occurrences_controller.rb @@ -0,0 +1,85 @@ +class OccurrencesController < ApplicationController + # GET /occurrences + # GET /occurrences.xml + def index + @occurrences = Occurrence.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @occurrences } + end + end + + # GET /occurrences/1 + # GET /occurrences/1.xml + def show + @occurrence = Occurrence.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @occurrence } + end + end + + # GET /occurrences/new + # GET /occurrences/new.xml + def new + @occurrence = Occurrence.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @occurrence } + end + end + + # GET /occurrences/1/edit + def edit + @occurrence = Occurrence.find(params[:id]) + end + + # POST /occurrences + # POST /occurrences.xml + def create + @occurrence = Occurrence.new(params[:occurrence]) + + respond_to do |format| + if @occurrence.save + flash[:notice] = 'Occurrence was successfully created.' + format.html { redirect_to(@occurrence) } + format.xml { render :xml => @occurrence, :status => :created, :location => @occurrence } + else + format.html { render :action => "new" } + format.xml { render :xml => @occurrence.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /occurrences/1 + # PUT /occurrences/1.xml + def update + @occurrence = Occurrence.find(params[:id]) + + respond_to do |format| + if @occurrence.update_attributes(params[:occurrence]) + flash[:notice] = 'Occurrence was successfully updated.' + format.html { redirect_to(@occurrence) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @occurrence.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /occurrences/1 + # DELETE /occurrences/1.xml + def destroy + @occurrence = Occurrence.find(params[:id]) + @occurrence.destroy + + respond_to do |format| + format.html { redirect_to(occurrences_url) } + format.xml { head :ok } + end + end +end -- cgit v1.3