forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeslot_edit.html
More file actions
443 lines (402 loc) · 16.6 KB
/
timeslot_edit.html
File metadata and controls
443 lines (402 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
{% extends "base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% load agenda_custom_tags misc_filters %}
{% block title %}IETF {{ meeting.number }} Meeting Agenda: Timeslots and Room Availability{% endblock %}
{% block morecss %}
{% comment %}
Put scrollbars on the editor table. Requires fixed height so the scroll bars appear on the div, not the page body.
Note that 100vh is viewport height. Using that minus 25rem seems to leave space for the page header/footer.
{% endcomment %}
.timeslot-edit { overflow: auto; height: max(30rem, calc(100vh - 25rem));}
.tstable { width: 100%; border-collapse: separate; } {# "separate" to ensure sticky cells keep their borders #}
.tstable thead { position: sticky; top: 0; z-index: 2; background-color: white;}
.tstable th:first-child, .tstable td:first-child {
background-color: white; {# needs to match the lighter of the striped-table colors! #}
position: sticky;
left: 0;
z-index: 1.5; {# render above other cells / borders but below thead (z-index 2, above) #}
}
.tstable tbody > tr:nth-of-type(odd) > th:first-child {
background-color: rgb(249, 249, 249); {# needs to match the darker of the striped-table colors! #}
}
.tstable th { white-space: nowrap;}
.tstable td { white-space: nowrap;}
.capacity { font-size:80%; font-weight: normal;}
a.new-timeslot-link { color: lightgray; font-size: large;}
{% endblock %}
{% block content %}
{% origin %}
<p class="pull-right">
<a href="{% url "ietf.meeting.views.create_timeslot" num=meeting.number %}">New timeslot</a>
·
{% if meeting.schedule %}
<a href="{% url "ietf.secr.meetings.views.rooms" meeting_id=meeting.number schedule_name=meeting.schedule.name %}">Edit rooms</a>
{% else %} {# secr app room view requires a schedule - show something for now (should try to avoid this possibility) #}
<span title="Must create meeting schedule to edit rooms">Edit rooms</span>
{% endif %}
·
<a href="{% url "ietf.meeting.views.list_schedules" num=meeting.number %}">Agenda list</a>
</p>
<p> IETF {{ meeting.number }} Meeting Agenda: Timeslots and Room Availability</p>
<div class="timeslot-edit">
{% if rooms|length == 0 %}
<p>No rooms exist for this meeting yet.</p>
{% if meeting.schedule %}
<a href="{% url "ietf.secr.meetings.views.rooms" meeting_id=meeting.number schedule_name=meeting.schedule.name %}">Create rooms</a>
{% else %}{# provide as helpful a link we can if we don't have an official schedule #}
<a href="{% url "ietf.secr.meetings.views.view" meeting_id=meeting.number %}">Create rooms through the secr app</a>
{% endif %}
{% else %}
<table id="timeslot-table" class="tstable table table-striped table-compact table-bordered">
{% with have_no_timeslots=time_slices|length_is:0 %}
<thead>
<tr>
{% if have_no_timeslots %}
<th></th>
<th></th>
{% else %}
<th></th>
{% for day in time_slices %}
<th class="day-label"
colspan="{{date_slices|colWidth:day}}">
{{day|date:'D'}} ({{day}})
<span class="fa fa-trash delete-button"
title="Delete all on this day"
data-delete-scope="day"
data-date-id="{{ day.isoformat }}">
</span>
</th>
{% endfor %}
{% endif %}
</tr>
<tr>
{% if have_no_timeslots %}
<th></th>
<th></th>
{% else %}
<th></th>
{% for day in time_slices %}
{% for slot in slot_slices|lookup:day %}
<th class="time-label">
{{slot.time|date:'H:i'}}-{{slot.end_time|date:'H:i'}}
<span class="fa fa-trash delete-button"
data-delete-scope="column"
data-date-id="{{ day.isoformat }}"
data-col-id="{{ day.isoformat }}T{{slot.time|date:'H:i'}}-{{slot.end_time|date:'H:i'}}"
title="Delete all in this column">
</span>
</th>
{% endfor %}
{% endfor %}
{% endif %}
</tr>
</thead>
<tbody>
{% for room in rooms %}
<tr>
<th><span class="room-heading">{{room.name}}{% if room.capacity %} <span class='capacity'>({{room.capacity}})</span>{% endif %}</span></th>
{% if have_no_timeslots and forloop.first %}
<td rowspan="{{ rooms|length }}">
<p>No timeslots exist for this meeting yet.</p>
<a href="{% url "ietf.meeting.views.create_timeslot" num=meeting.number %}">Create a timeslot.</a>
</td>
{% else %}
{% for day in time_slices %}{% with slots=slot_slices|lookup:day %}
{% for slice in date_slices|lookup:day %}{% with cell_ts=ts_list.popleft slot=slots|index:forloop.counter0 %}
<td class="tscell {% if cell_ts|length > 1 %}timeslot-collision {% endif %}{% for ts in cell_ts %}tstype_{{ ts.type.slug }} {% endfor %}">
{% if cell_ts %}
{% for ts in cell_ts %}
{% include 'meeting/timeslot_edit_timeslot.html' with ts=ts in_use=ts_with_any_assignments in_official_use=ts_with_official_assignments only %}
{% endfor %}
{% endif %}
<a class="new-timeslot-link {% if cell_ts %}hidden{% endif %}"
href="{% url "ietf.meeting.views.create_timeslot" num=meeting.number %}?day={{ day.toordinal }}&date={{ day|date:"Y-m-d" }}&location={{ room.pk }}&time={{ slot.time|date:'H:i' }}&duration={{ slot.duration }}">
<span class="fa fa-plus-square"></span>
</a>
{% endwith %}{% endfor %}
</td>
{% endwith %}{% endfor %}
{% endif %}
</tr>
{% endfor %}
</tbody>
{% endwith %}
</table>
{% endif %}
{# Modal to confirm timeslot deletion #}
<div id="delete-modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title">Confirm Delete</h4>
</div>
<div class="modal-body">
<p>
<span class="ts-singular">The following timeslot</span>
<span class="ts-plural"><span class="ts-count"></span> timeslots</span>
will be deleted:
</p>
<dl class="dl-horizontal">
<dt>Name</dt><dd><span class="ts-name"></span></dd>
<dt>Date</dt><dd><span class="ts-date"></span></dd>
<dt>Time</dt><dd><span class="ts-time"></span></dd>
<dt>Location</dt><dd><span class="ts-location"></span></dd>
</dl>
<p class="unofficial-use-warning">
The official schedule will not be affected, but sessions in
unofficial schedules currently assigned to
<span class="ts-singular">this timeslot</span>
<span class="ts-plural">any of these timeslots</span>
will become unassigned.
</p>
<p class="official-use-warning">
The official schedule will be affected.
Sessions currently assigned to
<span class="ts-singular">this timeslot</span>
<span class="ts-plural">any of these timeslots</span>
will become unassigned.
</p>
<p>
<span class="ts-singular">Are you sure you want to delete this timeslot?</span>
<span class="ts-plural">Are you sure you want to delete these <span class="ts-count"></span> timeslots?</span>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" id="confirm-delete-button" class="btn btn-primary">Delete</button>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script type="text/javascript">
// create a namespace for local JS
timeslotEdit = (function() {
let deleteModal;
let timeslotTableBody = document.querySelector('#timeslot-table tbody');
function initializeDeleteModal() {
deleteModal = jQuery('#delete-modal');
deleteModal.eltsToDelete = null; // PK of TimeSlot that modal 'Delete' button should delete
let spans = deleteModal.find('span');
deleteModal.elts = {
unofficialUseWarning: deleteModal.find('.unofficial-use-warning'),
officialUseWarning: deleteModal.find('.official-use-warning'),
timeslotNameSpans: spans.filter('.ts-name'),
timeslotDateSpans: spans.filter('.ts-date'),
timeslotTimeSpans: spans.filter('.ts-time'),
timeslotLocSpans: spans.filter('.ts-location'),
timeslotCountSpans: spans.filter('.ts-count'),
pluralSpans: spans.filter('.ts-plural'),
singularSpans: spans.filter('.ts-singular')
};
document.getElementById('confirm-delete-button').addEventListener(
'click',
() => timeslotEdit.handleDeleteButtonClick()
);
function uniqueArray(a) {
let s = new Set();
a.forEach(item => s.add(item));
return Array.from(s);
}
deleteModal.openModal = function (eltsToDelete) {
let eltArray = Array.from(eltsToDelete); // make sure this is an array
if (eltArray.length > 1) {
deleteModal.elts.pluralSpans.show();
deleteModal.elts.singularSpans.hide();
} else {
deleteModal.elts.pluralSpans.hide();
deleteModal.elts.singularSpans.show();
}
deleteModal.elts.timeslotCountSpans.text(String(eltArray.length));
let names = uniqueArray(eltArray.map(elt => elt.dataset.timeslotName));
if (names.length === 1) {
names = names[0];
} else {
names.sort();
names = names.join(', ');
}
deleteModal.elts.timeslotNameSpans.text(names);
let dates = uniqueArray(eltArray.map(elt => elt.dataset.timeslotDate));
if (dates.length === 1) {
dates = dates[0];
} else {
dates = 'Multiple';
}
deleteModal.elts.timeslotDateSpans.text(dates);
let times = uniqueArray(eltArray.map(elt => elt.dataset.timeslotTime));
if (times.length === 1) {
times = times[0];
} else {
times = 'Multiple';
}
deleteModal.elts.timeslotTimeSpans.text(times);
let locs = uniqueArray(eltArray.map(elt => elt.dataset.timeslotLocation));
if (locs.length === 1) {
locs = locs[0];
} else {
locs = 'Multiple';
}
deleteModal.elts.timeslotLocSpans.text(locs);
// Check whether any of the elts are used in official / unofficial schedules
let unofficialUse = eltArray.some(elt => elt.dataset.unofficialUse === 'true');
let officialUse = eltArray.some(elt => elt.dataset.officialUse === 'true');
deleteModal.elts.unofficialUseWarning.hide();
deleteModal.elts.officialUseWarning.hide();
if (officialUse) {
deleteModal.elts.officialUseWarning.show();
} else if (unofficialUse) {
deleteModal.elts.unofficialUseWarning.show();
}
deleteModal.eltsToDelete = eltsToDelete;
deleteModal.modal('show');
}
/**
* Handle deleting a single timeslot
*
* clicked arg is the clicked element, which must be a child of the timeslot element
*/
function deleteSingleTimeSlot(clicked) {
deleteModal.openModal([clicked.closest('.timeslot')]);
}
/**
* Handle deleting an entire day worth of timeslots
*
* clicked arg is the clicked element, which must be a child of the day header element
*/
function deleteDay(clicked) {
// Find all timeslots for this day
let dateId = clicked.dataset.dateId;
let timeslots = timeslotTableBody.querySelectorAll(
':scope .timeslot[data-date-id="' + dateId + '"]' // :scope prevents picking up results outside table body
);
if (timeslots.length > 0) {
deleteModal.openModal(timeslots);
}
}
/**
* Handle deleting an entire column worth of timeslots
*
* clicked arg is the clicked element, which must be a child of the column header element
*/
function deleteColumn(clicked) {
let colId = clicked.dataset.colId;
let timeslots = timeslotTableBody.querySelectorAll(
':scope .timeslot[data-col-id="' + colId + '"]' // :scope prevents picking up results outside table body
);
if (timeslots.length > 0) {
deleteModal.openModal(timeslots);
}
}
/**
* Event handler for clicks on the timeslot table
*
* Handles clicks on all the delete buttons to avoid large numbers of event handlers.
*/
document.getElementById('timeslot-table').addEventListener('click', function(event) {
let clicked = event.target; // find out what was clicked
if (clicked.dataset.deleteScope) {
switch (clicked.dataset.deleteScope) {
case 'timeslot':
deleteSingleTimeSlot(clicked)
break
case 'column':
deleteColumn(clicked)
break
case 'day':
deleteDay(clicked)
break
default:
throw new Error('Unexpected deleteScope "' + clicked.dataset.deleteScope + '"')
}
}
});
}
// Update timeslot classes when DOM changes
function tstableObserveCallback(mutationList) {
mutationList.forEach(mutation => {
if (mutation.type === 'childList' && mutation.target.classList.contains('tscell')) {
const tscell = mutation.target;
// mark collisions
if (tscell.getElementsByClassName('timeslot').length > 1) {
tscell.classList.add('timeslot-collision');
} else {
tscell.classList.remove('timeslot-collision');
}
// remove timeslot type classes for any removed timeslots
mutation.removedNodes.forEach(node => {
if (node.classList.contains('timeslot') && node.dataset.timeslotType) {
tscell.classList.remove('tstype_' + node.dataset.timeslotType);
}
});
// now add timeslot type classes for any remaining timeslots
Array.from(tscell.getElementsByClassName('timeslot')).forEach(elt => {
if (elt.dataset.timeslotType) {
tscell.classList.add('tstype_' + elt.dataset.timeslotType);
}
});
}
});
}
function initializeTsTableObserver() {
const observer = new MutationObserver(tstableObserveCallback);
observer.observe(timeslotTableBody, { childList: true, subtree: true });
}
window.addEventListener('load', function (event) {
initializeTsTableObserver();
initializeDeleteModal();
});
function removeTimeslotElement(elt) {
if (elt.parentNode) {
elt.parentNode.removeChild(elt);
}
}
function handleDeleteButtonClick() {
if (!deleteModal || !deleteModal.eltsToDelete) {
return; // do nothing if not yet initialized
}
let timeslotElts = Array.from(deleteModal.eltsToDelete); // make own copy as Array so we have .map()
ajaxDeleteTimeSlot(timeslotElts.map(elt => elt.dataset.timeslotPk))
.error(function(jqXHR, textStatus) {
displayError('Error deleting timeslot: ' + jqXHR.responseText)
})
.done(function () {timeslotElts.forEach(
tse => {
tse.closest('td.tscell').querySelector('.new-timeslot-link').classList.remove('hidden');
tse.parentNode.removeChild(tse);
}
)})
.always(function () {deleteModal.modal('hide')});
}
/**
* Make an AJAX request to delete a TimeSlot
*
* @param pkArray array of PKs of timeslots to delete
* @returns jqXHR object corresponding to jQuery ajax request
*/
function ajaxDeleteTimeSlot(pkArray) {
return jQuery.ajax({
method: 'post',
timeout: 5 * 1000,
data: {
action: 'delete',
slot_id: pkArray.join(',')
}
});
}
function displayError(msg) {
window.alert(msg);
}
// export callable methods
return {
handleDeleteButtonClick: handleDeleteButtonClick,
}
})();
</script>
{% endblock %}