|
Line 0
Link Here
|
|
|
1 |
<template> |
| 2 |
<div v-if="!initialized">{{ $__("Loading") }}</div> |
| 3 |
<div v-else> |
| 4 |
<div id="toolbar" class="btn-toolbar"> |
| 5 |
<div class="btn-group"> |
| 6 |
<button class="btn btn-default" @click="newRecordSource"> |
| 7 |
<i class="fa fa-plus"></i> New record source |
| 8 |
</button> |
| 9 |
</div> |
| 10 |
</div> |
| 11 |
<h1>{{ title }}</h1> |
| 12 |
<div v-if="record_sources_count > 0" class="page-section"> |
| 13 |
<KohaTable |
| 14 |
ref="table" |
| 15 |
v-bind="tableOptions" |
| 16 |
@edit="doEdit" |
| 17 |
@delete="doRemove" |
| 18 |
></KohaTable> |
| 19 |
</div> |
| 20 |
<div v-else> |
| 21 |
{{ $__("There are no record sources defined") }} |
| 22 |
</div> |
| 23 |
</div> |
| 24 |
</template> |
| 25 |
|
| 26 |
<script> |
| 27 |
import { useRouter } from "vue-router" |
| 28 |
import { inject } from "vue" |
| 29 |
import { RecordSourcesClient } from "../../fetch/record-sources" |
| 30 |
import KohaTable from "../KohaTable.vue" |
| 31 |
export default { |
| 32 |
name: "List", |
| 33 |
data() { |
| 34 |
return { |
| 35 |
title: this.$__("Record sources"), |
| 36 |
tableOptions: { |
| 37 |
columns: [ |
| 38 |
{ |
| 39 |
title: this.$__("Source name"), |
| 40 |
data: "name", |
| 41 |
searchable: true, |
| 42 |
}, |
| 43 |
{ |
| 44 |
title: __("Can be edited"), |
| 45 |
data: "can_be_edited", |
| 46 |
searchable: true, |
| 47 |
orderable: true, |
| 48 |
render: function (data, type, row, meta) { |
| 49 |
return escape_str( |
| 50 |
row.can_be_edited ? __("Yes") : __("No") |
| 51 |
) |
| 52 |
}, |
| 53 |
}, |
| 54 |
], |
| 55 |
actions: { |
| 56 |
"-1": ["edit", "delete"], |
| 57 |
}, |
| 58 |
url: "/api/v1/record_sources", |
| 59 |
}, |
| 60 |
initialized: false, |
| 61 |
record_sources_count: 0, |
| 62 |
} |
| 63 |
}, |
| 64 |
setup() { |
| 65 |
const { setWarning, setMessage, setError, setConfirmationDialog } = |
| 66 |
inject("mainStore") |
| 67 |
const { record_source } = new RecordSourcesClient() |
| 68 |
return { |
| 69 |
setWarning, |
| 70 |
setMessage, |
| 71 |
setError, |
| 72 |
setConfirmationDialog, |
| 73 |
api: record_source, |
| 74 |
} |
| 75 |
}, |
| 76 |
beforeRouteEnter(to, from, next) { |
| 77 |
next(vm => { |
| 78 |
vm.getRecordSourcesCount().then(() => (vm.initialized = true)) |
| 79 |
}) |
| 80 |
}, |
| 81 |
methods: { |
| 82 |
async getRecordSourcesCount() { |
| 83 |
const count = await this.api.count() |
| 84 |
this.record_sources_count = count |
| 85 |
}, |
| 86 |
newRecordSource() { |
| 87 |
this.$router.push({ path: "record-sources/add" }) |
| 88 |
}, |
| 89 |
doEdit(data) { |
| 90 |
this.$router.push({ |
| 91 |
path: `record-sources/${data.record_source_id}`, |
| 92 |
props: { |
| 93 |
data, |
| 94 |
}, |
| 95 |
}) |
| 96 |
}, |
| 97 |
doRemove(data, dt) { |
| 98 |
this.setConfirmationDialog( |
| 99 |
{ |
| 100 |
title: this.$__( |
| 101 |
"Are you sure you want to remove this record source?" |
| 102 |
), |
| 103 |
message: data.name, |
| 104 |
accept_label: this.$__("Yes, remove"), |
| 105 |
cancel_label: this.$__("No, do not remove"), |
| 106 |
}, |
| 107 |
() => { |
| 108 |
this.api |
| 109 |
.delete({ |
| 110 |
id: data.record_source_id, |
| 111 |
}) |
| 112 |
.then(response => { |
| 113 |
if (response) { |
| 114 |
this.setMessage( |
| 115 |
this.$__( |
| 116 |
"Record source '%s' removed" |
| 117 |
).format(data.name), |
| 118 |
true |
| 119 |
) |
| 120 |
dt.draw() |
| 121 |
} |
| 122 |
}) |
| 123 |
} |
| 124 |
) |
| 125 |
}, |
| 126 |
}, |
| 127 |
components: { |
| 128 |
KohaTable, |
| 129 |
}, |
| 130 |
} |
| 131 |
</script> |