caboose-cms 0.4.110 → 0.4.111

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTBjODNmMjE5YzM2OTc1YzdlNzQwNGUzYmFmN2RkYzdjNTk1MTRhMA==
4
+ ZDllZmVlZTkzZTkxYTM2ZGFiN2UxYjkwMGQwZTZhNTEwOTVjNDhiMA==
5
5
  data.tar.gz: !binary |-
6
- NDc1ZGI2MmNlZTA1NTkxYWExYTEyYzEzMmE1M2Y5NjZiMDk2ZDBhNA==
6
+ MTE3Yzk2MTM0MDhhMGFiY2NlMDI5MDM0ZmY0YjJlZDUwYzc5NDhkMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWM4YzA4ZmE0ZmI4NzczMWI1NWEzY2NlODVlMjQ5ZmYxMjA4MWEwMzE3MDE2
10
- YTU5ODgyNzk3NTc5YjU2NTdjNzNhZDkyOGVmODBmZmZjYWNiYzM1N2Q4MGVj
11
- NGM5ZWUyMzRhNjM3NTFiMTg2YmFiYzI3MTk2YmY2MDk4ZmMwMjA=
9
+ MTdlNmZiYzU3MWU5N2I5ZGI5YjE3NDVkNTBlOGFhNjU4MmE0NjBiOGNiMmEy
10
+ MzQ5ZDg0MzBjNmI5ZWI0NmI3ZGZhY2VhM2RjZDJiYWI2M2YwOGEwY2JlOGU1
11
+ Zjk3ZWQyYWUxYTk4MDZmMjVkMzcwNGM4MTA3NDIwZTE5NzQyMDM=
12
12
  data.tar.gz: !binary |-
13
- NDMzMzQ4OTk1ZTViYzYxZDQ4ZmVhNGNlZmFkZmViYjE3NjczZWVhOWZlNzEx
14
- OTM3ZjAxNDc2ZWFlYzAyY2MyZWRiMzRhMjI0OTY2ZmZhYWI0MTljZDk5MTAy
15
- NWM2ZGNlNTVjYTljNmQ1ZjBkNjhkODAyOTExYWJhZTU1Zjc4NzA=
13
+ NTU4NzcxOTZkZGEyY2RmMGI1OGY2NGIxMjNlOGFjMGM3YzYyZGYyNzNjNTgz
14
+ N2U0OGM2NWY5YjM1ZDQyMzBlMjc3MTlhYTJkYjZkOGZlNDQ3NTE3Nzk3MDZh
15
+ ZTNkZTRiMjIxNDY1ZWE1OGFkODAwYjlkNGVhMmNiZDllZTdhZWM=
@@ -4,69 +4,38 @@ module Caboose
4
4
 
5
5
  helper :application
6
6
 
7
- # GET /admin/calendars/:calendar_id/events/:id
8
- def admin_edit
9
- return unless user_is_allowed('calendars', 'edit')
10
- @event = CalendarEvent.find(params[:id])
11
- render :layout => 'caboose/modal'
12
- end
13
-
14
- # GET /admin/calendars/:calendar_id/events/new
15
- def admin_new
16
- return unless user_is_allowed('calendars', 'edit')
17
- @calendar = Calendar.find(params[:calendar_id])
18
- @begin_date = DateTime.iso8601(params[:begin_date])
19
- render :layout => 'caboose/modal'
20
- end
21
-
22
- # PUT /admin/calendars/:calendar_id/events/:id
7
+ # PUT /admin/calendars/:calendar_id/event-groups/:id
23
8
  def admin_update
24
9
  return unless user_is_allowed('calendars', 'edit')
25
10
 
26
11
  resp = StdClass.new
27
- event = CalendarEvent.find(params[:id])
12
+ g = CalendarEventGroup.find(params[:id])
28
13
 
29
14
  save = true
30
15
  params.each do |name, value|
31
16
  case name
32
- when 'name' then event.name = value
33
- when 'description' then event.description = value
17
+ when 'frequency' then g.frequency = value
18
+ when 'period' then g.period = value
19
+ when 'repeat_by' then g.repeat_by = value
20
+ when 'sun' then g.sun = value
21
+ when 'mon' then g.mon = value
22
+ when 'tue' then g.tue = value
23
+ when 'wed' then g.wed = value
24
+ when 'thu' then g.thu = value
25
+ when 'fri' then g.fri = value
26
+ when 'sat' then g.sat = value
27
+ when 'date_start' then g.date_start = DateTime.strptime(value, '%m/%d/%Y').to_date
28
+ when 'repeat_count' then g.repeat_count = value
29
+ when 'date_end' then g.date_end = DateTime.strptime(value, '%m/%d/%Y').to_date
34
30
  end
