github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/frontend/directeurs/src/components/home/DetailsII.vue (about)

     1  <template>
     2    <v-card flat>
     3      <v-card-text>
     4        <v-alert type="info" :value="true" dismissible>
     5          Vous pouvez ici choisir les <b>documents</b> affichés dans l'espace de
     6          suivi des responsables.
     7          <br />
     8          La <b>fiche sanitaire</b> est automatiquement demandée pour les
     9          participants mineurs. <br />
    10          En plus des trois documents standards, vous pouvez publier des documents
    11          supplémentaires, à ajouter ci-dessous.
    12        </v-alert>
    13        <v-alert
    14          v-model="lockAlert"
    15          :type="envois.__locked__ ? 'warning' : 'success'"
    16        >
    17          <span v-html="lockInfo"></span>
    18        </v-alert>
    19        <v-row justify-space-between>
    20          <v-col xs="12" md="3">
    21            <v-checkbox
    22              v-model="envois.lettre_directeur"
    23              label="Afficher la lettre du directeur"
    24            ></v-checkbox>
    25          </v-col>
    26          <v-col xs="12" md="3">
    27            <v-checkbox
    28              v-model="envois.liste_vetements"
    29              label="Afficher la liste de vêtements"
    30            ></v-checkbox>
    31          </v-col>
    32          <v-col xs="12" md="3">
    33            <v-checkbox
    34              v-model="envois.liste_participants"
    35              label="Afficher une liste des participants"
    36            ></v-checkbox>
    37          </v-col>
    38          <v-col style="margin: auto;" class="text-right">
    39            <v-btn @click="saveEnvois" class="success" :disabled="isEnvoisSame">
    40              <v-icon v-if="envois.__locked__">{{
    41                $icons["mdi-lock-open"]
    42              }}</v-icon>
    43              {{
    44                envois.__locked__ ? "Déverrouiller et sauvegarder" : "Sauvegarder"
    45              }}
    46            </v-btn>
    47          </v-col>
    48        </v-row>
    49  
    50        <v-card>
    51          <v-card-title class="subtitle-2">Pièces jointes</v-card-title>
    52          <v-card-text>
    53            <v-row v-for="pj in pieces_jointes" :key="pj.id_crypted">
    54              <v-col xs="6" sm="3">
    55                <v-img
    56                  :src="pj.url_miniature"
    57                  height="100px"
    58                  width="70px"
    59                ></v-img>
    60              </v-col>
    61              <v-col xs="6" sm="6">
    62                <b>{{ pj.nom_client }}</b>
    63                <br />
    64                modifié le {{ date_heure(pj.date_heure_modif) }}
    65                <br />
    66                taille: {{ taille(pj.taille) }}
    67              </v-col>
    68              <v-col xs="12" sm="3" style="margin: auto;">
    69                <tooltip-btn tooltip="Télécharger" icon :href="pj.url_download">
    70                  <v-icon>{{ $icons["mdi-download"] }}</v-icon>
    71                </tooltip-btn>
    72                <tooltip-btn
    73                  tooltip="Supprimer"
    74                  icon
    75                  @click="deletePieceJointe(pj)"
    76                >
    77                  <v-icon>{{ $icons["mdi-close"] }}</v-icon>
    78                </tooltip-btn>
    79              </v-col>
    80            </v-row>
    81  
    82            <v-row>
    83              <v-col xs="12" md="9">
    84                <v-file-input
    85                  label="Pièce jointe supplémentaire"
    86                  v-model="bonusFile"
    87                  :prepend-icon="$icons['mdi-paperclip']"
    88                  accept=".jpg, .jpeg, .png, .pdf"
    89                  show-size
    90                ></v-file-input>
    91              </v-col>
    92              <v-col xs="12" md="3" class="text-right" style="margin: auto;">
    93                <v-btn
    94                  color="success"
    95                  :disabled="!bonusFile"
    96                  @click="uploadPieceJointe"
    97                  >Ajouter</v-btn
    98                >
    99              </v-col>
   100            </v-row>
   101          </v-card-text>
   102        </v-card>
   103      </v-card-text>
   104    </v-card>
   105  </template>
   106  
   107  <script lang="ts">
   108  import Vue from "vue";
   109  import Component from "vue-class-component";
   110  import { Envois, DetailsEnvoisOut, PublicDocument } from "../../logic/types";
   111  import { C } from "../../logic/controller";
   112  import { Formatter } from "../../logic/formatter";
   113  import TooltipBtn from "@/components/TooltipBtn.vue";
   114  
   115  const DetailsIIProps = Vue.extend({
   116    props: {}
   117  });
   118  
   119  @Component({
   120    components: { TooltipBtn }
   121  })
   122  export default class DetailsII extends DetailsIIProps {
   123    date_heure = Formatter.date_heure;
   124    taille = Formatter.taille;
   125  
   126    lockAlert = true;
   127    initialEnvois: Envois = {
   128      __locked__: true,
   129      lettre_directeur: false,
   130      liste_participants: false,
   131      liste_vetements: false
   132    };
   133  
   134    envois: Envois = {
   135      __locked__: true,
   136      lettre_directeur: false,
   137      liste_participants: false,
   138      liste_vetements: false
   139    };
   140  
   141    pieces_jointes: PublicDocument[] = [];
   142    bonusFile = null;
   143  
   144    get lockInfo() {
   145      if (this.envois.__locked__) {
   146        return `L'envoi des documents est verrouillé. <br/>
   147          Le centre d'inscription ne peut donc pas, pour l'instant, envoyer une notification. <br/>
   148          Une fois vos documents prêts, penser à en notifier le centre d'inscriptions à l'aide du bouton <b>Déverrouiller et sauvegarder</b>.<br/>
   149          <small>
   150          Veuillez noter qu'il s'agit simplement d'une notification, et non pas de l'envoi effectif des mails aux contacts.
   151          </small>
   152          `;
   153      } else {
   154        return "L'envoi des documents est déverrouillé. <br/> Le centre d'inscription peut envoyer à tout moment un mail de notification.";
   155      }
   156    }
   157  
   158    get isEnvoisSame() {
   159      return (
   160        !this.envois.__locked__ &&
   161        !this.envois.lettre_directeur == !this.initialEnvois.lettre_directeur &&
   162        !this.envois.liste_vetements == !this.initialEnvois.liste_vetements &&
   163        !this.envois.liste_participants == !this.initialEnvois.liste_participants
   164      );
   165    }
   166  
   167    async created() {
   168      const r = await C.getDetails("envois");
   169      if (r != undefined) {
   170        this.pieces_jointes = r.pieces_jointes || [];
   171        this.setEnvois(r);
   172        C.notifications.success = ""; // hide progress
   173      }
   174    }
   175  
   176    private setEnvois(data: DetailsEnvoisOut) {
   177      this.envois = data.envois;
   178      this.initialEnvois = JSON.parse(JSON.stringify(data.envois));
   179    }
   180  
   181    async saveEnvois() {
   182      this.envois.__locked__ = false; // besoin de délock pour le serveur.
   183      const r = await C.updateDetails("envois", this.envois);
   184      if (r != undefined) {
   185        C.notifications.success = "Préférences d'envois bien modifiées.";
   186        this.setEnvois(r);
   187      }
   188    }
   189  
   190    async uploadPieceJointe() {
   191      const file = this.bonusFile;
   192      if (file == null) return;
   193  
   194      const docPub = await C.addBonusDoc(file);
   195      if (docPub == undefined) return;
   196      this.pieces_jointes.push(docPub);
   197      C.notifications.success = "Document ajouté avec succès.";
   198      this.bonusFile = null;
   199    }
   200  
   201    async deletePieceJointe(doc: PublicDocument) {
   202      const ok = await C.deleteDocument(doc.id_crypted);
   203      if (ok) {
   204        this.pieces_jointes = this.pieces_jointes.filter(
   205          r => r.id_crypted != doc.id_crypted
   206        );
   207        C.notifications.success = "Document supprimé avec succés.";
   208      }
   209    }
   210  }
   211  </script>
   212  
   213  <style scoped></style>