Skip to content
Browse files

convert calendar.js to coffeescript

  • Loading branch information...
1 parent 5b111ae commit 10db62b6d9df2d90c62aaeecde1f3fcd897f93a9 @twetzel committed Aug 15, 2012
View
4 Gemfile.lock
@@ -46,6 +46,9 @@ GEM
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
+ jquery-ui-rails (1.1.0)
+ jquery-rails
+ railties (>= 3.1.0)
json (1.7.4)
mail (2.4.4)
i18n (>= 0.4.0)
@@ -105,6 +108,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-rails
+ jquery-ui-rails
rails (= 3.2.8)
sass-rails (~> 3.2.3)
sqlite3
View
2 Rakefile
@@ -4,4 +4,4 @@
require File.expand_path('../config/application', __FILE__)
-Stuff::Application.load_tasks
+Calendar::Application.load_tasks
View
97 app/assets/javascripts/calendar.js.coffee
@@ -0,0 +1,97 @@
+date = new Date()
+d = date.getDate()
+m = date.getMonth()
+y = date.getFullYear()
+
+
+updateEvent = (the_event) ->
+ $.update(
+ "/events/" + the_event.id
+ event:
+ title: the_event.title
+ starts_at: "" + the_event.start
+ ends_at: "" + the_event.end
+ description: the_event.description
+ (reponse) -> alert "successfully updated event '#{reponse.title}'."
+ )
+
+createEvent = (title, start, end, allday) ->
+ $.create(
+ "/events"
+ event:
+ title: title
+ starts_at: start
+ ends_at: end
+ all_day: allday
+ (reponse) ->
+ $('#calendar').fullCalendar('renderEvent', reponse, true )
+ )
+
+$ ->
+ $('#calendar').fullCalendar
+ selectable: true
+ selectHelper: true
+ select: (start, end, allDay) ->
+ title = prompt('Event Title:')
+ if title
+ createEvent( title, start.toString(), end.toString(), allDay )
+ console?.log? "New Event: #{title} ... #{start} - #{end}"
+ $('#calendar').fullCalendar('unselect')
+ editable: true
+ header:
+ left: 'prev,next today'
+ center: 'title'
+ right: 'month,agendaWeek,agendaDay'
+ # time formats
+ titleFormat:
+ month: 'MMMM yyyy'
+ week: "d.[ MMMM][ yyyy]{ - d. MMMM yyyy}"
+ day: 'dddd, d.MMMM yyyy'
+ columnFormat:
+ month: 'ddd'
+ week: 'ddd d.M.'
+ day: 'dddd d.M.'
+ # timeFormat:
+ # '': 'H(:mm)' # default: 'h(:mm)t'
+ # locale
+ isRTL: false
+ firstDay: 1
+ monthNames: ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]
+ monthNamesShort: ["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"]
+ dayNames: ["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"]
+ dayNamesShort: ["So","Mo","Di","Mi","Do","Fr","Sa"]
+ buttonText:
+ prev: "&nbsp;&#9668;&nbsp;"
+ next: "&nbsp;&#9658;&nbsp;"
+ prevYear: "&nbsp;&lt;&lt;&nbsp;"
+ nextYear: "&nbsp;&gt;&gt;&nbsp;"
+ today: "heute"
+ month: "Monat"
+ week: "Woche"
+ day: "Tag"
+ defaultView: 'month'
+ height: 500
+ slotMinutes: 15
+ loading: (bool) ->
+ if bool
+ $('#loading').show()
+ else
+ $('#loading').hide()
+ # a future calendar might have many sources.
+ eventSources: [
+ url: '/events'
+ color: '#ccc'
+ textColor: '#333'
+ ignoreTimezone: false
+ ]
+ timeFormat: 'H:mm { - H:mm} '
+ dragOpacity: "0.5"
+ # http://arshaw.com/fullcalendar/docs/event_ui/eventDrop/
+ eventDrop: (event, dayDelta, minuteDelta, allDay, revertFunc) ->
+ updateEvent(event)
+ # http://arshaw.com/fullcalendar/docs/event_ui/eventResize/
+ eventResize: (event, dayDelta, minuteDelta, revertFunc) ->
+ updateEvent(event)
+ # http://arshaw.com/fullcalendar/docs/mouse/eventClick/
+ eventClick: (event, jsEvent, view) ->
+ #would like a lightbox here.
View
0 app/assets/javascripts/calendar.js → app/assets/javascripts/calendar.old.js
File renamed without changes.
View
11 app/assets/stylesheets/app.css
@@ -1,11 +0,0 @@
-body {
- margin-top: 40px;
- #text-align: center;
- font-size: 14px;
- font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
- }
-
-#calendar {
- width: 900px;
- margin: 0 auto;
- }
View
16 app/assets/stylesheets/application.css
@@ -8,7 +8,21 @@
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
+ *= require scaffold
*= require jquery.ui.all
+ *= require fullcalendar
*= require_self
- *= require_tree .
*/
+
+
+body {
+ margin-top: 40px;
+ #text-align: center;
+ font-size: 14px;
+ font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
+ }
+
+#calendar {
+ width: 900px;
+ margin: 0 auto;
+ }
View
4 app/controllers/events_controller.rb
@@ -55,9 +55,11 @@ def create
if @event.save
format.html { redirect_to(@event, :notice => 'Event was successfully created.') }
format.xml { render :xml => @event, :status => :created, :location => @event }
+ format.js { render :json => @event }
else
format.html { render :action => "new" }
format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
+ format.js { render :js => @event.errors, :status => :unprocessable_entity }
end
end
end
@@ -75,7 +77,7 @@ def update
if @event.update_attributes(params[:event])
format.html { redirect_to(@event, :notice => 'Event was successfully updated.') }
format.xml { head :ok }
- format.js { head :ok}
+ format.js { render :json => @event }
else
format.html { render :action => "edit" }
format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
View
2 app/models/event.rb
@@ -1,4 +1,6 @@
class Event < ActiveRecord::Base
+
+ attr_accessible :title, :starts_at, :ends_at, :all_day, :description
scope :before, lambda {|end_time| {:conditions => ["ends_at < ?", Event.format_date(end_time)] }}
scope :after, lambda {|start_time| {:conditions => ["starts_at > ?", Event.format_date(start_time)] }}
View
15 app/views/layouts/application.html.erb
@@ -1,17 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>
<head>
- <title>Calendar</title>
- <%= stylesheet_link_tag "fullcalendar.css" %>
- <%= stylesheet_link_tag "application.css" %>
- <%= javascript_include_tag "jquery.js" %>
- <%= javascript_include_tag "jquery.rest.js" %>
- <%= javascript_include_tag "rails.js" %>
- <%= javascript_include_tag "application.js" %>
-
- <!-- these are needed for the calendar. -->
- <%= javascript_include_tag "jquery-ui-1.8.11.custom.min.js" %>
- <%= javascript_include_tag "fullcalendar.js" %>
- <%= javascript_include_tag "calendar.js" %>
+ <title>fullCalendar on Rails 3.2</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
View
2 config.ru
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
-run Stuff::Application
+run Calendar::Application
View
2 config/application.rb
@@ -9,7 +9,7 @@
# Bundler.require(:default, :assets, Rails.env)
end
-module Stuff
+module Calendar
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
View
2 config/environment.rb
@@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application
-Stuff::Application.initialize!
+Calendar::Application.initialize!
View
2 config/environments/development.rb
@@ -1,4 +1,4 @@
-Stuff::Application.configure do
+Calendar::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
View
2 config/environments/production.rb
@@ -1,4 +1,4 @@
-Stuff::Application.configure do
+Calendar::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
View
2 config/environments/test.rb
@@ -1,4 +1,4 @@
-Stuff::Application.configure do
+Calendar::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
View
2 config/initializers/secret_token.rb
@@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-Stuff::Application.config.secret_token = 'ea0b2251a2e50f19279cd7ecd0011cd50464e61cde0f4d4fe6b541f2aa41e290e77636547b220f7c9537d60f3086d479e63b4e7cb8ec3e2f6f2e3a94dfa04a2f'
+Calendar::Application.config.secret_token = 'ea0b2251a2e50f19279cd7ecd0011cd50464e61cde0f4d4fe6b541f2aa41e290e77636547b220f7c9537d60f3086d479e63b4e7cb8ec3e2f6f2e3a94dfa04a2f'
View
4 config/initializers/session_store.rb
@@ -1,8 +1,8 @@
# Be sure to restart your server when you modify this file.
-Stuff::Application.config.session_store :cookie_store, key: '_stuff_session'
+Calendar::Application.config.session_store :cookie_store, key: '_stuff_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
-# Stuff::Application.config.session_store :active_record_store
+# Calendar::Application.config.session_store :active_record_store

0 comments on commit 10db62b

Please sign in to comment.
Something went wrong with that request. Please try again.