You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScopedAccessTokenSelector.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script>
  2. import {createApp} from 'vue';
  3. import {hideElem, showElem} from '../utils/dom.js';
  4. const sfc = {
  5. props: {
  6. isAdmin: {
  7. type: Boolean,
  8. required: true,
  9. },
  10. noAccessLabel: {
  11. type: String,
  12. required: true,
  13. },
  14. readLabel: {
  15. type: String,
  16. required: true,
  17. },
  18. writeLabel: {
  19. type: String,
  20. required: true,
  21. },
  22. },
  23. computed: {
  24. categories() {
  25. const categories = [
  26. 'activitypub',
  27. ];
  28. if (this.isAdmin) {
  29. categories.push('admin');
  30. }
  31. categories.push(
  32. 'issue',
  33. 'misc',
  34. 'notification',
  35. 'organization',
  36. 'package',
  37. 'repository',
  38. 'user');
  39. return categories;
  40. },
  41. },
  42. mounted() {
  43. document.getElementById('scoped-access-submit').addEventListener('click', this.onClickSubmit);
  44. },
  45. unmounted() {
  46. document.getElementById('scoped-access-submit').removeEventListener('click', this.onClickSubmit);
  47. },
  48. methods: {
  49. onClickSubmit(e) {
  50. e.preventDefault();
  51. const warningEl = document.getElementById('scoped-access-warning');
  52. // check that at least one scope has been selected
  53. for (const el of document.getElementsByClassName('access-token-select')) {
  54. if (el.value) {
  55. // Hide the error if it was visible from previous attempt.
  56. hideElem(warningEl);
  57. // Submit the form.
  58. document.getElementById('scoped-access-form').submit();
  59. // Don't show the warning.
  60. return;
  61. }
  62. }
  63. // no scopes selected, show validation error
  64. showElem(warningEl);
  65. },
  66. },
  67. };
  68. export default sfc;
  69. /**
  70. * Initialize category toggle sections
  71. */
  72. export function initScopedAccessTokenCategories() {
  73. for (const el of document.getElementsByClassName('scoped-access-token-mount')) {
  74. createApp({})
  75. .component('scoped-access-token-selector', sfc)
  76. .mount(el);
  77. }
  78. }
  79. </script>
  80. <template>
  81. <div v-for="category in categories" :key="category" class="field gt-pl-2 gt-pb-2 access-token-category">
  82. <label class="category-label" :for="'access-token-scope-' + category">
  83. {{ category }}
  84. </label>
  85. <div class="gitea-select">
  86. <select
  87. class="ui selection access-token-select"
  88. name="scope"
  89. :id="'access-token-scope-' + category"
  90. >
  91. <option value="">
  92. {{ noAccessLabel }}
  93. </option>
  94. <option :value="'read:' + category">
  95. {{ readLabel }}
  96. </option>
  97. <option :value="'write:' + category">
  98. {{ writeLabel }}
  99. </option>
  100. </select>
  101. </div>
  102. </div>
  103. </template>