Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1d69242
Preview email facility in tjnotification #65
punambaravkar Nov 25, 2019
66c4db3
Preview email facility in tjnotification #65
punambaravkar Nov 25, 2019
f96c719
Preview email facility in tjnotification #65 #67
punambaravkar Dec 3, 2019
b3e911f
Merge remote-tracking branch 'upstream/master' into email
punambaravkar Dec 3, 2019
591f884
Preview email facility in tjnotification #65 #67
punambaravkar Dec 11, 2019
524466c
Preview email facility in tjnotification #65 #67
punambaravkar Dec 11, 2019
dfd12dd
Preview email facility in tjnotification
punambaravkar Dec 12, 2019
ea3ef4e
Preview email facility in tjnotification
punambaravkar Dec 12, 2019
70444ad
Preview email facility in tjnotification
punambaravkar Dec 12, 2019
3948c89
Preview email facility in tjnotification
punambaravkar Dec 23, 2019
639dd38
Preview email facility in tjnotification
punambaravkar Dec 23, 2019
665d9a5
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
82ae957
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
b94af38
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
e6f88cf
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
a8aeb2f
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
e0707e6
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
ba9017e
Preview email facility in tjnotification
punambaravkar Dec 24, 2019
255dc33
Task #154509 chore: Adding sample data for TJ-Notification template
punambaravkar Dec 24, 2019
06bc4f0
Task #154509 chore: Adding sample data for TJ-Notification template
punambaravkar Dec 24, 2019
248dec6
Task #154509 chore: Adding sample data for TJ-Notification template
punambaravkar Dec 25, 2019
171a111
Preview email facility in tjnotification
punambaravkar Dec 25, 2019
13b9bec
Preview email facility in tjnotification
punambaravkar Dec 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/com_tjnotifications/admin/controllers/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,17 @@ public function add($key = null, $urlVar = null)

$this->setRedirect($link);
}

/**
* Function to print sample data for email template
*
* @return void
*/
public function getSampleData()
{
$data = Tjnotifications::getSampleBodyData();

echo $data;
jexit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."

47 changes: 44 additions & 3 deletions src/com_tjnotifications/admin/views/notification/tmpl/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

// No direct access
defined('_JEXEC') or die;
JHtml::_('formbehavior.chosen','select');
JHtml::_('behavior.formvalidator');
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;

HTMLHelper::_('formbehavior.chosen','select');
HTMLHelper::_('behavior.formvalidator');

$today= gmdate('Y-m-d');

$options['relative'] = true;

HTMLHelper::_('script', 'com_tjnotifications/template.min.js', $options);
?>
<script>
jQuery(document).ready(function()
Expand Down Expand Up @@ -93,6 +101,7 @@
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input ; ?></div>

</div>
<?php endforeach; ?>
</div>
Expand All @@ -109,7 +118,7 @@
<tbody>
<?php foreach ($this->tags as $tags): ?>
<tr>
<td scope="row"><?php echo('{' . $tags->name . '}'); ?></td>
<td scope="row"><?php echo ('{' . $tags->name . '}'); ?></td>
<td><?php echo($tags->description); ?></td>
</tr>
<?php endforeach; ?>
Expand All @@ -128,4 +137,36 @@
</div>
<input type="hidden" name="task" value="notification.edit" />
<?php echo JHtml::_('form.token'); ?>

<!-- Modal -->
<style>
.modal-body {
overflow-y: auto;
}
</style>
<div id="templatePreview" class="modal fade" role="dialog">
<div class="modal-dialog">
<button type="button" class="close" data-dismiss="modal" style="width: 40px;opacity: 0.7;">&times;</button>
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><?php echo Text::_('COM_TJNOTIFICATIONS_TEMPLATE_MODAL_PREVIEW_TITLE'); ?></h4>
<p class="alert alert-info hide" id="show-info"><?php echo Text::_('COM_TJNOTIFICATIONS_TEMPLATE_MODAL_HEADER_INFO'); ?></p>
</div>
<div class="modal-body" id="previewTempl">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>
</div>
</form>
<script type="text/javascript">
jQuery(document).ready(function () {

template.previewTemplate();

});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
40 changes: 40 additions & 0 deletions src/com_tjnotifications/media/js/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <extensions@techjoomla.com>
* @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 url = new URL(window.location.href);
var id= url.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=" + id,
type: 'GET',
success: function(data) {

jQuery("#previewTempl").append(data);
},
error: function(xhr, ajaxOptions, thrownError) {}
})

});
jQuery('#templatePreview').on('hidden.bs.modal', function () {

if (typeof tinyMCE != "undefined")
{
tinyMCE.execCommand('mceToggleEditor', false, 'jform_body');
}

jQuery('#previewTempl').empty();
});
}
}
9 changes: 9 additions & 0 deletions src/com_tjnotifications/media/js/template.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @package TJNotifications
* @subpackage com_tjnotifications
*
* @author Techjoomla <extensions@techjoomla.com>
* @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",success:function(e){jQuery("#previewTempl").append(e)},error:function(e,t,n){}})}),jQuery("#templatePreview").on("hidden.bs.modal",function(){"undefined"!=typeof tinyMCE&&tinyMCE.execCommand("mceToggleEditor",!1,"jform_body"),jQuery("#previewTempl").empty()})}};
4 changes: 4 additions & 0 deletions src/com_tjnotifications/tjnotifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<!-- Media files -->
<media destination="com_tjnotifications" folder="media">
<folder>js</folder>
</media>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
Expand Down
51 changes: 51 additions & 0 deletions src/techjoomla/tjnotifications/tjnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/models', 'NotificationsModel');
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjnotifications/models', 'NotificationsModel');

use Joomla\CMS\Table\Table;
use Joomla\CMS\Factory;

/**
* Tjnotifications
*
Expand Down Expand Up @@ -240,4 +243,52 @@ public static function getTags($data_template)
// $matches[0]= stores tag like {doner.name} and $matches[1] stores doner.name. Explode it and make it doner->name
return $matches;
}

/**
* Method to get Sample data for email template.
*
* @return string $body
*
* @since 1.0
*/
public static function getSampleBodyData()
{
$input = Factory::getApplication()->input;
$id = $input->get('id');

Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/tables');
$storeTable = Table::getInstance('Notification', 'TjnotificationTable');
$storeTable->load($id);

$bodyTemplate = $storeTable->email_body;

$matches = self::getTags($bodyTemplate);
$replacamentTags = $matches[1];

$index = 0;
$replacementsdata = $storeTable->replacement_tags;
$replacements = json_decode($replacementsdata);

foreach ($replacamentTags as $ind => $replacamentTag)
{
$replaceWith = '';
$replacamentTagName = '{' . $replacamentTag . '}';

foreach ($replacements as $value)
{
if ($replacamentTagName == $value->name)
{
$replaceWith = !empty($value->sampledata) ? $value->sampledata : " ";
}

if (!empty($replaceWith))
{
$bodyTemplate = str_replace($replacamentTagName, $replaceWith, $bodyTemplate);
break;
}
}
}

return $bodyTemplate;
}
}