| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class to Duplicate Booking into Another Resource - Option for "Actions Dropdown Menu" |
| 4 |
* |
| 5 |
* @package Support functions. |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit, if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class WPBC_Action_Duplicate_Booking |
| 14 |
*/ |
| 15 |
class WPBC_Action_Duplicate_Booking { |
| 16 |
|
| 17 |
const ACTION = 'duplicate_booking_to_other_resource'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Get Action Button |
| 21 |
* |
| 22 |
* @return false|string |
| 23 |
*/ |
| 24 |
public static function get_button() { |
| 25 |
|
| 26 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
if ( ! wpbc_is_user_can( self::ACTION, wpbc_get_current_user_id() ) ) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
// Change booking resource. |
| 34 |
$html = "<a class='ul_dropdown_menu_li_action ul_dropdown_menu_li_action_" . esc_js( self::ACTION ) . "' |
| 35 |
href=\"javascript:void(0)\" |
| 36 |
onclick=\"wpbc_boo_listing__click__duplicate_booking_to_other_resource( {{data['parsed_fields']['booking_id']}}, {{data['parsed_fields']['resource_id']}} );\" |
| 37 |
>" . |
| 38 |
esc_js( __( 'Duplicate booking', 'booking' ) ) . |
| 39 |
"<i class='menu_icon icon-1x wpbc_icn_content_copy'></i>" . |
| 40 |
'</a>'; |
| 41 |
|
| 42 |
return $html; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* Get Template for Modal Window - Booking Cost Edit - Layout - Modal Window structure |
| 48 |
* |
| 49 |
* @return false|void |
| 50 |
*/ |
| 51 |
public static function template_for_modal() { |
| 52 |
|
| 53 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
?> |
| 58 |
<span class="wpdevelop"> |
| 59 |
<div id="wpbc_modal__duplicate_booking_to_other_resource__section" class="modal wpbc_popup_modal wpbc_modal_in_listing" tabindex="-1" role="dialog"> |
| 60 |
<div class="modal-dialog"> |
| 61 |
<div class="modal-content"> |
| 62 |
<div class="modal-header"> |
| 63 |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
| 64 |
<h4 class="modal-title"> |
| 65 |
<?php |
| 66 |
esc_html_e( 'Duplicate booking', 'booking' ); |
| 67 |
?> |
| 68 |
<sup class="wpbc_modal__duplicate_booking_to_other_resource__booking_id wpbc_modal__booking_id__in_title"></sup> |
| 69 |
</h4> |
| 70 |
</div> |
| 71 |
<div class="modal-body"> |
| 72 |
<div id="section_in_in_modal__duplicate_booking_to_other_resource"></div> |
| 73 |
<label class="help-block"> |
| 74 |
<?php |
| 75 |
esc_html_e( 'Select the new booking resource for booking', 'booking' ); |
| 76 |
?> |
| 77 |
</label> |
| 78 |
<input type="hidden" id="wpbc_modal__duplicate_booking_to_other_resource__booking_id" value=""/> |
| 79 |
</div> |
| 80 |
<div class="modal-footer"> |
| 81 |
<a id="wpbc_modal__duplicate_booking_to_other_resource__button_send" class="button button-primary" |
| 82 |
href="javascript:void(0);" |
| 83 |
onclick="javascript: |
| 84 |
wpbc_ajx_booking_ajax_action_request( { |
| 85 |
'booking_action' : '<?php echo esc_js( self::ACTION ); ?>', |
| 86 |
'booking_id' : jQuery( '#wpbc_modal__duplicate_booking_to_other_resource__booking_id' ).val(), |
| 87 |
'selected_resource_id' : jQuery( '#wpbc_modal__duplicate_booking_to_other_resource__resource_id' ).val(), |
| 88 |
'ui_clicked_element_id': 'wpbc_modal__duplicate_booking_to_other_resource__button_send' |
| 89 |
} ); |
| 90 |
wpbc_button_enable_loading_icon( this ); |
| 91 |
jQuery( '#wpbc_modal__duplicate_booking_to_other_resource__section' ).wpbc_my_modal( 'hide' );" > |
| 92 |
<?php |
| 93 |
esc_html_e( 'Duplicate booking', 'booking' ); |
| 94 |
?> |
| 95 |
</a> |
| 96 |
<a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal"> |
| 97 |
<?php |
| 98 |
esc_html_e( 'Cancel', 'booking' ); |
| 99 |
?> |
| 100 |
</a> |
| 101 |
</div> |
| 102 |
</div><!-- /.modal-content --> |
| 103 |
</div><!-- /.modal-dialog --> |
| 104 |
</div><!-- /.modal --> |
| 105 |
</span> |
| 106 |
<?php |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
/** |
| 112 |
* Get Template for Modal Window - Booking Cost Edit - Layout - Modal Window structure |
| 113 |
* |
| 114 |
* @return false|void |
| 115 |
*/ |
| 116 |
public static function hidden_template() { |
| 117 |
|
| 118 |
// Template. |
| 119 |
?> |
| 120 |
<script type="text/html" id="tmpl-wpbc_ajx__modal__duplicate_booking_to_other_resource"> |
| 121 |
<select id="wpbc_modal__duplicate_booking_to_other_resource__resource_id" |
| 122 |
name="wpbc_modal__duplicate_booking_to_other_resource__resource_id" |
| 123 |
class="wpbc_ui_control wpbc_ui_select duplicate_booking_to_other_resource_selectbox"> |
| 124 |
<# |
| 125 |
_.each( data.ajx_booking_resources, function ( p_resource, p_resource_id, p_data ){ |
| 126 |
#><option value="{{p_resource.booking_type_id}}" style="<# |
| 127 |
if( undefined != p_resource.parent ) { |
| 128 |
if( '0' == p_resource.parent ) { |
| 129 |
#>font-weight:600;<# |
| 130 |
} else { |
| 131 |
#>font-size:0.95em;padding-left:20px;<# |
| 132 |
} |
| 133 |
} |
| 134 |
#>" |
| 135 |
><# |
| 136 |
if( undefined != p_resource.parent ) { |
| 137 |
if( '0' != p_resource.parent ) { |
| 138 |
#> <# |
| 139 |
} |
| 140 |
} |
| 141 |
#>{{p_resource.title}}</option><# |
| 142 |
}); |
| 143 |
#> |
| 144 |
</select> |
| 145 |
</script> |
| 146 |
<?php |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
// Loads hidden modal template. |
| 151 |
add_action( 'wpbc_hook_booking_template__hidden_templates', array( new WPBC_Action_Duplicate_Booking(), 'template_for_modal' ) ); |
| 152 |
|
| 153 |
// Loads hidden template. |
| 154 |
add_action( 'wpbc_hook_booking_template__hidden_templates', array( new WPBC_Action_Duplicate_Booking(), 'hidden_template' ) ); |
| 155 |
|