Skip to content

Commit 979bba1

Browse files
committed
Added guard to prevent multiple edit dialogs for the same event.
Added event lock capability. Moved Resource test data to the <resource> declarations BugFix: Events were losing date on drag.
1 parent 1e905ca commit 979bba1

File tree

8 files changed

+101
-67
lines changed

8 files changed

+101
-67
lines changed

css/test.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@
3838
font-size: 50%;
3939
color: #A00;
4040
border: 1px solid #aa0000;
41+
border-radius: 12px;
42+
-moz-border-radius: 12px;
4143
text-align: center;
4244
padding: 1px 3px;
4345
margin: 2px; }
4446

47+
.lockedevent {
48+
clear: both;
49+
float: right;
50+
width: 1em;
51+
height: auto; }
52+
4553
.calimg {
4654
height: 1em;
4755
width: auto;

img/padlock.png

2.83 KB
Loading

js/rc_calendar.js

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function Calendar( element, options )
180180
t.resources[resource_id],
181181
{
182182
start : start_time,
183-
date : date,
183+
date : date.valueOf(),
184184
}
185185
) ) {
186186
// was able to render in the new position, delete the original
@@ -234,29 +234,36 @@ function Calendar( element, options )
234234
t.eventmanager.deleteEvent, evt.attr.id );
235235
});
236236

