Bug 32030: Remove 'this' from template
[srvgit] / koha-tmpl / intranet-tmpl / prog / js / vue / components / ERM / AgreementLicenses.vue
1 <template>
2     <fieldset class="rows" id="agreement_licenses">
3         <legend>{{ $t("Licenses") }}</legend>
4         <fieldset
5             :id="`agreement_license_${counter}`"
6             class="rows"
7             v-for="(agreement_license, counter) in agreement_licenses"
8             v-bind:key="counter"
9         >
10             <legend>
11                 {{ $t("Agreement license .counter", { counter: counter + 1 }) }}
12                 <a href="#" @click.prevent="deleteLicense(counter)"
13                     ><i class="fa fa-trash"></i>
14                     {{ $t("Remove this license") }}</a
15                 >
16             </legend>
17             <ol>
18                 <li>
19                     <label :for="`license_id_${counter}`"
20                         >{{ $t("License") }}:</label
21                     >
22                     <v-select
23                         :id="`license_id_${counter}`"
24                         v-model="agreement_license.license_id"
25                         label="name"
26                         :reduce="(l) => l.license_id"
27                         :options="licenses"
28                     >
29                         <template #search="{ attributes, events }">
30                             <input
31                                 :required="!agreement_license.license_id"
32                                 class="vs__search"
33                                 v-bind="attributes"
34                                 v-on="events"
35                             />
36                         </template>
37                     </v-select>
38                     <span class="required">{{ $t("Required") }}</span>
39                 </li>
40                 <li>
41                     <label :for="`license_status_${counter}`"
42                         >{{ $t("Status") }}:</label
43                     >
44                     <v-select
45                         :id="`license_status_${counter}`"
46                         v-model="agreement_license.status"
47                         label="lib"
48                         :reduce="(av) => av.authorised_value"
49                         :options="av_agreement_license_statuses"
50                     >
51                         <template #search="{ attributes, events }">
52                             <input
53                                 :required="!agreement_license.status"
54                                 class="vs__search"
55                                 v-bind="attributes"
56                                 v-on="events"
57                             />
58                         </template>
59                     </v-select>
60                     <span class="required">{{ $t("Required") }}</span>
61                 </li>
62                 <li>
63                     <label :for="`license_location_${counter}`"
64                         >{{ $t("Physical location") }}:
65                     </label>
66                     <v-select
67                         :id="`license_location_${counter}`"
68                         v-model="agreement_license.physical_location"
69                         label="lib"
70                         :reduce="(av) => av.authorised_value"
71                         :options="av_agreement_license_location"
72                     />
73                 </li>
74                 <li>
75                     <label :for="`license_notes_${counter}`"
76                         >{{ $t("Notes") }}:</label
77                     >
78                     <input
79                         :id="`license_notes_${counter}`"
80                         v-model="agreement_license.notes"
81                         :placeholder="$t('Notes')"
82                     />
83                 </li>
84                 <li>
85                     <label :for="`license_uri_${counter}`"
86                         >{{ $t("URI") }}:</label
87                     >
88                     <input
89                         :id="`license_uri_${counter}`"
90                         v-model="agreement_license.uri"
91                         :placeholder="$t('URI')"
92                     />
93                 </li>
94             </ol>
95         </fieldset>
96         <a v-if="licenses.length" class="btn btn-default" @click="addLicense"
97             ><font-awesome-icon icon="plus" /> {{ $t("Add new license") }}</a
98         >
99         <span v-else>{{ $t("There are no licenses created yet") }}</span>
100     </fieldset>
101 </template>
102
103 <script>
104 import { fetchLicenses } from '../../fetch'
105 export default {
106     name: 'AgreementLicenses',
107     data() {
108         return {
109             licenses: [],
110         }
111     },
112     props: {
113         av_agreement_license_statuses: Array,
114         av_agreement_license_location: Array,
115         agreement_licenses: Array,
116     },
117     beforeCreate() {
118         fetchLicenses().then((licenses) => this.licenses = licenses)
119     },
120     methods: {
121         addLicense() {
122             this.agreement_licenses.push({
123                 license_id: null,
124                 status: null,
125                 physical_location: null,
126                 notes: '',
127                 uri: '',
128             })
129         },
130         deleteLicense(counter) {
131             this.agreement_licenses.splice(counter, 1)
132         },
133     },
134 }
135 </script>