|
Line 0
Link Here
|
|
|
1 |
<template> |
| 2 |
<BaseResource :routeAction="routeAction" :instancedResource="this" /> |
| 3 |
</template> |
| 4 |
|
| 5 |
<script> |
| 6 |
import { inject } from "vue"; |
| 7 |
import BaseResource from "./../BaseResource.vue"; |
| 8 |
import { useBaseResource } from "../../composables/base-resource.js"; |
| 9 |
import { storeToRefs } from "pinia"; |
| 10 |
import { APIClient } from "../../fetch/api-client.js"; |
| 11 |
import { $__ } from "@koha-vue/i18n"; |
| 12 |
|
| 13 |
export default { |
| 14 |
name: "ShibbolethMappingResource", |
| 15 |
components: { |
| 16 |
BaseResource, |
| 17 |
}, |
| 18 |
props: { |
| 19 |
routeAction: String, |
| 20 |
}, |
| 21 |
emits: ["select-resource"], |
| 22 |
setup(props) { |
| 23 |
const getBorrowerColumns = () => { |
| 24 |
return window.borrower_columns || []; |
| 25 |
}; |
| 26 |
|
| 27 |
const borrowerColumnsArray = getBorrowerColumns(); |
| 28 |
|
| 29 |
const resourceAttrs = [ |
| 30 |
{ |
| 31 |
name: "koha_field", |
| 32 |
required: true, |
| 33 |
type: "select", |
| 34 |
options: borrowerColumnsArray, |
| 35 |
requiredKey: "value", |
| 36 |
selectLabel: "label", |
| 37 |
label: __("Koha field"), |
| 38 |
group: "Details", |
| 39 |
toolTip: __("The field name in the Koha borrowers table"), |
| 40 |
}, |
| 41 |
{ |
| 42 |
name: "idp_field", |
| 43 |
type: "text", |
| 44 |
label: __("Identity Provider attribute"), |
| 45 |
group: "Details", |
| 46 |
toolTip: __( |
| 47 |
"The attribute name provided by the Shibboleth Identity Provider" |
| 48 |
), |
| 49 |
}, |
| 50 |
{ |
| 51 |
name: "default_content", |
| 52 |
type: "text", |
| 53 |
label: __("Default value"), |
| 54 |
group: "Details", |
| 55 |
toolTip: __( |
| 56 |
"Default value to use if the IdP doesn't provide this attribute" |
| 57 |
), |
| 58 |
}, |
| 59 |
{ |
| 60 |
name: "is_matchpoint", |
| 61 |
type: "boolean", |
| 62 |
label: __("Use as matchpoint"), |
| 63 |
group: "Details", |
| 64 |
toolTip: __( |
| 65 |
"Use this field to match existing users (only one matchpoint allowed)" |
| 66 |
), |
| 67 |
}, |
| 68 |
]; |
| 69 |
|
| 70 |
const additionalToolbarButtons = (resource, componentData) => { |
| 71 |
const buttons = { |
| 72 |
form: [ |
| 73 |
{ |
| 74 |
title: $__("Submit"), |
| 75 |
form: componentData.resourceForm, |
| 76 |
}, |
| 77 |
{ |
| 78 |
to: { |
| 79 |
name: "ShibbolethMappingsList", |
| 80 |
}, |
| 81 |
title: $__("Cancel"), |
| 82 |
cssClass: "btn btn-link", |
| 83 |
}, |
| 84 |
], |
| 85 |
}; |
| 86 |
return buttons; |
| 87 |
}; |
| 88 |
|
| 89 |
const baseResource = useBaseResource({ |
| 90 |
resourceName: "mapping", |
| 91 |
nameAttr: "koha_field", |
| 92 |
idAttr: "mapping_id", |
| 93 |
components: { |
| 94 |
show: "ShibbolethMappingsShow", |
| 95 |
list: "ShibbolethMappingsList", |
| 96 |
add: "ShibbolethMappingsFormAdd", |
| 97 |
edit: "ShibbolethMappingsFormEdit", |
| 98 |
}, |
| 99 |
apiClient: APIClient.shibboleth.mappings, |
| 100 |
i18n: { |
| 101 |
deleteConfirmationMessage: $__( |
| 102 |
"Are you sure you want to remove this field mapping?" |
| 103 |
), |
| 104 |
deleteSuccessMessage: $__("Mapping deleted"), |
| 105 |
displayName: $__("Field Mapping"), |
| 106 |
editLabel: $__("Edit field mapping"), |
| 107 |
emptyListMessage: $__("There are no field mappings defined"), |
| 108 |
newLabel: $__("New field mapping"), |
| 109 |
}, |
| 110 |
table: { |
| 111 |
resourceTableUrl: |
| 112 |
APIClient.shibboleth.httpClient._baseURL + "mappings", |
| 113 |
options: {}, |
| 114 |
}, |
| 115 |
additionalToolbarButtons, |
| 116 |
stickyToolbar: ["Form"], |
| 117 |
embedded: props.embedded, |
| 118 |
formGroupsDisplayMode: "accordion", |
| 119 |
resourceAttrs, |
| 120 |
props, |
| 121 |
moduleStore: "ShibbolethStore", |
| 122 |
}); |
| 123 |
|
| 124 |
const tableOptions = { |
| 125 |
url: () => baseResource.getResourceTableUrl(), |
| 126 |
options: {}, |
| 127 |
table_settings: null, |
| 128 |
actions: { |
| 129 |
0: ["show"], |
| 130 |
"-1": ["edit", "delete"], |
| 131 |
}, |
| 132 |
}; |
| 133 |
|
| 134 |
const onFormSave = async (e, mappingToSave) => { |
| 135 |
e.preventDefault(); |
| 136 |
|
| 137 |
const mapping = JSON.parse(JSON.stringify(mappingToSave)); |
| 138 |
const mapping_id = mapping.mapping_id; |
| 139 |
|
| 140 |
delete mapping.mapping_id; |
| 141 |
|
| 142 |
const client = APIClient.shibboleth.mappings; |
| 143 |
|
| 144 |
try { |
| 145 |
if (mapping_id) { |
| 146 |
await client.update(mapping, mapping_id); |
| 147 |
baseResource.setMessage(__("Mapping updated")); |
| 148 |
} else { |
| 149 |
await client.create(mapping); |
| 150 |
baseResource.setMessage(__("Mapping created")); |
| 151 |
} |
| 152 |
|
| 153 |
baseResource.router.push({ name: "ShibbolethMappingsList" }); |
| 154 |
} catch (error) { |
| 155 |
// Errors handled by base resource |
| 156 |
} |
| 157 |
}; |
| 158 |
|
| 159 |
return { |
| 160 |
...baseResource, |
| 161 |
tableOptions, |
| 162 |
onFormSave, |
| 163 |
}; |
| 164 |
}, |
| 165 |
}; |
| 166 |
</script> |