device-name.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <link rel="import" href="../../bower_components/paper-input/paper-input.html">
  2. <link rel="import" href="../../bower_components/iron-localstorage/iron-localstorage.html">
  3. <link rel="import" href="device-name-dialog.html">
  4. <dom-module id="device-name">
  5. <template>
  6. <style>
  7. :host {
  8. display: inline-block;
  9. cursor: pointer;
  10. }
  11. .name-label {
  12. @apply(--paper-font-subhead);
  13. text-align: center;
  14. cursor: pointer;
  15. width: 160px;
  16. line-height: 18px !important;
  17. }
  18. :root {
  19. /* Label and underline color when the input is not focused */
  20. --paper-input-container-color: #333;
  21. /* Label and underline color when the input is focused */
  22. --paper-input-container-focus-color: #4285f4;
  23. /* Label and underline color when the input is invalid */
  24. --paper-input-container-invalid-color: red;
  25. /* Input foreground color */
  26. --paper-input-container-input-color: #333;
  27. }
  28. @media all and (max-height: 370px) {
  29. :host {}
  30. }
  31. paper-dialog {
  32. width: 300px;
  33. text-align: left;
  34. }
  35. </style>
  36. <div class="name-label" hidden$="{{name}}">My Name</div>
  37. <div class="name-label" hidden$="{{!name}}">{{name}}</div>
  38. <iron-localstorage name="device-name" value="{{name}}" iron-localstorage-load="_nameChanged"></iron-localstorage>
  39. </template>
  40. <script>
  41. 'use strict';
  42. Polymer({
  43. is: 'device-name',
  44. properties: {
  45. name: {
  46. observer: '_nameChanged'
  47. }
  48. },
  49. open: function() {
  50. this.deviceNameDialog.open();
  51. },
  52. _nameChanged: function(name) {
  53. if (!name) {
  54. return;
  55. }
  56. this.cancelAsync(this.timer);
  57. this.timer = this.async(function() {
  58. if (!app.conn.notifyServer) {
  59. this._nameChanged(name);
  60. return;
  61. }
  62. this._sendNameToServer(name);
  63. }, 300);
  64. },
  65. _sendNameToServer: function(name) {
  66. app.conn.notifyServer({
  67. serverMsg: 'device-name',
  68. name: name
  69. });
  70. },
  71. _initialize: function() {
  72. console.log('initialize name');
  73. },
  74. get deviceNameDialog() {
  75. var deviceNameDialog = document.querySelector('device-name-dialog');
  76. if (!deviceNameDialog) {
  77. deviceNameDialog = Polymer.Base.create('device-name-dialog');
  78. deviceNameDialog.addEventListener('save-device-name', function(e) {
  79. this.name = e.detail;
  80. console.log(this.name);
  81. }.bind(this));
  82. document.body.appendChild(deviceNameDialog);
  83. };
  84. deviceNameDialog.deviceName = this.name;
  85. return deviceNameDialog;
  86. }
  87. });
  88. </script>
  89. </dom-module>