buddy-avatar.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. line-height: 22px;
  32. margin-top: 2px;
  33. }
  34. .paper-font-body1 {
  35. text-align: center;
  36. width: 100%;
  37. font-size: 13px;
  38. color: grey;
  39. line-height: 13px;
  40. }
  41. :host,
  42. .paper-font-subhead,
  43. .paper-font-body1 {
  44. -webkit-user-select: none;
  45. -moz-user-select: none;
  46. -ms-user-select: none;
  47. user-select: none;
  48. }
  49. :host([only1]) {
  50. @apply(--layout-fit);
  51. @apply(--layout-horizontal);
  52. @apply(--layout-center-center);
  53. cursor: pointer;
  54. }
  55. .container {
  56. @apply(--layout-vertical);
  57. @apply(--layout-center);
  58. height: 112px;
  59. padding-top: 16px;
  60. display: block;
  61. }
  62. </style>
  63. <div class="container">
  64. <paper-icon-button icon="{{_displayIcon}}"></paper-icon-button>
  65. <div class="paper-font-subhead">{{_displayName}}</div>
  66. <div class="paper-font-body1">{{status}}</div>
  67. </div>
  68. </template>
  69. <script>
  70. 'use strict';
  71. Polymer({
  72. is: 'buddy-avatar',
  73. behaviors: [Chat.FileInputBehavior, Chat.TextInputBehavior],
  74. properties: {
  75. contact: Object,
  76. _displayName: {
  77. computed: '_computeDisplayName(contact)'
  78. },
  79. _displayIcon: {
  80. computed: '_computeDisplayIcon(contact)'
  81. },
  82. status: {
  83. type: String,
  84. value: ''
  85. }
  86. },
  87. _computeDisplayName: function(contact) {
  88. contact = contact.name;
  89. if (contact.model) {
  90. return contact.os + ' ' + contact.model;
  91. }
  92. contact.os = contact.os.replace('Mac OS', 'Mac');
  93. return contact.os + ' ' + contact.browser;
  94. },
  95. _computeDisplayIcon: function(contact) {
  96. contact = contact.name;
  97. if (contact.type === 'mobile') {
  98. return 'chat:phone-iphone';
  99. }
  100. if (contact.type === 'tablet') {
  101. return 'chat:tablet-mac';
  102. }
  103. return 'chat:desktop-mac';
  104. },
  105. attached: function() {
  106. this.async(function() {
  107. app.conn.addEventListener('file-offered', function(e) {
  108. if (e.detail.to === this.contact.peerId) {
  109. this.status = 'Waiting to accept...';
  110. }
  111. }.bind(this), false);
  112. app.conn.addEventListener('upload-started', function(e) {
  113. if (e.detail.to === this.contact.peerId) {
  114. this.status = 'Uploading...';
  115. }
  116. }.bind(this), false);
  117. app.conn.addEventListener('download-started', function(e) {
  118. if (e.detail.from === this.contact.peerId) {
  119. this.status = 'Downloading...';
  120. }
  121. }.bind(this), false);
  122. app.conn.addEventListener('upload-complete', function(e) {
  123. if (e.detail.from === this.contact.peerId) {
  124. this.status = '';
  125. }
  126. }.bind(this), false);
  127. app.conn.addEventListener('download-complete', function(e) {
  128. if (e.detail.from === this.contact.peerId) {
  129. this.status = '';
  130. }
  131. }.bind(this), false);
  132. app.conn.addEventListener('file-declined', function(e) {
  133. if (e.detail.from === this.contact.peerId) {
  134. this.status = '';
  135. }
  136. }.bind(this), false);
  137. app.conn.addEventListener('upload-error', function(e) {
  138. this.status = '';
  139. }.bind(this), false);
  140. }, 200);
  141. }
  142. });
  143. </script>
  144. </dom-module>