contact_badge.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. // tslint:disable:max-line-length
  18. import {WebClientService} from '../services/webclient';
  19. /**
  20. * Show a contact receiver with small avatar, name and verification level
  21. */
  22. export default [
  23. 'WebClientService',
  24. '$state',
  25. function(webClientService: WebClientService, $state: ng.ui.IStateService) {
  26. return {
  27. restrict: 'EA',
  28. scope: {},
  29. bindToController: {
  30. identity: '=?eeeIdentity',
  31. contactReceiver: '=?eeeContact',
  32. linked: '=?eeeLinked',
  33. onRemove: '=?eeeOnRemove',
  34. },
  35. controllerAs: 'ctrl',
  36. controller: [function() {
  37. if (this.contactReceiver === undefined) {
  38. this.contactReceiver = webClientService.contacts.get(this.identity);
  39. } else {
  40. this.identity = this.contactReceiver.id;
  41. }
  42. this.click = () => {
  43. if (this.linked !== undefined
  44. && this.linked === true) {
  45. $state.go('messenger.home.conversation', {type: 'contact', id: this.identity, initParams: null});
  46. }
  47. };
  48. this.showActions = this.onRemove !== undefined;
  49. }],
  50. template: `
  51. <div class="contact-badge receiver-badge" ng-click="ctrl.click()">
  52. <section class="avatar-box">
  53. <eee-avatar eee-type="'contact'"
  54. eee-receiver="ctrl.contactReceiver"
  55. eee-resolution="'low'"></eee-avatar>
  56. </section>
  57. <div class="receiver-badge-name">
  58. {{ctrl.contactReceiver.displayName}}
  59. </div>
  60. <div class="contact-badge-identity">
  61. {{ctrl.contactReceiver.id}}
  62. </div>
  63. <div class="contact-badge-actions" ng-if="ctrl.showActions">
  64. <md-button aria-label="Remove" class="md-icon-button" ng-click="ctrl.onRemove(ctrl.contactReceiver)">
  65. <i class="material-icons md-dark md-24">delete</i>
  66. </md-button>
  67. </div>
  68. </div>
  69. `,
  70. };
  71. },
  72. ];