diff --git a/src/com_tjnotifications/admin/controllers/notification.php b/src/com_tjnotifications/admin/controllers/notification.php index edbe6bac..3fc085e1 100644 --- a/src/com_tjnotifications/admin/controllers/notification.php +++ b/src/com_tjnotifications/admin/controllers/notification.php @@ -8,6 +8,8 @@ // No direct access to this file defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; /** * Notification controller class. @@ -47,8 +49,7 @@ public function editSave() } else { - $link = JRoute::_( - 'index.php?option=com_tjnotifications&view=notification&layout=edit&id=' . $recordId , false); + $link = JRoute::_('index.php?option=com_tjnotifications&view=notification&layout=edit&id=' . $recordId, false); } $this->setRedirect($link, $msg); @@ -220,4 +221,23 @@ public function add($key = null, $urlVar = null) $this->setRedirect($link); } + + /** + * Function to print sample data for email template + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function getSampleData() + { + $input = Factory::getApplication()->input; + $id = $input->get('id'); + + $notificationsModel = $this->getModel('notification'); + $data = $notificationsModel->getSampleBodyData($id); + + echo $data; + jexit(); + } } diff --git a/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini b/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini index 141f6b92..a4c99d99 100644 --- a/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini +++ b/src/com_tjnotifications/admin/language/en-GB.com_tjnotifications.ini @@ -93,3 +93,9 @@ COM_TJNOTIFICATIONS_CORE_TEMPLATE_VALUE="No" COM_TJNOTIFICATIONS_TAGS_DESC="Enter the tag given on left in to the editor these tag names will be replaced by description given in notification template" COM_TJNOTIFICATIONS_REPLACEMENT_TAGS="Replacement Tag" COM_TJNOTIFICATIONS_REPLACEMENT_TAGS_DESC="Description" + +;preview email +COM_TJNOTIFICATIONS_TEMPLATE_PREVIEW="Preview" +COM_TJNOTIFICATIONS_TEMPLATE_MODAL_PREVIEW_TITLE="Preview" +COM_TJNOTIFICATIONS_TEMPLATE_MODAL_HEADER_INFO="If latest changes are not visible then try after saving the template." +COM_TJNOTIFICATIONS_TEMPLATE_MODAL_CLOSE="Close" diff --git a/src/com_tjnotifications/admin/models/notification.php b/src/com_tjnotifications/admin/models/notification.php index 785cbae0..c31468d7 100644 --- a/src/com_tjnotifications/admin/models/notification.php +++ b/src/com_tjnotifications/admin/models/notification.php @@ -9,6 +9,8 @@ defined('_JEXEC') or die; jimport('joomla.application.component.model'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/models'); +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; /** * notification model. @@ -296,4 +298,32 @@ public function updateReplacementTags($data) $result = $db->execute(); } + + /** + * Method to get Sample data for email template. + * + * @return string $body + * + * @since __DEPLOY_VERSION__ + */ + public static function getSampleBodyData($id) + { + Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/tables'); + $storeTable = Table::getInstance('Notification', 'TjnotificationTable'); + $storeTable->load($id); + + $bodyTemplate = $storeTable->email_body; + + $replacementsdata = $storeTable->replacement_tags; + $replacements = json_decode($replacementsdata); + + foreach ($replacements as $value) + { + $replaceWith = !empty($value->sampledata) ? $value->sampledata : $value->name; + + $bodyTemplate = str_replace($value->name, $replaceWith, $bodyTemplate); + } + + return $bodyTemplate; + } } diff --git a/src/com_tjnotifications/admin/views/notification/tmpl/edit.php b/src/com_tjnotifications/admin/views/notification/tmpl/edit.php index e7b822f6..dce0484e 100644 --- a/src/com_tjnotifications/admin/views/notification/tmpl/edit.php +++ b/src/com_tjnotifications/admin/views/notification/tmpl/edit.php @@ -2,41 +2,18 @@ // No direct access defined('_JEXEC') or die; -JHtml::_('formbehavior.chosen','select'); -JHtml::_('behavior.formvalidator'); -$today= gmdate('Y-m-d'); -?> - +HTMLHelper::_('formbehavior.chosen','select'); +HTMLHelper::_('behavior.formvalidator'); +$today= gmdate('Y-m-d'); + +$options = array("relative" => true); +HTMLHelper::_('script', 'com_tjnotifications/template.js', $options); +?>
@@ -93,6 +70,7 @@
label; ?>
input ; ?>
+
@@ -109,7 +87,7 @@ tags as $tags): ?> - name . '}'); ?> + name . '}'); ?> description); ?> @@ -128,4 +106,36 @@ + + + +
+ diff --git a/src/com_tjnotifications/admin/views/notification/view.html.php b/src/com_tjnotifications/admin/views/notification/view.html.php index dff5fa7e..8b008b68 100644 --- a/src/com_tjnotifications/admin/views/notification/view.html.php +++ b/src/com_tjnotifications/admin/views/notification/view.html.php @@ -83,6 +83,10 @@ protected function addToolBar() JToolBarHelper::apply('notification.editSave', 'JTOOLBAR_APPLY'); JToolBarHelper::save('notification.saveClose', 'JTOOLBAR_SAVE'); JToolBarHelper::custom('notification.saveNew', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); + + // Add preview toolbar + JToolbarHelper::modal('templatePreview', 'icon-eye', 'COM_TJNOTIFICATIONS_TEMPLATE_PREVIEW'); + JToolBarHelper::cancel('notification.cancel', 'JTOOLBAR_CANCEL'); } diff --git a/src/com_tjnotifications/media/js/template.js b/src/com_tjnotifications/media/js/template.js new file mode 100644 index 00000000..ee8a51ab --- /dev/null +++ b/src/com_tjnotifications/media/js/template.js @@ -0,0 +1,55 @@ +/** + * @package TJNotifications + * @subpackage com_tjnotifications + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +var template = { + previewTemplate: function() { + var e = new URL(window.location.href).searchParams.get("id"); + jQuery(document).on("click", 'button[data-target="#templatePreview"]', function() { + jQuery.ajax({ + url: Joomla.getOptions("system.paths").base + "/index.php?option=com_tjnotifications&task=notification.getSampleData&id=" + e, + type: "GET", + data: { + data: jQuery("#jform_email_body").serialize() + }, + success: function(e) { + jQuery("#previewTempl").empty(); + jQuery("#previewTempl").append(e); + }, + error: function(e, t, a) {} + }) + }) + }, + + init: function() { + jQuery("fieldset").click(function() + { + status=this.id+'0'; + statusChange=this.id+'1'; + var check=(jQuery("#"+status).attr("checked")); + + if(check=="checked") + { + var body=(this.id).replace("status", "body_ifr"); + var bodyData=(jQuery("#"+body).contents().find("body").find("p").html()); + if(bodyData=='
') + { + alert('Please fill the data'); + jQuery('#'+this.id).find('label[for='+statusChange+']').attr('class','btn active btn-danger'); + jQuery('#'+this.id).find('label[for='+status+']').attr('class','btn'); + return false; + } + else + { + jQuery('#'+this.id).find('label[for='+status+']').attr('class','btn active btn-success'); + jQuery('#'+this.id).find('label[for='+statusChange+']').attr('class','btn'); + } + } + }) + } +}; diff --git a/src/com_tjnotifications/media/js/template.min.js b/src/com_tjnotifications/media/js/template.min.js new file mode 100644 index 00000000..2e733879 --- /dev/null +++ b/src/com_tjnotifications/media/js/template.min.js @@ -0,0 +1,9 @@ +/** + * @package TJNotifications + * @subpackage com_tjnotifications + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ +var template={previewTemplate:function(){var t=new URL(window.location.href).searchParams.get("id");jQuery(document).on("click",'button[data-target="#templatePreview"]',function(){jQuery.ajax({url:Joomla.getOptions("system.paths").base+"/index.php?option=com_tjnotifications&task=notification.getSampleData&id="+t,type:"GET",data:{data:jQuery("#jform_email_body").serialize()},success:function(t){jQuery("#previewTempl").empty(),jQuery("#previewTempl").append(t)},error:function(t,e,a){}})})},init:function(){jQuery("fieldset").click(function(){if(status=this.id+"0",statusChange=this.id+"1","checked"==jQuery("#"+status).attr("checked")){var t=this.id.replace("status","body_ifr");if('
'==jQuery("#"+t).contents().find("body").find("p").html())return alert("Please fill the data"),jQuery("#"+this.id).find("label[for="+statusChange+"]").attr("class","btn active btn-danger"),jQuery("#"+this.id).find("label[for="+status+"]").attr("class","btn"),!1;jQuery("#"+this.id).find("label[for="+status+"]").attr("class","btn active btn-success"),jQuery("#"+this.id).find("label[for="+statusChange+"]").attr("class","btn")}})}}; diff --git a/src/com_tjnotifications/tjnotifications.xml b/src/com_tjnotifications/tjnotifications.xml index b8cdeab9..5eaeb7a8 100644 --- a/src/com_tjnotifications/tjnotifications.xml +++ b/src/com_tjnotifications/tjnotifications.xml @@ -18,6 +18,10 @@ sql/updates/mysql + + + js + sql/uninstall.mysql.utf8.sql