captcha
2 years ago
gateways
2 years ago
proAddons
2 years ago
proGateways
2 years ago
sidebar
2 years ago
tabs
2 years ago
IsPROIcon.vue
2 years ago
SettingsPage.vue
2 years ago
addons-tabs.js
2 years ago
index.js
2 years ago
SettingsPage.vue
173 lines
| 1 | <template> |
| 2 | <FormBuilderPage |
| 3 | :title="__( 'JetFormBuilder Settings', 'jet-form-builder' )" |
| 4 | > |
| 5 | <div class="jfb-content"> |
| 6 | <AlertsList/> |
| 7 | <div class="jfb-content-main"> |
| 8 | <div class="cx-vui-panel"> |
| 9 | <CxVuiTabs |
| 10 | :in-panel="false" |
| 11 | :value="activeTabSlug" |
| 12 | layout="vertical" |
| 13 | @input="onChangeActiveTab" |
| 14 | > |
| 15 | <CxVuiTabsPanel |
| 16 | v-for="( { displayButton = true, ...tab }, index ) in tabs" |
| 17 | :name="tab.component.name" |
| 18 | :label="tab.title" |
| 19 | :key="tab.component.name" |
| 20 | :disabled="tab.disabled" |
| 21 | :icon="tab.icon" |
| 22 | > |
| 23 | <template #default v-if="tab.component.render"> |
| 24 | <keep-alive> |
| 25 | <component |
| 26 | v-bind:is="tab.component" |
| 27 | :incoming="getIncoming( tab.component.name )" |
| 28 | :inner-slugs="activeTabInnerSlugs || []" |
| 29 | ref="tabComponents" |
| 30 | /> |
| 31 | </keep-alive> |
| 32 | <cx-vui-button |
| 33 | v-if="displayButton" |
| 34 | button-style="accent" |
| 35 | :loading="loadingTab[ tab.component.name ]" |
| 36 | @click="onSaveTab( index, tab.component.name )" |
| 37 | > |
| 38 | <template #label> |
| 39 | <span>Save</span> |
| 40 | </template> |
| 41 | </cx-vui-button> |
| 42 | </template> |
| 43 | </CxVuiTabsPanel> |
| 44 | </CxVuiTabs> |
| 45 | </div> |
| 46 | </div> |
| 47 | <SettingsSideBar/> |
| 48 | </div> |
| 49 | </FormBuilderPage> |
| 50 | </template> |
| 51 | |
| 52 | <script> |
| 53 | import * as captcha from './tabs/captcha'; |
| 54 | import * as mailchimp from './tabs/mailchimp'; |
| 55 | import * as getResponse from './tabs/getresponse'; |
| 56 | import * as paymentGateways from './tabs/payments-gateways'; |
| 57 | import * as options from './tabs/options'; |
| 58 | import SettingsSideBar from './sidebar/SettingsSideBar'; |
| 59 | |
| 60 | const { applyFilters, doAction } = wp.hooks; |
| 61 | |
| 62 | const { |
| 63 | SaveTabByAjax, |
| 64 | GetIncoming, |
| 65 | i18n, |
| 66 | } = window.JetFBMixins; |
| 67 | |
| 68 | const { |
| 69 | CxVuiTabsPanel, |
| 70 | CxVuiTabs, |
| 71 | AlertsList, |
| 72 | FormBuilderPage, |
| 73 | } = JetFBComponents; |
| 74 | |
| 75 | window.jfbEventBus = window.jfbEventBus || new Vue( {} ); |
| 76 | |
| 77 | const settingTabs = applyFilters( 'jet.fb.register.settings-page.tabs', [ |
| 78 | options, |
| 79 | paymentGateways, |
| 80 | captcha, |
| 81 | mailchimp, |
| 82 | getResponse, |
| 83 | ] ); |
| 84 | |
| 85 | const changeHash = hash => { |
| 86 | window.location.hash = '#' + hash; |
| 87 | }; |
| 88 | |
| 89 | const getActiveTab = () => { |
| 90 | const first = settingTabs[ 0 ].component.name; |
| 91 | |
| 92 | if ( ! window.location.hash ) { |
| 93 | changeHash( first ); |
| 94 | |
| 95 | return [ first ]; |
| 96 | } |
| 97 | let [ hash, ...others ] = window.location.hash.replace( '#', '' ).split( '__' ); |
| 98 | let tab = settingTabs.find( tab => tab?.component?.name === hash ); |
| 99 | |
| 100 | if ( ! tab ) { |
| 101 | changeHash( first ); |
| 102 | |
| 103 | return [ first ]; |
| 104 | } |
| 105 | changeHash( [ tab.component.name, ...others ].join( '__' ) ); |
| 106 | |
| 107 | return [ tab.component.name, others ]; |
| 108 | }; |
| 109 | |
| 110 | export default { |
| 111 | name: 'jfb-settings', |
| 112 | components: { |
| 113 | AlertsList, |
| 114 | CxVuiTabsPanel, |
| 115 | CxVuiTabs, |
| 116 | SettingsSideBar, |
| 117 | FormBuilderPage, |
| 118 | }, |
| 119 | data() { |
| 120 | const [ tabSlug, others ] = getActiveTab(); |
| 121 | return { |
| 122 | activeTabSlug: tabSlug, |
| 123 | activeTabInnerSlugs: others, |
| 124 | tabs: settingTabs, |
| 125 | loadingTab: {}, |
| 126 | isActivePro: false, |
| 127 | }; |
| 128 | }, |
| 129 | mixins: [ SaveTabByAjax, GetIncoming, i18n ], |
| 130 | created() { |
| 131 | this.isActivePro = this.getIncoming( 'is_active' ); |
| 132 | |
| 133 | jfbEventBus.$on( 'request-state', props => { |
| 134 | const { state, slug } = props; |
| 135 | this.$set( this.loadingTab, slug, state === 'begin' ); |
| 136 | } ); |
| 137 | jfbEventBus.$on( 'alert-click-thanks', ( { self } ) => { |
| 138 | self.closeAlert(); |
| 139 | } ); |
| 140 | jfbEventBus.$on( 'alert-click-check', ( { self } ) => { |
| 141 | self.closeAlert(); |
| 142 | } ); |
| 143 | }, |
| 144 | methods: { |
| 145 | onChangeActiveTab( activeTab ) { |
| 146 | const currentUrl = new URL( document.URL ); |
| 147 | currentUrl.hash = '#' + activeTab; |
| 148 | |
| 149 | document.location.href = currentUrl.href; |
| 150 | |
| 151 | jfbEventBus.$emit( 'change-tab', { slug: activeTab } ); |
| 152 | }, |
| 153 | onSaveTab( indexTab, tabSlug ) { |
| 154 | const currentTab = this.$refs.tabComponents[ indexTab ]; |
| 155 | |
| 156 | this.saveByAjax( currentTab, tabSlug ); |
| 157 | }, |
| 158 | }, |
| 159 | }; |
| 160 | </script> |
| 161 | |
| 162 | <style lang="scss"> |
| 163 | .jfb-content { |
| 164 | display: flex; |
| 165 | flex-wrap: wrap; |
| 166 | gap: 2em; |
| 167 | margin-top: 1em; |
| 168 | |
| 169 | &-main { |
| 170 | flex: 1; |
| 171 | } |
| 172 | } |
| 173 | </style> |