Skip to content

Commit a699568

Browse files
authored
Merge pull request #88 from kaidesu/navigate-away-prompt
Prompt on unsaved changes before navigating away
2 parents 39dfad6 + e41df4f commit a699568

7 files changed

Lines changed: 21 additions & 18 deletions

File tree

public/js/chunks/85.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/gravity.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/js/gravity.js": "/js/gravity.js?id=d29f2740dcbcc4c2b9b8",
2+
"/js/gravity.js": "/js/gravity.js?id=e8b497ebf1dfed47876d",
33
"/css/gravity.css": "/css/gravity.css?id=88cf59977307f36f5f29"
44
}

resources/js/pages/Customize.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<component
2323
v-for="(field, fieldHandle) in section.fields"
24-
v-model="theme.option[handle][fieldHandle]"
24+
v-model="form[handle][fieldHandle]"
2525
:key="fieldHandle"
2626
:is="field.fieldtype + '-fieldtype'"
2727
:field="{
@@ -62,10 +62,13 @@
6262
<iframe ref="iframe" @load="onLoadIframe"></iframe>
6363
</div>
6464
</div>
65+
66+
<confirm-modal></confirm-modal>
6567
</div>
6668
</template>
6769

6870
<script>
71+
import Form from '../services/Form'
6972
import _ from 'lodash'
7073
7174
var cancel
@@ -83,8 +86,8 @@
8386
data() {
8487
return {
8588
theme: {},
89+
form: null,
8690
url: '/customize',
87-
hasChanges: false,
8891
window: 'desktop',
8992
showControls: true,
9093
}
@@ -107,7 +110,7 @@
107110
watch: {
108111
'theme.option': {
109112
handler: function() {
110-
this.hasChanges = true;
113+
this.form.onFirstChange()
111114
this.update()
112115
},
113116
@@ -155,12 +158,9 @@
155158
},
156159
157160
submit() {
158-
this.theme.option['_method'] = 'PATCH'
159-
160-
axios.post(`/api/themes/${this.theme.namespace}`, this.theme.option).then(() => {
161+
this.form.patch('/api/themes/' + this.theme.namespace).then((response) => {
161162
toast('Theme options have been updated', 'success')
162-
})
163-
.catch((error) => {
163+
}).catch((error) => {
164164
toast(error.response.data.message, 'failed')
165165
})
166166
},
@@ -187,7 +187,12 @@
187187
axios.get('/api/theme'),
188188
]).then(axios.spread(function (theme) {
189189
next(function(vm) {
190+
let options = theme.data.data.option
191+
192+
_.unset(options, '_json')
193+
190194
vm.theme = theme.data.data
195+
vm.form = new Form(options, true)
191196
})
192197
}))
193198
},

resources/js/services/Form.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ export default class Form {
173173
* Handle the first input event. Prevents navigating
174174
* away from the form if the preventNavigation
175175
* setting has been enabled.
176-
*
177-
* @param {object} data
178176
*/
179-
onFirstChange(data) {
177+
onFirstChange() {
180178
this.hasChanges = true
181179
if (this.preventNavigation) {
182180
store.commit('form/setPreventNavigation', true)
@@ -186,10 +184,8 @@ export default class Form {
186184
/**
187185
* Helper method to reset the form to appear as if
188186
* it had no changes.
189-
*
190-
* @param {object} data
191187
*/
192-
resetChangeListener(data) {
188+
resetChangeListener() {
193189
this.hasChanges = false
194190
if (this.preventNavigation) {
195191
store.commit('form/setPreventNavigation', false)

resources/tailwind.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const spacing = {
100100
}
101101

102102
module.exports = {
103+
purge: false,
103104
theme: {
104105
cursors: cursors,
105106

src/Http/Controllers/Web/CustomizeController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public function show(Request $request)
1717
$previous = (object) parse_url(session()->get('_previous.url'));
1818

1919
if (
20-
(optional($previous)->path != '/admin/customize') and
20+
(optional($previous)->path != '/'.config('fusion.path')) and
21+
(optional($previous)->path != '/'.config('fusion.path').'/customize') and
2122
(optional($previous)->path != $request->path()) and
2223
(optional($previous)->path)
2324
) {

0 commit comments

Comments
 (0)