Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,16 @@ COM_TJNOTIFICATIONS_SETTINGS_WEBHOOK_URL_LABEL="Webhook URL"
COM_TJNOTIFICATIONS_SETTINGS_WEBHOOK_URL_DESC="Enter URL for your Webhook notification"
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_CUSTOM_WEBHOOK_URLS="Please add custom webhook URL or use global webhook URL"
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_GLOBAL_WEBHOOK_URLS="Please add webhook URLs in the global config or add custom webhook URL."

; Error messages
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_WEBHOOK_BODY_REQUIRED="Webhook body is required when webhook is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_WEBHOOK_LANGUAGE_REQUIRED="Language selection is required when webhook is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_EMAIL_BODY_REQUIRED="Email body is required when email is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_EMAIL_SUBJECT_REQUIRED="Email subject is required when email is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_EMAIL_LANGUAGE_REQUIRED="Language selection is required when email is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_SMS_BODY_REQUIRED="SMS body is required when SMS is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_SMS_LANGUAGE_REQUIRED="Language selection is required when SMS is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_PUSH_BODY_REQUIRED="Push body is required when push is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_PUSH_LANGUAGE_REQUIRED="Language selection is required when push is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_WHATSAPP_BODY_REQUIRED="WhatsApp body is required when WhatsApp is enabled."
COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_WHATSAPP_LANGUAGE_REQUIRED="Language selection is required when WhatsApp is enabled."
49 changes: 23 additions & 26 deletions src/com_tjnotifications/admin/models/forms/emailfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>

<field
name="subject"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_EMAIL_SUBJECT_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_EMAIL_SUBJECT_DESC"
required="true"
/>
<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
>
<option value="*">JALL</option>
</field>

<field
name="body"
type="editor"
label="COM_TJNOTIFICATIONS_FIELD_EMAIL_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_EMAIL_BODY_DESC"
buttons="true"
filter="JComponentHelper::filterText"
height="150px"
required="true"
<field
name="subject"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_EMAIL_SUBJECT_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_EMAIL_SUBJECT_DESC"
/>

<field
name="body"
type="editor"
label="COM_TJNOTIFICATIONS_FIELD_EMAIL_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_EMAIL_BODY_DESC"
buttons="true"
filter="JComponentHelper::filterText"
height="150px"
/>
</fieldset>
</form>
38 changes: 18 additions & 20 deletions src/com_tjnotifications/admin/models/forms/pushfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>
<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
>
<option value="*">JALL</option>
</field>

<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_PUSH_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_PUSH_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
class="validate-json"
required="true"
/>
<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_PUSH_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_PUSH_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
class="validate-json"
/>
</fieldset>
</form>
38 changes: 18 additions & 20 deletions src/com_tjnotifications/admin/models/forms/smsfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>
<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
>
<option value="*">JALL</option>
</field>

<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_SMS_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_SMS_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
required="true"
onchange="tjnotificationsAdmin.notification.validateSmsLength(this)"
/>
<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_SMS_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_SMS_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
onchange="tjnotificationsAdmin.notification.validateSmsLength(this)"
/>

<field
name="provider_template_id"
Expand Down
38 changes: 18 additions & 20 deletions src/com_tjnotifications/admin/models/forms/webhookfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>
<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
>
<option value="*">JALL</option>
</field>

<field
name="use_global_webhook_url"
Expand All @@ -36,16 +35,15 @@
formsource="/administrator/components/com_tjnotifications/models/forms/webhookurl.xml"
/>

<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_WEBHOOK_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_WEBHOOK_BODY_DESC"
rows="10"
cols="350"
filter="JComponentHelper::filterText"
class="validate-json"
required="true"
/>
<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_WEBHOOK_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_WEBHOOK_BODY_DESC"
rows="10"
cols="350"
filter="JComponentHelper::filterText"
class="validate-json"
/>
</fieldset>
</form>
36 changes: 17 additions & 19 deletions src/com_tjnotifications/admin/models/forms/whatsappfields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
name="id"
type="hidden" />

