Skip to content

Commit e82b5fd

Browse files
committed
Added postrender callback for calendar rendering. In the test system this is used to extend the week
containers horizontally to accommodate the width of a scrollbar if necessary. Added datepicker to pop-up form, and added date_changed parameter to the rendering callback from the pop-up dialog handler "rc_event_edit"
1 parent 9cd736f commit e82b5fd

File tree

6 files changed

+103
-25
lines changed

6 files changed

+103
-25
lines changed

css/test.css

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
h1 {
2+
margin-left: 180px; }
3+
14
.rc_bodyweek {
25
height: 400px;
36
overflow-y: scroll;
@@ -8,9 +11,21 @@
811

912
.event_palette {
1013
position: fixed;
11-
top: 10px;
14+
top: 50px;
1215
left: 10px; }
1316

17+
.unassigned {
18+
top: 300px;
19+
background: #FFD;
20+
width: 160px;
21+
min-height: 180px;
22+
border: 1px solid #888800;
23+
text-align: center; }
24+
.unassigned h2 {
25+
font-size: 18px;
26+
margin: 0;
27+
padding: 0; }
28+
1429
.ip_spacing {
1530
margin: 4px; }
1631

@@ -59,3 +74,12 @@
5974
height: 1em;
6075
width: auto;
6176
margin-left: 14px; }
77+
78+
.pf-form .pf-heading {
79+
width: auto;
80+
height: 160px; }
81+
82+
.form_datepicker {
83+
font-size: 80%;
84+
position: absolute;
85+
left: 230px; }

js/rc_calendar.js

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

1416
// persistent event storage accessor functions
@@ -193,6 +195,9 @@ function Calendar( element, options )
193195
}
194196
}
195197
});
198+
199+
// let the application do any required post-render cleanup:
200+
t.options.postcalrender();
196201
}
197202

198203
t.view_week = function( date, resources )
@@ -205,14 +210,24 @@ function Calendar( element, options )
205210
}
206211

207212

