-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebif.html
1416 lines (1330 loc) · 44.4 KB
/
webif.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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- The jQuery library is a prerequisite for all jqSuite products -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.5/js/jquery.jqGrid.min.js"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc. -->
<script type="text/ecmascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.5/js/i18n/grid.locale-en.min.js"></script>
<!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- The link to the CSS that the grid needs -->
<link rel="stylesheet" type="text/css" media="screen" href="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.5.4/css/ui.jqgrid.min.css" />
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Vbox recordings</title>
<style>
/* .ui-jqdialog-content .form-view-data { */
.record-red {
font-size:12px;
color:red;
}
.ui-tabs-panel {
font-size:12px;
}
.ui-tabs-anchor {
font-size:14px;
font-weight: bold;
}
.ui-jqgrids-labels .ui-sortable th,
#v_programme-desc, #v_programme-title, #v_desc, #v_title {
white-space: normal;
}
#rec-dial-tab {
border-collapse: collapse;
font-size: 12px;
}
#rec-dial-tab tr>:nth-child(1) {
font-weight: bold;
}
#rec-dial-tab td {
padding: 5px;
}
</style>
</head>
<body>
<div id=loadRecordings hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading Recordings</div>
<div id=loadChannels hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading Channels</div>
<div id=loadEPG hidden><i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i> Loading EPG</div>
<div id="tabs" class="">
<ul>
<li><a href="#tabs-1">EPG</a></li>
<li><a href="#tabs-2">Recordings and Scheduled</a></li>
<li><a href="#tabs-3">Series Recording Schedule</a></li>
</ul>
<div id="tabs-1">
<table id="epgGrid"></table>
<div id="epgMsg" hidden></div>
<div id="epgGridPager"></div>
</div>
<div id="tabs-2">
<table id="recordingsGrid"></table>
<div id="recordingsMsg" hidden></div>
<div id="recordingsGridPager"></div>
<button id="recordingsExport" hidden>Print</button>
</div>
<div id="tabs-3">
<table id="seriesGrid"></table>
<div id="seriesMsg" hidden></div>
<div id="seriesGridPager"></div>
<button id="seriesExport" hidden>Print</button>
</div>
</div>
<div id="dialog-form" title="Schedule Recording" hidden>
<table id="rec-dial-tab" border="1" class="ui-widget">
<tbody class="ui-widget-content">
<tr><td>Title</td><td id="rectitle"/></tr>
<tr><td>Channel</td><td id="recchan"/></tr>
<tr><td>Description</td><td id="recdesc"/></tr>
<tr><td>Start time</td><td id="recstart"/></tr>
<tr><td>Stop time</td><td id="recstop"/></tr>
<tr><td>Series CRID</td><td id="reccrid"/></tr>
<tr hidden><td>Rowid</td><td id="recrow"/></tr>
<tr><td>Recording Type</td><td id="rectyp">
<input type='radio' id='single' name='rectype' value='1' checked='true' />
<label for='single'>Single programme</label></br>
<input type='radio' id='series' name='rectype' value='2' />
<label for='series'>Series</label></br>
<input type='radio' id='manual' name='rectype' value='3' />
<label for='manual'>Periodic</label></br>
</td></tr>
</tbody>
</table>
</div>
<script type="text/javascript">
//jQuery.jgrid.no_legacy_api = true;
$(document).ready(function() {
$("#recordingsExport").hide();
$("#seriesExport").hide();
// set up tabs
$( "#tabs" ).tabs();
// set up modal dialog for recording schedule
dialog = $( "#dialog-form" ).dialog({
autoOpen: false,
height: "auto",
width: 600,
modal: true,
buttons: {
"Schedule Recording": addRecord,
Cancel: function() {
dialog.dialog( "close" );
}
},
close: function() {
//form[ 0 ].reset();
//allFields.removeClass( "ui-state-error" );
}
});
// Set grid defaults
jQuery.extend(jQuery.jgrid.defaults, {
altRows: true,
responsive: true,
autowidth: true,
forceFit: true,
sortable: true,
colMenu: true,
colMenuColumnDone: function(cols,column,checked) {
console.log("colMenuColumnDone "+column+" checked: "+checked);
if (column!="") {
if (checked) {
$(this).jqGrid("showCol",column).jqGrid("resizeGrid",500,true,false);
} else {
$(this).jqGrid("hideCol",column).jqGrid("resizeGrid",500,true,false);
}
}
},
// resizeStop: function(size,ix) {
// console.log("resizeStop size: "+size+" ix: "+ix);
// $(this).jqGrid("resizeColumn",ix,size,true).jqGrid("resizeGrid",500,true,false);
// },
headertitles: true,
rowNum: 25,
rowList: [10, 25, 50, 100, 150, 200, 250, 300],
cmTemplate: {
colmenu: true,
editable: false,
align: "center",
editrules:{edithidden:true},
viewable: true,
searchoptions: {
clearSearch: false,
searchOperMenu: false,
sopt: ['cn', 'eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'nc']
}
}
});
initRecordingsTable();
initEPGTable();
$("#loadChannels").show();
// Load the Channels list
$.ajax({
url: urlPfx+"Method=GetXmltvChannelsList&FromChIndex=FirstChannel&ToChIndex=LastChannel&Externals=YES",
success: function(ChannelList) {
$("#loadChannels").hide();
if (checkVboxResponse(ChannelList,'#loadChannels',"Load Channels")) {
initChannelsTable(ChannelList);
loadRecordings();
loadEPG(fullEPG);
}
},
error: function(xhr) {
ajaxError(xhr,"#loadChannels","Error loading Channels");
initChannelsTable(testChanList);
recordList=testRecList;
prepRecordingsTable();
epgList=testEPGList;
prepEPGTable();
}
});
//end of doc ready function
});
function loadRecordings() {
$("#loadRecordings").show();
// Load the recordings list
$.ajax({
url: urlPfx+"Method=GetRecordsList&Externals=YES",
success: function(recordings) {
$("#loadRecordings").hide();
if (checkVboxResponse(recordings,'#loadRecordings',"Load Recordings")) {
recordList=recordings;
prepRecordingsTable();
}
},
error: function(xhr) {
ajaxError(xhr,"#loadRecordings","Error loading Recordings");
}
});
}
function loadEPG(url) {
$("#loadEPG").show();
// Load the EPG list
$.ajax({
url: urlPfx+url,
success: function(epgData) {
$("#loadEPG").hide();
if (checkVboxResponse(epgData,'#loadEPG',"Load EPG")) {
epgList =epgData;
prepEPGTable();
}
},
error: function(xhr) {
ajaxError(xhr,"#loadEPF","Error loading EPG");
}
});
}
function prepRecordingsTable() {
// Create unique RowId, use negative for external recordings
var extix = 0;
var rec, recid, recids, i
var records = recordList.getElementsByTagName("record");
for (i = 0; i < records.length; i++) {
rec = records[i];
recids = rec.getElementsByTagName("record-id")
if (recids.length == 1) {
recid = rec.getElementsByTagName("record-id")[0].childNodes[0].nodeValue;
} else {
recid = --extix;
}
// append RowId elemnent to record
rowid = recordList.createElement("rowid");
rowix = recordList.createTextNode("rec"+recid);
rec.appendChild(rowid).appendChild(rowix);
//
}
reloadRecordingsTable();
}
function reloadRecordingsTable() {
$("#recordingsGrid").jqGrid("clearGridData")
.jqGrid('setGridParam', { datatype: "xmlstring", datastr: recordList })
.trigger('reloadGrid', [{ current:true}])
.jqGrid('sortGrid','start', true, 'desc');
$("#seriesGrid").jqGrid("clearGridData")
.jqGrid('setGridParam', { datatype: "xmlstring", datastr: recordList })
.trigger('reloadGrid', [{ current:true}])
.jqGrid('sortGrid', 'current-start', true, 'desc');
}
function initRecordingsTable() {
// Recordings Grid
var recColModel = colChan.concat(colRecChan,colTitle,colTime,colRec);
$("#recordingsGrid").jqGrid({
datatype: "xmlstring",
datastr: recordList,
colModel: recColModel,
xmlReader: {
root: "record-list",
row: "record",
repeatitems: false
// id: "record-id"
},
height: 'auto',
loadonce: true,
pager: '#recordingsGridPager',
sortname: 'record-id',
viewrecords: true,
sortorder: "desc",
caption: "Recordings"
})
.jqGrid('hideCol','channel-name')
.jqGrid('filterToolbar',{searchOperators: true})
.navGrid('#recordingsGridPager', {
edit: false,
add: false,
del: false
});
$("#recordingsExport").on("click", function() {
$("#recordingsGrid").jqGrid("exportToHtml", {
includeLabels: true,
includeGroupHeader: true,
includeFooter: true,
autoPrint: false
});
});
// Series Grid
var serColModel = colChan.concat(colTitle,colSer);
$("#seriesGrid").jqGrid({
datatype: "xmlstring",
datastr: recordList,
colModel: serColModel,
xmlReader: {
root: "record-list",
row: "record-series",
repeatitems: false
},
height: 'auto',
loadonce: true,
pager: '#seriesGridPager',
sortname: 'current-start',
viewrecords: true,
sortorder: "desc",
caption: "Series recording schedule"
})
.jqGrid('filterToolbar',{searchOperators: true})
.navGrid('#seriesGridPager', {
edit: false,
add: false,
del: false
});
$("#seriesExport").on("click", function() {
$("#seriesGrid").jqGrid("exportToHtml", {
includeLabels: true,
includeGroupHeader: true,
includeFooter: true,
autoPrint: false
});
});
// end Init recordings list
}
function initChannelsTable(ChannelList) {
// Create arrays of channel name, icon
var extix = 0;
var chan, id, dname, name, lcn, type, icon, url, i
var chans = ChannelList.getElementsByTagName("channel");
for (i = 0; i < chans.length; i++) {
chan = chans[i];
id = chan.getAttribute('id')
dname = chan.getElementsByTagName("display-name");
name = dname[0].childNodes[0].nodeValue;
type = dname[1].childNodes[0].nodeValue;
lcn = dname[4].childNodes[0].nodeValue;
icon = chan.getElementsByTagName("icon")[0].getAttribute('src');
url = chan.getElementsByTagName("url")[0].getAttribute('src');
// append elemnent to arrays
chanName[id] = name;
chanType[id] = type;
chanLCN[id] = lcn;
chanIcon[id] = icon;
chanURL[id] = url;
}
// end initChannelsTable
}
function prepEPGTable() {
// Create unique RowId, epgnnnn
var extix = 0;
var rec, recid, recids, i
var epgs = epgList.getElementsByTagName("programme");
for (i = 0; i < epgs.length; i++) {
rec = epgs[i];
recid = ++extix;
// append RowId elemnent to epg
rowid = epgList.createElement("rowid");
rowix = epgList.createTextNode("epg"+recid);
rec.appendChild(rowid).appendChild(rowix);
//
}
reloadEPGTable();
}
function reloadEPGTable() {
$("#epgGrid").jqGrid("clearGridData")
.jqGrid('setGridParam', { datatype: "xmlstring", datastr: epgList })
.trigger('reloadGrid', [{ current:true}])
.jqGrid('sortGrid', 'start', true, 'asc');
}
function initEPGTable() {
var epgColModel = colChan.concat(colEPGtitle,colTime,colEPG);
// epg Grid
$("#epgGrid").jqGrid({
datatype: "xmlstring",
datastr: epgList,
colModel: epgColModel,
xmlReader: {
root: "tv",
row: "programme",
repeatitems: false
// id: "epg-id"
},
height: 'auto',
loadonce: true,
pager: '#epgGridPager',
sortname: 'epg-id',
viewrecords: true,
sortorder: "desc",
caption: "EPG"
})
.jqGrid('filterToolbar',{searchOperators: true})
.navGrid('#epgGridPager', {
edit: false,
add: false,
del: false
});
// end EPG table init
}
/* checkVboxResponse
check XML returned by vbox for non zero error ErrCode
if found show in alert div and return false,
return true if no error reported */
function checkVboxResponse(vboxdat, divlabel, ident = "") {
if (vboxdat.getElementsByTagName("ErrorCode").length==0) {return true}
var ErrCode = vboxdat.getElementsByTagName("ErrorCode")[0].childNodes[0].nodeValue;
if (ErrCode==0) {return true}
var ErrDesc = vboxdat.getElementsByTagName("ErrorDescription")[0].childNodes[0].nodeValue;
$(divlabel).html(alertIcon+" "+ident+" Vbox response: "+ ErrCode + " - " + ErrDesc ).show();
alert(ident+" Vbox response: "+ ErrCode + " - " + ErrDesc );
console.log(divlabel +" "+ ident+" Vbox response: "+ ErrCode + " - " + ErrDesc );
return false;
}
function ajaxError(xhr, divlabel, ident = ""){
$(divlabel).html(alertIcon+" "+ident+", code: "+ xhr.status + " - " + xhr.statusText ).show();
console.log(divlabel+" "+ident+", code: "+ xhr.status + " - " + xhr.statusText)
}
/**
* Format bytes as human-readable text.
*
* @param bytes Number of bytes.
* @param si True to use metric (SI) units, aka powers of 1000. False to use
* binary (IEC), aka powers of 1024.
* @param dp Number of decimal places to display.
*
* @return Formatted string.
*
* From:
* https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string/10420404
*/
function humanFileSize(bytes, si = false, dp = 1) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si ?
['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] :
['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
let u = -1;
const r = 10 ** dp;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(dp) + ' ' + units[u];
}
function setChanName(rowObject) {
var cellvalue = $(rowObject).attr('channel');
if (typeof cellvalue == 'undefined') {
return "";
}
if (typeof chanName[cellvalue] == 'undefined') {
return "";
}
return chanName[cellvalue];
}
function setChanURL(rowObject) {
var cellvalue = $(rowObject).attr('channel');
if (typeof cellvalue == 'undefined') {
return "";
}
if (typeof chanURL[cellvalue] == 'undefined') {
return "";
}
return chanURL[cellvalue];
}
function setChanType(rowObject) {
var cellvalue = $(rowObject).attr('channel');
if (typeof cellvalue == 'undefined') {
return "";
}
if (typeof chanType[cellvalue] == 'undefined') {
return "";
}
return chanType[cellvalue];
}
function setChanIcon(rowObject) {
var cellvalue = $(rowObject).attr('channel');
if (typeof cellvalue == 'undefined') {
return "";
}
if (typeof chanIcon[cellvalue] == 'undefined') {
return "";
}
var text = "<img src='"+chanIcon[cellvalue]+"' alt='"+chanName[cellvalue]+"' title='"+chanName[cellvalue]+"' width=16 height=16 >";
return text;
}
function setChanLCN(rowObject) {
var cellvalue = $(rowObject).attr('channel');
if (typeof cellvalue == 'undefined') {
return "";
}
if (typeof chanLCN[cellvalue] == 'undefined') {
return "";
}
return chanLCN[cellvalue];
}
function fmtTimeStmp(cellvalue, options, rowObject) {
//console.log("fmtTimeStmp " + cellvalue);
if (typeof cellvalue == 'undefined') {
return ""
}
if (cellvalue.length < 12) {
return ""
}
var Yr = cellvalue.substr(0, 4);
var Mon = cellvalue.substr(4, 2);
var Day = cellvalue.substr(6, 2);
var Hr = cellvalue.substr(8, 2);
var Min = cellvalue.substr(10, 2);
var Sec = cellvalue.substr(12, 2);
var d = new Date(Yr, Mon - 1, Day, Hr, Min, Sec)
var text = d.toLocaleString({
dateStyle: 'short',
timeStyle: 'short'
});
//console.log("fmtTimeStmp " + cellvalue +" "+text+" "+Yr+" "+Mon+" "+Day);
return text;
}
function fmtTime(cellvalue, options, rowObject) {
//console.log("fmtTimeStmp " + cellvalue);
if (typeof cellvalue == 'undefined') {
return ""
}
if (cellvalue.length < 12) {
return ""
}
var Yr = cellvalue.substr(0, 4);
var Mon = cellvalue.substr(4, 2);
var Day = cellvalue.substr(6, 2);
var Hr = cellvalue.substr(8, 2);
var Min = cellvalue.substr(10, 2);
var Sec = cellvalue.substr(12, 2);
var d = new Date(Yr, Mon - 1, Day, Hr, Min, Sec)
var text = d.toLocaleTimeString({
dateStyle: 'short',
timeStyle: 'short'
});
//console.log("fmtTimeStmp " + cellvalue +" "+text+" "+Yr+" "+Mon+" "+Day);
return text;
}
function setDuration(rowObject) {
//console.log("fmtTimeStmp " + cellvalue);
if (typeof $(rowObject).attr('stop') == 'undefined') {
return ""
}
if (typeof $(rowObject).attr('start') == 'undefined') {
return ""
}
var stoptime = $(rowObject).attr('stop');
var starttime = $(rowObject).attr('start');
return calcDuration(starttime,stoptime);
}
function setDurationSeries(rowObject) {
if (rowObject.getElementsByTagName("start").length == 0) {
return ""
}
if (rowObject.getElementsByTagName("stop").length == 0) {
return ""
}
var stoptime = rowObject.getElementsByTagName("stop")[0].childNodes[0].nodeValue;
var starttime = rowObject.getElementsByTagName("start")[0].childNodes[0].nodeValue;
return calcDuration(starttime,stoptime);
}
function calcDuration(starttime,stoptime) {
var Yr = stoptime.substr(0, 4);
var Mon = stoptime.substr(4, 2);
var Day = stoptime.substr(6, 2);
var Hr = stoptime.substr(8, 2);
var Min = stoptime.substr(10, 2);
var Sec = stoptime.substr(12, 2);
var stop = new Date(Yr, Mon - 1, Day, Hr, Min, Sec);
Yr = starttime.substr(0, 4);
Mon = starttime.substr(4, 2);
Day = starttime.substr(6, 2);
Hr = starttime.substr(8, 2);
Min = starttime.substr(10, 2);
Sec = starttime.substr(12, 2);
var start = new Date(Yr, Mon - 1, Day, Hr, Min, Sec);
//var durn = new Date;
var durn = new Date(stop -start).getTime();
const hours = Math.floor(durn / 3600000);
durn -= hours * 3600000;
const minutes = Math.floor(durn / 60000);
return `${hours}:${('0' + minutes).slice(-2)}`
}
function fmtDate(cellvalue, options, rowObject) {
//console.log("fmtDate " + cellvalue);
if (typeof cellvalue == 'undefined') {
return ""
}
if (cellvalue.length < 8) {
return ""
}
var Yr = cellvalue.substr(0, 4);
var Mon = cellvalue.substr(4, 2);
var Day = cellvalue.substr(6, 2);
var Hr = 0;
var Min = 0;
var Sec = 0;
var d = new Date(Yr, Mon - 1, Day, Hr, Min, Sec)
var text = d.toLocaleDateString({
dateStyle: 'short',
timeStyle: 'short'
});
//console.log("fmtTimeStmp " + cellvalue +" "+text+" "+Yr+" "+Mon+" "+Day);
return text;
}
function fmtSize(cellvalue, options, rowObject) {
//console.log("fmtSize " + cellvalue);
if (isNaN(cellvalue)) {
return "";
}
var text = humanFileSize(cellvalue);
//console.log(cellvalue + " = " + text)
return text;
}
// Create a button for the Actions column
function fmtButton(grid,id,funcName,label,icon,opts = {}){
var text = '<div title="##label##" style="float:left;" class="ui-pg-div" id="##funcName##_##id##" \
onclick=\'##funcName##(\"##grid##\","##id##","##label##",##opts##);\' \
onmouseover="jQuery(this).addClass(\'ui-state-hover\');" \
onmouseout="jQuery(this).removeClass(\'ui-state-hover\');"><span class="##icon##"></span></div>';
text=text.replace(/##label##/g,label);
text=text.replace(/##id##/g,id);
text=text.replace(/##funcName##/g,funcName);
text=text.replace(/##icon##/g,icon);
text=text.replace(/##opts##/g,JSON.stringify(opts));
text=text.replace(/##grid##/g,grid);
//console.log("fmtButton = " + text)
return text;
}
function setEPGactions(rowObject) {
var rowid = rowObject.getElementsByTagName("rowid")[0].childNodes[0].nodeValue;
var text = "<div id='msg"+rowid+"' hidden width=150></div>";
text += fmtButton("#epgGrid",rowid,'viewRow','View row details','fa fa-eye',{});
var opts ={};
text += fmtButton("#epgGrid",rowid,'schedRecord','Schedule Recording','fa fa-circle record-red',{});
var state=$(rowObject).attr('state');
switch (state) {
case "scheduled":
if (typeof $(rowObject).attr('series-id') != 'undefined') {
// Can't delete series episode, must choose series table
return text;
}
case "recording":
opts.procurl = "Method=CancelRecord&RecordID="+rowid;
break;
case "recorded":
case "Error":
opts.procurl = "Method=DeleteRecord&RecordID="+rowid;
break;
case "External":
opts.procurl = "Method=DeleteRecord&RecordID=External&FileName="+$(rowObject).attr('LocalTarget');
break;
default:
return text;
}
text += fmtButton("#epgGrid",rowid,'procRecord','Delete recording','ui-icon ui-icon-trash',opts)
//console.log(cellvalue + " = " + text)
return text;
}
function setRecActions(rowObject) {
var rowid = rowObject.getElementsByTagName("rowid")[0].childNodes[0].nodeValue;
var state = rowObject.getElementsByTagName("state")[0].childNodes[0].nodeValue;
if (state != "External") {
var recid = rowObject.getElementsByTagName("record-id")[0].childNodes[0].nodeValue;
}
var text = "<div id='msg"+rowid+"' hidden width=150></div>";
text += fmtButton("#recordingsGrid",rowid,'viewRow','View row details','fa fa-eye',{});
var opts ={};
var butLabel="";
switch (state) {
case "scheduled":
if (rowObject.getElementsByTagName("series-id").length != 0) {
// Can't delete series episode, must choose series table
return text;
}
case "recording":
butLabel="Cancel recording";
opts.procurl = "Method=CancelRecord&RecordID="+recid;
break;
case "recorded":
case "Error":
butLabel="Delete recording";
opts.procurl = "Method=DeleteRecord&RecordID="+recid;
break;
case "External":
butLabel="Delete external recording";
opts.procurl = "Method=DeleteRecord&RecordID=External&FileName="+encodeURIComponent($(rowObject).attr('LocalTarget'));
break;
default:
return text;
}
text += fmtButton("#recordingsGrid",rowid,'procRecord',butLabel,'ui-icon ui-icon-trash',opts)
//console.log(cellvalue + " = " + text)
return text;
}
function setSerActions(rowObject) {
var serid =$(rowObject).attr('series-id');
var rowid=serid;
var opts = {};
opts.procurl = "Method=CancelRecord&RecordID="+serid;
var text = "<div id='msg"+rowid+"' hidden width=50></div>";
text += fmtButton("#seriesGrid",rowid,'viewRow','View row details','fa fa-eye',{});
text += fmtButton("#seriesGrid",rowid,'procRecord','Cancel series recording','ui-icon ui-icon-trash',opts);
//console.log(cellvalue + " = " + text)
return text;
}
function viewRow(grid, rowid, label, opts ={}) {
$(grid).jqGrid('viewGridRow',rowid,{modal:true,closeOnEscape:true,viewhidden:true});
};
function schedRecord(grid, rowid, label, opts ={}) {
var rowObj =$(grid).jqGrid('getRowData',rowid);
var chan = rowObj["channel-LCN"] + " " + rowObj["channel-icon"] + " " + rowObj["channel-name"] ;
$("#recchan").html(chan);
$("#rectitle").html(rowObj["title"]);
$("#recdesc").html(rowObj["desc"]);
$("#recstart").html(rowObj["start"]);
$("#recstop").html(rowObj["stop"]);
$("#recrow").html(rowObj["rowid"]);
$("#reccrid").html(rowObj["crid"]);
$("#single").prop('checked', true).trigger('change');
if (rowObj["crid"]== "") {
$("#series").prop('disabled', true);
} else {
$("#series").prop('disabled', false);
}
dialog.dialog( "open" );
};
function addRecord(grid, rowid, label, opts ={}) {
//$(grid).jqGrid('viewGridRow',rowid,{modal:true,closeOnEscape:true,viewhidden:true});
var rowid = $("#recrow").html();
var rowObj =$("#epgGrid").jqGrid('getRowData',rowid);
var chanid = rowObj["channel-id"];
var title = encodeURIComponent(rowObj["title"]);
var vbstart = encodeURIComponent(rowObj["vbstart"]);
//var vbstart = fmtVboxDate(start);
var opts= {}, label = "";
if ($("#single").prop("checked")){
opts.procurl = "Method=ScheduleProgramRecord&ChannelID="+chanid+"&ProgramTitle="+title+"&StartTime="+vbstart+"";
label= "record single programme";
} if ($("#series").prop("checked")){
opts.procurl = "Method=ScheduleProgramRecord&ChannelID="+chanid+"&ProgramTitle="+title+"&StartTime="+vbstart+"&SeriesRecording=YES";
label= "schedule series recording"
} if ($("#manual").prop("checked")){
alert ("Periodic not yet available");
return;
}
dialog.dialog( "close" );
procRecord("#epgGrid",rowid,label,opts)
};
function procRecord(grid, id, label, opts ={}) {
console.log("procRecord " + label + " " + id + ", "+grid +", "+ JSON.stringify(opts));
var procurl = opts.procurl
var ident = "Error " + label;
$.ajax({
url: urlPfx+procurl,
success: function(response) {
if (checkVboxResponse(response,"#msg"+id,ident)) {
// Reload recordings
loadRecordings();
}
},
error: function(xhr) {
ajaxError(xhr,"#msg"+id,ident);
alert(ident+", code: "+ xhr.status + " - " + xhr.statusText );
}
});
}
function fmtVboxDate(date) {
var dt = new Date(date);
var vbdt = dt.getFullYear();
return vbdt;
}
// Icons
var alertIcon = '<i class="fa fa-exclamation-triangle" style="font-size:16px;color:red"></i>';
var loadIcon = '<i class="fa fa-refresh fa-spin" style="font-size:16px;color:green"></i>';
// define variable to hold recordings, epg, and channel data
var recordList;
var epgList;
var chanName = [];
var chanIcon = [];
var chanLCN = [];
var chanURL = [];
var chanType = [];
// ColModel definitions for Channel related columns
var colChan = [
{
label: 'Channel Id',
name: 'channel-id',
tooltip: 'Vbox channel identifier',
hidden: true,
width: 120,
xmlmap: '[channel]'
},
{
label: 'Icon',
name: 'channel-icon',
tooltip: 'Channel icon, derived from channel-id',
width: 30,
sortable: false,
colmenu: false,
search:false,
xmlmap: setChanIcon,
//xmlmap: '[channel]'
},
{
label: 'Channel Name',
name: 'channel-name',
tooltip: 'Channel name, derived from channel-id',
width: 120,
xmlmap: setChanName,
//xmlmap: '[channel]'
},
{
label: 'LCN',
name: 'channel-LCN',
tooltip: 'Local channel number, derived from channel-id',
width: 60,
sorttype: "number",
formatter: 'integer',
hidden: true,
xmlmap: setChanLCN,
//xmlmap: '[channel]'
},
{
label: 'Type',
name: 'channel-Type',
tooltip: 'Channel type, derived from channel-id',
width: 60,
hidden: true,
xmlmap: setChanType,
//xmlmap: '[channel]'
},
{
label: 'Channel URL',
name: 'channel-URL',
tooltip: 'URL for channel, derived from channel-id',
width: 120,
hidden: true,
xmlmap: setChanURL,
//xmlmap: '[channel]'
}
];
// ColModel definitions for Start/Stop?duration columns
var colTime=[
{
label: 'VB Start',
name: 'vbstart',
tooltip: 'Programme start date and time (vbox format)',
width: 140,
hidden: true,
xmlmap: '[start]'
},
{
label: 'Start',
name: 'start',
tooltip: 'Programme start date and time',
width: 105,
hidden: true,
formatter: fmtTimeStmp,
xmlmap: '[start]'
},
{
label: 'Start Date',
name: 'start-date',
tooltip: 'Programme start date',
width: 90,
formatter: fmtDate,
xmlmap: function(obj) {
return $(obj).attr('start').substr(0, 8);
}
},
{
label: 'Start Time',
name: 'start-time',
tooltip: 'Programme start time',
width: 90,
formatter: fmtTime,
xmlmap: '[start]'
},
{
label: 'VB Stop',
name: 'vbstop',
tooltip: 'Programme stop date and time (vbox format)',
width: 140,
hidden: true,
xmlmap: '[stop]'
},
{
label: 'Stop',
name: 'stop',
tooltip: 'Programme end date and time',
width: 105,
hidden: true,
formatter: fmtTimeStmp,
xmlmap: '[stop]'
},
{
label: 'Stop Date',
name: 'stop-date',
tooltip: 'Programme end date',
width: 90,
hidden: true,
formatter: fmtDate,
xmlmap: function(obj) {
return $(obj).attr('stop').substr(0, 8);
}
},
{
label: 'Stop Time',
name: 'stop-time',
tooltip: 'Programme end time',
width: 90,
hidden: true,
formatter: fmtTime,
xmlmap: '[stop]'
},
{
label: 'Len',
tooltip: 'Programme length (stop - start)',
name: 'duration',
width: 50,
sorttype: "number",
xmlmap: setDuration,
//xmlmap: '[stop]-[start]'
}];