Skip to content

Commit 68f5c42

Browse files
committed
Added support for 'unassigned events' stash
1 parent e82b5fd commit 68f5c42

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

js/rc_calendar.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function Calendar( element, options )
119119
element.find('resource').each( function(i,element) {
120120
t.resources[$(this).attr('id')] = new Resource( $(this), t.options.insert_policy );
121121
});
122+
t.resources['unassigned_event_resource'] = new Resource( $('#unassigned_event_resource'), function(){} );
122123

123124
t.initialize_events = function(){
124125
t.eventmanager = new rc_EventManager( t.options.retrieve,
@@ -197,7 +198,7 @@ function Calendar( element, options )
197198
});
198199

199200
// let the application do any required post-render cleanup:
200-
t.options.postcalrender();
201+
t.options.postcalrender( t );
201202
}
202203

203204
t.view_week = function( date, resources )
@@ -219,7 +220,8 @@ function Calendar( element, options )
219220
}
220221

221222
// find new parent if the date has changed
222-
if( date_changed ){
223+
// not a valid operation if the event is in the unassigned resource
224+
if( date_changed && "unassigned_event_resource" != evt.attr.resource ){
223225
$('#'+evt.attr.resource+' > .rc_day_target').each( function(){
224226
if( evt.attr.date == $(this).attr('data-date') ){
225227
evt.attr.parent = $(this).attr('id');
@@ -273,11 +275,14 @@ function Calendar( element, options )
273275
handles: 's',
274276

275277
stop: function( event, ui ){
276-
var snapheight = ~~(ui.size.height/t.options.intervalpixels);
278+
var snapheight = ~~((ui.size.height+(t.options.intervalpixels/2))/t.options.intervalpixels);
277279
var total_mins = snapheight*t.options.interval;
278280

279281
evt.attr.duration = total_mins - (evt.attr.prep_time + evt.attr.cleanup_time);
280282
ui.helper.css('height',snapheight * t.options.intervalpixels -2 + 'px');
283+
t.view_week_render_event(evt);
284+
t.options.persist(evt);
285+
281286
}
282287
})
283288
}
@@ -293,6 +298,9 @@ function Calendar( element, options )
293298
return false; // this is a fix for form submit callback
294299
}
295300

301+
//
302+
// External Events Initialization
303+
//
296304
t.external_events_init = function( events ) {
297305
for( var event = 0; event < events.length; event++ )
298306
{
@@ -549,6 +557,9 @@ function Resource( resource_element, insert_policy ) {
549557
// This test can be as complex as you like, but should at least
550558
// perform basic sanity checking such as ensuring that (for example)
551559
// a room can accommodate all of the attendees for a meeting
560+
561+
// [TODO - fix this so that Resources do not have to specify validation]
562+
552563
t.attr.validateFn = window[resource_element.attr('data-validate')];
553564
t.attr.validateParams = $.parseJSON(resource_element.attr('data-params'));
554565

@@ -574,7 +585,7 @@ function Resource( resource_element, insert_policy ) {
574585
// false: unable to add the event
575586
//
576587
t.addEvent = function( event, no_confirm ){
577-
if( reason = t.attr.validateFn( event.attr, t.attr.validateParams ) ) {
588+
if( $.isFunction( t.attr.validateFn ) && (reason = t.attr.validateFn( event.attr, t.attr.validateParams )) ) {
578589
rc_notify('Unable to add the event','The '+reason+' requirement was not met', 'error');
579590
return false;
580591
}
@@ -608,10 +619,8 @@ function Resource( resource_element, insert_policy ) {
608619
return t.eventpool[date];
609620
}
610621

611-
//t.findCollisions = function( event )
612-
613622
return t;
614-
}
623+
}
615624

616625
}(jQuery))
617626

templates/week.template.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ var render_week = doT.template((function(){/*
6666
// This function is registered as "postcalrender", a callback to be executed
6767
// after every rerender of the calendars
6868
//
69-
function adjust_calendar_width()
69+
// calendar_state gives access to the public state of the calendar
70+
//
71+
function adjust_calendar_width( calendar_state )
7072
{
7173
// expand width of containers to accommodate pesky scrollbar
7274
// this is specific to the template used in the test system, but the techniques used
@@ -85,11 +87,16 @@ function adjust_calendar_width()
8587
// Template for an event in the calendar
8688
//
8789
var render_week_event = doT.template((function(){/*
88-
<div class="rc_event event {{=it.attr.ev_type}}"
89-
style="top:{{=it.attr.t_offset}}px;height:{{=it.attr.t_height}}px;"
90-
id="{{=it.attr.id}}">
91-
<div class="rc_event_prepad" style="height:{{=it.attr.t_prepad}}px;"></div>
92-
<div class="rc_event_head">{{=it.attr.start}} - {{=it.attr.end}}<div class='deleteevent'>X</div></div>
90+
<div class="rc_event event {{=it.attr.ev_type}}" id="{{=it.attr.id}}"
91+
{{? it.attr.resource == "unassigned_event_resource"}}
92+
style="height:40px;margin:4px auto;">
93+
<div class="rc_event_head">Unassigned
94+
{{??}}
95+
style="top:{{=it.attr.t_offset}}px;height:{{=it.attr.t_height}}px;">
96+
<div class="rc_event_prepad" style="height:{{=it.attr.t_prepad}}px;"></div>
97+
<div class="rc_event_head">{{=it.attr.start}} - {{=it.attr.end}}
98+
{{?}}
99+
<div class='deleteevent'>X</div></div>
93100
<div class="rc_event_body">{{=it.attr.ev_text}}
94101
{{? it.attr.locked }}<img class='lockedevent' alt='locked' src='img/padlock.png'></img>{{?}}
95102
</div>

test.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ <h1>Resource Calendar Demo Page</h1>
1616
<div class='ip_spacing'><div class='rc_event vendor event in_palette' data-evtype='vendor' ><p>Vendor Meeting</p></div></div>
1717
</div>
1818

19-
<div class='event_palette unassigned'>
20-
<h2>Unassigned Events</h2>
19+
<div id='unassigned_event_resource' data-validate ='void' data-params ='{}' data-attr ='{}';>
20+
<div class='event_palette rc_day_target unassigned' id='unassigned_events' data-date='unassigned'>
21+
<h2>Unassigned Events</h2>
22+
<p>You can drag events here to save them until room, date, and time have been finalized.</p>
23+
</div>
2124
</div>
2225

2326
<!-- This is a container class that will hold a calendar for each of the resources defined within it -->
@@ -115,7 +118,8 @@ <h3>Resource Calendar</h3>
115118
<script src="js/rc_utilities.js" type="text/javascript"></script>
116119
<script src="templates/week.template.js" type="text/javascript"></script>
117120
<script src="js/rc_calendar.js" type="text/javascript"></script>
118-
<script type="text/javascript">
121+
122+
<script type="text/javascript">
119123
//
120124
// Example function to verify that a resource can accept an event dropped onto it
121125
//

0 commit comments

Comments
 (0)