Browse Source

💬 Ajoute les catégories et des nouveaux textes

master
cdesmidt 2 years ago
parent
commit
e678b9e4c3
  1. 7
      public/email.php
  2. 373
      public/emails.json
  3. 9
      public/emails.php
  4. 6
      public/topics.php
  5. 69
      src/components/EmailModel.vue

7
public/email.php

@ -1,7 +1,12 @@
<?php
$slug = $_POST['slug'];
$emails_json = json_decode(file_get_contents(__DIR__.'/emails.json'), true);
$topic = $_POST['topic'];
$emails_json = json_decode(file_get_contents(__DIR__.'/emails.json'), true)[0];
if (!array_key_exists($topic, $emails_json)) {
header('HTTP/1.0 404 Not Found');
}
$emails_json = $emails_json[$topic];
$emails = [];
foreach ($emails_json as $email) {
$emails[$email['slug']] = $email;

373
public/emails.json

File diff suppressed because one or more lines are too long

9
public/emails.php

@ -1,4 +1,11 @@
<?php
header('Content-Type: application/json');
readfile(__DIR__.'/emails.json');
header('Content-Type: application/json');
$json_content = json_decode(file_get_contents(__DIR__.'/emails.json'), true)[0];
$topic = $_POST['topic'];
if (array_key_exists($topic, $json_content)) {
echo json_encode($json_content[$topic]);
}

6
public/topics.php

@ -0,0 +1,6 @@
<?php
header('Content-Type: application/json');
$json_content = json_decode(file_get_contents(__DIR__.'/emails.json'), true);
echo json_encode(array_map(function($json_content_part) { return array_keys($json_content_part); }, $json_content)[0]);

69
src/components/EmailModel.vue

@ -1,17 +1,28 @@
<template>
<div class="hello">
<h1>Modèles d'Email</h1>
<h2>Templates d'email potentiellement pré-rempli à usage professionnel et personnel !</h2>
<select v-model="selected" v-on:change="selectEmail">
<option v-for="template in emails" :value="template.slug" :key="template.slug">
{{ template.name }}
</option>
</select>
<div v-if="email != null">
<h4 class="email-subject">Sujet : {{ email.subject }}</h4>
<nl2br tag="p" :text="email.body" class-name="email-body"></nl2br>
</div>
</div>
<form class="pure-form pure-form-aligned">
<fieldset>
<div class="pure-control-group">
<label for="topic">Catégorie :</label>
<select v-model="topic" v-on:change="selectTopic" id="topic">
<option v-for="template in topics" :value="template" :key="template">
{{ template }}
</option>
</select>
</div>
<div class="pure-control-group">
<label for="subject">Sujet :</label>
<select v-model="selected" v-on:change="selectEmail" v-bind="topic === null">
<option v-for="template in emails" :value="template.slug" :key="template.slug">
{{ template.name }}
</option>
</select>
</div>
<div v-if="email != null">
<h4 class="email-subject">Sujet : {{ email.subject }}</h4>
<nl2br tag="p" :text="email.body" class-name="email-body"></nl2br>
</div>
</fieldset>
</form>
</template>
<script>
@ -31,21 +42,28 @@
return {
emails: [],
selected: "",
email: null
email: null,
topics: [],
topic: null
}
},
beforeCreate() {
let $this = this;
Vue.http.get("emails.php").then(response => {
$this.emails = response.body
Vue.http.get("topics.php").then(response => {
$this.topics = response.body
});
},
methods: {
selectTopic: function() {
let $this = this;
Vue.http.post("emails.php", {"topic": $this.topic}).then(response => {
$this.emails = response.body;
});
},
selectEmail: function() {
let $this = this;
Vue.http.post("email.php", {"slug": $this.selected}).then(response => {
Vue.http.post("email.php", {"topic": $this.topic, "slug": $this.selected}).then(response => {
$this.email = response.body;
// $this.email.body.replace(/(\r\n|\n\r|\r|\n)/g, '<br>$1');
});
}
}
@ -53,19 +71,8 @@
</script>
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
.pure-control-group {
text-align: left;
}
.email-subject, .email-body {
text-align: left;

Loading…
Cancel
Save