2015-12-19 01:18:02 +01:00
|
|
|
<link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">
|
|
|
|
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
|
|
|
|
<link rel="import" href="../../bower_components/neon-animation/animations/scale-up-animation.html">
|
|
|
|
<link rel="import" href="../../bower_components/neon-animation/animations/fade-out-animation.html">
|
2015-12-23 13:57:13 +01:00
|
|
|
<link rel="import" href="../../bower_components/iron-pages/iron-pages.html">
|
|
|
|
<link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html">
|
2015-12-19 01:18:02 +01:00
|
|
|
<dom-module id="file-receiver">
|
2015-12-18 17:43:46 +01:00
|
|
|
<template>
|
|
|
|
<style>
|
|
|
|
:host {
|
|
|
|
display: block;
|
2015-12-23 13:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#dialog,
|
|
|
|
#download {
|
|
|
|
width: 300px;
|
|
|
|
z-index: 101;
|
|
|
|
}
|
|
|
|
|
2015-12-26 13:33:16 +01:00
|
|
|
.filename {
|
|
|
|
word-break: break-all;
|
2015-12-23 13:57:13 +01:00
|
|
|
word-break: break-word;
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
</style>
|
2015-12-23 13:57:13 +01:00
|
|
|
<paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop modal>
|
|
|
|
<h2>Download File</h2>
|
2015-12-26 13:33:16 +01:00
|
|
|
<p><b class="filename">{{file.name}}</b></p>
|
2015-12-23 13:57:13 +01:00
|
|
|
<div class="buttons">
|
|
|
|
<paper-button dialog-dismiss on-tap="_decline">Discard</paper-button>
|
|
|
|
<paper-button dialog-confirm on-tap="_accept" autofocus>Download</paper-button>
|
|
|
|
</div>
|
|
|
|
</paper-dialog>
|
|
|
|
<paper-dialog id="download" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop modal>
|
2015-12-18 17:43:46 +01:00
|
|
|
<h2>File Received</h2>
|
2015-12-26 13:33:16 +01:00
|
|
|
<p>Open File or Right Click and "Save as"...</p>
|
2015-12-18 17:43:46 +01:00
|
|
|
<div class="buttons">
|
2015-12-23 13:57:13 +01:00
|
|
|
<paper-button dialog-dismiss>Discard</paper-button>
|
|
|
|
<a href="{{dataUri}}" target="_blank">
|
2015-12-26 13:33:16 +01:00
|
|
|
<paper-button dialog-confirm autofocus>Open File</paper-button>
|
2015-12-23 13:57:13 +01:00
|
|
|
</a>
|
2015-12-18 17:43:46 +01:00
|
|
|
</div>
|
|
|
|
</paper-dialog>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
'use strict';
|
2015-12-23 13:57:13 +01:00
|
|
|
(function() {
|
|
|
|
Polymer({
|
|
|
|
is: 'file-receiver',
|
|
|
|
attached: function() {
|
|
|
|
this.async(function() {
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.addEventListener('file-offer', function(e) {
|
2015-12-23 13:57:13 +01:00
|
|
|
this.file = e.detail;
|
|
|
|
this.$.dialog.open();
|
|
|
|
}.bind(this), false);
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.addEventListener('file-received', function(e) {
|
2015-12-23 13:57:13 +01:00
|
|
|
this._fileReceived(e.detail);
|
|
|
|
}.bind(this), false);
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.addEventListener('file-declined', function(e) {
|
2015-12-23 13:57:13 +01:00
|
|
|
app.displayToast('User declined file ' + e.detail.name);
|
|
|
|
}.bind(this), false);
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.addEventListener('upload-complete', function(e) {
|
2015-12-23 13:57:13 +01:00
|
|
|
app.displayToast('User received file ' + e.detail.name);
|
|
|
|
}.bind(this), false);
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.addEventListener('upload-error', function(e) {
|
2015-12-23 13:57:13 +01:00
|
|
|
app.displayToast('The other device did not respond. Please try again.');
|
|
|
|
}.bind(this), false);
|
|
|
|
}, 200);
|
|
|
|
},
|
|
|
|
_fileReceived: function(file) {
|
|
|
|
this.downloadURI(file);
|
|
|
|
},
|
|
|
|
_decline: function() {
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.decline(this.file);
|
2015-12-23 13:57:13 +01:00
|
|
|
},
|
|
|
|
_accept: function() {
|
2015-12-31 02:23:39 +01:00
|
|
|
app.conn.accept(this.file);
|
2015-12-23 13:57:13 +01:00
|
|
|
},
|
|
|
|
downloadURI: function(file) {
|
|
|
|
var link = document.createElement('a');
|
|
|
|
var uri = (window.URL || window.webkitURL).createObjectURL(file.blob);
|
|
|
|
if (typeof link.download !== 'undefined') {
|
|
|
|
//download attribute is supported
|
|
|
|
link.href = uri;
|
|
|
|
link.download = file.name || 'blank';
|
|
|
|
document.body.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
document.body.removeChild(link);
|
|
|
|
} else {
|
|
|
|
this.dataUri = uri;
|
|
|
|
this.$.download.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
2015-12-18 17:43:46 +01:00
|
|
|
</script>
|
|
|
|
</dom-module>
|