Permalink
Browse files

merge fix

  • Loading branch information...
seven-qi committed Apr 21, 2012
2 parents 5afdd94 + 1344369 commit a0ffe98ad0321bb14eeaf135baf4bbebf80dbd93
@@ -35,27 +35,38 @@ $(document).ready(function() {
url: window.location.pathname+".json",
dataType: "json",
success: function(data) {
- data.map(convertTimesIn);
- $events = data;
+ events = data.events;
+ events.map(convertTimesIn);
+ $events = events;
+ $start_date = Date.parse(data.start_date);
+ $end_date = Date.parse(data.end_date);
startCalendar();
}
});
}
function convertTimesIn(event) {
+ //alert(event.start_time);
timezone_offset = new Date().getTimezoneOffset();
timezone_offset = 0;
event.start_time = Date.parse(event.start_time).add(-timezone_offset).minutes().add(-2).hours();
+ event.start_time = Date.parse(event.start_time);
+ //alert(event.start_time);
+ event.start_time = Date.parse(event.start_time).add(-timezone_offset).minutes().add(-2).hours();
event.end_time = Date.parse(event.end_time).add(-timezone_offset).minutes().add(-2).hours();
+ //alert(event.start_time);
}
function convertTimesOut(event) {
event.start_time = event.start_time.add(2).hours();
event.end_time = event.end_time.add(2).hours();
+ //alert(event.start_time);
}
function startCalendar() {
$calendar.weekCalendar({
+ minDate: $start_date,
+ maxDate: $end_date,
displayOddEven:true,
timeslotsPerHour : 2,
allowCalEventOverlap : false,
@@ -152,7 +163,7 @@ $(document).ready(function() {
}
},
eventDrop : function(calEvent, $event) {
- //$calendar.weekCalendar("updateEvent", calEvent);
+ $calendar.weekCalendar("updateEvent", calEvent);
},
eventResize : function(calEvent, $event) {
$calendar.weekCalendar("updateEvent", calEvent);
@@ -385,7 +385,7 @@
self.element.find('.wc-day-column-inner').each(function() {
self._adjustOverlappingEvents($(this));
});
- self._removeEventInData(calEvent);
+ self._removeEventInData(eventId);
},
/*
@@ -511,7 +511,7 @@
newEvent = true;
$.each(options.data, function(i, event) {
if (event.id === calEvent.id) {
- event = calEvent;
+ options.data[i] = calEvent;
newEvent = false;
}
});
@@ -520,10 +520,10 @@
}
},
- _removeEventInData: function(calEvent) {
+ _removeEventInData: function(eventId) {
options = this.options;
for(i=0; i<options.data.length; i++) {
- if(options.data[i].id === calEvent.id) {
+ if(options.data[i].id === eventId) {
options.data.splice(i,1);
break;
}
@@ -1902,7 +1902,7 @@
* find the hour (12 hour day) for a given hour index
*/
_hourForIndex: function(index) {
- index = (index+2) % 24;
+ //index = (index+2) % 24;
if (index === 0) { //midnight
return 12;
} else if (index < 13) { //am
@@ -1913,7 +1913,7 @@
},
_24HourForIndex: function(index) {
- index = (index+2) % 24;
+ //index = (index+2) % 24;
if (index === 0) { //midnight
return '00:00';
} else if (index < 10) {
@@ -1924,7 +1924,7 @@
},
_amOrPm: function(hourOfDay) {
- hourOfDay = (hourOfDay+2) %24;
+ //hourOfDay = (hourOfDay+2) %24;
return hourOfDay < 12 ? 'AM' : 'PM';
},
@@ -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/
@@ -17,10 +17,8 @@ def index
if @current_user.isAdmin?
@calendars = Calendar.all
else
- @calendars = Calendar.find_by_user_id(@current_user.id)
+ @calendars = Calendar.find_all_by_user_id(@current_user.id)
end
-
- @calendars = Calendar.all
respond_to do |format|
format.html # index.html.erb
@@ -32,19 +30,22 @@ def index
# GET /calendars/1.json
def show
@calendar = Calendar.find(params[:id])
- @events = Entry.find_all_by_calendar_id(params[:id], :select=>[:id, :start_time, :end_time, :description, :entry_type] )
-
- if @current_user.isAdmin?
- @events.each do |e|
- e[:readOnly] = true
- @disable_submit = true
- end
- end
- @page_title = "My Calendar"
respond_to do |format|
format.html # show.html.erb
- format.json { render json: @events }
+ format.json do
+ results = {}
+ results[:start_date] = @calendar.period.start_date
+ results[:end_date] = @calendar.period.end_date
+ @events = Entry.find_all_by_calendar_id(params[:id], :select=>[:id, :start_time, :end_time, :description, :entry_type] )
+ if @current_user.id != @calendar.owner
+ @events.each do |e|
+ e[:readOnly] = true
+ end
+ end
+ results[:events] = @events
+ render json: results
+ end
end
end
@@ -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
View
@@ -2,8 +2,12 @@ class Calendar < ActiveRecord::Base
belongs_to :lab
has_many :entries
belongs_to :user
+ belongs_to :period
validates_presence_of :calendar_type, :name
+ AVAILABILITY = 0
+ SHIFTS = 1
+
#This should help with abstraction so we can use calendar.owner
#instead of calendar.user which is ambiguious.
def owner
View
@@ -0,0 +1,3 @@
+class Period < ActiveRecord::Base
+ has_many :calendars, :dependent => :destroy
+end
View
@@ -9,8 +9,11 @@ class User < ActiveRecord::Base
validates_presence_of :user_type, :if => :approved?
validates_presence_of :initials, :if => :approved?
+ ADMIN = 0
+ EMPLOYEE = 1
+
def isAdmin?
- user_type == 0
+ user_type == ADMIN
end
end
@@ -1,10 +1,15 @@
= javascript_include_tag "jquery.weekcalendar.js"
= javascript_include_tag "date.js"
-<input type='radio' name='entry_type_select' value='prefer' checked>Prefer</input><br>
-<input type='radio' name='entry_type_select' value='rather_not'>R/N</input><br>
-<input type='radio' name='entry_type_select' value='class'>Class</input><br>
-<input type='radio' name='entry_type_select' value='obligation'>Obligation</input><br>
+%table{:border=>0}
+ %tr
+ %td#radioGroup
+ <input type='radio' name='entry_type_select' value='prefer' checked>Prefer</input>
+ <input type='radio' name='entry_type_select' value='rather_not'>R/N</input>
+ <input type='radio' name='entry_type_select' value='class'>Class</input>
+ <input type='radio' name='entry_type_select' value='obligation'>Obligation</input>
+ -if @current_user.id == @calendar.owner
+ = button_tag :submit, :id=>:submit_calendar
#calendar
#event_edit_container
@@ -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'
@@ -59,6 +59,8 @@
%li
= link_to "Admin", users_path
%ul
+ %li
+ = link_to "Periods", periods_path
%li
= link_to "View Users", users_path
%li
@@ -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

Please sign in to comment.