communication.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <LayoutContainer v-if="!fetchState.pending">
  3. <UiForm :id="id" :model="model" :query="query()">
  4. <template #form.input="{entry, updateRepository}">
  5. <v-expansion-panels focusable multiple :value="[0, 1]">
  6. <!-- Site internet -->
  7. <UiExpansionPanel id="web_parameters" icon="fa-desktop">
  8. <v-container fluid class="container">
  9. <v-row>
  10. <v-col cols="12" sm="6">
  11. <div>
  12. <span>{{ $t('yourWebsiteAddressIs') }} : </span>
  13. <span>{{ getCurrentWebsite(entry) || $t('none') }}</span>
  14. </div>
  15. </v-col>
  16. <v-col cols="12" sm="6" v-if="!organizationProfile.isCmf()">
  17. <v-btn
  18. color="error"
  19. v-if="entry['desactivateOpentalentSiteWeb'] === false"
  20. @click="confirmWebsiteDeactivation()"
  21. >{{ $t('desactivateOpentalentSiteWeb') }} </v-btn>
  22. <v-btn
  23. color="primary"
  24. v-else
  25. @click="reactivateOpentalentSiteWeb()"
  26. >{{ $t('reactivateOpentalentSiteWeb') }}</v-btn>
  27. <lazy-LayoutDialog
  28. :show="showSiteWebConfirmationDialog"
  29. >
  30. <template #dialogTitle>{{ $t('please_confirm')}}</template>
  31. <template #dialogText>
  32. <div class="ma-2">
  33. {{ $t('areYourSureYouWantToDisableYourOpentalentWebsite')}} ?
  34. </div>
  35. </template>
  36. <template #dialogBtn>
  37. <v-btn
  38. color="ot_super_light_grey"
  39. @click="showSiteWebConfirmationDialog=false"
  40. >
  41. {{ $t('cancel') }}
  42. </v-btn>
  43. <v-btn
  44. color="primary"
  45. @click="showSiteWebConfirmationDialog=false;desactivateOpentalentSiteWeb()"
  46. >
  47. {{ $t('yes') }}
  48. </v-btn>
  49. </template>
  50. </lazy-LayoutDialog>
  51. </v-col>
  52. <v-col
  53. cols="12"
  54. sm="6"
  55. v-if="entry['desactivateOpentalentSiteWeb'] === false"
  56. >
  57. <FormParametersSubdomains :parametersId="entry['id']"></FormParametersSubdomains>
  58. </v-col>
  59. <v-col cols="12" sm="6">
  60. <UiInputText field="otherWebsite" :data="entry['otherWebsite']" @update="updateRepository" />
  61. </v-col>
  62. <v-col cols="12" sm="6" v-if="entry['desactivateOpentalentSiteWeb'] === false">
  63. <UiInputAutocompleteWithAPI
  64. field="publicationDirectors"
  65. label="publicationDirectors"
  66. :multiple="true"
  67. chips
  68. :remote-uri="entry['publicationDirectors']"
  69. remote-url="api/access_people"
  70. :item-text="['person.givenName', 'person.name']"
  71. :searchFunction="accessSearch"
  72. @update="updateRepository($event.map((id) => `/api/accesses/${id}`), 'publicationDirectors')"
  73. />
  74. </v-col>
  75. </v-row>
  76. </v-container>
  77. </UiExpansionPanel>
  78. <!-- Sms -->
  79. <UiExpansionPanel id="sms" icon="fa-mobile" v-if="organizationProfile.hasModule(['Sms'])">
  80. <v-container fluid class="container">
  81. <v-row>
  82. <v-col cols="12" sm="6">
  83. <UiInputText field="smsSenderName" :data="entry['smsSenderName']" @update="updateRepository" :rules="rules().smsSenderNameRules" />
  84. </v-col>
  85. <v-col cols="12" sm="6">
  86. <UiInputText field="usernameSMS" :data="entry['usernameSMS']" @update="updateRepository" />
  87. </v-col>
  88. <v-col cols="12" sm="6">
  89. <UiInputText field="passwordSMS" :data="entry['passwordSMS']" @update="updateRepository" type="password" />
  90. </v-col>
  91. </v-row>
  92. </v-container>
  93. </UiExpansionPanel>
  94. </v-expansion-panels>
  95. </template>
  96. </UiForm>
  97. </LayoutContainer>
  98. </template>
  99. <script lang="ts">
  100. import {computed, ComputedRef, defineComponent, reactive, ref, Ref, useContext} from '@nuxtjs/composition-api'
  101. import {useDataUtils} from "~/composables/data/useDataUtils";
  102. import {Parameters} from "~/models/Organization/Parameters";
  103. import {$organizationProfile} from "~/services/profile/organizationProfile";
  104. import {useAccessesProvider} from "~/composables/data/useAccessesProvider";
  105. import {repositoryHelper} from "~/services/store/repository";
  106. import {Query} from "@vuex-orm/core";
  107. import UrlBuilder from "~/services/connection/urlBuilder";
  108. import {Subdomain} from "~/models/Organization/Subdomain";
  109. import {AnyJson} from "~/types/interfaces";
  110. import {queryHelper} from "~/services/store/query";
  111. export default defineComponent({
  112. name: 'communication',
  113. setup () {
  114. const {store, $dataProvider, app: {i18n}} = useContext()
  115. const {getItemToEdit} = useDataUtils($dataProvider)
  116. const {getPhysicalByFullName: accessSearch} = useAccessesProvider($dataProvider)
  117. const showSiteWebConfirmationDialog: Ref<boolean> = ref(false);
  118. const organizationProfile = reactive($organizationProfile(store))
  119. const id = store.state.profile.organization.parametersId
  120. const {fetchState} = getItemToEdit(id, Parameters)
  121. const repository = repositoryHelper.getRepository(Parameters)
  122. const query: ComputedRef<Query> = computed(() => repository.query())
  123. const entry: ComputedRef<AnyJson> = computed(() => {
  124. return queryHelper.getFlattenEntry(query.value, id)
  125. })
  126. /**
  127. * Build the URL of the current website of the organization
  128. * Anywhere else, you can rely on organizationProfile.getWebsite(), but here this url has to be
  129. * dynamic.
  130. *
  131. * @see https://ressources.opentalent.fr/display/SPEC/Preferences#Preferences-Siteinternet
  132. *
  133. * @param parameters
  134. */
  135. const getCurrentWebsite = function (parameters: Parameters) {
  136. if (parameters.desactivateOpentalentSiteWeb) {
  137. if (parameters.otherWebsite) {
  138. return UrlBuilder.prependHttps(parameters.otherWebsite)
  139. }
  140. return null
  141. }
  142. if (parameters.customDomain) {
  143. return UrlBuilder.prependHttps(parameters.customDomain)
  144. }
  145. // A ce niveau, tous les attributs de Parameters qui pourraient influer sur l'url du site ont été testés, les
  146. // sous-domaines étant gérés sur d'autres écrans dédiés.
  147. // On peut donc se reposer sur le profil de l'organisation.
  148. return organizationProfile.getWebsite()
  149. }
  150. const confirmWebsiteDeactivation = function () {
  151. showSiteWebConfirmationDialog.value = true
  152. }
  153. const desactivateOpentalentSiteWeb = function() {
  154. repositoryHelper.updateStoreFromField(Parameters, entry.value, '1', 'desactivateOpentalentSiteWeb')
  155. }
  156. const reactivateOpentalentSiteWeb = function() {
  157. repositoryHelper.updateStoreFromField(Parameters, entry.value, '0', 'desactivateOpentalentSiteWeb')
  158. }
  159. return {
  160. query: () => query.value,
  161. rules: () => getRules(i18n),
  162. organizationProfile,
  163. id,
  164. fetchState,
  165. accessSearch,
  166. model: Parameters,
  167. getCurrentWebsite,
  168. confirmWebsiteDeactivation,
  169. desactivateOpentalentSiteWeb,
  170. showSiteWebConfirmationDialog,
  171. reactivateOpentalentSiteWeb,
  172. UrlBuilder
  173. }
  174. }
  175. })
  176. function getRules (i18n: any) {
  177. return {
  178. smsSenderNameRules: [
  179. (smsSenderNameValue: string) => {
  180. const pattern = /^[a-zA-z\d]+$/
  181. return pattern.test(smsSenderNameValue) || i18n.t('smsSenderName_error')
  182. }
  183. ]
  184. }
  185. }
  186. </script>