{"version":3,"file":"OrganisationChooser-fdDo9cCK.mjs","names":[],"sources":["../src/components/display/organisation/OrganisationChooser.vue","../src/components/display/organisation/OrganisationChooser.vue"],"sourcesContent":["<template>\n  <ClassicMultiselect\n    v-if=\"!orgaIdSelected || initLoaded\"\n    id=\"organisation-chooser\"\n    ref=\"selectOrganisation\"\n    option-label=\"name\"\n    :label=\"label ??t('select productor')\"\n    :display-label=\"displayLabel\"\n    :max-element=\"maxElement\"\n    :width=\"width\"\n    :in-modal=\"inModal\"\n    :option-chosen=\"organisationChosen\"\n    option-custom-templating=\"optionTemplating\"\n    option-selected-custom-templating=\"optionTemplating\"\n    :no-deselect=\"noDeselect\"\n    @on-search=\"onSearchOrganisation\"\n    @selected=\"emit('selected', $event)\"\n  >\n    <template v-if=\"isImage\" #optionTemplating=\"{ option }\">\n      <div\n        class=\"d-flex align-items-center\"\n        :data-selenium=\"'organisation-chooser-' + seleniumFormat(option.name)\"\n      >\n        <img\n          v-lazy=\"useProxyImageUrl(option.imageUrl, '32')\"\n          width=\"32\"\n          height=\"32\"\n          class=\"me-2\"\n          aria-hidden=\"true\"\n        alt=\"\"\n          \n          :title=\"t('Organisation name image', { name: option.name })\"\n        />\n        <span>\n          {{ option.name }}\n        </span>\n      </div>\n    </template>\n  </ClassicMultiselect>\n</template>\n\n<script setup lang=\"ts\">\nimport { useAuthStore } from \"../../../stores/AuthStore\";\nimport {useImageProxy} from \"../../composable/useImageProxy\";\nimport {useSelenium} from \"../../composable/useSelenium\";\nimport classicApi from \"../../../api/classicApi\";\nimport ClassicMultiselect from \"../../form/ClassicMultiselect.vue\";\nimport { computed, onBeforeMount, ref, Ref, useTemplateRef, watch } from \"vue\";\nimport {\n  emptyOrgaData,\n  Organisation,\n} from \"../../../stores/class/general/organisation\";\nimport { useSaveFetchStore } from \"../../../stores/SaveFetchStore\";\nimport { ListClassicReturn } from \"@/stores/class/general/listReturn\";\nimport { useI18n } from \"vue-i18n\";\n\n//Props \nconst props = defineProps({\n  defaultanswer: { default: \"\", type: String },\n  orgaIdSelected: { default: undefined, type: String },\n  reset: { default: false, type: Boolean },\n  width: { default: \"100%\", type: String },\n  isImage: { default: true, type: Boolean },\n  inModal: { default: false, type: Boolean },\n  noDeselect: { default: true, type: Boolean },\n  label:{default: undefined, type: String },\n  displayLabel: { default: false, type: Boolean },\n})\n\n//Emits\nconst emit = defineEmits([\"selected\"]);\n  \n//Data \nconst maxElement = ref(50);\nconst organisationChosen: Ref<Organisation | undefined> = ref(undefined);\nconst initLoaded = ref(false);\nconst selectOrganisationRef = useTemplateRef('selectOrganisation');\n\n//Composables\nconst { t } = useI18n();\nconst { seleniumFormat } = useSelenium();\nconst { useProxyImageUrl } = useImageProxy();\nconst authStore = useAuthStore();\nconst saveFetchStore = useSaveFetchStore();\n\n\n//Computed\nconst getDefaultOrganisation = computed(() => {\n  if (\"\" === props.defaultanswer) {\n    return undefined;\n  }\n  return emptyOrgaData(props.defaultanswer);\n});\nconst myOrganisation = computed(() => {\n  if (!authStore.authOrgaId) return undefined;\n  return {\n    ...authStore.authOrganisation,\n    ...{\n      name: `${t(\"Edit my organisation\")} (${\n        authStore.authOrganisation.name\n      })`,\n    },\n  };\n});\n\n\n//Watch\nwatch(()=>props.orgaIdSelected, () => {\n  if (!props.orgaIdSelected) {\n    organisationChosen.value = getDefaultOrganisation.value;\n    return;\n  }\n  if (\n    props.orgaIdSelected &&\n    organisationChosen.value?.id !== props.orgaIdSelected\n  ) {\n    fetchOrganisation();\n  }\n}, {immediate: true});\nwatch(()=>props.reset, () => {\n  organisationChosen.value = getDefaultOrganisation.value;\n});\n\nonBeforeMount(()=>organisationChosen.value = getDefaultOrganisation.value)\n\n\n//Methods\nasync function onSearchOrganisation(query?: string): Promise<void> {\n  const response = await classicApi.fetchData<\n    ListClassicReturn<Organisation>\n  >({\n    api: 0,\n    path: \"organisation/search\",\n    parameters: {\n      query: query,\n      first: 0,\n      size: maxElement.value,\n    },\n  });\n  let notNullOrga = response.result.filter((o: Organisation | null) => {\n    return null !== o;\n  });\n  if (getDefaultOrganisation.value) {\n    notNullOrga.unshift(getDefaultOrganisation.value);\n  }\n  if (myOrganisation.value) {\n    if (undefined === query) {\n      notNullOrga = notNullOrga.filter((obj: Organisation) => {\n        return obj.id !== authStore.authOrgaId;\n      });\n      notNullOrga.splice(1, 0, myOrganisation.value);\n    } else {\n      const foundIndex = notNullOrga.findIndex(\n        (obj: Organisation) => obj.id === authStore.authOrgaId,\n      );\n      if (foundIndex) {\n        notNullOrga[foundIndex] = myOrganisation.value;\n      }\n    }\n  }\n  (selectOrganisationRef?.value as InstanceType<typeof ClassicMultiselect>).afterSearch(notNullOrga, response.count);\n}\nasync function fetchOrganisation(): Promise<void> {\n  organisationChosen.value = await saveFetchStore.getOrgaData(\n    props.orgaIdSelected ?? \"\",\n  );\n  initLoaded.value = true;\n}\n</script>\n","<template>\n  <ClassicMultiselect\n    v-if=\"!orgaIdSelected || initLoaded\"\n    id=\"organisation-chooser\"\n    ref=\"selectOrganisation\"\n    option-label=\"name\"\n    :label=\"label ??t('select productor')\"\n    :display-label=\"displayLabel\"\n    :max-element=\"maxElement\"\n    :width=\"width\"\n    :in-modal=\"inModal\"\n    :option-chosen=\"organisationChosen\"\n    option-custom-templating=\"optionTemplating\"\n    option-selected-custom-templating=\"optionTemplating\"\n    :no-deselect=\"noDeselect\"\n    @on-search=\"onSearchOrganisation\"\n    @selected=\"emit('selected', $event)\"\n  >\n    <template v-if=\"isImage\" #optionTemplating=\"{ option }\">\n      <div\n        class=\"d-flex align-items-center\"\n        :data-selenium=\"'organisation-chooser-' + seleniumFormat(option.name)\"\n      >\n        <img\n          v-lazy=\"useProxyImageUrl(option.imageUrl, '32')\"\n          width=\"32\"\n          height=\"32\"\n          class=\"me-2\"\n          aria-hidden=\"true\"\n        alt=\"\"\n          \n          :title=\"t('Organisation name image', { name: option.name })\"\n        />\n        <span>\n          {{ option.name }}\n        </span>\n      </div>\n    </template>\n  </ClassicMultiselect>\n</template>\n\n<script setup lang=\"ts\">\nimport { useAuthStore } from \"../../../stores/AuthStore\";\nimport {useImageProxy} from \"../../composable/useImageProxy\";\nimport {useSelenium} from \"../../composable/useSelenium\";\nimport classicApi from \"../../../api/classicApi\";\nimport ClassicMultiselect from \"../../form/ClassicMultiselect.vue\";\nimport { computed, onBeforeMount, ref, Ref, useTemplateRef, watch } from \"vue\";\nimport {\n  emptyOrgaData,\n  Organisation,\n} from \"../../../stores/class/general/organisation\";\nimport { useSaveFetchStore } from \"../../../stores/SaveFetchStore\";\nimport { ListClassicReturn } from \"@/stores/class/general/listReturn\";\nimport { useI18n } from \"vue-i18n\";\n\n//Props \nconst props = defineProps({\n  defaultanswer: { default: \"\", type: String },\n  orgaIdSelected: { default: undefined, type: String },\n  reset: { default: false, type: Boolean },\n  width: { default: \"100%\", type: String },\n  isImage: { default: true, type: Boolean },\n  inModal: { default: false, type: Boolean },\n  noDeselect: { default: true, type: Boolean },\n  label:{default: undefined, type: String },\n  displayLabel: { default: false, type: Boolean },\n})\n\n//Emits\nconst emit = defineEmits([\"selected\"]);\n  \n//Data \nconst maxElement = ref(50);\nconst organisationChosen: Ref<Organisation | undefined> = ref(undefined);\nconst initLoaded = ref(false);\nconst selectOrganisationRef = useTemplateRef('selectOrganisation');\n\n//Composables\nconst { t } = useI18n();\nconst { seleniumFormat } = useSelenium();\nconst { useProxyImageUrl } = useImageProxy();\nconst authStore = useAuthStore();\nconst saveFetchStore = useSaveFetchStore();\n\n\n//Computed\nconst getDefaultOrganisation = computed(() => {\n  if (\"\" === props.defaultanswer) {\n    return undefined;\n  }\n  return emptyOrgaData(props.defaultanswer);\n});\nconst myOrganisation = computed(() => {\n  if (!authStore.authOrgaId) return undefined;\n  return {\n    ...authStore.authOrganisation,\n    ...{\n      name: `${t(\"Edit my organisation\")} (${\n        authStore.authOrganisation.name\n      })`,\n    },\n  };\n});\n\n\n//Watch\nwatch(()=>props.orgaIdSelected, () => {\n  if (!props.orgaIdSelected) {\n    organisationChosen.value = getDefaultOrganisation.value;\n    return;\n  }\n  if (\n    props.orgaIdSelected &&\n    organisationChosen.value?.id !== props.orgaIdSelected\n  ) {\n    fetchOrganisation();\n  }\n}, {immediate: true});\nwatch(()=>props.reset, () => {\n  organisationChosen.value = getDefaultOrganisation.value;\n});\n\nonBeforeMount(()=>organisationChosen.value = getDefaultOrganisation.value)\n\n\n//Methods\nasync function onSearchOrganisation(query?: string): Promise<void> {\n  const response = await classicApi.fetchData<\n    ListClassicReturn<Organisation>\n  >({\n    api: 0,\n    path: \"organisation/search\",\n    parameters: {\n      query: query,\n      first: 0,\n      size: maxElement.value,\n    },\n  });\n  let notNullOrga = response.result.filter((o: Organisation | null) => {\n    return null !== o;\n  });\n  if (getDefaultOrganisation.value) {\n    notNullOrga.unshift(getDefaultOrganisation.value);\n  }\n  if (myOrganisation.value) {\n    if (undefined === query) {\n      notNullOrga = notNullOrga.filter((obj: Organisation) => {\n        return obj.id !== authStore.authOrgaId;\n      });\n      notNullOrga.splice(1, 0, myOrganisation.value);\n    } else {\n      const foundIndex = notNullOrga.findIndex(\n        (obj: Organisation) => obj.id === authStore.authOrgaId,\n      );\n      if (foundIndex) {\n        notNullOrga[foundIndex] = myOrganisation.value;\n      }\n    }\n  }\n  (selectOrganisationRef?.value as InstanceType<typeof ClassicMultiselect>).afterSearch(notNullOrga, response.count);\n}\nasync function fetchOrganisation(): Promise<void> {\n  organisationChosen.value = await saveFetchStore.getOrgaData(\n    props.orgaIdSelected ?? \"\",\n  );\n  initLoaded.value = true;\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDA,MAAM,QAAQ;EAad,MAAM,OAAO;EAGb,MAAM,aAAa,IAAI,EAAE;EACzB,MAAM,qBAAoD,IAAI,KAAA,CAAS;EACvE,MAAM,aAAa,IAAI,KAAK;EAC5B,MAAM,wBAAwB,eAAe,oBAAoB;EAGjE,MAAM,EAAE,MAAM,QAAQ;EACtB,MAAM,E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