on-the-fly: add a 'parent' option to pass parent context. So we could now display resource.comment below the renderbox.

This commit is contained in:
Mathieu Jaumotte 2022-01-12 20:26:54 +01:00
parent c9e3960238
commit ecda740d81
7 changed files with 63 additions and 8 deletions

View File

@ -5,6 +5,7 @@
:action="context.action" :action="context.action"
:buttonText="options.buttonText" :buttonText="options.buttonText"
:displayBadge="options.displayBadge === 'true'" :displayBadge="options.displayBadge === 'true'"
:parent="options.parent"
@saveFormOnTheFly="saveFormOnTheFly"> @saveFormOnTheFly="saveFormOnTheFly">
</on-the-fly> </on-the-fly>
</template> </template>

View File

@ -28,6 +28,12 @@
v-bind:action="action" v-bind:action="action"
ref="castPerson"> ref="castPerson">
</on-the-fly-person> </on-the-fly-person>
<div v-if="hasResourceComment">
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
</div>
</template> </template>
<template v-slot:body v-else-if="type === 'thirdparty'"> <template v-slot:body v-else-if="type === 'thirdparty'">
@ -37,6 +43,12 @@
v-bind:action="action" v-bind:action="action"
ref="castThirdparty"> ref="castThirdparty">
</on-the-fly-thirdparty> </on-the-fly-thirdparty>
<div v-if="hasResourceComment">
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
</div>
</template> </template>
<template v-slot:body v-else> <template v-slot:body v-else>
@ -78,18 +90,27 @@ export default {
OnTheFlyThirdparty, OnTheFlyThirdparty,
OnTheFlyCreate OnTheFlyCreate
}, },
props: ['type', 'id', 'action', 'buttonText', 'displayBadge'], props: ['type', 'id', 'action', 'buttonText', 'displayBadge', 'parent'],
emits: ['saveFormOnTheFly'], emits: ['saveFormOnTheFly'],
data() { data() {
return { return {
modal: { modal: {
showModal: false, showModal: false,
modalDialogClass: "modal-dialog-scrollable modal-xl" modalDialogClass: "modal-dialog-scrollable modal-xl"
}, }
//action: this.action
} }
}, },
computed: { computed: {
hasResourceComment() {
//console.log('hasResourceComment', this.parent);
if (typeof this.parent === 'undefined' || this.parent === null) {
return false;
}
return this.action === 'show'
&& this.parent.type === 'accompanying_period_resource'
&& (this.parent.comment !== null || this.parent.comment !== '')
;
},
classAction() { classAction() {
switch (this.action) { switch (this.action) {
case 'show': case 'show':

View File

@ -17,6 +17,7 @@ const ontheflyMessages = {
person: "un nouvel usager", person: "un nouvel usager",
thirdparty: "un nouveau tiers professionnel" thirdparty: "un nouveau tiers professionnel"
}, },
resource_comment_title: "Un commentaire est associé à cet interlocuteur"
} }
} }
} }

View File

@ -21,7 +21,8 @@ containers.forEach((container) => {
}, },
options: { options: {
buttonText: container.dataset.buttonText || null, buttonText: container.dataset.buttonText || null,
displayBadge: container.dataset.displayBadge || false displayBadge: container.dataset.displayBadge || false,
parent: JSON.parse(container.dataset.parent) || null,
} }
} }
} }

View File

@ -10,6 +10,7 @@
* action string 'show', 'edit', 'create' * action string 'show', 'edit', 'create'
* buttonText string * buttonText string
* displayBadge boolean (default: false) replace button by badge, need to define buttonText for content * displayBadge boolean (default: false) replace button by badge, need to define buttonText for content
* parent object (optional) pass parent context of the targetEntity (used for course resource comment)
#} #}
<span class="onthefly-container" <span class="onthefly-container"
@ -31,6 +32,10 @@
data-display-badge="true" data-display-badge="true"
{% endif %} {% endif %}
{% if parent is defined %}
data-parent='{{ parent|json_encode }}'
{% endif %}
></span> ></span>
{{ encore_entry_script_tags('vue_onthefly') }} {{ encore_entry_script_tags('vue_onthefly') }}

View File

@ -22,6 +22,7 @@
</li> </li>
<li> <li>
<on-the-fly <on-the-fly
:parent="parent"
:type="resource.resource.type" :type="resource.resource.type"
:id="resource.resource.id" :id="resource.resource.id"
action="show"> action="show">
@ -29,6 +30,7 @@
</li> </li>
<li> <li>
<on-the-fly <on-the-fly
:parent="parent"
:type="resource.resource.type" :type="resource.resource.type"
:id="resource.resource.id" :id="resource.resource.id"
action="edit" action="edit"
@ -66,6 +68,7 @@
</li> </li>
<li> <li>
<on-the-fly <on-the-fly
:parent="parent"
:type="resource.resource.type" :type="resource.resource.type"
:id="resource.resource.id" :id="resource.resource.id"
action="show"> action="show">
@ -73,6 +76,7 @@
</li> </li>
<li> <li>
<on-the-fly <on-the-fly
:parent="parent"
:type="resource.resource.type" :type="resource.resource.type"
:id="resource.resource.id" :id="resource.resource.id"
action="edit" action="edit"
@ -110,6 +114,17 @@ export default {
props: ['resource'], props: ['resource'],
emits: ['remove'], emits: ['remove'],
computed: { computed: {
parent() {
return {
'type': this.resource.type,
'id': this.resource.id,
'comment': this.resource.comment,
'parent': {
'type': this.$store.state.accompanyingCourse.type,
'id': this.$store.state.accompanyingCourse.id
}
}
},
hasCurrentHouseholdAddress() { hasCurrentHouseholdAddress() {
if ( this.resource.resource.current_household_address !== null ) { if ( this.resource.resource.current_household_address !== null ) {
return true; return true;

View File

@ -4,11 +4,12 @@
{{ 'Resume Accompanying Course'|trans }} {{ 'Resume Accompanying Course'|trans }}
{% endblock %} {% endblock %}
{% macro insert_onthefly(type, entity) %} {% macro insert_onthefly(type, entity, parent = null) %}
{% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
action: 'show', displayBadge: true, action: 'show', displayBadge: true,
targetEntity: { name: type, id: entity.id }, targetEntity: { name: type, id: entity.id },
buttonText: entity|chill_entity_render_string buttonText: entity|chill_entity_render_string,
parent: parent
} %} } %}
{% endmacro %} {% endmacro %}
@ -106,11 +107,21 @@
<div class="mbloc col col-sm-6 col-lg-4"> <div class="mbloc col col-sm-6 col-lg-4">
<div class="resources"> <div class="resources">
<h4 class="item-key">{{ 'Resources'|trans }}</h4> <h4 class="item-key">{{ 'Resources'|trans }}</h4>
{% for r in accompanyingCourse.resources %} {% for r in accompanyingCourse.resources %}
{% set parent = {
'type': 'accompanying_period_resource',
'id': r.id,
'comment': r.comment,
'parent': {
'type': 'accompanying_period',
'id': accompanyingCourse.id
}
} %}
{% if r.person is not null %} {% if r.person is not null %}
{{ _self.insert_onthefly('person', r.person) }} {{ _self.insert_onthefly('person', r.person, parent) }}
{% elseif r.thirdParty is not null %} {% elseif r.thirdParty is not null %}
{{ _self.insert_onthefly('thirdparty', r.thirdParty) }} {{ _self.insert_onthefly('thirdparty', r.thirdParty, parent) }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>