| 1 |
(function($){ |
| 2 |
|
| 3 |
/* Create default steps */ |
| 4 |
var wcf_setup_default_steps = function() { |
| 5 |
|
| 6 |
$('.wcf-setup-default-steps').on('click', function(e) { |
| 7 |
|
| 8 |
e.preventDefault(); |
| 9 |
|
| 10 |
if( $( 'body' ).hasClass( 'post-type-cartflows_flow' ) && $( 'body' ).hasClass( 'post-new-php' ) ) { |
| 11 |
|
| 12 |
var $wpTitle = $( '#title' ); |
| 13 |
|
| 14 |
if ( ! $wpTitle.val() ) { |
| 15 |
$wpTitle.val( 'Flow #' + $( '#post_ID' ).val() ); |
| 16 |
} |
| 17 |
|
| 18 |
if ( wp.autosave ) { |
| 19 |
wp.autosave.server.triggerSave(); |
| 20 |
} |
| 21 |
|
| 22 |
$(window).off( 'beforeunload.edit-post' ); |
| 23 |
} |
| 24 |
|
| 25 |
var $this = $(this); |
| 26 |
post_id = $( 'form#post #post_ID').val(); |
| 27 |
|
| 28 |
$.ajax({ |
| 29 |
url: ajaxurl, |
| 30 |
data: { |
| 31 |
action: "cartflows_setup_default_steps", |
| 32 |
post_id : post_id, |
| 33 |
security: cartflows_admin.wcf_setup_default_steps_nonce |
| 34 |
}, |
| 35 |
dataType: 'json', |
| 36 |
type: 'POST', |
| 37 |
success: function ( data ) { |
| 38 |
|
| 39 |
if ( data.status ) { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
location.href = data.redirect.replace( '&', '&' ); |
| 44 |
} |
| 45 |
console.log( data ); |
| 46 |
} |
| 47 |
}); |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
var wcf_steps_hide_show_delete = function() { |
| 52 |
|
| 53 |
$('.wcf-flow-settings .wcf-step-delete').on('click', function(e) { |
| 54 |
|
| 55 |
e.preventDefault(); |
| 56 |
var current_target = $( e.target ); |
| 57 |
|
| 58 |
var $this = $(this), |
| 59 |
step_id = $this.data('id'), |
| 60 |
icon_span = $this.find('.dashicons-trash'), |
| 61 |
text_span = $this.find('.wcf-step-act-btn-text'), |
| 62 |
parent = $this.parents('.wcf-step-wrap'); |
| 63 |
|
| 64 |
var delete_status = confirm( "This action will delete this flow step. Are you sure?" ); |
| 65 |
if (true == delete_status) { |
| 66 |
|
| 67 |
console.log( 'Step Deleting' ); |
| 68 |
icon_span.addClass('wp-ui-text-notification'); |
| 69 |
text_span.addClass('wp-ui-text-notification').text('Deleting..'); |
| 70 |
//$this.text('Deleting..'); |
| 71 |
|
| 72 |
var post_id = $( 'form#post #post_ID').val(); |
| 73 |
|
| 74 |
$.ajax({ |
| 75 |
url: ajaxurl, |
| 76 |
data: { |
| 77 |
action: "cartflows_delete_flow_step", |
| 78 |
post_id : post_id, |
| 79 |
step_id : step_id, |
| 80 |
security: cartflows_admin.wcf_delete_flow_step_nonce |
| 81 |
}, |
| 82 |
dataType: 'json', |
| 83 |
type: 'POST', |
| 84 |
success: function ( data ) { |
| 85 |
parent.slideUp(400, 'swing', function() { |
| 86 |
parent.remove(); |
| 87 |
}); |
| 88 |
console.log( data ); |
| 89 |
} |
| 90 |
}); |
| 91 |
} |
| 92 |
}); |
| 93 |
} |
| 94 |
|
| 95 |
var wcf_flow_steps_sortbale = function() { |
| 96 |
|
| 97 |
$('.wcf-flow-settings .wcf-flow-steps-container').sortable({ |
| 98 |
|
| 99 |
connectWith: '.wcf-flow-steps-container', |
| 100 |
forcePlaceholderSize: true, |
| 101 |
placeholder: "sortable-placeholder", |
| 102 |
|
| 103 |
update: function(event, ui) { |
| 104 |
|
| 105 |
var $this = $(this), |
| 106 |
step_fields = $this.find('.wcf-steps-hidden'), |
| 107 |
step_ids = [], |
| 108 |
post_id = $( 'form#post #post_ID').val(); |
| 109 |
|
| 110 |
step_fields.each(function(i, obj) { |
| 111 |
step_ids.push( $(this).val() ) //test |
| 112 |
}); |
| 113 |
|
| 114 |
$this.sortable('disable'); |
| 115 |
|
| 116 |
$.ajax({ |
| 117 |
url: ajaxurl, |
| 118 |
data: { |
| 119 |
action: "cartflows_reorder_flow_steps", |
| 120 |
post_id : post_id, |
| 121 |
step_ids : step_ids, |
| 122 |
security: cartflows_admin.wcf_reorder_flow_steps_nonce |
| 123 |
}, |
| 124 |
dataType: 'json', |
| 125 |
type: 'POST', |
| 126 |
success: function ( data ) { |
| 127 |
|
| 128 |
$this.sortable('enable'); |
| 129 |
|
| 130 |
if ( data.status ) { |
| 131 |
console.log( 'Sorted' ); |
| 132 |
} |
| 133 |
|
| 134 |
console.log( data ); |
| 135 |
} |
| 136 |
}); |
| 137 |
} |
| 138 |
}); |
| 139 |
|
| 140 |
} |
| 141 |
$(document).ready(function($) { |
| 142 |
|
| 143 |
wcf_setup_default_steps(); |
| 144 |
|
| 145 |
wcf_steps_hide_show_delete(); |
| 146 |
|
| 147 |
wcf_flow_steps_sortbale(); |
| 148 |
}); |
| 149 |
})(jQuery); |
| 150 |
|