tb_events 1.1.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -1
- data/Rakefile +2 -2
- data/app/assets/javascripts/admin/events/application.js +16 -0
- data/app/assets/javascripts/{calendar_events.js → admin/events/calendar_events.js} +0 -0
- data/app/assets/javascripts/{spud/admin → admin/events}/calendars.js +0 -0
- data/app/assets/stylesheets/admin/events/application.css +4 -0
- data/app/assets/{javascripts/spud/events.js → stylesheets/admin/events/calendar_events.css} +0 -0
- data/app/assets/stylesheets/{spud → admin/events}/calendars.css +23 -28
- data/app/controllers/admin/calendar_events_controller.rb +13 -15
- data/app/controllers/admin/calendars_controller.rb +9 -11
- data/app/controllers/calendar_events_controller.rb +12 -6
- data/app/controllers/calendars_controller.rb +18 -18
- data/app/helpers/admin/calendars_helper.rb +6 -8
- data/app/helpers/calendars_helper.rb +66 -35
- data/app/models/spud_calendar.rb +30 -2
- data/app/models/spud_calendar_event.rb +1 -18
- data/app/models/spud_events/calendar_event_model.rb +31 -0
- data/app/views/admin/calendar_events/_calendar.html.erb +16 -11
- data/app/views/admin/calendar_events/_form.html.erb +16 -98
- data/app/views/admin/calendar_events/index.html.erb +24 -16
- data/app/views/admin/calendars/_calendar_legend.html.erb +5 -4
- data/app/views/admin/calendars/_form.html.erb +4 -19
- data/app/views/calendar_events/index.html.erb +22 -0
- data/app/views/calendar_events/show.html.erb +3 -1
- data/app/views/calendars/show.html.erb +18 -15
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +7 -10
- data/db/migrate/20120216191833_create_spud_calendars.rb +3 -3
- data/db/migrate/20120216192531_create_spud_calendar_events.rb +1 -1
- data/db/migrate/20130214131628_add_location_to_spud_calendar_event.rb +1 -1
- data/db/migrate/20140723203144_add_identifier_to_spud_calendars.rb +6 -0
- data/db/migrate/20140730182213_remove_color_from_spud_calendars.rb +9 -0
- data/lib/spud_events/calendar_builder.rb +53 -0
- data/lib/spud_events/configuration.rb +6 -0
- data/lib/spud_events/engine.rb +25 -0
- data/lib/spud_events/version.rb +3 -0
- data/lib/tb_events.rb +4 -4
- metadata +62 -110
- data/app/assets/javascripts/calendars.js +0 -2
- data/app/assets/javascripts/spud/admin/calendar_events.js +0 -2
- data/app/assets/javascripts/spud/admin/events.js +0 -51
- data/app/assets/lib/colorpicker/colorpicker.css +0 -164
- data/app/assets/lib/colorpicker/colorpicker.js +0 -484
- data/app/assets/lib/colorpicker/images/blank.gif +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_background.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_hex.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_hsb_b.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_hsb_h.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_hsb_s.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_indic.gif +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_overlay.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_rgb_b.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_rgb_g.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_rgb_r.png +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_select.gif +0 -0
- data/app/assets/lib/colorpicker/images/colorpicker_submit.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_background.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_hex.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_hsb_b.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_hsb_h.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_hsb_s.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_indic.gif +0 -0
- data/app/assets/lib/colorpicker/images/custom_rgb_b.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_rgb_g.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_rgb_r.png +0 -0
- data/app/assets/lib/colorpicker/images/custom_submit.png +0 -0
- data/app/assets/lib/colorpicker/images/select.png +0 -0
- data/app/assets/lib/colorpicker/images/select2.png +0 -0
- data/app/assets/lib/colorpicker/images/slider.png +0 -0
- data/app/assets/stylesheets/spud/admin/events.css +0 -16
- data/app/assets/stylesheets/spud/calendar_events.css +0 -18
- data/app/assets/stylesheets/spud/events.css +0 -4
- data/app/views/calendars/_calendar.html.erb +0 -26
- data/app/views/calendars/_calendar_options.html.erb +0 -4
- data/config/application.rb +0 -50
- data/config/boot.rb +0 -6
- data/lib/spud/events/calendar.rb +0 -85
- data/lib/spud/events/calendar_builder.rb +0 -58
- data/lib/spud/events/configuration.rb +0 -8
- data/lib/spud/events/engine.rb +0 -26
- data/lib/spud/events/table_builder.rb +0 -88
- data/lib/spud/events/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e19d7ca4e2a12520dec1b46836f3fb0a9fceaf973b028ee85a341ece8635a323
|
4
|
+
data.tar.gz: 1090bda847f92900155a812cc7c08221e764a2c74a315c85580fb49039f9a1fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d6a3e1ae6c08e9cd03cbe2bff49431147a815b435d9e1156d2fdc5ba19f6e1f9bbc36aa619a2c3c879b08f54179acbeb367cd41897646204de217d28a9114b
|
7
|
+
data.tar.gz: 667fd01ecad3c3e55f5dcc75a05430158ea517fa5304a168dab3f7a6a66104fdb6ea851215d7338870ffb3a8a73c1dc983f967ca362fc014f45c3a072d49e457
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Configruations
|
|
24
24
|
|
25
25
|
* Set the layout for the calendar pages (Defualt is layouts/spud/calendar)
|
26
26
|
|
27
|
-
|
27
|
+
SpudEvents.configure do |config|
|
28
28
|
config.calendar_layout = 'application'
|
29
29
|
end
|
30
30
|
|
@@ -36,6 +36,18 @@ Configruations
|
|
36
36
|
*= require spud/events
|
37
37
|
*/
|
38
38
|
|
39
|
+
## View Helpers
|
40
|
+
|
41
|
+
TB Events comes with a handful of view helpers for generating calendars. See the Rdoc documentation for detailed information.
|
42
|
+
|
43
|
+
Return a calendar as an html table for the given date:
|
44
|
+
|
45
|
+
spud_calendar_for_date(date)
|
46
|
+
|
47
|
+
Return a calendar for the given date, populated with event data:
|
48
|
+
|
49
|
+
spud_calendar_for_events(events, date, opts)
|
50
|
+
|
39
51
|
Testing
|
40
52
|
-----------------
|
41
53
|
|
data/Rakefile
CHANGED
@@ -20,9 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path(
|
23
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
27
27
|
|
28
|
-
require 'rake'
|
28
|
+
require 'rake'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
//= require_self
|
2
|
+
//= require_directory
|
3
|
+
|
4
|
+
(function(){
|
5
|
+
|
6
|
+
spud.admin.events = {
|
7
|
+
init: function(){
|
8
|
+
$(document).on('ajax:success','.js-spud-calendar-delete-action', deletedCalendar);
|
9
|
+
}
|
10
|
+
};
|
11
|
+
|
12
|
+
var deletedCalendar = function(){
|
13
|
+
$(this).closest('.spud_events_admin_calendar_legend_item').fadeOut(500, function(){ $(this).remove(); });
|
14
|
+
};
|
15
|
+
|
16
|
+
})();
|
File without changes
|
File without changes
|
File without changes
|
@@ -49,10 +49,8 @@
|
|
49
49
|
|
50
50
|
#spud_events_admin_calendar,
|
51
51
|
#spud_events_calendar {
|
52
|
-
|
53
|
-
padding-bottom: 50px;
|
52
|
+
margin: 0 0 20px;
|
54
53
|
position: relative;
|
55
|
-
float: left;
|
56
54
|
}
|
57
55
|
#spud_events_calendar {
|
58
56
|
width: auto;
|
@@ -66,7 +64,7 @@
|
|
66
64
|
margin: 15px 0 0;
|
67
65
|
}
|
68
66
|
#spud_events_admin_calendar th,
|
69
|
-
#spud_events_calendar th {
|
67
|
+
#spud_events_calendar th {
|
70
68
|
text-align: center;
|
71
69
|
}
|
72
70
|
#spud_events_admin_calendar td,
|
@@ -78,21 +76,33 @@
|
|
78
76
|
vertical-align: top;
|
79
77
|
width: 98px;
|
80
78
|
}
|
81
|
-
.
|
82
|
-
.spud_events_calendar_date_container {
|
83
|
-
display: block;
|
84
|
-
padding: 18px 5px 0;
|
85
|
-
position: relative;
|
86
|
-
}
|
87
|
-
span.spud_events_admin_calendar_date,
|
88
|
-
span.spud_events_calendar_date {
|
79
|
+
.calendar-day{
|
89
80
|
position: absolute;
|
90
81
|
top: 3px;
|
91
|
-
|
82
|
+
left: 3px;
|
92
83
|
font-size: 11px;
|
93
84
|
line-height: 11px;
|
94
85
|
}
|
95
86
|
|
87
|
+
.not-month .calendar-day {
|
88
|
+
display: none;
|
89
|
+
}
|
90
|
+
.not-month .calendar-events {
|
91
|
+
display: none;
|
92
|
+
}
|
93
|
+
|
94
|
+
.calendar-events-list{
|
95
|
+
list-style: none;
|
96
|
+
margin: 10px 0 0;
|
97
|
+
padding: 0;
|
98
|
+
}
|
99
|
+
.calendar-events-list li{
|
100
|
+
margin: 4px;
|
101
|
+
}
|
102
|
+
.calendar-events-list a{
|
103
|
+
text-decoration: none;
|
104
|
+
}
|
105
|
+
|
96
106
|
/* Calendar Legend
|
97
107
|
----------------------- */
|
98
108
|
#spud_events_admin_calendar_legend,
|
@@ -100,7 +110,6 @@ span.spud_events_calendar_date {
|
|
100
110
|
list-style: none;
|
101
111
|
border: 1px solid #d9d9d9;
|
102
112
|
padding: 0;
|
103
|
-
margin: 45px 0 0 725px;
|
104
113
|
}
|
105
114
|
#spud_events_admin_calendar_legend li,
|
106
115
|
#spud_events_calendar_legend li {
|
@@ -120,17 +129,3 @@ span.spud_events_calendar_date {
|
|
120
129
|
#spud_events_calendar_legend li:last-child {
|
121
130
|
border: none;
|
122
131
|
}
|
123
|
-
.spud_events_admin_calendar_actions,
|
124
|
-
.spud_events_calendar_actions {
|
125
|
-
text-align: right;
|
126
|
-
}
|
127
|
-
|
128
|
-
#spud_events_admin_calendar_legend span,
|
129
|
-
#spud_events_calendar_legend span {
|
130
|
-
display: inline-block;
|
131
|
-
-moz-border-radius: 3px;
|
132
|
-
-webkit-border-radius: 3px;
|
133
|
-
border-radius: 3px;
|
134
|
-
padding: 2px 8px;
|
135
|
-
margin: 8px 0 0 8px;
|
136
|
-
}
|
@@ -1,21 +1,20 @@
|
|
1
1
|
class Admin::CalendarEventsController < Admin::ApplicationController
|
2
|
-
|
3
|
-
|
4
|
-
belongs_to_spud_app :events
|
2
|
+
add_breadcrumb 'Events', :admin_list_spud_calendar_events_path
|
3
|
+
belongs_to_app :events
|
5
4
|
|
6
5
|
respond_to :html, :xml, :json
|
7
|
-
respond_to :js, :
|
6
|
+
respond_to :js, only: [:index]
|
8
7
|
|
9
8
|
def index
|
10
9
|
if params[:month]
|
11
|
-
year = params[:year] ? params[:year] :
|
10
|
+
year = params[:year] ? params[:year].to_i : Date.today.year
|
12
11
|
begin
|
13
|
-
@calendar_date =
|
12
|
+
@calendar_date = Date.new(year, params[:month].to_i)
|
14
13
|
rescue
|
15
|
-
@calendar_date =
|
14
|
+
@calendar_date = Date.today
|
16
15
|
end
|
17
16
|
else
|
18
|
-
@calendar_date =
|
17
|
+
@calendar_date = Date.today
|
19
18
|
end
|
20
19
|
|
21
20
|
if params[:spud_calendar] && calendar = SpudCalendar.find_by_title(params[:spud_calendar].titleize)
|
@@ -28,7 +27,7 @@ class Admin::CalendarEventsController < Admin::ApplicationController
|
|
28
27
|
@calendars = SpudCalendar.all
|
29
28
|
@current_calendar = params[:spud_calendar] ? params[:spud_calendar] : 0
|
30
29
|
|
31
|
-
respond_with(@calendars, :
|
30
|
+
respond_with(@calendars, include: :events)
|
32
31
|
end
|
33
32
|
|
34
33
|
def new
|
@@ -45,25 +44,24 @@ class Admin::CalendarEventsController < Admin::ApplicationController
|
|
45
44
|
def create
|
46
45
|
@calendar_event = SpudCalendarEvent.new(calendar_event_params)
|
47
46
|
flash[:notice] = 'Calendar event was successfully created.' if @calendar_event.save
|
48
|
-
respond_with(@calendar_event, :
|
47
|
+
respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
|
49
48
|
end
|
50
49
|
|
51
50
|
def update
|
52
51
|
@calendar_event = SpudCalendarEvent.find(params[:id])
|
53
52
|
flash[:notice] = 'Calendar event was successfully updated.' if @calendar_event.update_attributes(calendar_event_params)
|
54
|
-
respond_with(@calendar_event, :
|
53
|
+
respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
|
55
54
|
end
|
56
55
|
|
57
56
|
def destroy
|
58
57
|
@calendar_event = SpudCalendarEvent.find(params[:id])
|
59
|
-
@calendar_event.destroy
|
60
|
-
respond_with(@calendar_event, :
|
58
|
+
flash[:notice] = 'Calendar event deleted successfully' if @calendar_event.destroy
|
59
|
+
respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
|
61
60
|
end
|
62
61
|
|
63
|
-
private
|
62
|
+
private
|
64
63
|
|
65
64
|
def calendar_event_params
|
66
65
|
params.require(:spud_calendar_event).permit(:title, :description, :start_at, :end_at, :all_day, :spud_calendar_id, :spud_calendar, :location, :address, :address_2, :city, :state, :zip)
|
67
66
|
end
|
68
|
-
|
69
67
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class Admin::CalendarsController < Admin::ApplicationController
|
2
|
+
add_breadcrumb 'Events', :admin_list_spud_calendar_events_path
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
belongs_to_spud_app :events
|
4
|
+
belongs_to_app :events
|
6
5
|
|
7
6
|
respond_to :html, :xml, :json, :js
|
8
7
|
|
9
8
|
def new
|
10
|
-
@page_name =
|
9
|
+
@page_name = 'New Calendar'
|
11
10
|
@calendar = SpudCalendar.new
|
12
11
|
respond_with(@calendar)
|
13
12
|
end
|
@@ -17,12 +16,12 @@ class Admin::CalendarsController < Admin::ApplicationController
|
|
17
16
|
if @calendar.save
|
18
17
|
redirect_to admin_list_spud_calendar_events_path
|
19
18
|
else
|
20
|
-
render :
|
19
|
+
render action: 'new'
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def edit
|
25
|
-
@page_name =
|
24
|
+
@page_name = 'Edit Calendar'
|
26
25
|
@calendar = SpudCalendar.find(params[:id])
|
27
26
|
respond_with(@calendar)
|
28
27
|
end
|
@@ -33,7 +32,7 @@ class Admin::CalendarsController < Admin::ApplicationController
|
|
33
32
|
flash[:notice] = 'Calendar was successfully updated.'
|
34
33
|
redirect_to admin_list_spud_calendar_events_path
|
35
34
|
else
|
36
|
-
render :
|
35
|
+
render action: 'edit'
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -44,14 +43,13 @@ class Admin::CalendarsController < Admin::ApplicationController
|
|
44
43
|
end
|
45
44
|
@calendar.destroy
|
46
45
|
respond_with(@calendar) do |format|
|
47
|
-
format.js { render(:
|
46
|
+
format.js { render(nothing: true) }
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
private
|
50
|
+
private
|
52
51
|
|
53
52
|
def calendar_params
|
54
|
-
params.require(:spud_calendar).permit(:title
|
53
|
+
params.require(:spud_calendar).permit(:title)
|
55
54
|
end
|
56
|
-
|
57
55
|
end
|
@@ -1,8 +1,14 @@
|
|
1
1
|
class CalendarEventsController < ApplicationController
|
2
|
-
|
3
|
-
layout
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
respond_to :html, :json
|
3
|
+
layout SpudEvents.config.calendar_layout
|
4
|
+
|
5
|
+
def index
|
6
|
+
@events = SpudCalendarEvent.ordered.paginate(per_page: 10, page: params[:page])
|
7
|
+
respond_with @events
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
@event = SpudCalendarEvent.find(params[:id])
|
12
|
+
respond_with @event
|
13
|
+
end
|
8
14
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
class CalendarsController < ApplicationController
|
2
|
-
|
3
|
-
layout
|
2
|
+
respond_to :html, :json
|
3
|
+
layout SpudEvents.config.calendar_layout
|
4
|
+
before_action :calendar_date
|
4
5
|
|
5
6
|
def show
|
6
|
-
if params[:month]
|
7
|
-
year = params[:year] ? params[:year] : Time.new.year
|
8
|
-
begin
|
9
|
-
@calendar_date = Time.local(year, params[:month])
|
10
|
-
rescue
|
11
|
-
@calendar_date = default_date
|
12
|
-
end
|
13
|
-
else
|
14
|
-
@calendar_date = default_date
|
15
|
-
end
|
16
7
|
if params[:calendar] && calendar = SpudCalendar.find_by_title(params[:calendar].titleize)
|
17
|
-
@events = calendar.spud_calendar_events.
|
8
|
+
@events = calendar.spud_calendar_events.in_month_of(@calendar_date).order(:start_at).to_a
|
18
9
|
else
|
19
|
-
@events = SpudCalendarEvent.
|
10
|
+
@events = SpudCalendarEvent.in_month_of(@calendar_date).order(:start_at).to_a
|
20
11
|
end
|
21
12
|
@current_calendar = params[:calendar] ? params[:calendar] : 0
|
22
|
-
|
13
|
+
respond_with @events
|
23
14
|
end
|
24
15
|
|
25
|
-
|
26
|
-
tempDate = Time.new
|
27
|
-
return Time.local(tempDate.year,tempDate.month)
|
16
|
+
private
|
28
17
|
|
18
|
+
def calendar_date
|
19
|
+
if params[:month]
|
20
|
+
year = params[:year] ? params[:year].to_i : Date.today.year
|
21
|
+
begin
|
22
|
+
@calendar_date = Date.new(year, params[:month].to_i)
|
23
|
+
rescue
|
24
|
+
@calendar_date = Date.today
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@calendar_date = Date.today
|
28
|
+
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module Admin::CalendarsHelper
|
2
|
-
|
3
|
-
|
4
|
-
date = date.advance(:months => -1)
|
2
|
+
def link_to_previous_admin_calendar_month(date, _url_for_options = {})
|
3
|
+
date = date.advance(months: -1)
|
5
4
|
calendar = params[:calendar] ? params[:calendar] : nil
|
6
|
-
link_to('« Previous Month'.html_safe, admin_list_spud_calendar_events_path(:
|
5
|
+
link_to('« Previous Month'.html_safe, admin_list_spud_calendar_events_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link previous_calendar btn btn-sm btn-default').html_safe
|
7
6
|
end
|
8
7
|
|
9
|
-
def link_to_next_admin_calendar_month(date,
|
10
|
-
date = date.advance(:
|
8
|
+
def link_to_next_admin_calendar_month(date, _url_for_options = {})
|
9
|
+
date = date.advance(months: 1)
|
11
10
|
calendar = params[:calendar] ? params[:calendar] : nil
|
12
|
-
link_to('Next Month »'.html_safe, admin_list_spud_calendar_events_path(:
|
11
|
+
link_to('Next Month »'.html_safe, admin_list_spud_calendar_events_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link next_calendar btn btn-sm btn-default pull-right').html_safe
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
@@ -1,48 +1,79 @@
|
|
1
1
|
module CalendarsHelper
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
# Builds a calendar for the given date
|
3
|
+
#
|
4
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
5
|
+
# * opts:
|
6
|
+
# - headers: Array of weekday headers (optional)
|
7
|
+
#
|
8
|
+
def spud_calendar_for_date(date, opts = {}, &block)
|
9
|
+
events = SpudCalendarEvent.in_month_of(date)
|
10
|
+
spud_calendar_for_events(events, date, opts, &block)
|
7
11
|
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
options_for_select(SpudCalendar.all.collect { |f| [f.title, f.title.gsub(/([^A-Z0-9]+)/i, "-").downcase] }.insert(0, text_for_all), @current_calendar)
|
13
|
+
# Builds a calendar for the given date and identifier
|
14
|
+
#
|
15
|
+
# * identifier: Symbol for the SpudCalendar you wish to display
|
16
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
17
|
+
# * opts:
|
18
|
+
# - headers: Array of weekday headers (optional)
|
19
|
+
#
|
20
|
+
def spud_calendar_for_identifier(identifier, date, opts = {}, &block)
|
21
|
+
calendar = SpudCalendar.with_identifier(identifier)
|
22
|
+
if calendar.present?
|
23
|
+
events = calendar.spud_calendar_events.in_month_of(date)
|
24
|
+
else
|
25
|
+
logger.warn "Failed to load calendar by identifer '#{identifier}'. Does it exist?"
|
26
|
+
events = []
|
27
|
+
end
|
28
|
+
spud_calendar_for_events(events, date, opts, &block)
|
26
29
|
end
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
# Builds a calendar for the given date, with events
|
32
|
+
#
|
33
|
+
# * events: An array or relation of SpudCalendarEvent records
|
34
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
35
|
+
# * opts:
|
36
|
+
# - headers: Array of weekday headers (optional)
|
37
|
+
#
|
38
|
+
def spud_calendar_for_events(events, date, opts = {}, &block)
|
39
|
+
events_array = events.to_a
|
40
|
+
cache(['spud-calendar', date.to_s, events]) do
|
41
|
+
concat(
|
42
|
+
SpudEvents::CalendarBuilder.new(self, date, opts).table do |day|
|
43
|
+
events = extract_events_for_date(events_array, day)
|
44
|
+
if block
|
45
|
+
block.call(day, events)
|
46
|
+
else
|
47
|
+
concat content_tag(:span, day.day.to_s, class: 'calendar-day')
|
48
|
+
if events.length > 0
|
49
|
+
list_items = events.collect do |event|
|
50
|
+
'<li>' + link_to(event.title, calendar_event_path(event)) + '</li>'
|
51
|
+
end.join('')
|
52
|
+
concat content_tag(:ul, raw(list_items), class: 'events-list')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
)
|
32
57
|
end
|
58
|
+
end
|
33
59
|
|
34
|
-
|
35
|
-
|
36
|
-
|
60
|
+
def link_to_previous_calendar_month(date)
|
61
|
+
date = date.advance(months: -1)
|
62
|
+
calendar = params[:calendar] ? params[:calendar] : nil
|
63
|
+
link_to('« Previous Month'.html_safe, calendar_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link previous_calendar btn').html_safe
|
64
|
+
end
|
37
65
|
|
38
|
-
|
66
|
+
def link_to_next_calendar_month(date)
|
67
|
+
date = date.advance(months: 1)
|
68
|
+
calendar = params[:calendar] ? params[:calendar] : nil
|
69
|
+
link_to('Next Month »'.html_safe, calendar_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link next_calendar btn').html_safe
|
70
|
+
end
|
39
71
|
|
72
|
+
private
|
40
73
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
return fore_color
|
74
|
+
def extract_events_for_date(events, date)
|
75
|
+
events.select do |event|
|
76
|
+
date >= event.start_date && date <= event.end_date
|
46
77
|
end
|
47
78
|
end
|
48
79
|
end
|