| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking - Libraries |
| 4 |
* @subpackage html.rss |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
// prepare modal to display opt-in |
| 15 |
echo JHtml::fetch( |
| 16 |
'bootstrap.renderModal', |
| 17 |
'jmodal-rss-optin', |
| 18 |
array( |
| 19 |
'title' => '<i class="' . VikBookingIcons::i('rss-square') . '"></i> ' . __('Vik Booking - RSS Opt-in', 'vikbooking'), |
| 20 |
'closeButton' => false, |
| 21 |
'keyboard' => false, |
| 22 |
'top' => true, |
| 23 |
'width' => 70, |
| 24 |
'height' => 80, |
| 25 |
'footer' => '<button type="button" class="btn btn-success" id="rss-optin-save">' . __('Save') . '</button>', |
| 26 |
), |
| 27 |
$this->sublayout('modal') |
| 28 |
); |
| 29 |
|
| 30 |
?> |
| 31 |
|
| 32 |
<script> |
| 33 |
|
| 34 |
jQuery(function() { |
| 35 |
var aborted = false; |
| 36 |
|
| 37 |
if (typeof localStorage !== 'undefined') { |
| 38 |
aborted = localStorage.getItem('vikbooking.rss.aborted') ? true : false; |
| 39 |
} |
| 40 |
|
| 41 |
if (!aborted) { |
| 42 |
// open modal with a short delay |
| 43 |
setTimeout(function() { |
| 44 |
wpOpenJModal('rss-optin'); |
| 45 |
}, 1500); |
| 46 |
} |
| 47 |
|
| 48 |
jQuery('#rss-optin-save').on('click', function() { |
| 49 |
if (jQuery(this).prop('disabled')) { |
| 50 |
// already submitted |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
jQuery(this).prop('disabled', true); |
| 55 |
|
| 56 |
// check opt-in status |
| 57 |
var status = jQuery('input[name="rss_optin_status"]').is(':checked') ? 1 : 0; |
| 58 |
|
| 59 |
// make AJAX request |
| 60 |
doAjax( |
| 61 |
'admin-ajax.php?action=vikbooking&task=rss.optin', |
| 62 |
{ |
| 63 |
status: status, |
| 64 |
}, |
| 65 |
function(resp) { |
| 66 |
// auto-dismiss on save |
| 67 |
wpCloseJModal('rss-optin'); |
| 68 |
}, |
| 69 |
function(error) { |
| 70 |
if (!error.responseText) { |
| 71 |
// use default connection lost error |
| 72 |
error.responseText = Joomla.JText._('CONNECTION_LOST'); |
| 73 |
} |
| 74 |
|
| 75 |
// alert error message |
| 76 |
alert(error.responseText); |
| 77 |
|
| 78 |
// avoid to spam the dialog again and again at every page load |
| 79 |
if (typeof localStorage !== 'undefined') { |
| 80 |
localStorage.setItem('vikbooking.rss.aborted', 1); |
| 81 |
} |
| 82 |
|
| 83 |
// auto-dismiss on failure |
| 84 |
wpCloseJModal('rss-optin'); |
| 85 |
} |
| 86 |
); |
| 87 |
}); |
| 88 |
}); |
| 89 |
|
| 90 |
</script> |
| 91 |
|