Forms.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <section class="forms content relative">
  3. <h1 class="title is-4">{{ $t('forms.title') }}</h1>
  4. <hr />
  5. <b-loading v-if="loading.lists" :active="loading.lists" :is-full-page="false" />
  6. <p v-else-if="publicLists.length === 0">
  7. {{ $t('forms.noPublicLists') }}
  8. </p>
  9. <div class="columns" v-else-if="publicLists.length > 0">
  10. <div class="column is-4">
  11. <h4>{{ $t('forms.publicLists') }}</h4>
  12. <p>{{ $t('forms.selectHelp') }}</p>
  13. <b-loading :active="loading.lists" :is-full-page="false" />
  14. <ul class="no" data-cy="lists">
  15. <li v-for="l in publicLists" :key="l.id">
  16. <b-checkbox v-model="checked"
  17. :native-value="l.uuid">{{ l.name }}</b-checkbox>
  18. </li>
  19. </ul>
  20. <template v-if="settings['app.enable_public_subscription_page']">
  21. <hr />
  22. <h4>{{ $t('forms.publicSubPage') }}</h4>
  23. <p>
  24. <a :href="`${settings['app.root_url']}/subscription/form`"
  25. target="_blank" data-cy="url">{{ settings['app.root_url'] }}/subscription/form</a>
  26. </p>
  27. </template>
  28. </div>
  29. <div class="column" data-cy="form">
  30. <h4>{{ $t('forms.formHTML') }}</h4>
  31. <p>
  32. {{ $t('forms.formHTMLHelp') }}
  33. </p>
  34. <!-- eslint-disable max-len -->
  35. <pre v-if="checked.length > 0">&lt;form method=&quot;post&quot; action=&quot;{{ settings['app.root_url'] }}/subscription/form&quot; class=&quot;listmonk-form&quot;&gt;
  36. &lt;div&gt;
  37. &lt;h3&gt;Subscribe&lt;/h3&gt;
  38. &lt;p&gt;&lt;input type=&quot;email&quot; name=&quot;email&quot; required placeholder=&quot;{{ $t('subscribers.email') }}&quot; /&gt;&lt;/p&gt;
  39. &lt;p&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;{{ $t('public.subName') }}&quot; /&gt;&lt;/p&gt;
  40. <template v-for="l in publicLists"><span v-if="l.uuid in selected" :key="l.id" :set="id = l.uuid.substr(0, 5)">
  41. &lt;p&gt;
  42. &lt;input id=&quot;{{ id }}&quot; type=&quot;checkbox&quot; name=&quot;l&quot; checked value=&quot;{{ l.uuid }}&quot; /&gt;
  43. &lt;label for=&quot;{{ id }}&quot;&gt;{{ l.name }}&lt;/label&gt;
  44. &lt;/p&gt;</span></template>
  45. &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;{{ $t('public.sub') }}&quot; /&gt;&lt;/p&gt;
  46. &lt;/div&gt;
  47. &lt;/form&gt;</pre>
  48. </div>
  49. </div><!-- columns -->
  50. </section>
  51. </template>
  52. <script>
  53. import Vue from 'vue';
  54. import { mapState } from 'vuex';
  55. export default Vue.extend({
  56. name: 'ListForm',
  57. data() {
  58. return {
  59. checked: [],
  60. };
  61. },
  62. methods: {
  63. getPublicLists(lists) {
  64. return lists.filter((l) => l.type === 'public');
  65. },
  66. },
  67. computed: {
  68. ...mapState(['loading', 'lists', 'settings']),
  69. publicLists() {
  70. if (!this.lists.results) {
  71. return [];
  72. }
  73. return this.lists.results.filter((l) => l.type === 'public');
  74. },
  75. selected() {
  76. const sel = [];
  77. this.checked.forEach((uuid) => {
  78. sel[uuid] = true;
  79. });
  80. return sel;
  81. },
  82. },
  83. });
  84. </script>