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
17 changed files
with
784 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- ruby -*- | ||
|
||
require 'autotest/restart' | ||
|
||
# Autotest.add_hook :initialize do |at| | ||
# at.extra_files << "../some/external/dependency.rb" | ||
# | ||
# at.libs << ":../some/external" | ||
# | ||
# at.add_exception 'vendor' | ||
# | ||
# at.add_mapping(/dependency.rb/) do |f, _| | ||
# at.files_matching(/test_.*rb$/) | ||
# end | ||
# | ||
# %w(TestA TestB).each do |klass| | ||
# at.extra_class_map[klass] = "test/test_misc.rb" | ||
# end | ||
# end | ||
|
||
# Autotest.add_hook :run_command do |at| | ||
# system "rake build" | ||
# 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,8 @@ | ||
.autotest | ||
History.txt | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
bin/appointments | ||
lib/appointments.rb | ||
test/test_appointments.rb |
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,54 @@ | ||
= appointments | ||
|
||
Schedule appointments with Rails 3 and the jQuery-UI | ||
|
||
http://rubygems.org/gems/appointments | ||
|
||
== SYNOPSIS: | ||
|
||
Uses the jQuery UI datepicker and ActiveRecord to allow users to choose a date and then match the hours belonging to that date with hours that have already been scheduled. See the tutorial for more info http://leveton.wordpress.com/2012/02/19/schedule-appointments-with-rails3-and-jquery/ | ||
|
||
== REQUIREMENTS: | ||
|
||
Rails 3.0+ | ||
|
||
== INSTALL: | ||
|
||
<i>Ensure that you call '//= require jquery-ui' in your application.js file</i> | ||
|
||
run: | ||
|
||
<b>gem install appointments</b> | ||
|
||
Add the gem to your gemfile. | ||
|
||
If you want all the files pre-installed, then run the generator: | ||
|
||
<b>rails generate appointments:install</b> | ||
|
||
This will install the necessary model, view, and controller files | ||
|
||
== LICENSE: | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2012 FIX | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,22 @@ | ||
# -*- ruby -*- | ||
|
||
require 'rubygems' | ||
require 'hoe' | ||
|
||
# Hoe.plugin :compiler | ||
# Hoe.plugin :gem_prelude_sucks | ||
# Hoe.plugin :inline | ||
# Hoe.plugin :racc | ||
# Hoe.plugin :rubyforge | ||
|
||
Hoe.spec 'appointments' do | ||
# HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then | ||
# you'll never have to touch them again! | ||
# (delete this comment too, of course) | ||
|
||
developer('Michael Leveton', 'mleveton@prepcloud.com') | ||
|
||
# self.rubyforge_name = 'appointmentsx' # if different than 'appointments' | ||
end | ||
|
||
# vim: syntax=ruby |
Binary file not shown.
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,20 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "appointments" | ||
s.version = "1.0.13" | ||
s.platform = Gem::Platform::RUBY | ||
s.summary = "Schedule appointments with Rails 3 and the jQuery-UI" | ||
s.email = "mleveton@prepcloud.com" | ||
s.homepage = "https://github.com/Leveton/appointments" | ||
s.description = "Schedule appointments with Rails 3 and the jQuery-UI" | ||
s.authors = ['Michael Leveton'] | ||
s.files = `git ls-files`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.test_files = Dir["test/**/*"] | ||
s.require_paths = ["lib"] | ||
s.bindir = "bin" | ||
s.rubyforge_project = 'appointments' | ||
s.has_rdoc = true | ||
s.add_dependency('thor') | ||
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,38 @@ | ||
module Appointments | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
desc "Creates an appointment initializer and copies locale files to your application." | ||
class_option :orm | ||
|
||
def add_model | ||
template "appointment.rb", "app/models/appointment.rb" | ||
end | ||
|
||
def add_view | ||
template "new.html.erb", "app/views/appointments/new.html.erb" | ||
end | ||
|
||
def add_stub_view | ||
template "match_dates.html.erb", "app/views/appointments/match_dates.html.erb" | ||
end | ||
|
||
def add_controller | ||
template "appointments_controller.rb", "app/controllers/appointmentss_controller.rb" | ||
end | ||
|
||
def add_javascripts | ||
template "jquery.ui.datepicker.min.js", "public/jquery.ui.datepicker.min.js" | ||
template "jquery.ui.widget.min.js", "public/jquery.ui.widget.min.js" | ||
end | ||
|
||
def add_stylesheets | ||
template "jquery-ui-1.8.17.custom.css", "public/jquery-ui-1.8.17.custom.css" | ||
end | ||
|
||
def add_captivate_routes | ||
match_dates = "match 'appointments/match_dates' => 'appointments#match_dates'" | ||
route match_dates | ||
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,110 @@ | ||
$(function () { | ||
$('#appointment_form').hide(); | ||
$('#hour_picker').hide(); | ||
$('#hidden_hour_div').hide(); | ||
$('#cal_previous2').hide(); | ||
}); | ||
|
||
function findHours(current_date){ | ||
$.ajax({ | ||
type: "POST", | ||
url: "match_dates", | ||
cache: false, | ||
data: {matched_date:current_date}, | ||
success: function(html){ | ||
var hours_array = []; | ||
$("#hidden_hour_div").append(html); | ||
var hours_string = $("#hidden_hour_div").html() | ||
var one = hours_string.substring(2, 6); | ||
var two = hours_string.substring(10, 14); | ||
var three = hours_string.substring(18, 22); | ||
var four = hours_string.substring(26, 30); | ||
var five = hours_string.substring(34, 38); | ||
var six = hours_string.substring(42, 46); | ||
var seven = hours_string.substring(50, 54); | ||
var eight = hours_string.substring(58, 62); | ||
var nine = hours_string.substring(66, 70); | ||
var ten = hours_string.substring(74, 78); | ||
var eleven = hours_string.substring(82, 86); | ||
var twelve = hours_string.substring(90, 94); | ||
hours_array.push(one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve); | ||
for (var j in hours_array) { | ||
(final_array = '\.'+ hours_array[j]); | ||
$(final_array).hide(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
var disabledDays = []; | ||
|
||
$(function () { | ||
|
||
$('.schedules_dates').map(function () { | ||
disabledDays.push(this.id); | ||
}).get().join(','); | ||
|
||
}); | ||
|
||
function unavailableDays(date) { | ||
var y = date.getFullYear(), | ||
m = date.getMonth(), | ||
d = date.getDate(); | ||
if ($.inArray(y + '-' + (m + 1) + '-' + d, disabledDays) != -1 || new Date() > date) { | ||
return [false]; | ||
} | ||
return [true]; | ||
} | ||
|
||
$(function () { | ||
var currentTime = new Date() | ||
var month = currentTime.getMonth() | ||
var day = currentTime.getDate() | ||
var year = currentTime.getFullYear() | ||
|
||
$("#datepicker").datepicker({ | ||
minDate: new Date(year, month, day), | ||
dateFormat: 'yy-mm-dd', | ||
onSelect: function(dateText, inst) { | ||
setFinalDate = dateText; | ||
$('#hour_picker').show(); | ||
$('#datepicker').hide(); | ||
findHours(setFinalDate); | ||
$("th.selected_date").append("Date Chosen:" + " " + (setFinalDate)); | ||
pageNo = '2'; | ||
} | ||
|
||
}); | ||
}); | ||
|
||
|
||
function nextPage(hour, id){ | ||
setFinalHour = hour; | ||
if (setFinalHour == null || setFinalHour == "") return false; | ||
else { | ||
$('#hour_picker').hide(); | ||
$("#appointment_form").show(); | ||
document.getElementById('schedules_date').value = setFinalDate; | ||
document.getElementById('schedules_hour').value = setFinalHour; | ||
$('#cal_previous2').show(); | ||
document.getElementById('subData').style.display = 'block' | ||
$('#final_date h2').append(setFinalDate); | ||
$('#final_hour h2').append(id); | ||
pageNo = '3'; | ||
return true; | ||
} | ||
|
||
} | ||
|
||
function prevPage() { | ||
|
||
if (pageNo === '3') { | ||
setFinalHour = ""; | ||
$('#appointment_form').hide(); | ||
$("#hour_picker").show(); | ||
$('#cal_previous2').hide(); | ||
$('#final_date h2').empty(); | ||
$('#final_hour h2').empty(); | ||
pageNo = '2' | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/generators/appointments/templates/appointments_controller.rb
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,33 @@ | ||
class AppointmentsController < ApplicationController | ||
|
||
def match_dates | ||
date_from_ajax = params[:matched_date] | ||
reduce = Appointment.where(:date => date_from_ajax) | ||
hour_on_date = reduce.collect {|x| x.hour} | ||
@new_dates = hour_on_date | ||
render :layout => false | ||
end | ||
|
||
def new | ||
@appointments = Appointment.create | ||
respond_to do |format| | ||
format.html | ||
format.js | ||
end | ||
end | ||
|
||
|
||
def create | ||
@appointment = Appointment.create(params[:appointments]) | ||
if @appointment.save | ||
redirect_to root_path | ||
else | ||
err = '' | ||
@appointment.errors.full_messages.each do |m| | ||
err << m | ||
end | ||
|
||
redirect_to root_path, :flash => { :alert => "#{err}, please try again" } | ||
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,4 @@ | ||
Rails.application.configure do | ||
# Uncomment this to turn on verbose mode | ||
# config.my_gem.verbose = true | ||
end |
Empty file.
Oops, something went wrong.