Adapting page components for a SPA

parent 913f98da
...@@ -136,8 +136,6 @@ ...@@ -136,8 +136,6 @@
mixins: [Translate, Slugify], mixins: [Translate, Slugify],
props: { props: {
locales: {default: null}, locales: {default: null},
pageId: {default: null},
route: {default: null},
}, },
data() { data() {
return { return {
...@@ -171,14 +169,15 @@ ...@@ -171,14 +169,15 @@
onSubmit() { onSubmit() {
this.form = new Form(_.merge(this.page, {tags: this.tags})); this.form = new Form(_.merge(this.page, {tags: this.tags}));
this.loading = true; this.loading = true;
this.form.post(this.route)
this.form.post(this.getRoute())
.then(response => { .then(response => {
this.loading = false; this.loading = false;
this.$message({ this.$message({
type: 'success', type: 'success',
message: response.message message: response.message
}); });
window.location = route('admin.page.page.index'); this.$router.push({name: 'admin.page.page.index'});
}) })
.catch(error => { .catch(error => {
console.log(error); console.log(error);
...@@ -190,7 +189,7 @@ ...@@ -190,7 +189,7 @@
}); });
}, },
onCancel() { onCancel() {
window.location = route('admin.page.page.index'); this.$router.push({name: 'admin.page.page.index'});
}, },
fetchTemplates() { fetchTemplates() {
axios.get(route('api.page.page-templates.index')) axios.get(route('api.page.page-templates.index'))
...@@ -205,7 +204,7 @@ ...@@ -205,7 +204,7 @@
this.tags = tags; this.tags = tags;
}, },
fetchPage() { fetchPage() {
axios.post(route('api.page.page.find', {page: this.pageId})) axios.post(route('api.page.page.find', {page: this.$route.params.pageId}))
.then(response => { .then(response => {
this.page = response.data.data; this.page = response.data.data;
this.tags = response.data.data.tags; this.tags = response.data.data.tags;
...@@ -213,10 +212,17 @@ ...@@ -213,10 +212,17 @@
.catch(error => { .catch(error => {
}) })
}, },
getRoute() {
if (this.$route.params.pageId !== undefined) {
return route('api.page.page.update', {page: this.$route.params.pageId});
}
return route('api.page.page.store');
},
}, },
mounted() { mounted() {
this.fetchTemplates(); this.fetchTemplates();
if (this.pageId !== null) {
if (this.$route.params.pageId !== null) {
this.fetchPage(); this.fetchPage();
} }
} }
......
<template> <template>
<data-tables :data="data" :actions-def="actionsDef"> <div class="row">
<el-table-column prop="id" label="Id" width="100"> <div class="col-xs-12">
</el-table-column> <div class="box box-primary">
<el-table-column prop="title" :label="translate('page', 'title')"> <div class="box-body">
</el-table-column>
<el-table-column prop="slug" label="Slug">
</el-table-column>
<el-table-column prop="created_at" label="Created at">
</el-table-column>
<el-table-column fixed="right" prop="actions" label="Actions">
<template scope="scope">
<a class="btn btn-default btn-flat" @click.prevent="goToEdit(scope)"><i class="fa fa-pencil"></i></a>
<delete-button :scope="scope" :rows="data" :translations="translations"> <data-tables :data="data" :actions-def="actionsDef">
</delete-button> <el-table-column prop="id" label="Id" width="100">
</template> </el-table-column>
</el-table-column> <el-table-column prop="title" :label="translate('page', 'title')">
</data-tables> </el-table-column>
<el-table-column prop="slug" label="Slug">
</el-table-column>
<el-table-column prop="created_at" label="Created at">
</el-table-column>
<el-table-column fixed="right" prop="actions" label="Actions">
<template scope="scope">
<a class="btn btn-default btn-flat" @click.prevent="goToEdit(scope)"><i
class="fa fa-pencil"></i></a>
<delete-button :scope="scope" :rows="data" :translations="translations">
</delete-button>
</template>
</el-table-column>
</data-tables>
</div>
</div>
</div>
</div>
</template> </template>
<script> <script>
import axios from 'axios' import axios from 'axios'
import Translate from '../../../../Core/Assets/js/mixins/Translate' import Translate from '../../../../Core/Assets/js/mixins/Translate'
let data; let data;
export default { export default {
...@@ -34,7 +45,7 @@ ...@@ -34,7 +45,7 @@
name: this.translate('page', 'create page'), name: this.translate('page', 'create page'),
icon: 'edit', icon: 'edit',
handler: () => { handler: () => {
window.location = route('admin.page.page.create'); this.$router.push({name: 'admin.page.page.create'})
} }
}] }]
} }
...@@ -49,7 +60,7 @@ ...@@ -49,7 +60,7 @@
}); });
}, },
goToEdit(scope) { goToEdit(scope) {
window.location = scope.row.urls.edit_url; this.$router.push({name: 'admin.page.page.edit', params: {pageId: scope.row.id}})
}, },
}, },
mounted() { mounted() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment