buddy-avatar.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
  2. <link rel="import" href="../file-sharing/file-input-behavior.html">
  3. <link rel="import" href="../text-sharing/text-input-behavior.html">
  4. <dom-module id="buddy-avatar">
  5. <template>
  6. <style>
  7. :host {
  8. display: block;
  9. @apply(--layout-vertical);
  10. @apply(--layout-center-center);
  11. width: 120px;
  12. height: 124px;
  13. cursor: pointer;
  14. }
  15. paper-icon-button {
  16. display: inline-block;
  17. width: 64px !important;
  18. height: 64px !important;
  19. border-radius: 50%;
  20. overflow: hidden;
  21. padding: 12px;
  22. margin-bottom: 4px;
  23. background-color: #4285f4;
  24. color: white;
  25. }
  26. :host:hover paper-icon-button {
  27. transform: scale(1.05);
  28. }
  29. .paper-font-subhead {
  30. text-align: center;
  31. margin-top: 0px;
  32. line-height: 18px;
  33. }
  34. .paper-font-body1 {
  35. text-align: center;
  36. width: 100%;
  37. font-size: 13px;
  38. color: grey;
  39. margin-top: 0px !important;
  40. line-height: 16px;
  41. }
  42. :host,
  43. .paper-font-subhead,
  44. .paper-font-body1 {
  45. -webkit-user-select: none;
  46. -moz-user-select: none;
  47. -ms-user-select: none;
  48. user-select: none;
  49. width: 120px;
  50. white-space: nowrap;
  51. overflow: hidden;
  52. text-overflow: ellipsis;
  53. }
  54. @media all and (min-height: 440px) {
  55. :host([only]) {
  56. padding: 20vh;
  57. }
  58. }
  59. .container {
  60. @apply(--layout-vertical);
  61. @apply(--layout-center);
  62. height: 112px;
  63. padding-top: 16px;
  64. display: block;
  65. }
  66. </style>
  67. <div class="container">
  68. <paper-icon-button icon="{{_displayIcon}}"></paper-icon-button>
  69. <div class="paper-font-subhead">{{_displayName}}</div>
  70. <div class="paper-font-body1">{{status}}</div>
  71. </div>
  72. </template>
  73. <script>
  74. 'use strict';
  75. Polymer({
  76. is: 'buddy-avatar',
  77. behaviors: [Chat.FileInputBehavior, Chat.TextInputBehavior],
  78. properties: {
  79. contact: Object,
  80. _displayName: {
  81. computed: '_computeDisplayName(contact)'
  82. },
  83. _displayIcon: {
  84. computed: '_computeDisplayIcon(contact)'
  85. },
  86. status: {
  87. type: String,
  88. value: '',
  89. },
  90. defaultStatus: {
  91. computed: '_computeDefaultStatus(contact)'
  92. }
  93. },
  94. _computeDisplayName: function(contact) {
  95. if (!contact.name.os) {
  96. return contact.name;
  97. }
  98. return this._computeDeviceName(contact.name);
  99. },
  100. _computeDeviceName: function(contact) {
  101. if (contact.model) {
  102. return contact.os + ' ' + contact.model;
  103. }
  104. contact.os = contact.os.replace('Mac OS', 'Mac');
  105. return contact.os + ' ' + contact.browser;
  106. },
  107. _computeDisplayIcon: function(contact) {
  108. contact = contact.device || contact.name;
  109. if (contact.type === 'mobile') {
  110. return 'chat:phone-iphone';
  111. }
  112. if (contact.type === 'tablet') {
  113. return 'chat:tablet-mac';
  114. }
  115. return 'chat:desktop-mac';
  116. },
  117. _computeDefaultStatus: function(contact) {
  118. var status = contact.device ? this._computeDeviceName(contact.device) : '';
  119. this.status = status;
  120. return status;
  121. },
  122. attached: function() {
  123. this.async(function() {
  124. app.conn.addEventListener('file-offered', function(e) {
  125. if (e.detail.to === this.contact.peerId) {
  126. this.status = 'Waiting to accept...';
  127. }
  128. }.bind(this), false);
  129. app.conn.addEventListener('upload-started', function(e) {
  130. if (e.detail.to === this.contact.peerId) {
  131. this.status = 'Uploading...';
  132. }
  133. }.bind(this), false);
  134. app.conn.addEventListener('download-started', function(e) {
  135. if (e.detail.from === this.contact.peerId) {
  136. this.status = 'Downloading...';
  137. }
  138. }.bind(this), false);
  139. app.conn.addEventListener('upload-complete', function(e) {
  140. if (e.detail.from === this.contact.peerId) {
  141. this.status = this.defaultStatus;
  142. }
  143. }.bind(this), false);
  144. app.conn.addEventListener('download-complete', function(e) {
  145. if (e.detail.from === this.contact.peerId) {
  146. this.status = this.defaultStatus;
  147. }
  148. }.bind(this), false);
  149. app.conn.addEventListener('file-declined', function(e) {
  150. if (e.detail.from === this.contact.peerId) {
  151. this.status = this.defaultStatus;
  152. }
  153. }.bind(this), false);
  154. app.conn.addEventListener('upload-error', function(e) {
  155. this.status = this.defaultStatus;
  156. }.bind(this), false);
  157. }, 200);
  158. }
  159. });
  160. </script>
  161. </dom-module>