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); +?>