-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblox-backup.js
More file actions
58 lines (54 loc) · 1.27 KB
/
blox-backup.js
File metadata and controls
58 lines (54 loc) · 1.27 KB
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
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
/**
* `blox-backup`
* Creates a file to download with the given extension and data
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class BloxBackup extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
</style>
`;
}
static get properties() {
return {
filename: {
type: String,
observer: '_start',
},
data: {
type: String,
},
suffix: {
type: String,
},
error: {
type: String,
notify: true,
reflectToAttribute: true,
},
};
}
_start(){
if(this.filename && this.data && this.suffix){
this.backup(this.filename, this.data, this.suffix)
}
}
backup(name, data, suffix) {
const filename = `${name}_${+new Date()}.${suffix}`;
const popup = window.document.createElement('a');
popup.target = '_blank';
popup.href = window.URL.createObjectURL(new Blob([data], {type: 'text/csv'}));
popup.download = filename;
document.body.appendChild(popup);
popup.click();
document.body.removeChild(popup);
}
} window.customElements.define('blox-backup', BloxBackup);