35
31
  end
32
+ g.save
33
+ g.create_events
36
34
 
37
- resp.success = save && event.save
38
- render :json => resp
39
- end
40
-
41
- # POST /admin/calendars/:calendar_id/events
42
- def admin_add
43
- return unless user_is_allowed('calendars', 'edit')
44
-
45
- resp = StdClass.new
46
- event = CalendarEvent.new
47
- event.calendar_id = params[:calendar_id]
48
- event.name = params[:name]
49
- event.begin_date = DateTime.iso8601("#{params[:begin_date]}T10:00:00-05:00")
50
- event.end_date = DateTime.iso8601("#{params[:begin_date]}T10:00:00-05:00")
51
- event.all_day = true
52
-
53
- if event.name.nil? || event.name.strip.length == 0
54
- resp.error = "Please enter an event name."
55
- else
56
- event.save
57
- resp.redirect = "/admin/calendars/#{event.calendar_id}/events/#{event.id}"
58
- end
59
- render :json => resp
60
- end
61
-
62
- # DELETE /admin/calendars/:id
63
- def admin_delete
64
- return unless user_is_allowed('calendars', 'delete')
65
- Calendar.find(params[:id]).destroy
66
- resp = StdClass.new({ 'redirect' => "/admin/calendars" })
35
+ resp.success = true
67
36
  render :json => resp
68
37
  end
69
-
38
+
70
39
  # GET /admin/event-groups/period-options
71
40
  def admin_period_options
72
41
  render :json => [
@@ -64,13 +64,13 @@ module Caboose
64
64
  event.begin_date = DateTime.strptime("#{value} #{t}", '%m/%d/%Y %H:%M %z')
65
65
  when 'begin_time'
66
66
  d = event.begin_date ? event.begin_date.strftime('%Y-%m-%d') : DateTime.now.strftime('%Y-%m-%d')
67
- event.begin_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %H:%M %z')
67
+ event.begin_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %I:%M %P')
68
68
  when 'end_date'
69
69
  t = event.end_date ? event.end_date.strftime('%H:%M %z') : '10:00 -0500'
70
70
  event.end_date = DateTime.strptime("#{value} #{t}", '%m/%d/%Y %H:%M %z')
71
71
  when 'end_time'
72
72
  d = event.end_date ? event.end_date.strftime('%Y-%m-%d') : DateTime.now.strftime('%Y-%m-%d')
73
- event.end_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %H:%M %z')
73
+ event.end_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %I:%M %P')
74
74
  when 'repeats'
75
75
  g = event.calendar_event_group
76
76
  if value == true || value.to_i == 1
@@ -12,15 +12,31 @@ module Caboose
12
12
  :location ,
13
13
  :begin_date ,
14
14
  :end_date ,
15
- :all_day
15
+ :all_day ,
16
+ :repeats
16
17
 
17
18
  def self.events_for_day(calendar_id, d)
18
19
  q = ["calendar_id = ?
19
- and concat(date_part('year', begin_date),date_part('month', begin_date),date_part('day', begin_date)) <= ?
20
- and concat(date_part('year', end_date ),date_part('month', end_date ),date_part('day', end_date )) >= ?",
21
- calendar_id, d.strftime('%Y%m%d'), d.strftime('%Y%m%d')]
20
+ and cast(begin_date as date) <= ?
21
+ and cast(end_date as date) >= ?",
22
+ calendar_id, d.to_date, d.to_date]
22
23
  self.where(q).reorder(:begin_date).all
23
24
  end
25
+
26
+ def duplicate(d)
27
+ e = CalendarEvent.create(
28
+ :calendar_id => self.calendar_id,
29
+ :calendar_event_group_id => self.calendar_event_group_id,
30
+ :name => self.name,
31
+ :description => self.description,
32
+ :location => self.location,
33
+ :begin_date => d,
34
+ :end_date => d + (self.end_date - self.begin_date).seconds,
35
+ :all_day => self.all_day,
36
+ :repeats => self.repeats
37
+ )
38
+ return e
39
+ end
24
40
 
25
41
  end
26
42
  end
