Permalink
Browse files

Initial Import

  • Loading branch information...
0 parents commit 2dfcfe320ef2ea142cf879ffd8f5649d25263968 @brianjlandau committed Dec 7, 2007
Showing with 4,623 additions and 0 deletions.
  1. +19 −0 MIT-LICENSE
  2. +77 −0 README
  3. +22 −0 Rakefile
  4. +9 −0 init.rb
  5. +14 −0 install.rb
  6. +107 −0 lib/12_hour_time.rb
  7. +258 −0 lib/unobtrusive_date_picker.rb
  8. BIN public/images/backstripes.gif
  9. BIN public/images/bg_header.jpg
  10. BIN public/images/bullet1.gif
  11. BIN public/images/bullet2.gif
  12. BIN public/images/cal.gif
  13. BIN public/images/gradient-e5e5e5-ffffff.gif
  14. +1,438 −0 public/javascripts/datepicker.js
  15. +40 −0 public/javascripts/lang/af.js
  16. +50 −0 public/javascripts/lang/ar.js
  17. +40 −0 public/javascripts/lang/de.js
  18. +40 −0 public/javascripts/lang/du.js
  19. +42 −0 public/javascripts/lang/en.js
  20. +41 −0 public/javascripts/lang/es.js
  21. +40 −0 public/javascripts/lang/fi.js
  22. +44 −0 public/javascripts/lang/fr.js
  23. +40 −0 public/javascripts/lang/gr.js
  24. +49 −0 public/javascripts/lang/he.js
  25. +13 −0 public/javascripts/lang/it.js
  26. +40 −0 public/javascripts/lang/nl.js
  27. +40 −0 public/javascripts/lang/no.js
  28. +40 −0 public/javascripts/lang/pt.js
  29. +40 −0 public/javascripts/lang/ro.js
  30. +40 −0 public/javascripts/lang/ru.js
  31. +40 −0 public/javascripts/lang/sp.js
  32. +41 −0 public/javascripts/lang/sv.js
  33. +40 −0 public/javascripts/lang/ua.js
  34. +263 −0 public/stylesheets/datepicker.css
  35. +112 −0 rdoc/classes/UnobtrusiveDatePicker.html
  36. +147 −0 rdoc/classes/UnobtrusiveDatePicker/AssetTagHelper.html
  37. +487 −0 rdoc/classes/UnobtrusiveDatePicker/UnobtrusiveDatePickerHelper.html
  38. +1 −0 rdoc/created.rid
  39. +129 −0 rdoc/files/MIT-LICENSE.html
  40. +194 −0 rdoc/files/README.html
  41. +125 −0 rdoc/files/lib/12_hour_time_rb.html
  42. +109 −0 rdoc/files/lib/unobtrusive_date_picker_rb.html
  43. +29 −0 rdoc/fr_class_index.html
  44. +30 −0 rdoc/fr_file_index.html
  45. +37 −0 rdoc/fr_method_index.html
  46. +24 −0 rdoc/index.html
  47. +208 −0 rdoc/rdoc-style.css
  48. +4 −0 tasks/unobtrusive_date_picker_tasks.rake
  49. +8 −0 test/unobtrusive_date_picker_test.rb
  50. +12 −0 uninstall.rb
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Brian J. Landau, <brianjlandau@gmail.com>
+
+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.
77 README
@@ -0,0 +1,77 @@
+
+= Unobtrusive Date-Picker Widget Plugin
+
+This is a helper for creating a date or date-time picker that uses the
+{Unobtrusive Date-Picker Widgit}[http://www.frequency-decoder.com/2006/10/02/unobtrusive-date-picker-widgit-update]
+to add a clickable calendar image that will bring up a calendar picker if javascript is available.
+
+The two main form helper methods are <tt>unobtrusive_date_picker</tt> and <tt>unobtrusive_datetime_picker</tt>.
+
+It also uses the {12 Hour Time plugin}[http://code.google.com/p/rails-twelve-hour-time-plugin/]
+so that 12 Hour times can be processed by Active Record.
+
+You may want to consider compressing the javascript files with {Dean Edward's Packer}[http://dean.edwards.name/packer/]
+or {Douglas Crockford's JSMin}[http://www.crockford.com/javascript/jsmin.html] before deploying your application.
+
+
+== Usage
+The main options are <tt>start_year</tt>, <tt>end_year</tt>, which control the year range.
+
+==== Example:
+ <% form_for :article, :url => { :action => @form_action, :id => @article } do |f| %>
+ <fieldset>
+ ...
+ <label>Date: <%= f.unobtrusive_datetime_picker :date %></label><br />
+ ...
+ </fieldset>
+ <% end %>
+
+==== Produces (Current date when output: 12/6/07):
+ <form action="/form/create" method="post">
+ <fieldset>
+
+ <label>Date:
+ <select id="article_date-dd" name="article[date(3i)]">
+ <option value="1">1</option>
+ ...
+ <option value="31">31</option>
+ </select>
+ <select id="article_date-mm" name="article[date(2i)]">
+ <option value="1">January</option>
+ ...
+ <option value="12" selected="selected">December</option>
+ </select>
+ <select id="article_date" name="article[date(1i)]" class="split-date">
+ <option value="2002">2002</option>
+ ...
+ <option value="2012">2012</option>
+ </select>
+ &nbsp;
+ <select id="article_date_4i" name="article[date(4i)]">
+ <option value="1">1</option>
+ ...
+ <option value="12">12</option>
+ </select>
+ :
+ <select id="article_date_5i" name="article[date(5i)]">
+ <option value="00">00</option>
+ ...
+ <option value="59">59</option>
+ </select>
+ <select id="article_date_6i" name="article[date(6i)]">
+ <option value="AMPM>AMPM</option>
+ <option value="AMPM>AMPM</option>
+ </select>
+ </label><br />
+
+ </fieldset>
+ </form>
+
+
+
+=== LICENSE
+
+See MIT-LICENSE file for copyright and licensing information for this plugin.
+
+Unobtrusive Date-Picker Widgit is provided under the Creative Commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/) by frequency-decoder.com
+
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the unobtrusive_date_picker plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the unobtrusive_date_picker plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Unobtrusive Date-Picker'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.add ['lib/**/*.rb', 'README', 'MIT-LICENSE']
+ rdoc.options << '--main' << 'README'
+end
@@ -0,0 +1,9 @@
+require '12_hour_time'
+require 'unobtrusive_date_picker'
+
+# Include all the necessary functions in to the appropriate point in the Rails framework
+ActionView::Base.send :include, UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
+ActionView::Helpers::DateHelper.send :include, UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
+ActionView::Base.send :include, UnobtrusiveDatePicker::AssetTagHelper
+ActionView::Helpers::AssetTagHelper.send :include, UnobtrusiveDatePicker::AssetTagHelper
+ActionView::Helpers::InstanceTag.send :include, UnobtrusiveDatePicker::InstanceTag
@@ -0,0 +1,14 @@
+require 'fileutils'
+
+# Install all the needed support files (CSS and JavaScript)
+
+js_dir = File.dirname(__FILE__) + '/../../../public/javascripts/'
+datepicker_js = js_dir + 'datepicker.js'
+lang_dir = js_dir + 'lang'
+datepicker_css = File.dirname(__FILE__) + '/../../../public/stylesheets/datepicker.css'
+images_dir = File.dirname(__FILE__) + '/../../../public/images/datepicker'
+
+FileUtils.cp File.dirname(__FILE__) + '/public/javascripts/datepicker.js', datepicker_js unless File.exists?(datepicker_js)
+FileUtils.cp_r File.dirname(__FILE__) + '/public/javascripts/lang/', lang_dir unless File.exists?(lang_dir)
+FileUtils.cp File.dirname(__FILE__) + '/public/stylesheets/datepicker.css', datepicker_css unless File.exists?(datepicker_css)
+FileUtils.cp_r File.dirname(__FILE__) + '/public/images/', images_dir unless File.exists?(images_dir)
@@ -0,0 +1,107 @@
+
+#
+# == Rails Twelve Hour Time Plugin
+#
+# http://code.google.com/p/rails-twelve-hour-time-plugin/
+#
+# ==== Authors
+# * Nick Muerdter (original code)
+# * Maurice Aubrey
+#
+# ==== Used for
+# Allows UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper to use a AM/PM select of it's own,
+# and still be processed correctly by Active Record.
+#
+
+# :enddoc:
+class ActiveRecord::Base # :nodoc: all
+ def extract_callstack_for_multiparameter_attributes_with_ampm(pairs)
+ attributes = extract_callstack_for_multiparameter_attributes_without_ampm(pairs)
+ attributes.each do |name, values|
+ klass = (self.class.reflect_on_aggregation(name) ||
+ column_for_attribute(name)).klass
+ if klass == Time && values.length == 6
+ if values[5] == ActionView::Helpers::DateHelper::AM && values[3] == 12
+ values[3] = 0
+ elsif values[5] == ActionView::Helpers::DateHelper::PM && values[3] != 12
+ values[3] += 12
+ end
+ end
+ end
+ end
+
+ alias_method_chain :extract_callstack_for_multiparameter_attributes, :ampm
+end
+
+module ActionView::Helpers::DateHelper # :nodoc: all
+ AM = 'AM'
+ PM = 'PM'
+
+ def select_hour_with_ampm(datetime, options = {})
+ options[:twelve_hour] or return select_hour_without_ampm(datetime, options)
+
+ val = ''
+ if datetime
+ val = datetime.kind_of?(Fixnum) ? datetime : datetime.hour
+ val -= 12 if val > 12
+ end
+
+ if options[:use_hidden]
+ return hidden_html(options[:field_name] || 'hour', val, options)
+ end
+
+ hour_options = []
+ 1.upto(12) do |hour|
+ selected = (hour == val) ? ' selected="selected"' : ''
+ hour_options << %(<option value="#{leading_zero_on_single_digits(hour)}"#{selected}>#{leading_zero_on_single_digits(hour)}</option>\n)
+ end
+
+ select_html(options[:field_name] || 'hour', hour_options, options)
+ end
+
+ alias_method_chain :select_hour, :ampm
+
+
+ def select_ampm(datetime, options = {})
+ ampm = [AM, PM]
+ val = datetime ? (choices.include?(datetime) ? datetime : datetime.strftime("%p")) : ''
+
+ if options[:use_hidden]
+ return hidden_html(options[:field_name] || 'ampm', val, options)
+ end
+
+ ampm_options = []
+ ampm.each do |meridiem|
+ selected = (meridiem == val) ? ' selected="selected"' : ''
+ ampm_options << %(<option value="#{meridiem}"#{selected}>#{meridiem}</option>\n)
+ end
+
+ select_html(options[:field_name] || 'ampm', ampm_options, options)
+ end
+
+ def select_time_with_ampm(datetime = Time.now, options = {})
+ select = select_time_without_ampm(datetime, options)
+ select << select_ampm(datetime, options) if options[:twelve_hour]
+ select
+ end
+
+ alias_method_chain :select_time, :ampm
+end
+
+class ActionView::Helpers::InstanceTag # :nodoc: all
+ def date_or_time_select_with_ampm(options)
+ options[:twelve_hour] and not options[:discard_hour] or
+ return date_or_time_select_without_ampm(options)
+
+ defaults = { :discard_type => true }
+ options = defaults.merge(options)
+
+ datetime = value(object)
+ datetime ||= Time.now unless options[:include_blank]
+
+ date_or_time_select_without_ampm(options) +
+ select_ampm(datetime, options_with_prefix(6, options.merge(:use_hidden => options[:discard_hour])))
+ end
+
+ alias_method_chain :date_or_time_select, :ampm
+end
Oops, something went wrong.

0 comments on commit 2dfcfe3

Please sign in to comment.