text-input-dialog.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. <link rel="import" href="../../bower_components/iron-pages/iron-pages.html">
  6. <link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html">
  7. <link rel="import" href="../../bower_components/paper-spinner/paper-textarea.html">
  8. <dom-module id="text-input-dialog">
  9. <template>
  10. <style>
  11. :host {
  12. display: block;
  13. }
  14. #dialog,
  15. #download {
  16. width: 300px;
  17. z-index: 101;
  18. }
  19. .filename {
  20. word-break: break-all;
  21. word-break: break-word;
  22. }
  23. paper-textarea {
  24. height: 200px;
  25. }
  26. </style>
  27. <paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop modal>
  28. <h2>Send Text</h2>
  29. <paper-textarea label="Enter Text"></paper-textarea>
  30. <div class="buttons">
  31. <paper-button dialog-dismiss on-tap="_decline">Discard</paper-button>
  32. <paper-button dialog-confirm on-tap="_accept" autofocus>Send</paper-button>
  33. </div>
  34. </paper-dialog>
  35. <paper-dialog id="download" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop modal>
  36. <h2>Text Received</h2>
  37. <p>Open File or Right Click and "Save as"...</p>
  38. <div class="buttons">
  39. <paper-button dialog-dismiss>Discard</paper-button>
  40. <a href="{{dataUri}}" target="_blank">
  41. <paper-button dialog-confirm autofocus>Open File</paper-button>
  42. </a>
  43. </div>
  44. </paper-dialog>
  45. </template>
  46. <script>
  47. 'use strict';
  48. (function() {
  49. Polymer({
  50. is: 'text-input-dialog',
  51. open: function() {
  52. this.$.dialog.open();
  53. },
  54. attached: function() {
  55. // this.async(function() {
  56. // app.conn.addEventListener('file-offer', function(e) {
  57. // this.file = e.detail;
  58. // this.$.dialog.open();
  59. // }.bind(this), false);
  60. // app.conn.addEventListener('file-received', function(e) {
  61. // this._fileReceived(e.detail);
  62. // }.bind(this), false);
  63. // app.conn.addEventListener('file-declined', function(e) {
  64. // app.displayToast('User declined file ' + e.detail.name);
  65. // }.bind(this), false);
  66. // app.conn.addEventListener('upload-complete', function(e) {
  67. // app.displayToast('User received file ' + e.detail.name);
  68. // }.bind(this), false);
  69. // app.conn.addEventListener('upload-error', function(e) {
  70. // app.displayToast('The other device did not respond. Please try again.');
  71. // }.bind(this), false);
  72. // }, 200);
  73. },
  74. _fileReceived: function(file) {
  75. this.downloadURI(file);
  76. },
  77. _decline: function() {
  78. app.conn.decline(this.file);
  79. },
  80. _accept: function() {
  81. app.conn.accept(this.file);
  82. },
  83. downloadURI: function(file) {
  84. var link = document.createElement('a');
  85. var uri = (window.URL || window.webkitURL).createObjectURL(file.blob);
  86. if (typeof link.download !== 'undefined') {
  87. //download attribute is supported
  88. link.href = uri;
  89. link.download = file.name || 'blank';
  90. document.body.appendChild(link);
  91. link.click();
  92. document.body.removeChild(link);
  93. } else {
  94. this.dataUri = uri;
  95. this.$.download.open();
  96. }
  97. }
  98. });
  99. }());
  100. </script>
  101. </dom-module>