<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
required="true"
>
<option value="*">JALL</option>
</field>
<field
name="language"
type="contentlanguage"
label="JFIELD_LANGUAGE_LABEL"
description="COM_TJNOTIFICATIONS_NOTIFICATION_LANGUAGE_DESC"
>
<option value="*">JALL</option>
</field>

<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_WHATSAPP_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_WHATSAPP_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
required="true"
/>
<field
name="body"
type="textarea"
label="COM_TJNOTIFICATIONS_FIELD_WHATSAPP_BODY_LABEL"
description="COM_TJNOTIFICATIONS_FIELD_WHATSAPP_BODY_DESC"
rows="10"
cols="150"
filter="JComponentHelper::filterText"
/>
</fieldset>
</form>
67 changes: 54 additions & 13 deletions src/com_tjnotifications/admin/models/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ public function updateReplacementTags($data)
*/
public function save($data)
{
$isNew = true;
// Determine if this is a new record or edit
$isNew = empty($data['id']) || $data['id'] == 0;

// 1 - save template first
if (!empty($data))
Expand All @@ -345,14 +346,22 @@ public function save($data)

if (!parent::save($data))
{
// Log the error for debugging
Factory::getApplication()->getLogger()->error('TJNotifications: Failed to save template - ' . $this->getError());
return false;
}
else
{
$db = Factory::getDbo();
$db = Factory::getDbo();

// Get the template ID - use insertid() for new records, or the existing ID for edits
if ($isNew) {
$templateId = $db->insertid();
} else {
$templateId = $data['id'];
}

// IMPORTANT to set new id in state, it is fetched in controller later
// Get current Template id
$templateId = $db->insertid();
$this->setState('com_tjnotifications.edit.notification.id', $templateId);
$this->setState('com_tjnotifications.edit.notification.new', $isNew);
}
Expand Down Expand Up @@ -397,25 +406,57 @@ public function save($data)
// 2.2 Find existing template config entries to be deleted (i.e. language specific templates removed by user)
foreach ($data[$backend][$backend . 'fields'] as $backendName => $backendFieldValues)
{
// Webhook stuff starts here
if ($backend == 'webhook' && $data[$backend]['state'])
// Backend-specific validation - only validate when backend is enabled
if ($data[$backend]['state'])
{
// If not using global webhook URLs & custom webhooks URLs are also empty
if (empty($backendFieldValues['use_global_webhook_url']) && empty($backendFieldValues['webhook_url']))
// Common validation for all backends
if (empty($backendFieldValues['language']))
{
$this->setError(Text::_('COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_CUSTOM_WEBHOOK_URLS'));
$errorKey = 'COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_' . strtoupper($backend) . '_LANGUAGE_REQUIRED';
$this->setError(Text::_($errorKey));

return false;
}
// If using global webhook URL & the global URLs are empty
elseif ($backendFieldValues['use_global_webhook_url'] && empty($webhookUrls[0]))

if (empty($backendFieldValues['body']))
{
$this->setError(Text::_('COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_GLOBAL_WEBHOOK_URLS'));
$errorKey = 'COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_' . strtoupper($backend) . '_BODY_REQUIRED';
$this->setError(Text::_($errorKey));

return false;
}

// Email-specific validation
if ($backend == 'email')
{
if (empty($backendFieldValues['subject']))
{
$this->setError(Text::_('COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_EMAIL_SUBJECT_REQUIRED'));

return false;
}
}

// Webhook-specific validation
if ($backend == 'webhook')
{
// If not using global webhook URLs & custom webhooks URLs are also empty
if (empty($backendFieldValues['use_global_webhook_url']) && empty($backendFieldValues['webhook_url']))
{
$this->setError(Text::_('COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_CUSTOM_WEBHOOK_URLS'));

return false;
}
// If using global webhook URL & the global URLs are empty
elseif (!empty($backendFieldValues['use_global_webhook_url']) && empty($webhookUrls[0]))
{
$this->setError(Text::_('COM_TJNOTIFICATIONS_TEMPLATE_ERR_MSG_GLOBAL_WEBHOOK_URLS'));

return false;
}
}
}
// Webhook stuff ends here
// Backend validation ends here

// Iterate through each lang. specific config entry
foreach ($existingBackendConfigs as $existingBackendConfig)
Expand Down