-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
146 lines (137 loc) · 5.56 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
<!DOCTYPE html>
<html>
<head>
<title>starcounter-include demo</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href="starcounter-upload.html" rel="import" />
<script src="test/mockServer.js"></script>
<style>
body {
padding: 50px;
}
span.btn-link,
span.btn-link:hover {
text-decoration: none;
color: inherit;
cursor: text;
}
</style>
</head>
<body>
<dom-bind>
<template is="dom-bind">
<fieldset>
<legend>Uploaded files</legend>
<dom-if>
<template is="dom-if" if="{{model.files.length}}">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Size</th>
<th>Progress</th>
<th></th>
</tr>
</thead>
<tbody>
<template is="dom-repeat" items="{{model.files}}">
<tr>
<td>{{item.file.name}}</td>
<td>{{item.file.type}}</td>
<td>{{item.sizeString}}</td>
<td>
<span>{{item.progress}}</span>%
</td>
<td>{{item.error}}</td>
</tr>
</template>
</tbody>
</table>
</template>
</dom-if>
<dom-if>
<template is="dom-if" if="{{!model.files.length}}">
<p>No files uploaded so far</p>
</template>
</dom-if>
</fieldset>
<hr />
<div class="starcounter-upload-tasks">
<h4>The <code>starcounter-upload.tasks</code> collection</h4>
<dom-if>
<template is="dom-if" if="{{tasks.length}}">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Size</th>
<th>Progress</th>
<th></th>
</tr>
</thead>
<tbody>
<template is="dom-repeat" items="{{tasks}}">
<tr>
<td>{{item.file.name}}</td>
<td>{{item.file.type}}</td>
<td>{{item.sizeString}}</td>
<td>
<span>{{item.progress}}</span>%
</td>
<td>{{item.error}}</td>
</tr>
</template>
</tbody>
</table>
</template>
</dom-if>
<dom-if>
<template is="dom-if" if="{{!tasks.length}}">
<p>No files in queue</p>
</template>
</dom-if>
</div>
<hr />
<p>
<starcounter-upload upload-url="/starcounter-upload" session-id="mock-session" tasks="{{tasks}}" on-statechange="onUploadingStateChange" multiple="true" auto-upload="true">
<button type="button" class="btn btn-sm btn-default" on-click="selectFile">Select files to upload</button>
<span class="btn btn-sm btn-link">Click <code>Ctrl + V</code> to paste image from clipboard</span>
</starcounter-upload>
</p>
<p>
<small>
<b>Note:</b> this example mocks <code>WebSocket</code> connection.
</small>
</p>
</template>
</dom-bind>
<script>
(function () {
var script = document._currentScript || document.currentScript;
var template = script.previousElementSibling;
var parentNode = template.parentNode;
if (!Polymer.Element) {
// Polymer v 1.0
template = template.firstElementChild;
parentNode = parentNode.parentNode;
}
var model = {
files: []
};
template.selectFile = function () {
parentNode.querySelector("starcounter-upload").selectFile();
};
template.onUploadingStateChange = function (e) {
var task = e.detail;
if (task.progress >= 100 || task.error) {
template.push("model.files", task);
}
};
template.model = model;
})();
</script>
</body>
</html>