verification_level.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. export default [
  18. '$log', '$translate',
  19. function($log: ng.ILogService, $translate: ng.translate.ITranslateService) {
  20. return {
  21. restrict: 'EA',
  22. scope: {},
  23. bindToController: {
  24. contact: '=',
  25. },
  26. controllerAs: 'ctrl',
  27. controller: [function() {
  28. const contact: threema.ContactReceiver = this.contact;
  29. let label;
  30. switch (parseInt(this.contact.verificationLevel, 10)) {
  31. case 1:
  32. this.cls = 'level1';
  33. label = 'VERIFICATION_LEVEL1_EXPLAIN';
  34. break;
  35. case 2:
  36. this.cls = 'level2';
  37. if (contact.isWork) {
  38. label = 'VERIFICATION_LEVEL2_WORK_EXPLAIN';
  39. } else {
  40. label = 'VERIFICATION_LEVEL2_EXPLAIN';
  41. }
  42. break;
  43. case 3:
  44. this.cls = 'level3';
  45. label = 'VERIFICATION_LEVEL3_EXPLAIN';
  46. break;
  47. default:
  48. /* ignore, handled on next line */
  49. }
  50. if (label === undefined) {
  51. $log.error('invalid verification level', this.level);
  52. return;
  53. }
  54. if (contact.isWork) {
  55. // append work class
  56. this.cls += ' work';
  57. }
  58. this.description = $translate.instant('messenger.' + label);
  59. }],
  60. template: `
  61. <span class="verification-dots {{ctrl.cls}}" title="{{ctrl.description}}">
  62. <div></div><div></div><div></div>
  63. </span>
  64. `,
  65. };
  66. },
  67. ];