-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
163 lines (136 loc) · 3.72 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
<!DOCTYPE html>
<html>
<head>
<title>Simple Secure File Browser</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<style>
#capInput {
width: 400px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="span12">
<h1>Simple Secure File Browser</h1>
</div>
</div>
<div id="capprompt" class="row" hidden>
<div class="span12">
<form class="form-inline" role="form" action="/static/simpleui/index.html" method="get">
<div class="form-group">
<label class="sr-only" for="capInput">Root Capability</label>
<input type="text" class="form-control" name="capInput" id="capInput" placeholder="Enter root capability">
</div>
<button type="submit" class="btn btn-default">Enter</button>
</form>
</div>
</div>
<div class="row">
<div class="span12">
<ul class="breadcrumb" id="pathList"></ul>
</div>
</div>
<div class="row">
<div class="span12">
<table class="table table-condensed" id="entriesTable"></table>
</div>
</div>
</div>
<script id="pathScript" type="text/html">
{{#path}}
<li><a href="#" onclick="truncatePath({{idx}});">{{name}}</a></li>
{{/path}}
</script>
<script id="listing" type="text/html">
<tr><th>Name</th><th>Type</th><th>Size</th><th>Time</th></tr>
{{#entries}}
<tr><td><a href="{{target}}" onclick="{{action}}">{{name}}</a></td>
<td>{{type}}</td>
<td>{{size}}</td>
<td>{{time}}</td></tr>
{{/entries}}
</script>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/ICanHaz.min.js"></script>
<script>
var path = [];
$(document).ready(function() {
// try to load root cap from prompt
var rcap = getParam('capInput');
if(rcap == null) {
$("#capprompt").show();
$("#pathList").hide();
}
else {
path = [{'name':'root', 'uri':rcap, 'idx':0}];
loadTable();
}
});
function goTo(dir) {
dir.idx = path.length;
path.push(dir);
loadTable();
}
function truncatePath(i) {
path = path.slice(0, i+1);
loadTable();
}
function getParam(sParam) {
var sPageURL = document.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
return null;
}
function loadTable() {
var uri = path[path.length-1].uri;
$.getJSON('/uri/' + uri + '?t=json', function(data) {
//console.log(data);
var entries = [];
$.each(data[1].children, function(k,v) {
var sz = '';
if(v[1].hasOwnProperty('size')) {
sz = v[1].size;
}
var dt = '';
if(v[1].hasOwnProperty('metadata') &&
v[1].metadata.hasOwnProperty('tahoe')) {
dt = new Date(v[1].metadata.tahoe.linkmotime * 1000)
}
// defaults for directories
var target='#';
var action = "goTo({'name':'" + k + "','uri':'"+ v[1].ro_uri + "'});"
var typ = 'dir';
// changes for files
if(v[0] != 'dirnode') {
typ = 'file';
action = '';
target = '/uri/' + v[1].ro_uri + '?filename=' + k + '&save=true';
}
entries.push({
'name':k,
'type':typ,
'size':sz,
'time':dt,
'action': action,
'target': target
});
});
var contentsHtml = ich.listing({'entries': entries});
$("#entriesTable").html(contentsHtml);
var pathHtml = ich.pathScript({'path': path});
$('#pathList').html(pathHtml);
});
}
</script>
</body>
</html>