mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 22:04:59 +00:00
Merge branch 'master' into upgrade-sf5
This commit is contained in:
@@ -55,11 +55,20 @@ export interface ServerExceptionInterface extends TransportExceptionInterface {
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface ConflictHttpExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'ConflictHttpException';
|
||||
violations: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic api method that can be adapted to any fetch request
|
||||
*/
|
||||
export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DELETE', url: string, body?: body | Input | null, options?: FetchParams): Promise<Output> => {
|
||||
export const makeFetch = <Input, Output>(
|
||||
method: 'POST'|'GET'|'PUT'|'PATCH'|'DELETE',
|
||||
url: string, body?: body | Input | null,
|
||||
options?: FetchParams
|
||||
): Promise<Output> => {
|
||||
|
||||
let opts = {
|
||||
method: method,
|
||||
headers: {
|
||||
@@ -67,6 +76,7 @@ export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DEL
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
if (body !== null && typeof body !== 'undefined') {
|
||||
Object.assign(opts, {body: JSON.stringify(body)})
|
||||
}
|
||||
@@ -90,6 +100,10 @@ export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DEL
|
||||
throw AccessException(response);
|
||||
}
|
||||
|
||||
if (response.status === 409) {
|
||||
throw ConflictHttpException(response);
|
||||
}
|
||||
|
||||
throw {
|
||||
name: 'Exception',
|
||||
sta: response.status,
|
||||
@@ -220,3 +234,12 @@ const ServerException = (code: number, body: string): ServerExceptionInterface =
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
const ConflictHttpException = (response: Response): ConflictHttpExceptionInterface => {
|
||||
const error = {} as ConflictHttpExceptionInterface;
|
||||
|
||||
error.name = 'ConflictHttpException';
|
||||
error.violations = ['Sorry, but someone else has already changed this entity. Please refresh the page and apply the changes again']
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@@ -24,7 +24,10 @@ function loadDynamicPicker(element) {
|
||||
(input.value === '[]' || input.value === '') ?
|
||||
null : [ JSON.parse(input.value) ]
|
||||
)
|
||||
suggested = JSON.parse(el.dataset.suggested)
|
||||
suggested = JSON.parse(el.dataset.suggested),
|
||||
as_id = parseInt(el.dataset.asId) === 1,
|
||||
submit_on_adding_new_entity = parseInt(el.dataset.submitOnAddingNewEntity) === 1
|
||||
label = el.dataset.label;
|
||||
|
||||
if (!isMultiple) {
|
||||
if (input.value === '[]'){
|
||||
@@ -39,6 +42,7 @@ function loadDynamicPicker(element) {
|
||||
':picked="picked" ' +
|
||||
':uniqid="uniqid" ' +
|
||||
':suggested="notPickedSuggested" ' +
|
||||
':label="label" ' +
|
||||
'@addNewEntity="addNewEntity" ' +
|
||||
'@removeEntity="removeEntity"></pick-entity>',
|
||||
components: {
|
||||
@@ -50,7 +54,10 @@ function loadDynamicPicker(element) {
|
||||
types: JSON.parse(el.dataset.types),
|
||||
picked: picked === null ? [] : picked,
|
||||
uniqid: el.dataset.uniqid,
|
||||
suggested: suggested
|
||||
suggested,
|
||||
as_id,
|
||||
submit_on_adding_new_entity,
|
||||
label,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -69,7 +76,12 @@ function loadDynamicPicker(element) {
|
||||
return el.type === entity.type && el.id === entity.id;
|
||||
})) {
|
||||
this.picked.push(entity);
|
||||
input.value = JSON.stringify(this.picked);
|
||||
if (!as_id) {
|
||||
input.value = JSON.stringify(this.picked);
|
||||
} else {
|
||||
const ids = this.picked.map(el => el.id);
|
||||
input.value = ids.join(',');
|
||||
}
|
||||
console.log(entity)
|
||||
}
|
||||
} else {
|
||||
@@ -78,9 +90,17 @@ function loadDynamicPicker(element) {
|
||||
})) {
|
||||
this.picked.splice(0, this.picked.length);
|
||||
this.picked.push(entity);
|
||||
input.value = JSON.stringify(this.picked[0]);
|
||||
if (!as_id) {
|
||||
input.value = JSON.stringify(this.picked[0]);
|
||||
} else {
|
||||
input.value = this.picked.map(el => el.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.submit_on_adding_new_entity) {
|
||||
input.form.submit();
|
||||
}
|
||||
},
|
||||
removeEntity({entity}) {
|
||||
if (-1 === this.suggested.findIndex(e => e.type === entity.type && e.id === entity.id)) {
|
||||
|
@@ -56,6 +56,10 @@ export default {
|
||||
suggested: {
|
||||
type: Array,
|
||||
default: []
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
required: false,
|
||||
}
|
||||
},
|
||||
emits: ['addNewEntity', 'removeEntity'],
|
||||
@@ -80,6 +84,10 @@ export default {
|
||||
};
|
||||
},
|
||||
translatedListOfTypes() {
|
||||
if (this.label !== '') {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
let trans = [];
|
||||
this.types.forEach(t => {
|
||||
if (this.$props.multiple) {
|
||||
|
@@ -256,7 +256,10 @@
|
||||
data-types="{{ form.vars['types']|json_encode }}"
|
||||
data-multiple="{{ form.vars['multiple'] }}"
|
||||
data-uniqid="{{ form.vars['uniqid'] }}"
|
||||
data-suggested="{{ form.vars['suggested']|json_encode|escape('html_attr') }}"></div>
|
||||
data-suggested="{{ form.vars['suggested']|json_encode|escape('html_attr') }}"
|
||||
data-as-id="{{ form.vars['as_id'] }}"
|
||||
data-submit-on-adding-new-entity="{{ form.vars['submit_on_adding_new_entity'] }}"
|
||||
data-label="{{ form.vars['label']|trans|escape('html_attr') }}"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block pick_postal_code_widget %}
|
||||
|
Reference in New Issue
Block a user