|
@@ -40,7 +40,8 @@ export default {
|
|
...mapState(UserStore,['isloggedin', 'csrf_token']),
|
|
...mapState(UserStore,['isloggedin', 'csrf_token']),
|
|
...mapState(ConcernementsStore,['opened_concernement',
|
|
...mapState(ConcernementsStore,['opened_concernement',
|
|
'ct_concernement',
|
|
'ct_concernement',
|
|
- 'ct_entite'
|
|
|
|
|
|
+ 'ct_entite',
|
|
|
|
+ 'allBesoinsById'
|
|
]),
|
|
]),
|
|
...mapState(CommonStore,['hover_elmt'])
|
|
...mapState(CommonStore,['hover_elmt'])
|
|
},
|
|
},
|
|
@@ -155,6 +156,90 @@ export default {
|
|
// resolve('test')
|
|
// resolve('test')
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ addRessource(besoin_id){
|
|
|
|
+ console.log('addRessource', besoin_id);
|
|
|
|
+ this.reloading_concernements = true;
|
|
|
|
+ // 1 create reponse node
|
|
|
|
+ this.createRessourceNode(besoin_id)
|
|
|
|
+ .then((ressource) => {
|
|
|
|
+ console.log('createRessourceNode then node', ressource);
|
|
|
|
+ // 2 record new besoin in concernement's field_besoin
|
|
|
|
+ // this.recordBesoinRessourceField(besoin_id, ressource)
|
|
|
|
+ // .then((besoin) => {
|
|
|
|
+ // console.log('besoin', besoin);
|
|
|
|
+ // reload the map item
|
|
|
|
+ this.reloadConcernementBesoins(this.cid)
|
|
|
|
+ .then(() => {
|
|
|
|
+ this.reloading_concernements = false;
|
|
|
|
+ });
|
|
|
|
+ // })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ createRessourceNode(besoin_id){
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ // 1 create entite node
|
|
|
|
+ let besoin_title = this.allBesoinsById[besoin_id].title;
|
|
|
|
+ const params_node_ressource = {
|
|
|
|
+ type: 'reponse',
|
|
|
|
+ title: [{value:`reponse-${besoin_title}-${Date.now()}`}],
|
|
|
|
+ field_besoin_on_reponses: [{target_id: besoin_id}],
|
|
|
|
+ field_confidentialite: [{value:'confidentialite_public'}]
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const configs = {
|
|
|
|
+ headers: {'X-CSRF-Token': this.csrf_token}
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ REST.post(`/node?_format=json`, params_node_ressource, configs)
|
|
|
|
+ .then(({ data }) => {
|
|
|
|
+ console.log('REST post new node ressource', data);
|
|
|
|
+ resolve(data)
|
|
|
|
+ })
|
|
|
|
+ .catch(error => {
|
|
|
|
+ console.warn(`Issue with post new node ressource`, error)
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ recordBesoinRessourceField(besoin_id, new_reponse){
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ // 3 record concernement field_entite
|
|
|
|
+
|
|
|
|
+ // get all the field_entite values, we don't want to ersae everything
|
|
|
|
+ let reponses = [];
|
|
|
|
+ this.allBesoinsById[besoin_id].reponses.forEach((reponse) =>{
|
|
|
|
+ reponses.push({
|
|
|
|
+ target_id: reponse.id
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ // add the new field value
|
|
|
|
+ reponses.push({
|
|
|
|
+ target_id: new_reponse.nid[0].value
|
|
|
|
+ })
|
|
|
|
+ console.log('reponses', reponses);
|
|
|
|
+
|
|
|
|
+ const params_node = {
|
|
|
|
+ type: 'besoin',
|
|
|
|
+ nid: [{value: besoin_id}],
|
|
|
|
+ 'field_reponse': reponses
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const configs = {
|
|
|
|
+ headers: {'X-CSRF-Token': this.csrf_token}
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ REST.patch(`/node/${this.cid}?_format=json`, params_node, configs)
|
|
|
|
+ .then(({ data }) => {
|
|
|
|
+ console.log('REST patch besoin new field_reponse', data)
|
|
|
|
+ resolve(data)
|
|
|
|
+ })
|
|
|
|
+ .catch(error => {
|
|
|
|
+ console.warn(`Issue with patch node besoin field_reponse`, error)
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ // resolve('test')
|
|
|
|
+ })
|
|
|
|
+ }
|
|
},
|
|
},
|
|
components: {
|
|
components: {
|
|
CartoucheLayout,
|
|
CartoucheLayout,
|
|
@@ -267,16 +352,27 @@ export default {
|
|
<label for="reponse-avec">Avec</label>
|
|
<label for="reponse-avec">Avec</label>
|
|
<p name="reponse-avec" v-html="reponse.avec" />
|
|
<p name="reponse-avec" v-html="reponse.avec" />
|
|
</section>
|
|
</section>
|
|
- </li>
|
|
|
|
|
|
+ </li>
|
|
|
|
+
|
|
</ul>
|
|
</ul>
|
|
- <a
|
|
|
|
|
|
+ <!-- <a
|
|
v-if="isloggedin && !opened_concernement.can_update"
|
|
v-if="isloggedin && !opened_concernement.can_update"
|
|
:href="'/api/node/add/reponse?besoin_id='+besoin.id"
|
|
:href="'/api/node/add/reponse?besoin_id='+besoin.id"
|
|
target="_blank"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
rel="noopener noreferrer"
|
|
class="contribute-link mdi mdi-pencil-plus">
|
|
class="contribute-link mdi mdi-pencil-plus">
|
|
<svg-icon type="mdi" :path="pencilplusoutline_path" /> contribuer à ce besoin
|
|
<svg-icon type="mdi" :path="pencilplusoutline_path" /> contribuer à ce besoin
|
|
- </a>
|
|
|
|
|
|
+ </a> -->
|
|
|
|
+ <template v-if="isloggedin && !opened_concernement.can_update">
|
|
|
|
+ <div v-if="!reloading_concernements" @click="addRessource(besoin.id)" class="add-ressource-btn">
|
|
|
|
+ <span>Proposer une ressource</span>
|
|
|
|
+ <svg-icon type="mdi" :path="mdiStickerPlusOutline_path"/>
|
|
|
|
+ </div>
|
|
|
|
+ <div v-else class="add-ressource-btn">
|
|
|
|
+ <div class="loading">Chargement</div>
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
|
|
+
|
|
</li>
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
</template>
|
|
</template>
|
|
@@ -292,8 +388,10 @@ export default {
|
|
<div class="loading">Chargement</div>
|
|
<div class="loading">Chargement</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
+
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
+
|
|
</CartoucheLayout>
|
|
</CartoucheLayout>
|
|
|
|
|
|
</template>
|
|
</template>
|