Skip to content

Commit 2942bac

Browse files
committed
Added pop-up datepicker (click calendar icon in top-left corner of calendars in the demo). Various fixes to ensure that events are correctly retrieved from the Resource objects.
1 parent 07fab6c commit 2942bac

File tree

8 files changed

+72
-22
lines changed

8 files changed

+72
-22
lines changed

css/rc_calendar.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@
7676

7777
.col_7dayweek {
7878
float: left;
79-
width: col_7days_width;
79+
width: 84px;
8080
border: 1px solid #cccccc;
81+
border-left: none;
8182
overflow: hidden;
8283
position: relative; }
8384

css/test.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@
4141
text-align: center;
4242
padding: 1px 3px;
4343
margin: 2px; }
44+
45+
.calimg {
46+
height: 1em;
47+
width: auto;
48+
margin-left: 14px; }

img/CalendarIcon.gif

6.16 KB
Loading

js/rc_calendar.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var defaults = {
88
// view-specific settings
9+
startdate : new moment().valueOf(),
910
render : 'view_week',
1011
render_event : 'view_week_render_event',
1112
get_time_offset : function( evt, ui ){return ui.offset.top - evt.target.offsetTop;},
@@ -60,7 +61,7 @@
6061
var element = $(_element);
6162
var calendar = new Calendar( element, options );
6263
element.data('rc_Calendar', calendar);
63-
calendar.render(1375293414903);
64+
calendar.render( options.startdate );
6465
calendar.initialize_events();
6566
});
6667

@@ -157,7 +158,7 @@ function Calendar( element, options )
157158
t.resources[resource_id],
158159
{
159160
start : start_time,
160-
date : date,
161+
date : date.valueOf(),
161162
duration : t.options.default_duration,
162163
ev_type : dragged.attr('data-evtype'),
163164
ev_text : dragged.text(),
@@ -343,6 +344,17 @@ function Calendar( element, options )
343344
}
344345

345346
t.element.append( render_week( params ) );
347+
348+
// show all known events for this resource
349+
for(var i = 0; i < params.col_count; i++ ) {
350+
var todays_events = resource.listEvents(params.dates[i]);
351+
352+
if( undefined != todays_events ){
353+
for( var j in todays_events) {
354+
t[t.options.render_event]( todays_events[j] );
355+
}
356+
}
357+
}
346358
}
347359

