device-name-dialog.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">
  2. <link rel="import" href="../../bower_components/paper-input/paper-input.html">
  3. <dom-module id="device-name-dialog">
  4. <template>
  5. <style>
  6. :host {
  7. display: block;
  8. }
  9. paper-dialog {
  10. width: 400px;
  11. max-width: 90%
  12. }
  13. </style>
  14. <paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation" with-backdrop>
  15. <h2>Name this Device</h2>
  16. <p>
  17. <paper-input id="input" value="{{deviceName}}" label="Name this Device" char-counter maxlength="18" on-keypress="_keyPressed" autofocus></paper-input>
  18. </p>
  19. <div class="buttons">
  20. <paper-button dialog-dismiss>Cancel</paper-button>
  21. <paper-button on-tap="_save">Rename</paper-button>
  22. </div>
  23. </paper-dialog>
  24. </template>
  25. <script>
  26. 'use strict';
  27. Polymer({
  28. is: 'device-name-dialog',
  29. properties: {
  30. deviceName: {
  31. notify: true
  32. }
  33. },
  34. open: function() {
  35. this.$.dialog.open();
  36. },
  37. _keyPressed: function(e) {
  38. if (e.which === 13 || e.charCode === 13) {
  39. this.$.input.inputElement.blur();
  40. this._save();
  41. }
  42. },
  43. _save: function() {
  44. this.$.dialog.close();
  45. this.fire('save-device-name', this.deviceName);
  46. }
  47. });
  48. </script>
  49. </dom-module>