@@ -26,5 +26,96 @@ module Caboose
26
26
  REPEAT_BY_DAY_OF_MONTH = 'Day of month'
27
27
  REPEAT_BY_DAY_OF_WEEK = 'Day of week'
28
28
 
29
+ def create_events
30
+ return if self.date_start.nil?
31
+ return if self.date_end.nil?
32
+ return if self.date_end < self.date_start
33
+
34
+ e = self.calendar_events.reorder(:begin_date).first
35
+ return if e.nil?
36
+
37
+ dates = [e.begin_date.to_date]
38
+ if self.period == 'Day'
39
+ d = self.date_start
40
+ while d <= self.date_end
41
+ if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
42
+ e.duplicate(d)
43
+ dates << d.to_date
44
+ end
45
+ d = d + 1.day
46
+ end
47
+
48
+ elsif self.period == 'Week'
49
+
50
+ d = self.date_start - self.date_start.strftime('%w').to_i.days
51
+ while d <= self.date_end
52
+ (0..6).each do |i|
53
+ d = d + 1
54
+ Caboose.log("d = #{d}")
55
+ next if d < self.date_start
56
+ break if d > self.date_end
57
+ w = d.strftime('%w').to_i
58
+ if (w == 0 && self.sun) || (w == 1 && self.mon) || (w == 2 && self.tue) || (w == 3 && self.wed) || (w == 4 && self.thu) || (w == 5 && self.fri) || (w == 6 && self.sat)
59
+ Caboose.log("Found a day")
60
+ if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
61
+ e.duplicate(d)
62
+ dates << d.to_date
63
+ end
64
+ end
65
+ end
66
+ d = d + (self.frequency-1).weeks
67
+ end
68
+
69
+ elsif self.period == 'Month'
70
+ d = self.date_start
71
+ if self.repeat_by == self::REPEAT_BY_DAY_OF_MONTH
72
+ while d <= self.date_end
73
+ if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
74
+ e.duplicate(d)
75
+ dates << d.to_date
76
+ end
77
+ d = d + self.frequency.months
78
+ end
79
+ elsif self.repeat_by == self::REPEAT_BY_DAY_OF_WEEK
80
+
81
+ #d0 = DateTime.new(d.strftime('%Y'), d.strftime('%m'), 1)
82
+ #w = d0.strftime('%w').to_i
83
+ #i = 0
84
+ #while d0 <= d
85
+ # i = i + 1 if d0.strftime('%w').to_i == w
86
+ # d0 = d0 + 1.day
87
+ #end
88
+ #
89
+ ## Now set the i'th occurance of the w day of the week
90
+ #d = DateTime.new(d.strftime('%Y'), d.strftime('%m'), 1)
91
+ #while d <= self.date_end
92
+ # d0 = d
93
+ # while d
94
+ #
95
+ #
96
+ # if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
97
+ # CalendarEvent.duplicate(d)
98
+ # end
99
+ # d = d + self.frequency.months
100
+ #end
101
+
102
+ end
103
+
104
+ elsif self.period == 'Year'
105
+ d = self.date_start
106
+ while d <= self.date_end
107
+ if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
108
+ e.duplicate(d)
109
+ dates << d.to_date
110
+ end
111
+ d = d + 1.year
112
+ end
113
+
114
+ end
115
+
116
+ # Get rid of events that shouldn't be in the group
117
+ CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) not in (?)", self.id, dates).destroy_all
118
+
119
+ end
29
120
  end
30
121
  end
@@ -31,7 +31,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
31
31
  Caboose::User => [:timezone],
32
32
  #Caboose::Field => [:child_block_id],
33
33
  Caboose::BlockType => [:layout_function],
34
- Caboose::CalendarEventGroup => [
34
+ Caboose::CalendarEvent => [
35
35
  :repeat_period ,
36
36
  :repeat_sun ,
37
37
  :repeat_mon ,
@@ -42,6 +42,18 @@ class Caboose::Schema < Caboose::Utilities::Schema
42
42
  :repeat_sat ,
43
43
  :repeat_start ,
44
44
  :repeat_end
45
+ ],
46
+ Caboose::CalendarEventGroup => [
47
+ :repeat_period ,
48
+ :repeat_sun ,
49
+ :repeat_mon ,
50
+ :repeat_tue ,
51
+ :repeat_wed ,
52
+ :repeat_thu ,
53
+ :repeat_fri ,
54
+ :repeat_sat ,
55
+ :repeat_start ,
56
+ :repeat_end
45
57
  ]
46
58
  }
