Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
609 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the periods controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
class PeriodsController < ApplicationController | ||
# GET /periods | ||
# GET /periods.json | ||
def index | ||
@periods = Period.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @periods } | ||
end | ||
end | ||
|
||
# GET /periods/1 | ||
# GET /periods/1.json | ||
def show | ||
@period = Period.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @period } | ||
end | ||
end | ||
|
||
# GET /periods/new | ||
# GET /periods/new.json | ||
def new | ||
@period = Period.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @period } | ||
end | ||
end | ||
|
||
# GET /periods/1/edit | ||
def edit | ||
@period = Period.find(params[:id]) | ||
end | ||
|
||
# POST /periods | ||
# POST /periods.json | ||
def create | ||
@period = Period.new(params[:period]) | ||
debugger | ||
|
||
# TODO transactions? | ||
User.all.each do |user| | ||
calendar = Calendar.create!(:name=> "#{user.name} #{@period.name}", | ||
:calendar_type=>Calendar::AVAILABILITY, :user_id=>user.id, :period_id=>@period.id) | ||
user.calendars << calendar | ||
user.save! | ||
@period.calendars << calendar | ||
end | ||
|
||
respond_to do |format| | ||
if @period.save | ||
format.html { redirect_to @period, notice: 'Period was successfully created.' } | ||
format.json { render json: @period, status: :created, location: @period } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @period.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /periods/1 | ||
# PUT /periods/1.json | ||
def update | ||
@period = Period.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @period.update_attributes(params[:period]) | ||
format.html { redirect_to @period, notice: 'Period was successfully updated.' } | ||
format.json { head :ok } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @period.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /periods/1 | ||
# DELETE /periods/1.json | ||
def destroy | ||
@period = Period.find(params[:id]) | ||
@period.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to periods_url } | ||
format.json { head :ok } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PeriodsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Period < ActiveRecord::Base | ||
has_many :calendars, :dependent => :destroy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
-@page_title = @calendar.name | ||
|
||
%p#notice= notice | ||
|
||
%table | ||
%tr | ||
%td | ||
%h3= @calendar.name | ||
%td | ||
-if !@disable_submit | ||
= button_tag :submit, :id=>:submit_calendar | ||
= render 'calendar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
= form_for @period do |f| | ||
-if @period.errors.any? | ||
#error_explanation | ||
%h2= "#{pluralize(@period.errors.count, "error")} prohibited this period from being saved:" | ||
%ul | ||
- @period.errors.full_messages.each do |msg| | ||
%li= msg | ||
|
||
.field | ||
= f.label :name | ||
= f.text_field :name | ||
.field | ||
= f.label :start_date | ||
= f.date_select :start_date | ||
.field | ||
= f.label :end_date | ||
= f.date_select :end_date | ||
.field | ||
= f.label :visible | ||
= f.check_box :visible | ||
.field | ||
= f.label :exception | ||
= f.check_box :exception | ||
.field | ||
= f.label :type | ||
= f.number_field :type | ||
.actions | ||
= f.submit 'Save' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-@page_title = "Editing period" | ||
|
||
= render 'form' | ||
|
||
= link_to 'Show', @period | ||
\| | ||
= link_to 'Back', periods_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-@page_title = "Manage Periods" | ||
|
||
%table | ||
%tr | ||
%th Name | ||
%th Start date | ||
%th End date | ||
%th Visible | ||
%th Exception | ||
%th Type | ||
%th | ||
%th | ||
%th | ||
|
||
- @periods.each do |period| | ||
%tr | ||
%td= period.name | ||
%td= period.start_date | ||
%td= period.end_date | ||
%td= period.visible | ||
%td= period.exception | ||
%td= period.type | ||
%td= link_to 'Show', period | ||
%td= link_to 'Edit', edit_period_path(period) | ||
%td= link_to 'Destroy', period, :confirm => 'Are you sure?', :method => :delete | ||
|
||
%br | ||
|
||
= link_to 'New Period', new_period_path |
Oops, something went wrong.