348360
}
@@ -393,7 +405,7 @@ function rc_EventManager( retrieve_events, save_event, delete_event, resources,
393405
for( var i in t.Events ) {
394406
var evt = t.Events[i];
395407
if( undefined != resources[evt.attr.resource] ) {
396-
resources[evt.attr.resource].addEvent( evt );
408+
resources[evt.attr.resource].addEvent( evt, 'no_confirm' );
397409
render( evt );
398410
}
399411
else {
@@ -428,7 +440,7 @@ function rc_EventManager( retrieve_events, save_event, delete_event, resources,
428440
var stash = evt.attr;
429441

430442
evt.attr.start = options.start;
431-
evt.attr.date = options.date;
443+
evt.attr.date = options.date.valueOf;
432444
evt.attr.t_offset= options.t_offset;
433445

434446

@@ -495,7 +507,7 @@ function Resource( resource_element, init_mode ) {
495507
// To optimize searching and drawing times, events are grouped
496508
// by date (each event has 'midnight' at the start of the day encoded within it)
497509
//
498-
t.eventpool = [];
510+
t.eventpool = {};
499511

500512
t.id = resource_element.attr('id');
501513

@@ -504,7 +516,6 @@ function Resource( resource_element, init_mode ) {
504516
{
505517
case 'localtest': {
506518
t.attr = init_resource[t.id];
507-
//t.eventpool = init_resource_events[t.id];
508519
break;
509520
}
510521

@@ -533,11 +544,14 @@ function Resource( resource_element, init_mode ) {
533544
// "Reasons" are application specific and are registered as callbacks read from the
534545
// resource declaration
535546
//
547+
// no_confirm parameter allows known events to be populated on page load without
548+
// causing "success" notifications to be generated
549+
//
536550
// returns
537551
// true : could add the event
538552
// false: unable to add the event
539553
//
540-
t.addEvent = function( event ){
554+
t.addEvent = function( event, no_confirm ){
541555
if( reason = t.attr.validateFn( event.attr, t.attr.validateParams ) ) {
542556
rc_notify('Unable to add the event','The '+reason+' requirement was not met', 'error');
543557
return false;
@@ -554,23 +568,29 @@ function Resource( resource_element, init_mode ) {
554568

555569
t.eventpool[event.attr.date][event.attr.id] = event;
556570

557-
var formatted_date = new moment( event.attr.date ).format("dddd, Do MMM YYYY");
558-
559-
rc_notify('Success',
560-
'Added '+event.attr.ev_text+' to '+t.attr.title+' at '+event.attr.start+' on '+formatted_date,
561-
'success');
571+
if( undefined == no_confirm ){
572+
var formatted_date = new moment( event.attr.date ).format("dddd, Do MMM YYYY");
573+
574+
rc_notify('Success',
575+
'Added '+event.attr.ev_text+' to '+t.attr.title+' at '+event.attr.start+' on '+formatted_date,
576+
'success');
577+
}
562578
}
563579
return true;
564580
}
565581

566-
t.removeEvent = function( event ){
567-
t.eventpool[event.attr.date][event.attr.id] = undefined;
582+
t.removeEvent = function( evt ){
583+
t.eventpool[evt.attr.date][evt.attr.id] = undefined;
584+
}
585+
586+
t.listEvents = function( date ){
587+
return t.eventpool[date];
568588
}
569589

570590
//t.findCollisions = function( event )
571591

572592
return t;
573-
}
593+
}
574594

575595
}(jQuery))
576596

sass/rc_calendar.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ $col_7days_width : 595/7 - 1px;
9898

9999
.col_7dayweek {
100100
float:left;
101-
width:col_7days_width;
101+
width:$col_7days_width;
102102
border:1px solid #ccc;
103+
border-left:none;
103104
overflow:hidden;
104105
position:relative;
105106
}

sass/test.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@
4848
text-align:center;
4949
padding:1px 3px;
5050
margin:2px;
51-
}
51+
}
52+
53+
.calimg{
54+
height:1em;
55+
width:auto;
56+
margin-left:14px;
57+
}

templates/week.template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ var render_week = doT.template((function(){/*
1515
<span class='rc_name'>{{=it.resource_name}}</span>
1616
<span class='rc_location'>{{=it.resource_location}}</span>
1717
</div>
18-
<div class="rc_headerweek"><div class="rc_gutter">&nbsp;</div>
18+
<div class="rc_headerweek"><div class="rc_gutter" style='relative'>
19+
<img src='img/CalendarIcon.gif' alt='click here to change date range' class='calimg'/>
20+
</div>
1921
{{ for(var i = 0; i < it.col_count; i++ ) { }}
2022
<div class="{{=it.col_class}}">{{=it.dows[i]+' '+it.months[i]+'/'+it.days[i]}}</div>
2123
{{ } }}
@@ -52,6 +54,7 @@ var render_week = doT.template((function(){/*
5254
{{ } }}
5355
</div>
5456
</div>
57+
{{ $('.calimg').click(function(){ $(this).datepicker( "dialog", {{= it.baseDate }}, dateSelect ) }); }}
5558
*/}).heredoc());
5659

5760

test.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,25 @@ <h3>Resource Calendar</h3>
158158
}
159159

160160

161+
//
162+
// This function is needed as a callback when the user clicks on a new
163+
// date using a datepicker dialog. The callback mechanism doesn't let
164+
// us conveniently patch through to the current calendar without exposing
165+
// a lot of internals to the template system.
166+
//
167+
// We can revisit this at a later date.
168+
//
169+
function dateSelect( date, selector )
170+
{
171+
$('.calendar').empty();
172+
$('.calendar').rc_calendar( 'render', moment(date).valueOf() );
173+
}
174+
161175
$(document).ready(function() {
162176
$('.calendar').rc_calendar({
163-
persist: saveEvent,
164-
retrieve: loadEvents,
165-
remove: removeEvent
177+
persist : saveEvent,
178+
retrieve : loadEvents,
179+
remove : removeEvent,
166180
});
167181
$('.calendar').rc_calendar( 'external_events_init', $('.in_palette') );
168182
});

0 commit comments

Comments
 (0)