47
59
  end
@@ -37,7 +37,7 @@
37
37
  <% events = Caboose::CalendarEvent.events_for_day(@calendar.id, d) %>
38
38
  <% if events.count > 0 %>
39
39
  <ul>
40
- <% events.each do |ev| %><li><%= ev.name %></li><% end %>
40
+ <% events.each do |ev| %><li><a href='/admin/calendars/<%= @calendar.id %>/events/<%= ev.id %>' class='event_link'><%= ev.name %></a></li><% end %>
41
41
  </ul>
42
42
  <% end %>
43
43
  </td>
@@ -76,12 +76,19 @@ $(document).ready(function() {
76
76
  .mouseout(function(e) { $(this).removeClass('over'); })
77
77
  .click(function(e) {
78
78
  e.preventDefault();
79
+ e.stopPropagation();
79
80
  if (!$(this).hasClass('blank'))
80
81
  {
81
82
  var d = $(this).attr('id').replace('day_', '');
82
83
  caboose_modal_url('/admin/calendars/<%= @calendar.id %>/events/new?begin_date=' + d);
83
84
  }
84
85
  });
86
+ $('#calendar td a.event_link')
87
+ .click(function(e) {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ caboose_modal_url($(this).attr('href'));
91
+ });
85
92
  });
86
93
 
87
94
  function delete_calendar(calendar_id, confirm)
@@ -114,10 +121,14 @@ function delete_calendar(calendar_id, confirm)
114
121
 
115
122
  #calendar table { border-collapse: collapse; width: 95%; }
116
123
  #calendar th { border: #666 1px solid; background: #666; color: #fff; margin: 0; padding: 4px 8px; }
117
- #calendar td { border: #666 1px solid; position: relative; margin: 0; padding: 0; height: 100px; vertical-align: top; }
124
+ #calendar td { border: #666 1px solid; position: relative; margin: 0; padding: 0; width: 14%; height: 100px; vertical-align: top; }
118
125
  #calendar td.blank { background: #efefef; border: #666 1px solid; }
119
126
  #calendar td.over { background: #ffcc99; }
120
127
  #calendar td span.day { display: block; float: left; border-right: #666 1px solid; border-bottom: #666 1px solid; width: 20px; text-align: center; }
128
+ #calendar td ul { margin: 0; padding: 0; list-style: none; }
129
+ #calendar td ul li { margin: 0; padding: 0; list-style: none; }
130
+ #calendar td ul li a { display: block; }
131
+ #calendar td ul li a:hover { background: #fff; }
121
132
 
122
133
  </style>
123
134
  <% end %>
@@ -25,7 +25,7 @@ g = @event.calendar_event_group
25
25
  <div id='repeat_by_container' <% if g.repeat_by != Caboose::CalendarEventGroup::PERIOD_MONTH %>style='display: none;'<% end %>>
26
26
  <div id='calendareventgroup_<%= g.id %>_repeat_by' ></div>
27
27
  </div>
28
- <div id='week_container' <% if g.repeat_by != Caboose::CalendarEventGroup::PERIOD_WEEK %>style='display: none;'<% end %>>
28
+ <div id='week_container' <% if g.period != Caboose::CalendarEventGroup::PERIOD_WEEK %>style='display: none;'<% end %>>
29
29
  <table class='data'>
30
30
  <tr><th>S</th><th>M</th><th>T</th><th>W</th><th>R</th><th>F</th><th>S</th></tr>
31
31
  <tr>
@@ -59,7 +59,7 @@ g = @event.calendar_event_group
59
59
 
60
60
  var modal = false;
61
61
  $(window).ready(function() {
62
- modal = new CabooseModal(600);
62
+ modal = new CabooseModal(460);
63
63
  });
64
64
 
