Skip to content

Commit

Permalink
Preview email facility in tjnotification techjoomla#65
Browse files Browse the repository at this point in the history
  • Loading branch information
punambaravkar committed Nov 25, 2019
2 parents b634bbf + 78dbd82 commit b9946a0
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 39 deletions.
64 changes: 64 additions & 0 deletions src/com_tjnotifications/admin/models/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,68 @@ public function getKeys($client)

return $existingKeys;
}

/**
* Method to get tag replacement count
*
* @param string $key Template key.
* @param string $client client.
*
* @return integer replacement tags count
*
* @since 1.0.4
*/
public function getReplacementTagsCount($key, $client)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('replacement_tags'));
$query->from($db->quoteName('#__tj_notification_templates'));
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
$query->where($db->quoteName('key') . ' = ' . $db->quote($key));
$db->setQuery($query);
$replacementTags = $db->loadResult();

return count(json_decode($replacementTags));
}

/**
* Method to replace tags if they are changed
*
* @param array $data template data
*
* @return void
*
* @since 1.0.4
*/
public function updateReplacementTags($data)
{
if (!empty($data['replacement_tags']))
{
$replacementTags = json_encode($data['replacement_tags']);
}
else
{
return;
}

$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Fields to update.
$fields = array(
$db->quoteName('replacement_tags') . ' = ' . $db->quote($replacementTags)
);

// Conditions for which records should be updated.
$conditions = array(
$db->quoteName('client') . ' = ' . $db->quote($data['client']),
$db->quoteName('key') . ' = ' . $db->quote($data['key'])
);

$query->update($db->quoteName('#__tj_notification_templates'))->set($fields)->where($conditions);
$db->setQuery($query);

$result = $db->execute();
}
}
37 changes: 4 additions & 33 deletions src/com_tjnotifications/admin/sql/install.mysql.utf8.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_notification_providers` (
`provider` varchar(100) NOT NULL,
`state` int(1) NOT NULL,
primary key(provider)
)
AUTO_INCREMENT =0
DEFAULT CHARSET =utf8;

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__tj_notification_templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -35,41 +32,15 @@ CREATE TABLE IF NOT EXISTS `#__tj_notification_templates` (
UNIQUE KEY `client_2` (`client`,`key`),
KEY `client` (`client`),
KEY `key` (`key`)
)
DEFAULT CHARSET=utf8
AUTO_INCREMENT=0 ;
) AUTO_INCREMENT=1 ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__tj_notification_user_exclusions` (
`user_id` int(11) NOT NULL,
`client` varchar(100) NOT NULL,
`key` varchar(100) NOT NULL,
`provider` varchar(100) NOT NULL,
KEY `client1` (`client`,`provider`,`key`),
KEY `client1` (`client`(100),`provider`(50),`key`(100)),
KEY `key` (`key`),
KEY `provider` (`provider`),
CONSTRAINT `#__tj_notification_user_exclusions_ibfk_1` FOREIGN KEY (`provider`) REFERENCES `#__tj_notification_providers` (`provider`)
)
DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__tj_notification_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key` varchar(100) NOT NULL,
`client` varchar(100) NOT NULL,
`provider` varchar(50) NOT NULL,
`subject` varchar(250) NOT NULL,
`title` varchar(100) NOT NULL,
`body` text NOT NULL,
`from` varchar(500) NOT NULL,
`to` text NOT NULL,
`cc` text NOT NULL,
`bcc` text NOT NULL,
`date` datetime NOT NULL,
`state` tinyint(2) NOT NULL,
`params` text NOT NULL,
`priority`int(11) NOT NULL,
`message` text NOT NULL,
`category` text NOT NULL,
PRIMARY KEY (`id`)
)
DEFAULT CHARSET=utf8
AUTO_INCREMENT=0 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
8 changes: 8 additions & 0 deletions src/com_tjnotifications/admin/sql/updates/mysql/1.0.5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

--
-- Change table ENGINE;
--

ALTER TABLE `#__tj_notification_providers` ENGINE = InnoDB;
ALTER TABLE `#__tj_notification_templates` ENGINE = InnoDB;
ALTER TABLE `#__tj_notification_user_exclusions` ENGINE = InnoDB;
3 changes: 3 additions & 0 deletions src/com_tjnotifications/admin/sql/updates/mysql/1.0.6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
----Change table Key;

