buddy-avatar.html 4.6 KB

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