annotate .svn/pristine/d1/d17ed0048a8732d627b6e8e9b53ae2903c41d045.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 module Redmine
Chris@909 19 module Helpers
Chris@909 20
Chris@909 21 # Simple class to compute the start and end dates of a calendar
Chris@909 22 class Calendar
Chris@909 23 include Redmine::I18n
Chris@909 24 attr_reader :startdt, :enddt
Chris@909 25
Chris@909 26 def initialize(date, lang = current_language, period = :month)
Chris@909 27 @date = date
Chris@909 28 @events = []
Chris@909 29 @ending_events_by_days = {}
Chris@909 30 @starting_events_by_days = {}
Chris@909 31 set_language_if_valid lang
Chris@909 32 case period
Chris@909 33 when :month
Chris@909 34 @startdt = Date.civil(date.year, date.month, 1)
Chris@909 35 @enddt = (@startdt >> 1)-1
Chris@909 36 # starts from the first day of the week
Chris@909 37 @startdt = @startdt - (@startdt.cwday - first_wday)%7
Chris@909 38 # ends on the last day of the week
Chris@909 39 @enddt = @enddt + (last_wday - @enddt.cwday)%7
Chris@909 40 when :week
Chris@909 41 @startdt = date - (date.cwday - first_wday)%7
Chris@909 42 @enddt = date + (last_wday - date.cwday)%7
Chris@909 43 else
Chris@909 44 raise 'Invalid period'
Chris@909 45 end
Chris@909 46 end
Chris@909 47
Chris@909 48 # Sets calendar events
Chris@909 49 def events=(events)
Chris@909 50 @events = events
Chris@909 51 @ending_events_by_days = @events.group_by {|event| event.due_date}
Chris@909 52 @starting_events_by_days = @events.group_by {|event| event.start_date}
Chris@909 53 end
Chris@909 54
Chris@909 55 # Returns events for the given day
Chris@909 56 def events_on(day)
Chris@909 57 ((@ending_events_by_days[day] || []) + (@starting_events_by_days[day] || [])).uniq
Chris@909 58 end
Chris@909 59
Chris@909 60 # Calendar current month
Chris@909 61 def month
Chris@909 62 @date.month
Chris@909 63 end
Chris@909 64
Chris@909 65 # Return the first day of week
Chris@909 66 # 1 = Monday ... 7 = Sunday
Chris@909 67 def first_wday
Chris@909 68 case Setting.start_of_week.to_i
Chris@909 69 when 1
Chris@909 70 @first_dow ||= (1 - 1)%7 + 1
Chris@909 71 when 6
Chris@909 72 @first_dow ||= (6 - 1)%7 + 1
Chris@909 73 when 7
Chris@909 74 @first_dow ||= (7 - 1)%7 + 1
Chris@909 75 else
Chris@909 76 @first_dow ||= (l(:general_first_day_of_week).to_i - 1)%7 + 1
Chris@909 77 end
Chris@909 78 end
Chris@909 79
Chris@909 80 def last_wday
Chris@909 81 @last_dow ||= (first_wday + 5)%7 + 1
Chris@909 82 end
Chris@909 83 end
Chris@909 84 end
Chris@909 85 end