@@ -35,7 +35,7 @@ jQuery(function ($) {
3535 const feedUrl = $ ( this ) . attr ( 'href' ) ;
3636 $ ( this ) . parents ( '.fz-row' ) . find ( 'input:text' ) . val ( feedUrl ) ;
3737
38- $ ( '[data-step_number="2"]' ) . removeClass ( 'disabled' ) ;
38+ $ ( '[data-step_number="2"], #preflight ' ) . removeClass ( 'disabled' ) ;
3939 return false ;
4040 } ) ;
4141
@@ -211,6 +211,8 @@ jQuery(function ($) {
211211 post_status : $ (
212212 'select[name="feedzy_meta_data[import_post_status]"]'
213213 ) . val ( ) ,
214+ fallback_image : $ ( 'input[name="feedzy_meta_data[default_thumbnail_id]"]' ) . val ( ) ,
215+ excluded_post_title : $ ( 'input[name="feedzy_meta_data[exc_key]"]' ) . val ( ) ,
214216 action : 'feedzy' ,
215217 _action : 'wizard_import_feed' ,
216218 } ,
@@ -329,9 +331,9 @@ jQuery(function ($) {
329331 // Remove disabled class from save button.
330332 $ ( document ) . on ( 'input' , '#wizard_feed_source' , function ( ) {
331333 if ( '' === $ ( this ) . val ( ) ) {
332- $ ( '[data-step_number="2"]' ) . addClass ( 'disabled' ) ;
334+ $ ( '[data-step_number="2"], #preflight ' ) . addClass ( 'disabled' ) ;
333335 } else {
334- $ ( '[data-step_number="2"]' ) . removeClass ( 'disabled' ) ;
336+ $ ( '[data-step_number="2"], #preflight ' ) . removeClass ( 'disabled' ) ;
335337 }
336338 } ) ;
337339
@@ -359,4 +361,100 @@ jQuery(function ($) {
359361
360362 // Init chosen selectbox.
361363 $ ( '.feedzy-chosen' ) . chosen ( { width : '100%' } ) ;
364+
365+ // on upload button click
366+ $ ( 'body' ) . on ( 'click' , '.feedzy-open-media' , function ( e ) {
367+ e . preventDefault ( ) ;
368+ const button = $ ( this ) ,
369+ wp_media_uploader = wp . media ( {
370+ title : feedzySetupWizardData . mediaUploadText . iframeTitle ,
371+ library : {
372+ type : 'image'
373+ } ,
374+ button : {
375+ text : feedzySetupWizardData . mediaUploadText . iframeButton
376+ } ,
377+ multiple : false
378+ } ) . on ( 'select' , function ( ) { // it also has "open" and "close" events
379+ const selectedAttachments = wp_media_uploader . state ( ) . get ( 'selection' ) ;
380+ button . parents ( '.fz-form-group' ) . find ( '.feedzy-media-preview' ) . remove ( ) ;
381+ // Display image preview when a single image is selected.
382+ const attachment = selectedAttachments . first ( ) . toJSON ( ) ;
383+ let attachmentUrl = attachment . url ;
384+ if ( attachment . sizes . thumbnail ) {
385+ attachmentUrl = attachment . sizes . thumbnail . url ;
386+ }
387+ if ( $ ( '.feedzy-media-preview' ) . length ) {
388+ $ ( '.feedzy-media-preview' ) . find ( 'img' ) . attr ( 'src' , attachmentUrl ) ;
389+ } else {
390+ $ ( '<div class="fz-form-group mb-20 feedzy-media-preview"><img src="' + attachmentUrl + '"></div>' ) . insertBefore ( button . parent ( ) ) ;
391+ }
392+ // Get all selected attachment ids.
393+ const ids = selectedAttachments . map ( function ( image ) {
394+ return image . id ;
395+ } ) . join ( ',' ) ;
396+
397+ button . parent ( ) . find ( '.feedzy-remove-media' ) . addClass ( 'is-show' ) ;
398+ button . parent ( ) . find ( 'input:hidden' ) . val ( ids ) . trigger ( 'change' ) ;
399+ $ ( '.feedzy-open-media' ) . html ( feedzySetupWizardData . mediaUploadText . actionButtonTextTwo ) ;
400+ } ) ;
401+
402+ wp_media_uploader . on ( ' open' , function ( ) {
403+ const selectedVal = button . parent ( ) . find ( 'input:hidden' ) . val ( ) ;
404+ if ( '' === selectedVal ) {
405+ return ;
406+ }
407+ const selection = wp_media_uploader . state ( ) . get ( 'selection' ) ;
408+
409+ selectedVal . split ( ',' ) . forEach ( function ( id ) {
410+ const attachment = wp . media . attachment ( id ) ;
411+ attachment . fetch ( ) ;
412+ selection . add ( attachment ? [ attachment ] : [ ] ) ;
413+ } ) ;
414+ } ) ;
415+
416+ wp_media_uploader . open ( ) ;
417+ } ) ;
418+
419+ $ ( document ) . on ( 'click' , '.feedzy-remove-media' , function ( e ) {
420+ $ ( this )
421+ e . preventDefault ( ) ;
422+ $ ( '.feedzy-media-preview' ) . remove ( ) ;
423+ $ ( this ) . removeClass ( 'is-show' ) ;
424+
425+ // Reset the input.
426+ $ ( 'input[name="feedzy_meta_data[default_thumbnail_id]"]' ) . val ( 0 ) ;
427+ $ ( '.feedzy-open-media' ) . html ( feedzySetupWizardData . mediaUploadText . actionButtonTextOne ) ;
428+ } ) ;
429+
430+ $ ( '#preflight' ) . on ( 'click' , function ( e ) {
431+ e . preventDefault ( ) ;
432+ const $fields = { } ;
433+ // collect all elements.
434+ $ ( '#smartwizard' )
435+ . find ( ':input' )
436+ . each ( function ( index , element ) {
437+ if ( 'undefined' === typeof $ ( element ) . attr ( 'name' ) ) {
438+ return ;
439+ }
440+ $fields [ $ ( element ) . attr ( 'name' ) ] = $ ( element ) . val ( ) ;
441+ } ) ;
442+ $fields [ 'feedzy_meta_data[source]' ] = $ ( '#wizard_feed_source' ) . val ( ) ;
443+ tb_show ( feedzySetupWizardData . dryRun . title , 'TB_inline?' ) ;
444+ $ ( '#TB_ajaxContent' ) . html ( feedzySetupWizardData . dryRun . loading ) ;
445+ $ . post (
446+ ajaxurl ,
447+ {
448+ security : window . feedzySetupWizardData . ajax . security ,
449+ fields : $ . param ( $fields ) ,
450+ action : 'feedzy' ,
451+ _action : 'dry_run' ,
452+ environment : 'wizard' ,
453+ } ,
454+ function ( data ) {
455+ $ ( '#TB_ajaxContent' ) . addClass ( 'loaded' ) ;
456+ $ ( '#TB_ajaxContent div' ) . html ( data . data . output ) ;
457+ } ,
458+ ) ;
459+ } ) ;
362460} ) ;
0 commit comments