237-
newev.draggable({
238-
appendTo : 'body',
239-
helper : 'clone',
240-
zIndex : 9999,
241-
/* drag : function( event, ui ){
242-
var time_offset = t.options.get_time_offset( event, ui );
243-
var start_time = nearest_time( time_offset );
244-
ui.helper.find(".rc_event_head").text(start_time);
245-
}
246-
*/
247-
}).resizable({
248-
handles: 's',
249-
250-
stop: function( event, ui ){
251-
var snapheight = ~~(ui.size.height/t.options.intervalpixels);
252-
var total_mins = snapheight*t.options.interval;
253-
254-
evt.attr.duration = total_mins - (evt.attr.prep_time + evt.attr.cleanup_time);
255-
ui.helper.css('height',snapheight * t.options.intervalpixels -2 + 'px');
256-
}
237+
if( !evt.attr.locked ){
238+
newev.draggable({
239+
appendTo : 'body',
240+
helper : 'clone',
241+
zIndex : 9999,
242+
/* drag : function( event, ui ){
243+
var time_offset = t.options.get_time_offset( event, ui );
244+
var start_time = nearest_time( time_offset );
245+
ui.helper.find(".rc_event_head").text(start_time);
246+
}
247+
*/
248+
}).resizable({
249+
handles: 's',
250+
251+
stop: function( event, ui ){
252+
var snapheight = ~~(ui.size.height/t.options.intervalpixels);
253+
var total_mins = snapheight*t.options.interval;
254+
255+
evt.attr.duration = total_mins - (evt.attr.prep_time + evt.attr.cleanup_time);
256+
ui.helper.css('height',snapheight * t.options.intervalpixels -2 + 'px');
257+
}
258+
})
259+
}
257260

258-
}).click( function(){
259-
rc_event_edit( evt, t.view_week_render_event );
261+
newev.click( function(){
262+
rc_event_edit( evt, function(evt){
263+
t.view_week_render_event(evt);
264+
t.options.persist(evt);
265+
return false;
266+
});
260267
});
261268

262269
return false; // this is a fix for form submit callback
@@ -281,7 +288,7 @@ function Calendar( element, options )
281288
{
282289
return addMinutes_timeOfDay(
283290
t.options.min_time,
284-
~~(offset / t.options.intervalpixels) * t.options.interval,
291+
~~((offset + t.options.intervalpixels/2) / t.options.intervalpixels) * t.options.interval,
285292
t.options.max_time
286293
).newtime;
287294
}
@@ -378,7 +385,8 @@ function rc_Event( options )
378385
prep_time : 0, // pre-event room preparation time
379386
cleanup_time: 0, // post-event room
380387
resource : 'none', // remove from this resource when added to another
381-
written_to_server : false
388+
locked : false, // when locked, can not be dragged, resized, or bumped
389+
written_to_server : false
382390
};
383391

384392
t.attr = $.extend( true, {}, defaults, options );
@@ -440,7 +448,7 @@ function rc_EventManager( retrieve_events, save_event, delete_event, resources,
440448
var stash = evt.attr;
441449

442450
evt.attr.start = options.start;
443-
evt.attr.date = options.date.valueOf;
451+
evt.attr.date = options.date;
444452
evt.attr.t_offset= options.t_offset;
445453

446454

@@ -490,15 +498,6 @@ function rc_EventManager( retrieve_events, save_event, delete_event, resources,
490498
// 3: live Ajax + localStorage for offline working
491499

492500

493-
//--- TEST DATA -------------------------------------------------------
494-
var init_resource = {
495-
Room1:{title:"Orca",capacity:250,location:"Rochester North"},
496-
Room2:{title:"Narwhal",capacity:50,location:"Rochester North"},
497-
Room3:{title:"Walrus",capacity:500,location:"Rochester East"},
498-
};
499-
500-
//--- END TEST DATA ---------------------------------------------------
501-
502501

503502
function Resource( resource_element, init_mode ) {
504503
var t = this;
@@ -509,18 +508,8 @@ function Resource( resource_element, init_mode ) {
509508
//
510509
t.eventpool = {};
511510

512-
t.id = resource_element.attr('id');
513-
514-
// initialization
515-
switch( init_mode )
516-
{
517-
case 'localtest': {
518-
t.attr = init_resource[t.id];
519-
break;
520-
}
521-
522-
default: alert("unrecognized Resource initialization mode");
523-
}
511+
t.id = resource_element.attr('id');
512+
t.attr = $.parseJSON(resource_element.attr('data-attr'));
524513

525514
//
526515
// Set up automated event acceptance test (application-level function)

js/rc_utilities.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ function rc_notify( title, text, type ) {
3030

3131
function rc_event_edit( evt, callback ) {
3232

33+
// check for guard element
34+
if( $('#nodupe-'+evt.attr.id).length ){
35+
return false;
36+
}
37+
3338
var notice = $.pnotify({
3439
text: $('#form_event_edit').html(),
3540
icon: false,
@@ -46,9 +51,16 @@ function rc_event_edit( evt, callback ) {
4651
var t = $(this);
4752
if( t.attr('id') in evt.attr ) {
4853
t.val(evt.attr[t.attr('id')]);
54+
// handle checkboxes
55+
if( t.attr('type') == 'checkbox' ) {
56+
t.prop("checked", evt.attr[t.attr('id')] );
57+
}
4958
}
5059
});
5160

61+
// Add guard element
62+
notice.append("<input type='hidden' id='nodupe-"+evt.attr.id+"'>");
63+
5264
notice.find('form.pf-form').submit(function() {
5365

5466

@@ -66,7 +78,10 @@ function rc_event_edit( evt, callback ) {
6678
notice.find('.pf-field').each( function(){
6779
var t = $(this);
6880
if( t.attr('id') in evt.attr ) {
69-
if(typeof(evt.attr[t.attr('id')]) == 'number' ) {
81+
if( t.attr('type') == 'checkbox' ) {
82+
evt.attr[t.attr('id')] = t.prop("checked");
83+
}
84+
else if(typeof(evt.attr[t.attr('id')]) == 'number' ) {
7085
evt.attr[t.attr('id')] = parseInt(t.val(),10);
7186
}
7287
else {

sass/rc_calendar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ $col_7days_width : 595/7 - 1px;
5151
left:0;
5252
bottom:0;
5353
}
54+
5455
#sgrip{
5556
width:20px;
5657
height:10px;

sass/test.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,20 @@
4545
font-size:50%;
4646
color: #A00;
4747
border:1px solid #A00;
48+
border-radius: 12px;
49+
-moz-border-radius: 12px;
4850
text-align:center;
4951
padding:1px 3px;
5052
margin:2px;
5153
}
5254

55+
.lockedevent{
56+
clear:both;
57+
float:right;
58+
width:1em;
59+
height:auto;
60+
}
61+
5362
.calimg{
5463
height:1em;
5564
width:auto;

templates/week.template.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ var render_week_event = doT.template((function(){/*
7171
id="{{=it.attr.id}}">
7272
<div class="rc_event_prepad" style="height:{{=it.attr.t_prepad}}px;"></div>
7373
<div class="rc_event_head">{{=it.attr.start}} - {{=it.attr.end}}<div class='deleteevent'>X</div></div>
74-
<div class="rc_event_body">{{=it.attr.ev_text}}</div>
74+
<div class="rc_event_body">{{=it.attr.ev_text}}
75+
{{? it.attr.locked }}<img class='lockedevent' alt='locked' src='img/padlock.png'></img>{{?}}
76+
</div>
7577
<div class="rc_event_postpad" style="height:{{=it.attr.t_postpad}}px;"></div>
7678
</div>
7779
*/}).heredoc());

test.html

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,25 @@
1818
<!-- This is a container class that will hold a calendar for each of the resources defined within it -->
1919
<div class='calendar'>
2020
<!-- Declare resources, set up validation function and parameters-->
21-
<resource id='Room1' data-validate='validateEvent' data-params='{"capacity":["LE",30], "campus":["EQ","N"]}'></resource>
22-
<resource id='Room2' data-validate='validateEvent' data-params='{"capacity":["LE",50], "campus":["EQ","N"]}'></resource>
23-
<resource id='Room3' data-validate='validateEvent' data-params='{"capacity":["LE",120],"campus":["EQ","E"]}'></resource>
21+
<resource id='Room1'
22+
data-validate ='validateEvent'
23+
data-params ='{"capacity":["LE",30], "campus":["EQ","N"]}'
24+
data-attr ='{"title":"Orca","capacity":250,"location":"Rochester North"}';
25+
>
26+
</resource>
27+
<resource id='Room2'
28+
data-validate ='validateEvent'
29+
data-params ='{"capacity":["LE",50], "campus":["EQ","N"]}'
30+
data-attr ='{"title":"Narwhal","capacity":50,"location":"Rochester North"}'
31+
>
32+
</resource>
33+
<resource id='Room3'
34+
data-validate ='validateEvent'
35+
data-params ='{"capacity":["LE",120], "campus":["EQ","E"]}'
36+
data-attr ='{"title":"Walrus","capacity":500,"location":"Rochester East"}'
37+
>
38+
</resource>
39+
2440
</div>
2541

2642
<!-- This form is displayed by Pine Notify when editing Event details -->
@@ -56,35 +72,29 @@ <h3>Resource Calendar</h3>
5672
</div>
5773
<div class="pf-element">
5874
<label>
59-
<span class="pf-label">Day</span>
60-
<input class="pf-field" type="text" name="meeting_day" id="date" />
61-
</label>
62-
</div>
63-
<div class="pf-element">
64-
<label>
65-
<span class="pf-label">Start</span>
66-
<input class="pf-field" type="text" name="meeting_start" id="start" />
75+
<span class="pf-label">Duration (minutes)</span>
76+
<input class="pf-field" type="text" name="meeting_duration" id="duration" />
6777
</label>
6878
</div>
6979
<div class="pf-element">
7080
<label>
71-
<span class="pf-label">Duration</span>
72-
<input class="pf-field" type="text" name="meeting_duration" id="duration" />
81+
<span class="pf-label">Preparation Time (minutes)</span>
82+
<input class="pf-field" type="text" name="meeting_prep" id="prep_time" />
7383
</label>
7484
</div>
7585
<div class="pf-element">
7686
<label>
77-
<span class="pf-label">Preparation Time</span>
78-
<input class="pf-field" type="text" name="meeting_prep" id="prep_time" />
87+
<span class="pf-label">Cleanup Time (minutes)</span>
88+
<input class="pf-field" type="text" name="meeting_clean" id="cleanup_time" />
7989
</label>
8090
</div>
8191
<div class="pf-element">
8292
<label>
83-
<span class="pf-label">Cleanup Time</span>
84-
<input class="pf-field" type="text" name="meeting_clean" id="cleanup_time" />
93+
<span class="pf-label">Lock Meeting</span>
94+
<span class="pf-label">Locked meetings can not be dragged or resized</span>
95+
<input class="pf-field" type="checkbox" name="meeting_locked" id="locked" />
8596
</label>
8697
</div>
87-
8898
<div class="pf-element pf-buttons pf-centered">
8999
<input class="pf-button btn btn-primary" type="submit" name="submit" value="Submit" />
90100
</div>

0 commit comments

Comments
 (0)