communication.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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(updateRepository)"
  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(updateRepository)"
  46. >
  47. {{ $t('yes') }}
  48. </v-btn>
  49. </template>
  50. </lazy-LayoutDialog>
  51. </v-col>
  52. <v-col cols="12" sm="6" v-if="entry['desactivateOpentalentSiteWeb'] === false">
  53. <span>{{ $t('subDomainHistorical') }} : </span>
  54. <!-- <span>{{ entry['subdomains'] }}</span>-->
  55. <FormParametersSubdomain :parametersId="entry['id']" />
  56. </v-col>
  57. <v-col cols="12" sm="6">
  58. <UiInputText field="otherWebsite" :data="entry['otherWebsite']" @update="updateRepository" />
  59. </v-col>
  60. <v-col cols="12" sm="6" v-if="entry['desactivateOpentalentSiteWeb'] === false">
  61. <UiInputAutocompleteWithAPI
  62. field="publicationDirectors"
  63. label="publicationDirectors"
  64. :multiple="true"
  65. chips
  66. :remote-uri="entry['publicationDirectors']"
  67. remote-url="api/access_people"
  68. :item-text="['person.givenName', 'person.name']"
  69. :searchFunction="accessSearch"
  70. @update="updateRepository($event.map((id) => `/api/accesses/${id}`), 'publicationDirectors')"
  71. />
  72. </v-col>
  73. </v-row>
  74. </v-container>
  75. </UiExpansionPanel>
  76. <!-- Sms -->
  77. <UiExpansionPanel id="sms" icon="fa-mobile" v-if="organizationProfile.hasModule(['Sms'])">
  78. <v-container fluid class="container">
  79. <v-row>
  80. <v-col cols="12" sm="6">
  81. <UiInputText field="smsSenderName" :data="entry['smsSenderName']" @update="updateRepository" :rules="rules().smsSenderNameRules" />
  82. </v-col>
  83. <v-col cols="12" sm="6">
  84. <UiInputText field="usernameSMS" :data="entry['usernameSMS']" @update="updateRepository" />
  85. </v-col>
  86. <v-col cols="12" sm="6">
  87. <UiInputText field="passwordSMS" :data="entry['passwordSMS']" @update="updateRepository" type="password" />
  88. </v-col>
  89. </v-row>
  90. </v-container>
  91. </UiExpansionPanel>
  92. </v-expansion-panels>
  93. </template>
  94. </UiForm>
  95. </LayoutContainer>
  96. </template>
  97. <script lang="ts">
  98. import {computed, ComputedRef, defineComponent, reactive, ref, Ref, useContext} from '@nuxtjs/composition-api'
  99. import {useDataUtils} from "~/composables/data/useDataUtils";
  100. import {Parameters} from "~/models/Organization/Parameters";
  101. import {$organizationProfile} from "~/services/profile/organizationProfile";
  102. import {useAccessesProvider} from "~/composables/data/useAccessesProvider";
  103. import {repositoryHelper} from "~/services/store/repository";
  104. import {Query} from "@vuex-orm/core";
  105. import UrlBuilder from "~/services/connection/urlBuilder";
  106. export default defineComponent({
  107. name: 'communication',
  108. setup () {
  109. const {store, $dataProvider, app: {i18n}} = useContext()
  110. const {getItemToEdit} = useDataUtils($dataProvider)
  111. const {getPhysicalByFullName: accessSearch} = useAccessesProvider($dataProvider)
  112. const showSiteWebConfirmationDialog: Ref<boolean> = ref(false);
  113. const organizationProfile = reactive($organizationProfile(store))
  114. const id = store.state.profile.organization.parametersId
  115. const {fetchState} = getItemToEdit(id, Parameters)
  116. const repository = repositoryHelper.getRepository(Parameters)
  117. const query: ComputedRef<Query> = computed(() => repository.query())
  118. /**
  119. * Build the URL of the current website of the organization
  120. * Anywhere else, you can rely on organizationProfile.getWebsite(), but here this url has to be
  121. * dynamic.
  122. *
  123. * @see https://ressources.opentalent.fr/display/SPEC/Preferences#Preferences-Siteinternet
  124. *
  125. * @param parameters
  126. */
  127. const getCurrentWebsite = function (parameters: Parameters) {
  128. if (parameters.desactivateOpentalentSiteWeb) {
  129. if (parameters.otherWebsite) {
  130. return UrlBuilder.prependHttps(parameters.otherWebsite)
  131. }
  132. return null
  133. }
  134. if (parameters.customDomain) {
  135. return UrlBuilder.prependHttps(parameters.customDomain)
  136. }
  137. // A ce niveau, tous les attributs de Parameters qui pourraient influer sur l'url du site ont été testés, les
  138. // sous-domaines étant gérés sur d'autres écrans dédiés.
  139. // On peut donc se reposer sur le profil de l'organisation.
  140. return organizationProfile.getWebsite()
  141. }
  142. const confirmWebsiteDeactivation = function () {
  143. showSiteWebConfirmationDialog.value = true
  144. }
  145. const desactivateOpentalentSiteWeb = function(updateRepository: ((newValue: string, field: string) => void)) {
  146. updateRepository('1', 'desactivateOpentalentSiteWeb')
  147. }
  148. const reactivateOpentalentSiteWeb = function(updateRepository: ((newValue: string, field: string) => void)) {
  149. updateRepository('0', 'desactivateOpentalentSiteWeb')
  150. }
  151. return {
  152. query: () => query.value,
  153. rules: () => getRules(i18n),
  154. organizationProfile,
  155. id,
  156. fetchState,
  157. accessSearch,
  158. model: Parameters,
  159. getCurrentWebsite,
  160. confirmWebsiteDeactivation,
  161. desactivateOpentalentSiteWeb,
  162. showSiteWebConfirmationDialog,
  163. reactivateOpentalentSiteWeb,
  164. UrlBuilder
  165. }
  166. }
  167. })
  168. function getRules (i18n: any) {
  169. return {
  170. smsSenderNameRules: [
  171. (smsSenderNameValue: string) => {
  172. const pattern = /^[a-zA-z\d]+$/
  173. return pattern.test(smsSenderNameValue) || i18n.t('smsSenderName_error')
  174. }
  175. ]
  176. }
  177. }
  178. </script>