GetIncoming.js
2 years ago
ParseIncomingValueMixin.js
2 years ago
PromiseWrapper.js
2 years ago
SaveTabByAjax.js
2 years ago
i18n.js
2 years ago
SaveTabByAjax.js
97 lines
| 1 | export default { |
| 2 | methods: { |
| 3 | saveByAjax( currentTab, tabSlug ) { |
| 4 | const self = this; |
| 5 | let ajaxRequest = {}; |
| 6 | |
| 7 | try { |
| 8 | ajaxRequest = this.getAjaxObject( currentTab, tabSlug ); |
| 9 | } catch ( error ) { |
| 10 | if ( ! error ) { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | if ( 'object' === typeof error.noticeOptions ) { |
| 15 | self.$CXNotice.add( { |
| 16 | message: 'Invalid request data.', |
| 17 | type: 'error', |
| 18 | duration: 2000, |
| 19 | ...error.noticeOptions, |
| 20 | } ); |
| 21 | |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | self.$CXNotice.add( { |
| 26 | message: error, |
| 27 | type: 'error', |
| 28 | duration: 2000, |
| 29 | } ); |
| 30 | |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | jfbEventBus.$emit( 'request-state', { state: 'begin', slug: tabSlug } ); |
| 35 | |
| 36 | jQuery.ajax( ajaxRequest ) |
| 37 | .done( function( response ) { |
| 38 | |
| 39 | if ( 'function' === typeof currentTab.onSaveDone ) { |
| 40 | currentTab.onSaveDone( response ); |
| 41 | } else { |
| 42 | if ( response.success ) { |
| 43 | self.$CXNotice.add( { |
| 44 | message: response.data.message, |
| 45 | type: 'success', |
| 46 | duration: 5000, |
| 47 | } ); |
| 48 | if ( 'function' === typeof currentTab.onSaveDoneSuccess ) { |
| 49 | currentTab.onSaveDoneSuccess( response ); |
| 50 | } |
| 51 | } else { |
| 52 | self.$CXNotice.add( { |
| 53 | message: response.data.message, |
| 54 | type: 'error', |
| 55 | duration: 5000, |
| 56 | } ); |
| 57 | if ( 'function' === typeof currentTab.onSaveDoneError ) { |
| 58 | currentTab.onSaveDoneError( response ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | jfbEventBus.$emit( 'request-state', { state: 'end', slug: tabSlug } ); |
| 63 | } ) |
| 64 | .fail( function( jqXHR, textStatus, errorThrown ) { |
| 65 | if ( 'function' === typeof currentTab.onSaveFail ) { |
| 66 | currentTab.onSaveFail( jqXHR, textStatus, errorThrown ); |
| 67 | } else { |
| 68 | self.$CXNotice.add( { |
| 69 | message: errorThrown, |
| 70 | type: 'error', |
| 71 | duration: 5000, |
| 72 | } ); |
| 73 | } |
| 74 | jfbEventBus.$emit( 'request-state', { state: 'end', slug: tabSlug } ); |
| 75 | } ); |
| 76 | }, |
| 77 | |
| 78 | getAjaxObject( currentTab, tabSlug ) { |
| 79 | const ajaxRequest = { |
| 80 | url: window.ajaxurl, |
| 81 | type: 'POST', |
| 82 | dataType: 'json', |
| 83 | ...currentTab.getRequestOnSave(), |
| 84 | }; |
| 85 | ajaxRequest.data = { |
| 86 | action: `jet_fb_save_tab__${ tabSlug }`, |
| 87 | ...ajaxRequest.data, |
| 88 | }; |
| 89 | |
| 90 | if ( window?.JetFBPageConfigPackage?.nonce ) { |
| 91 | ajaxRequest.data._nonce = window.JetFBPageConfigPackage.nonce; |
| 92 | } |
| 93 | |
| 94 | return ajaxRequest; |
| 95 | }, |
| 96 | }, |
| 97 | } |