-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
471 lines (424 loc) · 14.5 KB
/
index.html
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Planlægning af øvesegmenter i revyens øveuge</title>
<style type="text/css">
@import url("style.css")
</style>
<script type="text/javascript">
// Fallback. Will be overwritten by revue.data.json.js
var data = [];
</script>
<script type="text/javascript" src="json.js"></script>
<script type="text/javascript" src="BO.js"></script>
<script type="text/javascript" src="DOMBuilder.js"></script>
<script type="text/javascript" src="Array.js"></script>
<!-- <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.delegate.js"></script>-->
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script language="javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
if(localStorage.segmentData == undefined)
localStorage.segmentData = null;
if(localStorage.currentSegment == undefined)
localStorage.currentSegment = null;
//This is the variable that stores information in json about the
//segments
var segmentData = JSON.parse(localStorage.segmentData);
if(segmentData == null){
var segmentData = {
'day':'Indsæt ugedag',
segments:[]
};
}
window.revy = {
drawRehersal : function() {
var $ = DOMBuilder;
var acts = data['acts'];
var table,
colGroup,
headRow,
tr;
var segmentsTable;
var actors = [];
var sketches = [];
for (var i = 0; i < acts.length; i++) {
for (var j = 0; j < acts[i].materials.length; j++) {
for (var k = 0; k < acts[i].materials[j].roles.length; k++) {
if (actors.findInSorted(acts[i].materials[j].roles[k].actor) < 0) {
actors.insertIntoSorted(acts[i].materials[j].roles[k].actor);
}
}
}
}
for (i = 0; i < actors.length; i++) {
actors[i] = {
'name' : actors[i],
'col' : i,
'rows' : []
};
}
table = $.TABLE({'id': 'segment'},
$.COL(),
colGroup = $.COLGROUP(),
$.THEAD({},
headRow = $.TR({},
$.TH({}, "Sketch / Navn")
)
)
);
//Create a colgroup for each actor
for (i = 0; i < actors.length; i++) {
headRow.appendChild($.TH({'class':'name'}, actors[i].name));
colGroup.appendChild($.COL());
}
//Setup the acts
for (i = 0; i < acts.length; i++) {
table.appendChild(
$.TR(
$.TH({'colspan': actors.length + 1, 'class': 'pause'}, acts[i].title)
)
);
var actBody = $.TBODY();
table.appendChild(actBody);
//For each act
for (j = 0; j < acts[i].materials.length; j++) {
if (acts[i].materials[j].type !== 'video') {
//Add the sketch
actBody.appendChild(
tr = $.TR(
$.TH({},
$.LABEL({'for': acts[i].materials[j].title + j},
$.INPUT({'type': 'checkbox', 'id': acts[i].materials[j].title + j, 'name': acts[i].materials[j].title + j}),
acts[i].materials[j].title
)
)
)
);
sketches[tr.rowIndex] = [];
for (var k = 0; k < actors.length; k++) {
var td = $.TD();
var input;
for (var l = 0; l < acts[i].materials[j].roles.length; l++) {
var role = acts[i].materials[j].roles[l];
if (role.actor === actors[k].name) {
actors[k].rows.push(tr.rowIndex);
td.appendChild(
$.LABEL({'for':
acts[i].materials[j].title.replace(/ /g,'-') +
role.abbr},
role.abbr,
input = $.INPUT({'type': 'checkbox', 'name':
acts[i].materials[j].title + role.abbr, 'id':
acts[i].materials[j].title.replace(/ /g,'-') + role.abbr})
)
);
sketches[tr.rowIndex].push({
'col' : k,
'input' : input
});
}
}
tr.appendChild(td);
}
}
}
}
jQuery(table).delegate(
'#segment tbody th input',
'change',
function() {
var input = this;
var thisRow = jQuery(this).closest('tr')[0];
var sketch = sketches[thisRow.rowIndex];
if(input.checked){
jQuery(thisRow).addClass('inUse');
} else {
jQuery(thisRow).removeClass('inUse');
}
//thisRow.className += (input.checked) ? ' inUse' : '';
for (var i = 0; i < sketch.length; i++) {
if (sketch[i].input !== input) {
sketch[i].input.checked = input.checked;
jQuery(sketch[i].input).trigger('change');
}
}
}
);
jQuery(table).delegate(
'#segment tbody td input',
'change',
function() {
var input = this;
var thisCell = jQuery(this).closest('td')[0];
var thisRow = thisCell.parentNode;
// Mark the column as (un)occupied
col = colGroup.childNodes[thisCell.cellIndex - 1];
elm = jQuery(col);
if(input.checked){
if(elm.hasClass('inUse')){
elm.addClass('doubleBook');
} else {
elm.addClass('inUse');
}
} else {
if(elm.hasClass('doubleBook')){
elm.removeClass('doubleBook');
} else if(elm.hasClass('inUse')) {
elm.removeClass('inUse');
}
}
// colGroup.childNodes[thisCell.cellIndex - 1].className = (input.checked) ? 'inUse' : '';
// Iterate over all other rows where this actor is present and disable them
var actor = actors[thisCell.cellIndex - 1];
for (var i = 0; i < actor.rows.length; i++) {
var row = table.rows[actor.rows[i]];
var roles = sketches[actor.rows[i]];
// This is only run if the user is unchecking a box
// Find out if freeing up an actor really enables a previously blocked sketch
var unckeckingEnabledSketch = true;
if (!input.checked) {
for (j = 0; j < roles.length; j++) {
if (colGroup.childNodes[roles[j].col].className === 'inUse') {
unckeckingEnabledSketch = false;
break;
}
}
}
// Block/unblock all rows that arent this one and arent in use.
if (row !== thisRow && row.className !== 'inUse' && unckeckingEnabledSketch) {
row.className = (input.checked) ? 'blocked' : '';
var inputs = row.getElementsByTagName('input');
for (var k = 0; k < inputs.length; k++) {
// inputs[k].disabled = input.checked;
}
} else if(row == thisRow && input.checked) {
jQuery(row).children('th').children('label').children(':checkbox').attr('checked',true);
jQuery(row).addClass('inUse');
}
}
localStorage.currentSegment = JSON.stringify(updateDisplay());
}
);
segmentsTable = $.TABLE({'id':'segments'},
$.THEAD({},
headRow = $.TR({})
)
);
headRow.appendChild($.TH({},'Tidspunkt'));
headRow.appendChild($.TH({},'Segment'));
headRow.appendChild($.TH({},''));
headRow.appendChild($.TH({'onclick':'jQuery("#segments tbody").hide()'},'+'));
window.loadSession = function(){
var json = prompt("Indsæt JSON kode her");
var data = eval('(' + json + ')');
document.getElementById("day").value = data.day;
for(var i =0;i < data.segments.length;i++){
addSegment(data.segments[i]);
}
}
window.storeSession = function(){
localStorage.segmentData = JSON.stringify(segmentData);
}
window.saveSession = function(){
var jsonObject = JSON.stringify(segmentData); //This is firefox 3.5.4+ specific
document.getElementById('jsondata').value = jsonObject;
jQuery('#sessiondata').show();
jQuery('#jsondata').focus();
}
window.loadSegment = function(segment){
if(segment != null){
jQuery('#from').val(segment.start);
jQuery('#to').val(segment.end);
for(var i=0;i<segment.sketches.length;i++) {
var sketch = segment.sketches[i];
if(sketch != null && sketch.actors) {
var thesketch = sketches[sketch.row];
var rows = jQuery('#segment tbody tr');
for(var j=0;j<sketch.actors.length;j++){
var actor = sketch.actors[j];
for(var k=0;k<thesketch.length;k++){
var input = thesketch[k].input;
var row = jQuery(input).parent().parent().parent();
row.addClass('inUse');
row.children('th').children('label').children(':checkbox').attr('checked',true).attr('disabled',false);
row.children('td').children('label').children(':checkbox').attr('disabled',false);
if(actor.col == thesketch[k].col){
input.disabled = false;
input.checked = true;
jQuery(input).trigger('change');
// jQuery(input).trigger('click');
//get the row and set proper values there
break;
}
}
}
}
}
}
}
window.addSegmentRow = function(segment){
var tr = $.TR({});
if(segment.start && segment.end && segment.sketches){
tr.appendChild($.TD({'class':'segment-time'},segment.start+' - '+segment.end));
content ='';
for(var i=0;i<segment.sketches.length;i++) {
if(segment.sketches[i])
content += ' ' + segment.sketches[i].sketch + ',';
}
content = content.replace(/(,$)/g,"");
} else {
tr.appendChild($.TD({'class':'segment-time'},''));
content = '';
}
tr.appendChild($.TD({},content));
segmentsTable.appendChild(tr);
/* jQuery(td).click(function(event){
loadSegment(this.parentNode.rowIndex-1);
});*/
tr.appendChild(td = $.TD({'class':'segment-edit'},'Edit'));
jQuery(td).click(function(event){
var thisRow = this.parentNode;
window.editSegment(thisRow.rowIndex-1);
});
tr.appendChild(td = $.TD({'class':'segment-del'},'Slet'));
jQuery(td).click(function(event){
var thisRow = this.parentNode;
var thisTable = thisRow.parentNode;
segmentData.segments.splice(thisRow.rowIndex - 1,1);
thisTable.removeChild(thisRow);
localStorage.segmentData = JSON.stringify(segmentData);
content = '';
for(i = 0; i < segmentData.segments.length;i++){
content += segmentData.segments[i].start + '\n';
}
});
}
window.addSegment = function(segment){
if(segment.start && segment.end){
segmentData.segments.push(segment);
addSegmentRow(segment);
var thedata = JSON.stringify(segmentData);
localStorage.segmentData = thedata;
} else {
alert('nej nej nej! Du skal skrive start og slut paa');
}
}
window.displayTime = function(segment){
jQuery('#time').show();
jQuery('#from').focus();
}
window.hideTime = function(){
jQuery('#time').hide();
}
//Unchecks all checkboxes :)
window.clearSegment = function(){
jQuery('input:checkbox').attr('checked',false).removeAttr('disabled');
jQuery('.inUse').removeClass('inUse').removeClass('doubleBook');
jQuery('.blocked').removeClass('blocked');
localStorage.currentSegment = null;
}
window.editSegment = function(index){
window.clearSegment();
var segment = segmentData.segments[index];
loadSegment(segment);
}
window.sortSegments = function() {
//This line should be in a change eventhandler but don't have time to
//fix it
segmentData.day = document.getElementById('day').value;
var w = window.open('plan.html','planner');
}
//This function takes care of creating the segment object. Should really
//be changed to a more saying name...
window.updateDisplay = function () {
var inUse = [];
var ret = {
'start': document.getElementById('from').value,
'end': document.getElementById('to').value,
'sketches': new Array(rooms.length), //Dirty hack, this should match the number of rooms
'free': []
};
var i = 0;
jQuery('#segment tbody tr:has("th input:checked")').map(function(index,domElement) {
var sketch = {
'row': domElement.rowIndex,
'sketch': domElement.firstChild.textContent,
'actors':[]
}
jQuery(domElement).children('td:has("input:checked")').map(function(index,domElement) {
var actor = actors[domElement.cellIndex -1];
inUse.push(actor);
sketch.actors.push(actor);
})
ret.sketches[i] = sketch;
i++;
});
actors.map(function(actor) {
if (inUse.indexOf(actor) === -1) {
ret.free.push(actor.name);
}
});
return ret;
};
document.body.appendChild(table);
document.body.appendChild(segmentsTable);
jQuery('#segments').draggable({handle:"thead"});
for(var i=0;i<segmentData.segments.length;i++)
{
window.addSegmentRow(segmentData.segments[i]);
}
var currentSegment = JSON.parse(localStorage.currentSegment);
window.loadSegment(currentSegment);
}
};
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
revy.drawRehersal();
});
</script>
</head>
<body>
<div id="menu"><button
onclick="displayTime()">Tilføj segment</button>
<button onclick="clearSegment()">Ryd segment</button>
<!-- <button onclick="addSegment({})">Tilføj pause</button> -->
<button onclick="loadSession()">Indlæs session</button>
<button onclick="saveSession()">Gem session</button>
<label for="day">Dag</label>
<input type="textfield" name="day" id="day" value="" />
<button onclick="sortSegments()">Sortér segmenter</button>
<!-- <label for="from">Segment start:</label>
<input type="textfield" name="from" id="from" value="" />
<label for="to">Segment slut:</label>
<input type="textfield" name="to" id="to" value="" />-->
</div>
<div id="time" style="display:none;">
<form id="time-form">
Hvornår starter og slutter dit segment?
<table>
<tr>
<td>Start time:</td><td> <input type="textfield" name="from" id="from"
value="" /></td></tr><tr><td>
End time:</td><td> <input type="textfield" name="to" id="to"
/></td></tr><tr><td></td><td>
<input type="button" onclick="hideTime()" value="Annulér"
/> <input type="button"
onclick="addSegment(updateDisplay());hideTime()"
value="Tilføj"/></td></tr>
</table>
</form>
</div>
<div id="sessiondata">
Kopiér strengen og gem den i en simpel tekstfil.<br/>
<textarea name="jsondata" id="jsondata" onfocus="this.select()"
cols="100" rows="20"></textarea><br/>
<input type="button" onclick="jQuery('#sessiondata').hide()" value="OK" />
</div>
</body>
</html>