file-receiver.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">
  2. <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  3. <link rel="import" href="../../bower_components/neon-animation/animations/scale-up-animation.html">
  4. <link rel="import" href="../../bower_components/neon-animation/animations/fade-out-animation.html">
  5. <dom-module id="file-receiver">
  6. <template>
  7. <style>
  8. :host {
  9. display: block;
  10. position: fixed;
  11. z-index: 100;
  12. }
  13. </style>
  14. <paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdro>
  15. <h2>File Received</h2>
  16. <p>You received file {{file.name}}</p>
  17. <div class="buttons">
  18. <paper-button dialog-dismiss>Dismiss</paper-button>
  19. <paper-button dialog-confirm on-tap="_download">Download</paper-button>
  20. </div>
  21. </paper-dialog>
  22. </template>
  23. <script>
  24. 'use strict';
  25. Polymer({
  26. is: 'file-receiver',
  27. attached: function() {
  28. this.async(function() {
  29. app.p2p.addEventListener('file-received', function(e) {
  30. this.fileReceived(e.detail);
  31. }.bind(this), false);
  32. },200);
  33. },
  34. fileReceived: function(file) {
  35. this.set('file', file);
  36. this.$.dialog.open();
  37. },
  38. _download: function() {
  39. var link = document.createElement('a');
  40. link.download = this.file.name;
  41. // Construct the uri
  42. var uri = this.file.dataURI;
  43. link.href = uri;
  44. document.body.appendChild(link);
  45. link.click();
  46. // Cleanup the DOM
  47. document.body.removeChild(link);
  48. //delete link;
  49. }
  50. });
  51. </script>
  52. </dom-module>