-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinished.php
73 lines (57 loc) · 2.45 KB
/
finished.php
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
<input id="filter-finished-input" data-type="search" type="search" autocomplete="off">
<br/>
<div id="list-finished">
<!-- downloads placeholder -->
</div>
<br/>
<a href="#" class="ui-btn ui-corner-all clear-all"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> Clear all</a>
<div id="list-finished-tpl" class="handlebars-template">
<ul data-role="listview" data-divider-theme="d">
<li data-role="list-divider">Finished downloads<span class="ui-li-count">{{count}}</span></li>
{{#each list}}
<li data-filtertext="{{name}}">
<h3 data-hash="{{hash}}">{{name}}</h3>
<p>{{size}}</p>
</li>
{{/each}}
<li><p><strong>Important:</strong> the listed files was present last time you connected in downloads and no more there</p></li>
</ul>
</div>
<script>
$(document).one('pagecreate', function() {
var $listFinished = $('#list-finished');
var listDownloadHb = Handlebars.compile($("#list-finished-tpl").html());
var $filterName = $('#filter-finished-input');
getList();
$('.clear-all').on('vclick', function(event) {
event.preventDefault();
idbDownloads.clear();
idbDownloads.addCurrentDownloads();
var htmlListGenerated = listDownloadHb({ list: [], count: 0 });
$listFinished.html(htmlListGenerated);
});
$filterName.on('input', function () {
getList();
});
function getList() {
$.getJSON('downloads-ajax.php', function (data) {
var finished = { list: [], count: 0 };
idbDownloads.getAll().then(function (downloadsDb) {
data.downloads.list.forEach(function (download) {
downloadsDb = downloadsDb.filter(function (file) {
return download.hash != file.hash;
});
});
finished.list = downloadsDb;
finished.count = finished.list.length;
filterName = $filterName.val().toUpperCase()
finished.list = _.filter(finished.list, function(file) {
return file.name.toUpperCase().includes(filterName);
});
var htmlListGenerated = listDownloadHb(finished);
$listFinished.html(htmlListGenerated);
});
});
}
});
</script>