| @@ -11,19 +11,20 @@ | ||
| 11 | 11 | defined('ABSPATH') or die('No script kiddies please!'); |
| 12 | 12 | |
| 13 | 13 | $vbo_app = VikBooking::getVboApplication(); |
| 14 | 14 | |
| 15 | +JText::script('VBOCONFIGEDITTMPLFILE'); | |
| 16 | +JText::script('VBOSAVETMPLFILE'); | |
| 17 | +JText::script('VBANNULLA'); | |
| 18 | +JText::script('VBOPREVIEW'); | |
| 19 | + | |
| 15 | 20 | if (VBOPlatformDetection::isWordPress() && function_exists('wp_enqueue_code_editor')) { |
| 16 | 21 | /** |
| 17 | - * @wponly - cannot load iFrame with FancyBox, so we use the BS's Modal | |
| 18 | 22 | * WP >= 4.9.0 |
| 19 | 23 | */ |
| 20 | - wp_enqueue_code_editor(array('type' => 'php')); | |
| 24 | + wp_enqueue_code_editor(['type' => 'php']); | |
| 21 | 25 | } |
| 22 | 26 | |
| 23 | -echo $vbo_app->getJmodalScript($suffix = 'VboTplfiles', $hide_js = "VBOCore.emitEvent('vbo-dismiss-modal-tmplfile');"); | |
| 24 | -echo $vbo_app->getJmodalHtml('VboTplfiles', JText::translate('VBOCONFIGEDITTMPLFILE')); | |
| 25 | - | |
| 26 | 27 | $editor = JEditor::getInstance(JFactory::getApplication()->get('editor')); |
| 27 | 28 | $document = JFactory::getDocument(); |
| 28 | 29 | $document->addStyleSheet(VBO_SITE_URI.'resources/jquery.fancybox.css'); |
| 29 | 30 | $document->addStyleSheet(VBO_ADMIN_URI.'resources/js_upload/colorpicker.css'); |
| @@ -35,9 +36,9 @@ | ||
| 35 | 36 | $themesel = '<select name="theme">'; |
| 36 | 37 | $themesel .= '<option value="default">default</option>'; |
| 37 | 38 | $themes = glob(VBO_SITE_PATH.DS.'themes'.DS.'*'); |
| 38 | 39 | $acttheme = VikBooking::getTheme(); |
| 39 | -if (count($themes) > 0) { | |
| 40 | +if ($themes) { | |
| 40 | 41 | $strip = VBO_SITE_PATH.DS.'themes'.DS; |
| 41 | 42 | foreach ($themes as $th) { |
| 42 | 43 | if (is_dir($th)) { |
| 43 | 44 | $tname = str_replace($strip, '', $th); |
| @@ -47,9 +48,9 @@ | ||
| 47 | 48 | } |
| 48 | 49 | } |
| 49 | 50 | } |
| 50 | 51 | $themesel .= '</select>'; |
| 51 | -$firstwday = VikBooking::getFirstWeekDay(true); | |
| 52 | +$firstwday = VikBooking::getFirstWeekDay(); | |
| 52 | 53 | ?> |
| 53 | 54 | <div class="vbo-config-maintab-left"> |
| 54 | 55 | <fieldset class="adminform"> |
| 55 | 56 | <div class="vbo-params-wrap"> |
| @@ -373,18 +374,145 @@ | ||
| 373 | 374 | } |
| 374 | 375 | |
| 375 | 376 | jQuery(function() { |
| 376 | 377 | |
| 377 | - jQuery(".vbo-edit-tmpl").click(function() { | |
| 378 | - var vbo_tmpl_path = jQuery(this).attr("data-tmpl-path"); | |
| 379 | - var vbo_prew_path = jQuery(this).attr("data-prew-path"); | |
| 378 | + jQuery('.vbo-edit-tmpl').click(function() { | |
| 379 | + let vbo_tmpl_path = jQuery(this).attr('data-tmpl-path'); | |
| 380 | + let vbo_prew_path = jQuery(this).attr('data-prew-path'); | |
| 380 | 381 | if (!vbo_tmpl_path && !vbo_prew_path) { |
| 381 | 382 | return; |
| 382 | 383 | } |
| 383 | - var basetask = !vbo_tmpl_path ? 'tmplfileprew' : 'edittmplfile'; | |
| 384 | - var basepath = !vbo_tmpl_path ? vbo_prew_path : vbo_tmpl_path; | |
| 385 | - // we use the BS's Modal to open the template files editing page | |
| 386 | - vboOpenJModalVboTplfiles('VboTplfiles', "index.php?option=com_vikbooking&task=" + basetask + "&path=" + basepath + "&tmpl=component"); | |
| 384 | + let basetask = !vbo_tmpl_path ? 'tmplfileprew' : 'edittmplfile'; | |
| 385 | + let basepath = !vbo_tmpl_path ? vbo_prew_path : vbo_tmpl_path; | |
| 386 | + let base_ajax = '<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=edittmplfile'); ?>'; | |
| 387 | + let ajax_uri = base_ajax.replace('edittmplfile', basetask); | |
| 388 | + | |
| 389 | + // define the modal cancel button | |
| 390 | + let cancel_btn = jQuery('<button></button>') | |
| 391 | + .attr('type', 'button') | |
| 392 | + .addClass('btn') | |
| 393 | + .text(Joomla.JText._('VBANNULLA')) | |
| 394 | + .on('click', () => { | |
| 395 | + VBOCore.emitEvent('vbo-edit-tmplfile-dismiss'); | |
| 396 | + }); | |
| 397 | + | |
| 398 | + let apply_btn = jQuery('<button></button>') | |
| 399 | + .attr('type', 'button') | |
| 400 | + .addClass('btn btn-success') | |
| 401 | + .text(Joomla.JText._('VBOSAVETMPLFILE')) | |
| 402 | + .on('click', () => { | |
| 403 | + // start loading | |
| 404 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 405 | + | |
| 406 | + /** | |
| 407 | + * On some CMSs, the real textarea may not update with the new codemirror content | |
| 408 | + * and so we force the update of the textarea before submitting the form. | |
| 409 | + */ | |
| 410 | + try { | |
| 411 | + let is_wp = <?php echo VBOPlatformDetection::isWordPress() ? 'true' : 'false'; ?>; | |
| 412 | + if (is_wp) { | |
| 413 | + Joomla.editors.instances['vik_editor_cont'].element.codemirror.save(); | |
| 414 | + } else { | |
| 415 | + Joomla.editors.instances['vik_editor_cont'].save(); | |
| 416 | + } | |
| 417 | + } catch (err) { | |
| 418 | + console.error(err); | |
| 419 | + } | |
| 420 | + | |
| 421 | + // get the content from the editor | |
| 422 | + let editor_element = document.querySelector('[name="cont"]'); | |
| 423 | + let editor_content = editor_element ? editor_element.value : ''; | |
| 424 | + | |
| 425 | + if (!editor_content) { | |
| 426 | + alert('No source code found'); | |
| 427 | + return false; | |
| 428 | + } | |
| 429 | + | |
| 430 | + VBOCore.doAjax( | |
| 431 | + "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=savetmplfile'); ?>", | |
| 432 | + { | |
| 433 | + path: basepath, | |
| 434 | + ajax: 1, | |
| 435 | + cont: editor_content, | |
| 436 | + }, | |
| 437 | + (response) => { | |
| 438 | + // stop loading | |
| 439 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 440 | + | |
| 441 | + let message = 'Success!'; | |
| 442 | + try { | |
| 443 | + let data = typeof response === 'string' ? JSON.parse(response) : response; | |
| 444 | + message = data.message; | |
| 445 | + } catch(e) { | |
| 446 | + // do nothing | |
| 447 | + } | |
| 448 | + | |
| 449 | + VBOToast.enqueue(new VBOToastMessage({ | |
| 450 | + body: message, | |
| 451 | + icon: '<?php echo VikBookingIcons::i('check-circle'); ?>', | |
| 452 | + status: VBOToast.SUCCESS_STATUS, | |
| 453 | + action: () => { | |
| 454 | + VBOToast.dispose(true); | |
| 455 | + }, | |
| 456 | + })); | |
| 457 | + }, | |
| 458 | + (error) => { | |
| 459 | + // stop loading | |
| 460 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 461 | + alert(error.responseText); | |
| 462 | + } | |
| 463 | + ); | |
| 464 | + }); | |
| 465 | + | |
| 466 | + let modal_body = VBOCore.displayModal({ | |
| 467 | + extra_class: 'vbo-modal-large' + (!vbo_tmpl_path ? ' vbo-modal-nofooter' : ''), | |
| 468 | + lock_scroll: true, | |
| 469 | + // prepend to body to let the toast br visible as z-index | |
| 470 | + body_prepend: true, | |
| 471 | + title: (vbo_tmpl_path ? Joomla.JText._('VBOCONFIGEDITTMPLFILE') : Joomla.JText._('VBOPREVIEW')), | |
| 472 | + dismiss_event: 'vbo-edit-tmplfile-dismiss', | |
| 473 | + loading_event: 'vbo-edit-tmplfile-loading', | |
| 474 | + footer_left: (vbo_tmpl_path ? cancel_btn : null), | |
| 475 | + footer_right: (vbo_tmpl_path ? apply_btn : null), | |
| 476 | + onDismiss: () => { | |
| 477 | + VBOCore.emitEvent('vbo-dismiss-modal-tmplfile'); | |
| 478 | + }, | |
| 479 | + }); | |
| 480 | + | |
| 481 | + // start loading | |
| 482 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 483 | + | |
| 484 | + // make the AJAX request to obtain the modal body | |
| 485 | + VBOCore.doAjax( | |
| 486 | + ajax_uri, | |
| 487 | + { | |
| 488 | + path: basepath, | |
| 489 | + ajax: 1, | |
| 490 | + tmpl: 'component', | |
| 491 | + }, | |
| 492 | + (response) => { | |
| 493 | + // stop loading | |
| 494 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 495 | + | |
| 496 | + let html = response; | |
| 497 | + | |
| 498 | + try { | |
| 499 | + html = typeof response === 'string' ? JSON.parse(response) : response; | |
| 500 | + html = html[0]; | |
| 501 | + } catch(e) { | |
| 502 | + // do nothing | |
| 503 | + } | |
| 504 | + | |
| 505 | + modal_body.append(html); | |
| 506 | + }, | |
| 507 | + (error) => { | |
| 508 | + // stop loading | |
| 509 | + VBOCore.emitEvent('vbo-edit-tmplfile-loading'); | |
| 510 | + // log and display error | |
| 511 | + console.error(error); | |
| 512 | + alert(error.responseText); | |
| 513 | + } | |
| 514 | + ); | |
| 387 | 515 | }); |
| 388 | 516 | |
| 389 | 517 | jQuery(".vbo-colortag-add").click(function() { |
| 390 | 518 | jQuery("#vbo-colortag-lasttr").before( |