Permalink
Please sign in to comment.
Showing
with
609 additions
and 40 deletions.
- +14 −3 app/assets/javascripts/calendar.js
- +7 −7 app/assets/javascripts/jquery.weekcalendar.js
- +3 −0 app/assets/javascripts/periods.js.coffee
- +3 −0 app/assets/stylesheets/periods.css.scss
- +14 −13 app/controllers/calendars_controller.rb
- +93 −0 app/controllers/periods_controller.rb
- +2 −0 app/helpers/periods_helper.rb
- +4 −0 app/models/calendar.rb
- +3 −0 app/models/period.rb
- +4 −1 app/models/user.rb
- +9 −4 app/views/calendars/_calendar.html.haml
- +2 −7 app/views/calendars/show.html.haml
- +2 −0 app/views/layouts/application.html.haml
- +28 −0 app/views/periods/_form.html.haml
- +7 −0 app/views/periods/edit.html.haml
- +29 −0 app/views/periods/index.html.haml
- +5 −0 app/views/periods/new.html.haml
- +24 −0 app/views/periods/show.html.haml
- +1 −0 config/routes.rb
- +2 −1 db/migrate/20120404221303_create_calendars.rb
- +14 −0 db/migrate/20120421171137_create_periods.rb
- +1 −0 db/seeds.rb
- +4 −4 lib/tasks/db.rake
- +164 −0 spec/controllers/periods_controller_spec.rb
- +15 −0 spec/helpers/periods_helper_spec.rb
- +5 −0 spec/models/period_spec.rb
- +11 −0 spec/requests/periods_spec.rb
- +35 −0 spec/routing/periods_routing_spec.rb
- +24 −0 spec/views/periods/edit.html.haml_spec.rb
- +32 −0 spec/views/periods/index.html.haml_spec.rb
- +24 −0 spec/views/periods/new.html.haml_spec.rb
- +24 −0 spec/views/periods/show.html.haml_spec.rb
@@ -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/ |
@@ -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/ |
@@ -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 |
@@ -0,0 +1,2 @@ | ||
+module PeriodsHelper | ||
+end |
@@ -0,0 +1,3 @@ | ||
+class Period < ActiveRecord::Base | ||
+ has_many :calendars, :dependent => :destroy | ||
+end |
@@ -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' |
@@ -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' |
@@ -0,0 +1,7 @@ | ||
+-@page_title = "Editing period" | ||
+ | ||
+= render 'form' | ||
+ | ||
+= link_to 'Show', @period | ||
+\| | ||
+= link_to 'Back', periods_path |
@@ -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.
0 comments on commit
a0ffe98