Permalink
Browse files

Added holiday indicator in datepicker calender

  • Loading branch information...
1 parent f1203dc commit 3da897767ce994750157f841ad4855bd40b24f58 kiran committed Jul 6, 2011
Showing with 19 additions and 1 deletion.
  1. +10 −1 app/helpers/global_helpers.rb
  2. +8 −0 app/models/holiday.rb
  3. +1 −0 public/stylesheets/screen.css
@@ -143,7 +143,16 @@ def date_select_html (attrs, obj = nil, col = nil)
<input type='text' name="#{attrs[:name]}" id="#{attrs[:id]}" value="#{attrs[:date]}" size="#{attrs[:size]}" #{attrs[:nullable] ? "" : "readonly='true'"}>
<script type="text/javascript">
$(function(){
- $("##{attrs[:id]}").datepicker('destroy').datepicker({altField: '##{attrs[:id]}', buttonImage: "/images/calendar.png", changeYear: true, buttonImageOnly: true,
+ var holidays= #{Holiday.get_list.to_json};
+ function nonWorkingDays(date) {
+ for (var j = 0; j < holidays.length; j++) {
+ if (date.getMonth() == holidays[j][1] - 1 && date.getDate() == holidays[j][0]) {
+ return [true, 'holiday_indicator'];
+ }
+ }
+ return [true, ''];
+ }
+ $("##{attrs[:id]}").datepicker('destroy').datepicker({beforeShowDay: nonWorkingDays, altField: '##{attrs[:id]}', buttonImage: "/images/calendar.png", changeYear: true, buttonImageOnly: true,
yearRange: '#{attrs[:min_date].year}:#{attrs[:max_date].year}',
dateFormat: '#{datepicker_dateformat}', altFormat: '#{datepicker_dateformat}', minDate: '#{attrs[:min_date]}',
maxDate: '#{attrs[:max_date]}', showOn: 'both', setDate: "#{attrs[:date]}" })
@@ -12,4 +12,12 @@ def update_loan_history
$holidays = Holiday.all.map{|h| [h.date, h]}.to_hash
repository.adapter.execute("update loan_history set date='#{date.holiday_bump.strftime('%Y-%m-%d')}' where date='#{date.strftime('%Y-%m-%d')}'")
end
+
+ def self.get_list
+ list = []
+ Holiday.all.each do |h|
+ list << [h.date.day, h.date.month]
+ end
+ return list
+ end
end
@@ -280,3 +280,4 @@ input.error, textarea.error, select.error {background:#FBE3E4;}
.container .notice a {color:#514721; background:none; padding:0; margin:0; }
.container .success a {color:#264409; background:none; padding:0; margin:0; }
.container .center {text-align: center;}
+.holiday_indicator, .ui-datepicker .holiday_indicator a { background-color:red;color:red }

0 comments on commit 3da8977

Please sign in to comment.