Skip to content

Commit

Permalink
feat: Email templates handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rakieta2015 committed Mar 23, 2020
1 parent c441ab1 commit 3b5cec8
Show file tree
Hide file tree
Showing 13 changed files with 791 additions and 2 deletions.
46 changes: 45 additions & 1 deletion coreui/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ const Resource = () => import('@/views/resources/Resource')
const EditResource = () => import('@/views/resources/EditResource')
const DeleteResource = () => import('@/views/resources/DeleteResource')

//Email
const Emails = () => import('@/views/email/Emails')
const CreateEmail = () => import('@/views/email/CreateEmail')
const EditEmail = () => import('@/views/email/EditEmail')
const ShowEmail = () => import('@/views/email/ShowEmail')
const SendEmail = () => import('@/views/email/SendEmail')

const EditMenu = () => import('@/views/menu/EditMenu')
const Media = () => import('@/views/media/Media')

Expand Down Expand Up @@ -212,7 +219,7 @@ function configRoutes () {
{
path: 'create',
meta: { label: 'Create Role' },
name: 'Create Note',
name: 'Create Role',
component: CreateRole
},
{
Expand Down Expand Up @@ -266,6 +273,43 @@ function configRoutes () {
},
]
},
{
path: 'email',
meta: { label: 'Emails'},
component: {
render (c) { return c('router-view') }
},
children: [
{
path: '',
component: Emails,
},
{
path: 'create',
meta: { label: 'Create Email Template' },
name: 'Create Email Template',
component: CreateEmail
},
{
path: ':id',
meta: { label: 'Show Email Template'},
name: 'Show Email Tempalte',
component: ShowEmail,
},
{
path: ':id/edit',
meta: { label: 'Edit Email Tempalate' },
name: 'Edit Email Template',
component: EditEmail
},
{
path: ':id/sendEmail',
meta: { label: 'Send Email' },
name: 'Send Email',
component: SendEmail
},
]
},
{
path: 'resource',
meta: { label: 'Resources'},
Expand Down
93 changes: 93 additions & 0 deletions coreui/src/views/email/CreateEmail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<template>
<CRow>
<CCol col="12" lg="6">
<CCard no-header>
<CCardBody>
<h4>
Create Email Template
</h4>
<CAlert
:show.sync="dismissCountDown"
color="primary"
fade
>
({{dismissCountDown}}) {{ message }}
</CAlert>

<CInput label="Name" type="text" placeholder="Name" v-model="template.name"></CInput>

<CInput label="Subject" type="text" placeholder="Subject" v-model="template.subject"></CInput>

<CTextarea textarea="true" label="Content" :rows="15" placeholder="Content.." v-model="template.content"></CTextarea>

<CButton color="primary" @click="store()">Create</CButton>
<CButton color="primary" @click="goBack">Back</CButton>
</CCardBody>
</CCard>
</CCol>
</CRow>
</template>

<script>
import axios from 'axios'
export default {
name: 'CreateEmailTemplate',
data: () => {
return {
template: {
name: '',
subject: '',
content: '',
},
message: '',
dismissSecs: 7,
dismissCountDown: 0,
showDismissibleAlert: false
}
},
methods: {
goBack() {
this.$router.go(-1)
// this.$router.replace({path: '/users'})
},
store() {
let self = this;
axios.post( '/api/mail?token=' + localStorage.getItem("api_token"),
self.template
)
.then(function (response) {
self.template = {
name: '',
subject: '',
content: '',
}
self.message = 'Successfully created Email Template.';
self.showAlert();
}).catch(function (error) {
if(error.response.data.message == 'The given data was invalid.'){
self.message = '';
for (let key in error.response.data.errors) {
if (error.response.data.errors.hasOwnProperty(key)) {
self.message += error.response.data.errors[key][0] + ' ';
}
}
self.showAlert();
}else{
console.log(error);
self.$router.push({ path: 'login' });
}
});
},
countDownChanged (dismissCountDown) {
this.dismissCountDown = dismissCountDown
},
showAlert () {
this.dismissCountDown = this.dismissSecs
},
},
mounted: function(){
}
}
</script>
94 changes: 94 additions & 0 deletions coreui/src/views/email/EditEmail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<CRow>
<CCol col="12" lg="6">
<CCard>
<CCardBody>
<h3>
Edit Email Template
</h3>
<CAlert
:show.sync="dismissCountDown"
color="primary"
fade
>
({{dismissCountDown}}) {{ message }}
</CAlert>

<CInput label="Name" type="text" placeholder="Name" v-model="template.name"></CInput>
<CInput label="Subject" type="text" placeholder="Subject" v-model="template.subject"></CInput>
<CTextarea textarea="true" label="Content" :rows="15" placeholder="Content.." v-model="template.content"></CTextarea>

<CButton color="primary" @click="update()">Save</CButton>
<CButton color="primary" @click="goBack">Back</CButton>
</CCardBody>
</CCard>
</CCol>
</CRow>
</template>

<script>
import axios from 'axios'
export default {
name: 'EditEmailTemplate',
data: () => {
return {
template: {
name: '',
subject: '',
content: '',
},
message: '',
dismissSecs: 7,
dismissCountDown: 0,
}
},
methods: {
goBack() {
this.$router.go(-1)
// this.$router.replace({path: '/users'})
},
update() {
let self = this;
axios.post( '/api/mail/' + self.$route.params.id + '?token=' + localStorage.getItem("api_token"),
{
_method: 'PUT',
name: self.template.name,
subject: self.template.subject,
content: self.template.content,
})
.then(function (response) {
self.message = 'Successfully updated note.';
self.showAlert();
}).catch(function (error) {
if(error.response.data.message == 'The given data was invalid.'){
self.message = '';
for (let key in error.response.data.errors) {
if (error.response.data.errors.hasOwnProperty(key)) {
self.message += error.response.data.errors[key][0] + ' ';
}
}
self.showAlert();
}else{
console.log(error);
self.$router.push({ path: '/login' });
}
});
},
showAlert () {
this.dismissCountDown = this.dismissSecs
},
},
mounted: function(){
let self = this;
axios.get( '/api/mail/' + self.$route.params.id + '/edit?token=' + localStorage.getItem("api_token"))
.then(function (response) {
self.template = response.data.template;
}).catch(function (error) {
console.log(error);
self.$router.push({ path: '/login' });
});
}
}
</script>
Loading

0 comments on commit 3b5cec8

Please sign in to comment.