65
65
  $(document).ready(function() {
@@ -72,9 +72,9 @@ $(document).ready(function() {
72
72
  { name: 'name' , nice_name: 'Name' , type: 'text' , value: <%= raw Caboose.json(e.name ) %>, width: 430 },
73
73
  { name: 'description' , nice_name: 'Description' , type: 'textarea' , value: <%= raw Caboose.json(e.description ) %>, width: 430, height: 100 },
74
74
  { name: 'location' , nice_name: 'Location' , type: 'text' , value: <%= raw Caboose.json(e.location ) %>, width: 430 },
75
- { name: 'begin_date' , nice_name: 'Begin date' , type: 'date' , value: <%= raw Caboose.json(e.begin_date.strftime('%m/%d/%Y') ) %>, width: 200 },
75
+ { name: 'begin_date' , nice_name: 'Begin date' , type: 'date' , value: <%= raw Caboose.json(e.begin_date.strftime('%m/%d/%Y') ) %>, width: 200 , align: 'right' },
76
76
  { name: 'begin_time' , nice_name: 'Begin time' , type: 'time' , value: <%= raw Caboose.json(e.begin_date.strftime('%I:%M %P') ) %>, width: 200 , fixed_placeholder: false },
77
- { name: 'end_date' , nice_name: 'End date' , type: 'date' , value: <%= raw Caboose.json(e.end_date.strftime('%m/%d/%Y') ) %>, width: 200 },
77
+ { name: 'end_date' , nice_name: 'End date' , type: 'date' , value: <%= raw Caboose.json(e.end_date.strftime('%m/%d/%Y') ) %>, width: 200 , align: 'right' },
78
78
  { name: 'end_time' , nice_name: 'End time' , type: 'time' , value: <%= raw Caboose.json(e.end_date.strftime('%I:%M %P') ) %>, width: 200 , fixed_placeholder: false },
79
79
  { name: 'all_day' , nice_name: 'All day' , type: 'checkbox' , value: <%= raw e.all_day ? 1 : 0 %>, width: 100, after_update: after_all_day_update },
80
80
  { name: 'repeats' , nice_name: 'Repeats' , type: 'checkbox' , value: <%= raw e.repeats ? 1 : 0 %>, width: 100, after_update: after_repeats_update }
@@ -121,7 +121,7 @@ function delete_event(event_id, confirm)
121
121
  type: 'delete',
122
122
  success: function(resp) {
123
123
  if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
124
- if (resp.redirect) window.location = resp.redirect;
124
+ if (resp.redirect) modal.close();
125
125
  }
126
126
  });
127
127
  }
@@ -4,7 +4,7 @@
4
4
  <form action='/admin/calendars/<%= @calendar.id %>' method='post' id='new_event_form'>
5
5
  <input type='hidden' name='authenticity_token' value='<%= form_authenticity_token %>'>
6
6
  <input type='hidden' name='begin_date' value='<%= @begin_date.strftime('%Y-%m-%d') %>'>
7
- <p><input type='text' name='name' id='name' placeholder='Name' style='width: 500px;'></p>
7
+ <p><input type='text' name='name' id='name' placeholder='Name' style='width: 430px;'></p>
8
8
  <div id='message'></div>
9
9
  <p>
10
10
  <input type='button' value='Cancel' onclick="modal.close();" />
@@ -17,7 +17,7 @@
17
17
  <script type="text/javascript">
18
18
 
19
19
  $(window).load(function() {
20
- modal = new CabooseModal(600);
20
+ modal = new CabooseModal(460);
21
21
  });
22
22
 
23
23
  function add_event()
data/config/routes.rb CHANGED
@@ -220,11 +220,12 @@ Caboose::Engine.routes.draw do
220
220
  get "admin/calendars/:calendar_id/events/:id" => "events#admin_edit"
221
221
  put "admin/calendars/:calendar_id/events/:id" => "events#admin_update"
222
222
  post "admin/calendars/:calendar_id/events" => "events#admin_add"
223
- delete "admin/calendars/:calendar_id/events" => "events#admin_delete"
223
+ delete "admin/calendars/:calendar_id/events/:id" => "events#admin_delete"
224
224
 
225
- get "admin/event-groups/period-options" => "event_groups#admin_period_options"
226
- get "admin/event-groups/frequency-options" => "event_groups#admin_frequency_options"
227
- get "admin/event-groups/repeat-by-options" => "event_groups#admin_repeat_by_options"
225
+ put "admin/calendars/:calendar_id/event-groups/:id" => "event_groups#admin_update"
226
+ get "admin/event-groups/period-options" => "event_groups#admin_period_options"
227
+ get "admin/event-groups/frequency-options" => "event_groups#admin_frequency_options"
228
+ get "admin/event-groups/repeat-by-options" => "event_groups#admin_repeat_by_options"
228
229
 
229
230
  get "admin/ab-variants" => "ab_variants#admin_index"
230
231
  get "admin/ab-variants/new" => "ab_variants#admin_new"
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.4.110'
2
+ VERSION = '0.4.111'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.110
4
+ version: 0.4.111
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails