Skip to content

Commit 9d963bd

Browse files
committed
Added application callback for resource availability / opening times
1 parent b9c5885 commit 9d963bd

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

css/rc_calendar.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111

1212
.rc_day_target {
1313
overflow: auto; }
14+
.rc_day_target .pre_day {
15+
position: absolute;
16+
top: 0;
17+
width: 100%;
18+
background: rgba(0, 0, 0, 0.1); }
19+
.rc_day_target .post_day {
20+
position: absolute;
21+
bottom: 0;
22+
width: 100%;
23+
background: rgba(0, 0, 0, 0.1); }
1424

1525
.rc_event {
1626
width: 99%;

js/rc_calendar.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
render_event : 'view_week_render_event',
3131
postcalrender : function(){},
3232

33+
// get_time_offset calculates distance in pixels of booking from start-of-day
3334
get_time_offset : function( draggable, droppable ){
3435
return draggable.offset.top - droppable.offset().top;
3536
},
@@ -45,6 +46,9 @@
4546

4647
min_time : '07:00', // 7am
4748
max_time : '20:00', // 8pm
49+
50+
get_open_time : function( date_ms, resource ){ return ['07:00','20:00']; },
51+
4852
interval : 20, // minutes
4953
intervalpixels : 24,
5054
weekends : false,
@@ -386,11 +390,14 @@ function Calendar( element, options )
386390
// Called during dragging and on drop, this function returns the id of a div beneath
387391
// the draggable object, if that div is visible and a droppable target.
388392
//
393+
// [TODO - problem dragging new event onto scrolled Narwhal, ends up in Orca]
394+
//
389395
function findDroppable( ui )
390396
{
391397
retval = false;
398+
var pos = ui.offset;
392399

393-
// [TODO] should cache this selection...
400+
// [TODO] should probably cache this selection...
394401
$('.ui-droppable').each(function(){
395402

396403
var parent = $(this).parent();
@@ -399,8 +406,6 @@ function Calendar( element, options )
399406
var viewableTop = parent.position().top + adjust_scroll;
400407
var viewableBottom = viewableTop + parent.height() + adjust_scroll;
401408

402-
var pos = ui.position;
403-
404409
if( pos.top > viewableTop &&
405410
pos.top < viewableBottom &&
406411
(pos.left + 20) > $(this).position().left &&
@@ -421,6 +426,8 @@ function Calendar( element, options )
421426
params.months = [];
422427
params.dows = [];
423428
params.dates = [];
429+
params.opentime = [];
430+
params.closetime = [];
424431
params.min_time = t.options.min_time;
425432
params.max_time = t.options.max_time;
426433
params.inc_time = t.options.interval;
@@ -443,6 +450,11 @@ function Calendar( element, options )
443450
//--- header ---
444451
for(var i = 0; i < params.col_count; i++ ) {
445452
params.dates[i] = dcalc.valueOf();
453+
454+
var openclose = t.options.get_open_time( params.dates[i], resource );
455+
params.opentime[i] = ((diffMinutes_timeOfDay( t.options.min_time, openclose[0] )/ t.options.interval) * t.options.intervalpixels);
456+
params.closetime[i] = ((diffMinutes_timeOfDay( openclose[1], params.max_time )/ t.options.interval) * t.options.intervalpixels);
457+
446458
params.dows[i] = t.options.days[ (i+t.options.startweek) % 7 ];
447459
params.months[i]= (1+dcalc.getMonth());
448460
params.days[i] = dcalc.getDate();

sass/rc_calendar.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ $col_7days_width : 595/7 - 1px;
3030

3131
.rc_day_target {
3232
overflow:auto;
33+
.pre_day{
34+
position:absolute;
35+
top:0;
36+
width:100%;
37+
background:rgba(0,0,0,0.1);
38+
}
39+
.post_day{
40+
position:absolute;
41+
bottom:0;
42+
width:100%;
43+
background:rgba(0,0,0,0.1);
44+
}
3345
}
3446

3547

test.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ <h3>Resource Calendar</h3>
183183

184184
{{ for(var i = 0; i < it.col_count; i++ ) { }}
185185
<div class="rc_day_target {{=it.col_class}}" id="{{= it.resource_name+'_'+it.months[i]+'_'+it.days[i] }}" data-date="{{=it.dates[i]}}">
186+
<div class="pre_day" style="height:{{=it.opentime[i]}}px"></div>
187+
<div class="post_day" style="height:{{=it.closetime[i]}}px"></div>
186188
{{ for(var j = 0; j < hrcount; j++ ) { }}
187189
{{? it.inc_time == 15 }}
188190
<div class="rc_quarters_slot"></div>
@@ -335,12 +337,35 @@ <h3>Resource Calendar</h3>
335337
$('.calendar').rc_calendar( 'render', moment(date).valueOf() );
336338
}
337339

340+
//
341+
// This function returns the opening and closing times for any given date
342+
// and resource (resources may have different availability, but this isn't
343+
// shown in the example). In a real system this would be a server AJAX call,
344+
// which would include a lookup for holidays, vacations and company shutdowns
345+
//
346+
function openTimes( date_ms, resource )
347+
{
348+
var times = [
349+
['10:00','16:30'],
350+
['09:00','18:30'],
351+
['08:00','19:00'],
352+
['10:00','18:00'],
353+
['08:00','19:00'],
354+
['08:00','20:00'],
355+
['09:30','18:30']
356+
];
357+
var d = new Date( date_ms );
358+
return times[d.getDay()];
359+
}
360+
361+
338362
$(document).ready(function() {
339363
$('.calendar').rc_calendar({
340364
persist : saveEvent,
341365
retrieve : loadEvents,
342366
remove : removeEvent,
343-
postcalrender : adjust_calendar_width,
367+
postcalrender : adjust_calendar_width,
368+
get_open_time : openTimes,
344369
});
345370
$('.calendar').rc_calendar( 'external_events_init', $('.in_palette') );
346371
});

0 commit comments

Comments
 (0)