buddy-avatar.html 4.9 KB

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