ALTER TABLE `#__tj_notification_user_exclusions` CHANGE KEY `client1` (`client`(100),`provider`(50),`key`(100));
37 changes: 37 additions & 0 deletions src/com_tjnotifications/admin/views/notification/tmpl/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
defined('_JEXEC') or die;
JHtml::_('formbehavior.chosen','select');
JHtml::_('behavior.formvalidator');
use Joomla\CMS\Language\Text;

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

$options['relative'] = true;

JHtml::_('script', 'com_tjnotifications/template.js', $options);
?>
<script>
jQuery(document).ready(function()
Expand Down Expand Up @@ -128,4 +134,35 @@
</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_CERTIFICATE_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
47 changes: 47 additions & 0 deletions src/com_tjnotifications/media/js/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @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 () {

jQuery(document).on('click', 'button[data-target="#templatePreview"]', function () {

jQuery('#show-info').hide();

if (typeof tinyMCE != "undefined")
{
tinyMCE.execCommand('mceToggleEditor', false, 'jform_email_body');
}
else if (typeof CodeMirror != "undefined")
{
var editor = document.querySelector('.CodeMirror').CodeMirror;
jQuery('#jform_email_body').html(editor.getValue());
}
else
{
jQuery('#show-info').show();
}

jQuery('#previewTempl').empty();
jQuery('<style>').html(jQuery('#jform_template_css').val()).appendTo('#previewTempl');
jQuery('<div>').html(jQuery('#jform_email_body').val()).appendTo('#previewTempl');
});

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

if (typeof tinyMCE != "undefined")
{
tinyMCE.execCommand('mceToggleEditor', false, 'jform_email_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(){jQuery(document).on("click",'button[data-target="#templatePreview"]',function(){if(jQuery("#show-info").hide(),"undefined"!=typeof tinyMCE)tinyMCE.execCommand("mceToggleEditor",!1,"jform_email_body");else if("undefined"!=typeof CodeMirror){var e=document.querySelector(".CodeMirror").CodeMirror;jQuery("#jform_email_body").html(e.getValue())}else jQuery("#show-info").show();jQuery("#previewTempl").empty(),jQuery("<style>").html(jQuery("#jform_template_css").val()).appendTo("#previewTempl"),jQuery("<div>").html(jQuery("#jform_email_body").val()).appendTo("#previewTempl")}),jQuery("#templatePreview").on("hidden.bs.modal",function(){"undefined"!=typeof tinyMCE&&tinyMCE.execCommand("mceToggleEditor",!1,"jform_email_body"),jQuery("#previewTempl").empty()})}};
9 changes: 7 additions & 2 deletions src/com_tjnotifications/tjnotifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
<authorUrl>https://techjoomla.com</authorUrl>
<copyright>Copyright (C) 2016 - 2019 Techjoomla. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<creationDate>7th Feb 2019</creationDate>
<version>1.0.3</version>
<creationDate>13th Nov 2019</creationDate>
<version>1.0.6</version>
<install>
<sql>
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
</sql>
</install>
<update>
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/actionlog/tjnotification/tjnotification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<extension version="3.9" type="plugin" group="actionlog" method="upgrade">
<name>plg_actionlog_tjnotification</name>
<author>Techjoomla</author>
<creationDate>7th Feb 2019</creationDate>
<creationDate>13th Nov 2019</creationDate>
<copyright>Copyright (C) 2016 - 2019 Techjoomla. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>extensions@techjoomla.com</authorEmail>
<authorUrl>https://techjoomla.com</authorUrl>
<version>1.0.3</version>
<version>1.0.6</version>
<description>PLG_ACTIONLOG_TJNOTIFICATION_XML_DESCRIPTION</description>
<files>
<filename plugin="tjnotification">tjnotification.php</filename>
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/privacy/tjnotification/tjnotification.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.9" type="plugin" group="privacy" method="upgrade">
<name>plg_privacy_tjnotification</name>
<version>1.0.3</version>
<creationDate>7th Feb 2019</creationDate>
<version>1.0.6</version>
<creationDate>13th Nov 2019</creationDate>
<author>Techjoomla</author>
<authorEmail>extensions@techjoomla.com</authorEmail>
<authorUrl>https://techjoomla.com</authorUrl>
Expand Down

0 comments on commit b9946a0

Please sign in to comment.