Skip to content

Commit 9cd736f

Browse files
committed
Added support for scrollable calendars. Started adding support for insert policies
1 parent 979bba1 commit 9cd736f

File tree

6 files changed

+77
-11
lines changed

6 files changed

+77
-11
lines changed

css/test.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
.rc_bodyweek {
2+
height: 400px;
3+
overflow-y: scroll;
4+
overflow-x: hidden; }
5+
16
.calendar {
27
margin-left: 180px; }
38

js/rc_calendar.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
startdate : new moment().valueOf(),
1010
render : 'view_week',
1111
render_event : 'view_week_render_event',
12-
get_time_offset : function( evt, ui ){return ui.offset.top - evt.target.offsetTop;},
12+
get_time_offset : function( evt, ui ){return ui.offset.top + $(evt.target).parent().scrollTop() - evt.target.offsetTop;},
1313

1414
// persistent event storage accessor functions
1515
// (override with application functions in rc_calendar constructor call)
1616
persist : function( evt ){},
1717
retrieve : function(){ return [] },
1818
remove : function(){},
1919

20+
// default insert_policy is simple - allow overlaps:
21+
insert_policy : function( event_list, evt ){event_list[evt.attr.id] = evt;},
22+
2023
min_time : '07:00', // 7am
2124
max_time : '20:00', // 8pm
2225
interval : 20, // minutes
@@ -112,7 +115,7 @@ function Calendar( element, options )
112115
//
113116
t.resources = [];
114117
element.find('resource').each( function(i,element) {
115-
t.resources[$(this).attr('id')] = new Resource($(this),'localtest');
118+
t.resources[$(this).attr('id')] = new Resource( $(this), t.options.insert_policy );
116119
});
117120

118121
t.initialize_events = function(){
@@ -240,6 +243,12 @@ function Calendar( element, options )
240243
helper : 'clone',
241244
zIndex : 9999,
242245
/* drag : function( event, ui ){
246+
247+
// [TODO]
248+
// Update Time in helper during drag
249+
// Add "next week, previous week" drag zones?
250+
//
251+
243252
var time_offset = t.options.get_time_offset( event, ui );
244253
var start_time = nearest_time( time_offset );
245254
ui.helper.find(".rc_event_head").text(start_time);
@@ -498,8 +507,16 @@ function rc_EventManager( retrieve_events, save_event, delete_event, resources,
498507
// 3: live Ajax + localStorage for offline working
499508

500509

510+
//
511+
// [TODO] - register per-day availability times for each resource
512+
// This accommodates different open/close times on different days, or
513+
// worker shifts, or holiday/vacation times.
514+
//
515+
// Implement regular hours function, and specific overrides
516+
//
517+
501518

502-
function Resource( resource_element, init_mode ) {
519+
function Resource( resource_element, insert_policy ) {
503520
var t = this;
504521

505522
//
@@ -509,6 +526,7 @@ function Resource( resource_element, init_mode ) {
509526
t.eventpool = {};
510527

511528
t.id = resource_element.attr('id');
529+
t.insert_policy = insert_policy;
512530
t.attr = $.parseJSON(resource_element.attr('data-attr'));
513531

514532
//
@@ -547,15 +565,14 @@ function Resource( resource_element, init_mode ) {
547565
}
548566
else {
549567

550-
// [TODO - add in policy code for overlapping events, locked events]
551-
552-
553-
554568
if( "undefined" == typeof( t.eventpool[event.attr.date] ) ){
555569
t.eventpool[event.attr.date] = [];
556570
}
557571

558-
t.eventpool[event.attr.date][event.attr.id] = event;
572+
//
573+
// Policy code for overlapping events, locked events
574+
//
575+
t.insert_policy( t.eventpool[event.attr.date], event );
559576

560577
if( undefined == no_confirm ){
561578
var formatted_date = new moment( event.attr.date ).format("dddd, Do MMM YYYY");

js/rc_utilities.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,23 @@ function confirm(message, callback, param) {
255255
$('#confirm').remove();
256256
}
257257
});
258-
}
258+
}
259+
260+
261+
//
262+
// insert_shuffle_meeting
263+
// ======================
264+
// This is an example callback function that is called when an event is dropped onto
265+
// a resource calendar day. Parameters are a list of all events for that resource on
266+
// that day, the event that has been dropped onto the calendar,
267+
///?????and the function that
268+
// is called to rerender moved events.?????
269+
//
270+
// This example attempts to insert the new event; if the new event overlaps an earlier
271+
// event, then it is bumped forward to the end of the existing meeting. Any existing
272+
// meetings starting at or after the new meeting are bumped forward, with gaps between
273+
// meetings being reduced to minimize disruptions to existing meetings.
274+
//
275+
// The insert will fail if it would require a locked meeting to be bumped, or if a moved
276+
// meeting would be pushed beyond the end-of-day for the calendar.
277+
//

sass/test.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
.rc_bodyweek{
2+
height: 400px;
3+
overflow-y:scroll;
4+
overflow-x:hidden;
5+
}
6+
7+
18
.calendar {
29
margin-left:180px;
310
}

templates/week.template.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var render_week = doT.template((function(){/*
2121
{{ for(var i = 0; i < it.col_count; i++ ) { }}
2222
<div class="{{=it.col_class}}">{{=it.dows[i]+' '+it.months[i]+'/'+it.days[i]}}</div>
2323
{{ } }}
24-
<div class="rc_bodyweek" id='{{=it.resource_id}}'>
24+
</div>
25+
<div class="rc_bodyweek clearfix" id='{{=it.resource_id}}'>
2526
<div class="rc_gutter">
2627
{{var hrcount =0; var t = it.min_time; do { }}
2728
<div class='rc_hour_slot'>{{=t}}</div>
@@ -54,7 +55,10 @@ var render_week = doT.template((function(){/*
5455
{{ } }}
5556
</div>
5657
</div>
57-
{{ $('.calimg').click(function(){ $(this).datepicker( "dialog", {{= it.baseDate }}, dateSelect ) }); }}
58+
{{
59+
$('.calimg').click(function(){ $(this).datepicker( "dialog", {{= it.baseDate }}, dateSelect ) });
60+
}}
61+
5862
*/}).heredoc());
5963

6064

test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,22 @@ <h3>Resource Calendar</h3>
189189
remove : removeEvent,
190190
});
191191
$('.calendar').rc_calendar( 'external_events_init', $('.in_palette') );
192+
193+
// expand width of containers to accommodate pesky scrollbar
194+
// this is specific to the template used in the test system, but the techniques used
195+
// may be useful in similar templates where the calendar is scrollable
196+
var first_week = $('.rc_bodyweek').first();
197+
var days = $(first_week).find('.rc_day_target');
198+
var first = $(days).first();
199+
var last = $(days).last();
200+
var retries = 5;
201+
while( --retries && $(first).offset().top != $(last).offset().top ){
202+
$('.rc_week').animate({width: "+=10px"});
203+
}
204+
192205
});
193206

207+
194208
</script>
195209
</body>
196210
</html>

0 commit comments

Comments
 (0)