| @@ -1,0 +1,109 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking - Libraries | |
| 4 | + * @subpackage html.managetos | |
| 5 | + * @author E4J s.r.l. | |
| 6 | + * @copyright Copyright (C) 2022 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 | +$field = $displayData['field']; | |
| 15 | + | |
| 16 | +// render inspector to manage ToS fields | |
| 17 | +echo JHtml::fetch( | |
| 18 | + 'bootstrap.renderModal', | |
| 19 | + 'jmodal-tos-' . $field['id'], | |
| 20 | + array( | |
| 21 | + 'title' => JText::translate('VBMAINCUSTOMFTITLE'), | |
| 22 | + 'closeButton' => true, | |
| 23 | + 'keyboard' => false, | |
| 24 | + 'width' => 70, | |
| 25 | + 'height' => 80, | |
| 26 | + 'footer' => '<button type="button" class="btn btn-success" id="tos-save-' . $field['id'] . '">' . JText::translate('JAPPLY') . '</button>', | |
| 27 | + ), | |
| 28 | + JLayoutHelper::render('html.managetos.modal', $displayData) | |
| 29 | +); | |
| 30 | + | |
| 31 | +// render modal script | |
| 32 | +echo VikBooking::getVboApplication()->getJmodalScript(); | |
| 33 | + | |
| 34 | +JText::script('JLIB_APPLICATION_SAVE_SUCCESS'); | |
| 35 | +JText::script('FATAL_ERROR'); | |
| 36 | +?> | |
| 37 | + | |
| 38 | +<script> | |
| 39 | + (function($) { | |
| 40 | + 'use strict'; | |
| 41 | + | |
| 42 | + $(function() { | |
| 43 | + // get ToS table row | |
| 44 | + var tr = $('input[name="cid[]"][value="<?php echo (int) $field['id']; ?>"]').closest('tr'); | |
| 45 | + | |
| 46 | + // get column that contains the field name | |
| 47 | + var nameTD = tr.children().eq(1); | |
| 48 | + | |
| 49 | + // wrap name within a div | |
| 50 | + nameTD.html('<div style="float: left;"> ' + nameTD.html() + ' </div>'); | |
| 51 | + | |
| 52 | + // create edit button | |
| 53 | + var editButton = $('<a href="javascript:void(0)" style="float: right;"><i class="<?php echo VikBookingIcons::i('pen-square'); ?>" style="font-size: 18px;"></i></a>'); | |
| 54 | + | |
| 55 | + // register click event | |
| 56 | + editButton.on('click', function() { | |
| 57 | + // open modal | |
| 58 | + vboOpenJModal('tos-<?php echo (int) $field['id']; ?>'); | |
| 59 | + }); | |
| 60 | + | |
| 61 | + // append edit button | |
| 62 | + nameTD.append(editButton); | |
| 63 | + | |
| 64 | + // register save event | |
| 65 | + $('#tos-save-<?php echo (int) $field['id']; ?>').on('click', function() { | |
| 66 | + // get form containing the field value | |
| 67 | + var form = $('form#tos-form-<?php echo (int) $field['id']; ?>'); | |
| 68 | + | |
| 69 | + // make save request | |
| 70 | + $.ajax({ | |
| 71 | + // request end-point | |
| 72 | + url: 'admin-ajax.php?action=vikbooking&task=customf.savetosajax', | |
| 73 | + type: 'post', | |
| 74 | + // serialize form | |
| 75 | + data: form.serialize(), | |
| 76 | + }).done((data) => { | |
| 77 | + if (typeof data === 'string') { | |
| 78 | + data = JSON.parse(data); | |
| 79 | + } | |
| 80 | + | |
| 81 | + // update name within table column | |
| 82 | + nameTD.find('.name').html(data.name); | |
| 83 | + | |
| 84 | + // auto-close modal on successful save | |
| 85 | + $('#jmodal-tos-<?php echo (int) $field['id']; ?>').modal('toggle'); | |
| 86 | + | |
| 87 | + VBOToast.enqueue(new VBOToastMessage({ | |
| 88 | + title: Joomla.JText._('JLIB_APPLICATION_SAVE_SUCCESS'), | |
| 89 | + icon: '<?php echo VikBookingIcons::i('check-circle'); ?> vbo-chart-icon-positive', | |
| 90 | + delay: 3000, | |
| 91 | + action: () => { | |
| 92 | + VBOToast.dispose(true); | |
| 93 | + }, | |
| 94 | + })); | |
| 95 | + }).fail((error) => { | |
| 96 | + VBOToast.enqueue(new VBOToastMessage({ | |
| 97 | + title: Joomla.JText._('FATAL_ERROR'), | |
| 98 | + body: error.responseText || 'Unknown.', | |
| 99 | + icon: '<?php echo VikBookingIcons::i('times-circle'); ?> vbo-chart-icon-negative', | |
| 100 | + delay: 5000, | |
| 101 | + action: () => { | |
| 102 | + VBOToast.dispose(true); | |
| 103 | + }, | |
| 104 | + })); | |
| 105 | + }); | |
| 106 | + }); | |
| 107 | + }); | |
| 108 | + })(jQuery); | |
| 109 | +</script> | |