Skip to content

Commit

Permalink
Merge branch 'pr/1030' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ifox committed Aug 26, 2021
2 parents b1cb1f5 + d16aea5 commit 8331989
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 21 deletions.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/assets/admin/js/chunk-common.1ddb8ece.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/assets/admin/js/chunk-common.60be8508.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/assets/admin/twill-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"Inter-MediumItalic.woff2": "/assets/admin/fonts/Inter-MediumItalic.7a7fd735.woff2",
"Inter-Regular.woff": "/assets/admin/fonts/Inter-Regular.aebfbb3c.woff",
"Inter-Regular.woff2": "/assets/admin/fonts/Inter-Regular.bffaed79.woff2",
"chunk-common.css": "/assets/admin/css/chunk-common.a716eada.css",
"chunk-common.js": "/assets/admin/js/chunk-common.1ddb8ece.js",
"chunk-common.css": "/assets/admin/css/chunk-common.0ac3c728.css",
"chunk-common.js": "/assets/admin/js/chunk-common.60be8508.js",
"chunk-vendors.css": "/assets/admin/css/chunk-vendors.e0f3ef32.css",
"chunk-vendors.js": "/assets/admin/js/chunk-vendors.91e7f646.js",
"icons-files.php": "/views/partials/icons/icons-files-svg.blade.php",
Expand All @@ -23,8 +23,8 @@
"main-dashboard.css": "/assets/admin/css/main-dashboard.7e178125.css",
"main-dashboard.js": "/assets/admin/js/main-dashboard.a32913e7.js",
"main-form.css": "/assets/admin/css/main-form.41163a5e.css",
"main-form.js": "/assets/admin/js/main-form.b33fd342.js",
"main-form.js": "/assets/admin/js/main-form.2d4f287f.js",
"main-free.js": "/assets/admin/js/main-free.75070804.js",
"main-listing.css": "/assets/admin/css/main-listing.32e2c205.css",
"main-listing.js": "/assets/admin/js/main-listing.1e3d07ca.js"
"main-listing.js": "/assets/admin/js/main-listing.8aaa95c2.js"
}
9 changes: 8 additions & 1 deletion frontend/js/components/Textfield.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,18 @@
this.focused = false
this.$emit('blur', newValue)
},
onInput: debounce(function (event) {
onInput: function (event) {
this.preventSubmit()
this._onInputInternal(event)
},
_onInputInternal: debounce(function (event) {
const newValue = event.target.value
this.updateAndSaveValue(newValue)
this.$emit('change', newValue)
this.allowSubmit()
}, 250),
resizeTextarea: function () {
if (this.type !== 'textarea') return
Expand Down
9 changes: 7 additions & 2 deletions frontend/js/components/Wysiwyg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,13 @@
this.updateEditor(newValue)
}
},
textUpdate: debounce(function () {
this.saveIntoStore() // see formStore mixin
textUpdate: function () {
this.preventSubmit()
this._textUpdateInternal()
},
_textUpdateInternal: debounce(function () {
this.saveIntoStore()
this.allowSubmit()
}, 600),
toggleSourcecode: function () {
this.editorHeight = (Math.max(50, this.$refs.editor.clientHeight) + this.toolbarHeight - 1) + 'px'
Expand Down
9 changes: 7 additions & 2 deletions frontend/js/components/WysiwygTiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,13 @@
this.updateEditor(newValue)
}
},
textUpdate: debounce(function () {
this.saveIntoStore() // see formStore mixin
textUpdate: function () {
this.preventSubmit()
this._textUpdateInternal()
},
_textUpdateInternal: debounce(function () {
this.saveIntoStore()
this.allowSubmit()
}, 600),
toggleSourcecode: function () {
this.editorHeight = (Math.max(50, this.$refs.editor.clientHeight) + this.toolbarHeight - 1) + 'px'
Expand Down
9 changes: 8 additions & 1 deletion frontend/js/components/modals/ModalAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import { NOTIFICATION, FORM } from '@/store/mutations'
import ACTIONS from '@/store/actions'
import a17ModalValidationButtons from './ModalValidationButtons.vue'
import retrySubmitMixin from '@/mixins/retrySubmit'
export default {
name: 'A17ModalAdd',
mixins: [retrySubmitMixin],
props: {
name: {
type: String,
Expand All @@ -35,7 +37,12 @@
open: function () {
if (this.$refs.modal) this.$refs.modal.open()
},
submit: function (event) {
submit: function () {
if (this.isSubmitPrevented) {
this.shouldRetrySubmitWhenAllowed = true
return
}
if (this._isSubmitting) return
this._isSubmitting = true
Expand Down
9 changes: 8 additions & 1 deletion frontend/js/components/modals/ModalCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import { NOTIFICATION, FORM, DATATABLE, LANGUAGE } from '@/store/mutations'
import ACTIONS from '@/store/actions'
import a17ModalValidationButtons from './ModalValidationButtons.vue'
import retrySubmitMixin from '@/mixins/retrySubmit'
export default {
name: 'A17ModalCreate',
mixins: [retrySubmitMixin],
props: {
formCreate: {
type: String,
Expand Down Expand Up @@ -80,7 +82,12 @@
this.$refs.modal.open()
},
submit: function (event) {
submit: function () {
if (this.isSubmitPrevented) {
this.shouldRetrySubmitWhenAllowed = true
return
}
if (this._isSubmitting) return
this._isSubmitting = true
Expand Down
10 changes: 8 additions & 2 deletions frontend/js/main-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import attributes from '@/store/modules/attributes'
import formatPermalink from '@/mixins/formatPermalink'
import editorMixin from '@/mixins/editor.js'
import BlockMixin from '@/mixins/block'
import retrySubmitMixin from '@/mixins/retrySubmit'

// configuration
Vue.use(A17Config)
Expand Down Expand Up @@ -144,7 +145,7 @@ importedComponents.keys().map(block => {
window[process.env.VUE_APP_NAME].vm = window.vm = new Vue({
store, // inject store to all children
el: '#app',
mixins: [formatPermalink, editorMixin],
mixins: [formatPermalink, editorMixin, retrySubmitMixin],
data: function () {
return {
unSubscribe: function () {
Expand All @@ -165,7 +166,12 @@ window[process.env.VUE_APP_NAME].vm = window.vm = new Vue({
])
},
methods: {
submitForm: function (event) {
submitForm: function () {
if (this.isSubmitPrevented) {
this.shouldRetrySubmitWhenAllowed = true
return
}

if (!this.loading) {
this.isFormUpdated = false
this.$store.commit(FORM.UPDATE_FORM_LOADING, true)
Expand Down
6 changes: 6 additions & 0 deletions frontend/js/mixins/formStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export default {
// in Modal or in Form
if (this.inModal) this.$store.commit(FORM.UPDATE_MODAL_FIELD, field)
else this.$store.commit(FORM.UPDATE_FORM_FIELD, field)
},
preventSubmit: function () {
this.$store.commit(FORM.PREVENT_SUBMIT)
},
allowSubmit: function () {
this.$store.commit(FORM.ALLOW_SUBMIT)
}
},
beforeMount: function () {
Expand Down
31 changes: 31 additions & 0 deletions frontend/js/mixins/retrySubmit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { mapState } from 'vuex'

export default {
data: function () {
return {
shouldRetrySubmitWhenAllowed: false
}
},
computed: {
...mapState({
isSubmitPrevented: state => state.form.isSubmitPrevented
})
},
watch: {
isSubmitPrevented: function (isSubmitPrevented) {
if (!isSubmitPrevented && this.shouldRetrySubmitWhenAllowed) {
this.shouldRetrySubmitWhenAllowed = false
this.retrySubmit()
}
}
},
methods: {
retrySubmit: function () {
if (this.submitForm) {
this.submitForm() // @see main-form.js
} else if (this.submit) {
this.submit() // @see ModalCreate.vue & ModalAdd.vue
}
}
}
}
18 changes: 14 additions & 4 deletions frontend/js/store/modules/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@ const state = {
errors: {},
/**
* Is this a custom form (that will let the browser submit the form instead of hooking up the submit event)
* @type {Bookean}
* @type {Boolean}
*/
isCustom: window[process.env.VUE_APP_NAME].STORE.form.isCustom || false,
/**
* Force reload on successful submit
* @type {Bookean}
* @type {Boolean}
*/
reloadOnSuccess: window[process.env.VUE_APP_NAME].STORE.form.reloadOnSuccess || false

reloadOnSuccess: window[process.env.VUE_APP_NAME].STORE.form.reloadOnSuccess || false,
/**
* Determines if the form should prevent submitting before an input value is pushed into the store
* @type {Boolean}
*/
isSubmitPrevented: false
}

// getters
Expand Down Expand Up @@ -104,6 +108,12 @@ const mutations = {
state.permalink = newValue
}
},
[FORM.PREVENT_SUBMIT] (state) {
state.isSubmitPrevented = true
},
[FORM.ALLOW_SUBMIT] (state) {
state.isSubmitPrevented = false
},
// ----------- Form fields ----------- //
[FORM.EMPTY_FORM_FIELDS] (state, status) {
state.fields = []
Expand Down
5 changes: 5 additions & 0 deletions frontend/js/store/mutations/form.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const PREVENT_SUBMIT = 'preventSubmit'
export const ALLOW_SUBMIT = 'allowSubmit'

/* form */
export const UPDATE_FORM_PERMALINK = 'updateFormPermalink'
export const UPDATE_FORM_FIELD = 'updateFormField'
Expand All @@ -23,6 +26,8 @@ export const REMOVE_MODAL_FIELD = 'removeModalField'
export const REPLACE_MODAL_FIELDS = 'replaceModalField'

export default {
PREVENT_SUBMIT,
ALLOW_SUBMIT,
UPDATE_FORM_PERMALINK,
UPDATE_FORM_FIELD,
REMOVE_FORM_FIELD,
Expand Down

0 comments on commit 8331989

Please sign in to comment.