208-
t.view_week_render_event = function( evt )
213+
t.view_week_render_event = function( evt, date_changed )
209214
// evt : event object
210215
{
211216
// Delete the old copy of this element if it exists
212217
if( $('#'+evt.attr.id).length) {
213218
$('#'+evt.attr.id).remove( );
214219
}
215220

221+
// find new parent if the date has changed
222+
if( date_changed ){
223+
$('#'+evt.attr.resource+' > .rc_day_target').each( function(){
224+
if( evt.attr.date == $(this).attr('data-date') ){
225+
evt.attr.parent = $(this).attr('id');
226+
return;
227+
}
228+
});
229+
}
230+
216231
var elapsed_mins= evt.attr.prep_time + evt.attr.duration + evt.attr.cleanup_time;
217232

218233
evt.attr.end = addMinutes_timeOfDay(
@@ -268,8 +283,8 @@ function Calendar( element, options )
268283
}
269284

270285
newev.click( function(){
271-
rc_event_edit( evt, function(evt){
272-
t.view_week_render_event(evt);
286+
rc_event_edit( evt, function(evt, date_changed){
287+
t.view_week_render_event(evt, date_changed);
273288
t.options.persist(evt);
274289
return false;
275290
});

js/rc_utilities.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ function rc_event_edit( evt, callback ) {
4646
styling: 'jqueryui'
4747
});
4848

49+
var datepick = notice.find('.form_datepicker');
50+
datepick.datepicker({defaultDate:new Date(evt.attr.date)});
51+
4952
// populate form fields
5053
notice.find('.pf-field').each( function(){
5154
var t = $(this);
@@ -63,6 +66,9 @@ function rc_event_edit( evt, callback ) {
6366

6467
notice.find('form.pf-form').submit(function() {
6568

69+
// recover date
70+
var old_date = evt.attr.date;
71+
evt.attr.date = datepick.datepicker("getDate").valueOf();
6672

6773
//!!!! [TO DO] Validate form here
6874

@@ -93,6 +99,7 @@ function rc_event_edit( evt, callback ) {
9399
});
94100

95101
// Close the form
102+
$('#nodupe-'+evt.attr.id).remove();
96103
notice.pnotify({
97104
title: 'Thank you',
98105
text: 'Record successfully updated',
@@ -105,7 +112,7 @@ function rc_event_edit( evt, callback ) {
105112
styling: 'jqueryui'
106113
});
107114

108-
return callback( evt ); // Rerender the event
115+
return callback( evt, evt.attr.date != old_date ); // Rerender the event
109116
});
110117
}
111118

sass/test.scss

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
h1{ margin-left:180px; }
2+
13
.rc_bodyweek{
24
height: 400px;
35
overflow-y:scroll;
@@ -11,10 +13,20 @@
1113

1214
.event_palette {
1315
position: fixed;
14-
top: 10px;
16+
top: 50px;
1517
left: 10px;
1618
}
1719

20+
.unassigned {
21+
top: 300px;
22+
h2 { font-size:18px; margin:0; padding:0; }
23+
background: #FFD;
24+
width:160px;
25+
min-height:180px;
26+
border: 1px solid #880;
27+
text-align:center;
28+
}
29+
1830
.ip_spacing{ margin:4px; }
1931

2032
.in_palette {
@@ -71,3 +83,14 @@
7183
width:auto;
7284
margin-left:14px;
7385
}
86+
87+
.pf-form .pf-heading{
88+
width:auto;
89+
height: 160px;
90+
}
91+
.form_datepicker{
92+
font-size:80%;
93+
position:absolute;
94+
left:230px;
95+
96+
}

templates/week.template.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,24 @@ var render_week = doT.template((function(){/*
6262
*/}).heredoc());
6363

6464

65-
66-
// Compiled on http://olado.github.io/doT/
67-
65+
//
66+
// This function is registered as "postcalrender", a callback to be executed
67+
// after every rerender of the calendars
68+
//
69+
function adjust_calendar_width()
70+
{
71+
// expand width of containers to accommodate pesky scrollbar
72+
// this is specific to the template used in the test system, but the techniques used
73+
// may be useful in similar templates where the calendar is scrollable
74+
var first_week = $('.rc_bodyweek').first();
75+
var days = $(first_week).find('.rc_day_target');
76+
var first = $(days).first();
77+
var last = $(days).last();
78+
var retries = 5;
79+
while( --retries && $(first).offset().top != $(last).offset().top ){
80+
$('.rc_week').animate({width: "+=10px"},0);
81+
}
82+
}
6883

6984
//
7085
// Template for an event in the calendar

test.html

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
<link rel="stylesheet" type="text/css" href="css/test.css">
1010
</head>
1111
<body>
12+
<h1>Resource Calendar Demo Page</h1>
1213
<div class='event_palette'>
1314
<div class='ip_spacing'><div class='rc_event client event in_palette' data-evtype='client' ><p>Client Meeting</p></div></div>
1415
<div class='ip_spacing'><div class='rc_event internal event in_palette' data-evtype='internal' ><p>Internal Meeting</p></div></div>
1516
<div class='ip_spacing'><div class='rc_event vendor event in_palette' data-evtype='vendor' ><p>Vendor Meeting</p></div></div>
1617
</div>
1718

19+
<div class='event_palette unassigned'>
20+
<h2>Unassigned Events</h2>
21+
</div>
22+
1823
<!-- This is a container class that will hold a calendar for each of the resources defined within it -->
1924
<div class='calendar'>
2025
<!-- Declare resources, set up validation function and parameters-->
@@ -42,6 +47,7 @@
4247
<!-- This form is displayed by Pine Notify when editing Event details -->
4348
<div id="form_event_edit" style="display: none;">
4449
<form class="pf-form pform_custom" action="" method="post">
50+
<div class='form_datepicker'></div>
4551
<div class="pf-element pf-heading">
4652
<h3>Resource Calendar</h3>
4753
<p>Edit event details here.</p>
@@ -184,24 +190,12 @@ <h3>Resource Calendar</h3>
184190

185191
$(document).ready(function() {
186192
$('.calendar').rc_calendar({
187-
persist : saveEvent,
188-
retrieve : loadEvents,
189-
remove : removeEvent,
193+
persist : saveEvent,
194+
retrieve : loadEvents,
195+
remove : removeEvent,
196+
postcalrender : adjust_calendar_width,
190197
});
191198
$('.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-
205199
});
206200

207201

0 commit comments

Comments
 (0)