user-avatar.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
  2. <dom-module id="user-avatar">
  3. <template>
  4. <style>
  5. :host {
  6. display: block;
  7. @apply(--layout-vertical);
  8. @apply(--layout-center);
  9. width: 120px;
  10. height: 152px;
  11. }
  12. paper-icon-button {
  13. display: inline-block;
  14. width: 64px !important;
  15. height: 64px !important;
  16. border-radius: 50%;
  17. overflow: hidden;
  18. padding: 12px;
  19. margin-bottom: 4px;
  20. background-color: #4285f4;
  21. color: white;
  22. }
  23. :host:hover paper-icon-button {
  24. transform: scale(1.05);
  25. }
  26. .paper-font-subhead {
  27. text-align: center;
  28. }
  29. .paper-font-body1 {
  30. text-align: center;
  31. width: 100%;
  32. font-size: 13px;
  33. color: grey;
  34. margin-top: 2px;
  35. }
  36. :host,
  37. .paper-font-subhead,
  38. .paper-font-body1 {
  39. -webkit-user-select: none;
  40. -moz-user-select: none;
  41. -ms-user-select: none;
  42. user-select: none;
  43. margin-top: 4px;
  44. }
  45. </style>
  46. <paper-icon-button icon="{{_displayIcon}}"></paper-icon-button>
  47. <div class="paper-font-subhead">{{_displayName}}</div>
  48. <div class="paper-font-body1">{{status}}</div>
  49. </template>
  50. <script>
  51. 'use strict';
  52. Polymer({
  53. is: 'user-avatar',
  54. properties: {
  55. contact: Object,
  56. _displayName: {
  57. computed: '_computeDisplayName(contact)'
  58. },
  59. _displayIcon: {
  60. computed: '_computeDisplayIcon(contact)'
  61. },
  62. status: {
  63. type: String,
  64. value: ''
  65. }
  66. },
  67. _computeDisplayName: function(contact) {
  68. contact = contact.name;
  69. if (contact.model) {
  70. return contact.os + ' ' + contact.model;
  71. }
  72. contact.os = contact.os.replace('Mac OS', 'Mac');
  73. return contact.os + ' ' + contact.browser;
  74. },
  75. _computeDisplayIcon: function(contact) {
  76. contact = contact.name;
  77. if (contact.type === 'mobile') {
  78. return 'chat:phone-iphone';
  79. }
  80. if (contact.type === 'tablet') {
  81. return 'chat:tablet-mac';
  82. }
  83. return 'chat:desktop-mac';
  84. },
  85. attached: function() {
  86. this.async(function() {
  87. app.p2p.addEventListener('file-offered', function(e) {
  88. if (e.detail.to === this.contact.peerId) {
  89. this.status = 'Waiting to accept...';
  90. }
  91. }.bind(this), false);
  92. app.p2p.addEventListener('upload-started', function(e) {
  93. if (e.detail.to === this.contact.peerId) {
  94. this.status = 'Uploading...';
  95. }
  96. }.bind(this), false);
  97. app.p2p.addEventListener('download-started', function(e) {
  98. if (e.detail.from === this.contact.peerId) {
  99. this.status = 'Downloading...';
  100. }
  101. }.bind(this), false);
  102. app.p2p.addEventListener('upload-complete', function(e) {
  103. if (e.detail.from === this.contact.peerId) {
  104. this.status = '';
  105. }
  106. }.bind(this), false);
  107. app.p2p.addEventListener('download-complete', function(e) {
  108. if (e.detail.from === this.contact.peerId) {
  109. this.status = '';
  110. }
  111. }.bind(this), false);
  112. app.p2p.addEventListener('file-declined', function(e) {
  113. if (e.detail.from === this.contact.peerId) {
  114. this.status = '';
  115. }
  116. }.bind(this), false);
  117. app.p2p.addEventListener('upload-error', function(e) {
  118. this.status = '';
  119. }.bind(this), false);
  120. }, 200);
  121. }
  122. });
  123. </script>
  124. </dom-module>