Newer
Older
<hr class="divider" />
<div v-if="!showCreationForm">
<label for="organisationSelector-organisation">
{{ $tc('signup.form.organisation.subtitle') }}
</label>

Florent Lavelle
committed
<div class="infos">
{{ $tc('signup.form.organisation.info') }}
</div>
<Multiselect
id="organisationSelector-organisation"

Florent Lavelle
committed
data-test="organisationSelector-organisation"
v-model="organisation"
style="margin-top: 0.5em;"
class="search-usergroups"
:options="suggestions.local"
:optionsLimit="10"
:allow-empty="false"
track-by="id"
label="display_name"
:resetAfter="false"
selectLabel=""
selectedLabel=""
deselectLabel=""
:searchable="true"
:placeholder="$tc('signup.form.organisation.placeholder')"
:showNoResults="true"
:loading="loading"
:clearOnSelect="false"
:preserveSearch="false"
@search-change="search"
>
<template slot="clear">
<div
v-if="organisation"
class="multiselect__clear"
data-test="organisationSelector-removeOrganisation"
Mathilde POMMIER
committed
@click.prevent.stop="clearOrganisation()"
>
<b-icon-x font-scale="2"/>
</div>
</template>
<span slot="noResult">
</span>
<span slot="noOptions">
</span>
</Multiselect>
<label>

Florent Lavelle
committed
<a
data-test="organisationSelector-showCreationFormTrue"
Mathilde POMMIER
committed
@click="updateShowCreationForm(true)"

Florent Lavelle
committed
>

Florent Lavelle
committed
</a>
</label>
</div>
<OrganisationCreation
v-if="showCreationForm"
data-test="organisationSelector-showCreationFormFalse"
Mathilde POMMIER
committed
:name="displayName"
:siret="registrationNumber"
@update="updateOrganisationToCreate"
Mathilde POMMIER
committed
@cancel="updateShowCreationForm(false)"
/>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import Bloodhound from 'corejs-typeahead/dist/bloodhound';
import OrganisationCreation from '@/components/OrganisationCreation.vue';
export default {
name: 'OrganisationSelector',
components: {
OrganisationCreation
},
Mathilde POMMIER
committed
props: {
showCreationForm: {
type: Boolean,
default: false
},
displayName: {
type: String,
default: null
},
registrationNumber: {
type: String,
default: null
}
},
data() {
return {
loading: false,
text: null,
suggestions: {
local: []
},
results: [],
organisation: null,
role: null,
organisationToCreate: {
codename: null,
display_name: null,
description: null,
organisation_type: null,
registration_number: null,
phone_number: null,
website_url: null,
postal_address: null,
Mathilde POMMIER
committed
isValid: false,
},
organisationThumbnail: null,
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
selectedOrganisation: null,
};
},
computed: {
...mapState('organisations', [
'organisationsList',
'organisationsRoles'
])
},
watch: {
text(newValue) {
this.suggestions.search(newValue, data => {
this.results = data.map(function(item) {
return item.id;
});
});
},
organisationsList: {
deep: true,
handler(newValue) {
const SuggestionsEngine = Bloodhound.noConflict();
let local = [];
newValue.map(function(item) {
local.push({
id: item.id,
display_name: item.display_name
});
});
this.suggestions = new SuggestionsEngine({
local: local,
initialize: true,
datumTokenizer: Bloodhound.tokenizers.obj.nonword('title'),
queryTokenizer: Bloodhound.tokenizers.nonword
});
}
},
organisation(newValue) {
if (newValue) {
this.selectedOrganisation = newValue;
}
},
organisationToCreate: {
deep: true,
handler(newValue) {
if (newValue) {
this.selectedOrganisation = newValue;
}
}
},
organisationThumbnail(newValue) {
if (newValue) {
this.$emit('select', {
selected: true,
orga: this.selectedOrganisation,
thumbnail: newValue,
spheres: this.organisationSpheres
});
}
},
organisationSpheres: {
deep: true,
handler(newValue) {
if (newValue) {
this.$emit('select', {
selected: true,
orga: this.selectedOrganisation,
thumbnail: this.organisationThumbnail,
spheres: newValue
});
}
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
}
},
selectedOrganisation(newValue) {
if (newValue) {
this.$emit('select', {
selected: true,
orga: newValue,
thumbnail: this.organisationThumbnail,
spheres: this.organisationSpheres
});
}
},
},
created() {
this.GET_ORGANISATIONS_LIST();
},
methods: {
...mapActions('organisations', [
'GET_ORGANISATIONS_LIST',
'GET_ORGANISATIONS_ROLES',
]),
search(text) {
this.text = text;
},
updateOrganisationToCreate(e) {
this.organisationToCreate.codename =
e.form.name ?
e.form.name.normalize('NFD').replace(/[\u0300-\u036f]|[^A-Z0-9]/ig, '').toLowerCase() :
null;
this.organisationToCreate.acronym = e.form.sigle;
this.organisationToCreate.display_name = e.form.name;
this.organisationToCreate.description = e.form.description;
this.organisationToCreate.organisation_type = e.form.type;
this.organisationToCreate.registration_number = e.form.siret;
this.organisationToCreate.phone_number = e.form.tel;
this.organisationToCreate.website_url = e.form.web;
this.organisationToCreate.postal_address = e.form.postalAddress;
Mathilde POMMIER
committed
this.organisationSpheres = e.spheres;
this.organisationThumbnail = e.thumbnail;
Mathilde POMMIER
committed
if (e.form.name && e.form.type) {
this.organisationToCreate.isValid = true;
}
else {
this.organisationToCreate.isValid = false;
}
},
updateShowCreationForm(value) {
this.$emit('update:showCreationForm', value);
},
clearOrganisation() {
this.organisation = null;
this.$emit('select', {
selected: false,
orga: null,
thumbnail: null,
spheres: []
});
},
},
};
</script>
<style lang="less" scoped>
label {
font-size: 1rem;
font-weight: normal;

Florent Lavelle
committed
a {
color: #105182 !important;
}
a:hover {
cursor: pointer;
text-decoration: underline !important;
}
}
.infos {
font-size: 0.8em;
font-style: italic;
margin-right: 1em;