feat: add subject field for messages and implement validation based on selected channel

This commit is contained in:
Focuslinkstech
2025-04-09 12:36:13 +01:00
parent 1740c568f9
commit 1cc7057dca
3 changed files with 154 additions and 56 deletions

View File

@ -18,9 +18,9 @@
{if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
<div class="btn-group pull-right">
<a class="btn btn-primary btn-xs" title="save"
href="{Text::url('customers/csv&token=', $csrf_token)}"
onclick="return ask(this, '{Lang::T("This will export to CSV")}?')"><span
class="glyphicon glyphicon-download" aria-hidden="true"></span> CSV</a>
href="{Text::url('customers/csv&token=', $csrf_token)}" onclick="return ask(this, '{Lang::T("
This will export to CSV")}?')"><span class="glyphicon glyphicon-download"
aria-hidden="true"></span> CSV</a>
</div>
{/if}
{Lang::T('Manage Contact')}
@ -205,14 +205,15 @@
</button>
</div>
<div class="modal-body">
<select id="messageType" class="form-control">
<select style="margin-bottom: 10px;" id="messageType" class="form-control">
<option value="all">{Lang::T('All')}</option>
<option value="email">{Lang::T('Email')}</option>
<option value="inbox">{Lang::T('Inbox')}</option>
<option value="sms">{Lang::T('SMS')}</option>
<option value="wa">{Lang::T('WhatsApp')}</option>
</select>
<br>
<input type="text" style="margin-bottom: 10px;" class="form-control" id="subject-content" value=""
placeholder="{Lang::T('Enter message subject here')}">
<textarea id="messageContent" class="form-control" rows="4"
placeholder="{Lang::T('Enter your message here...')}"></textarea>
</div>
@ -260,6 +261,8 @@
$('#sendMessageButton').on('click', function () {
const message = $('#messageContent').val().trim();
const messageType = $('#messageType').val();
const subject = $('#subject-content').val().trim();
if (!message) {
Swal.fire({
@ -332,4 +335,31 @@
});
});
</script>
<script>
document.getElementById('messageType').addEventListener('change', function () {
const messageType = this.value;
const subjectField = document.getElementById('subject-content');
subjectField.style.display = (messageType === 'all' || messageType === 'email' || messageType === 'inbox') ? 'block' : 'none';
switch (messageType) {
case 'all':
subjectField.placeholder = 'Enter a subject for all channels';
subjectField.required = true;
break;
case 'email':
subjectField.placeholder = 'Enter a subject for email';
subjectField.required = true;
break;
case 'inbox':
subjectField.placeholder = 'Enter a subject for inbox';
subjectField.required = true;
break;
default:
subjectField.placeholder = 'Enter message subject here';
subjectField.required = false;
break;
}
});
</script>
{include file = "sections/footer.tpl" }

View File

@ -23,12 +23,26 @@
<label class="col-md-2 control-label">{Lang::T('Send Via')}</label>
<div class="col-md-6">
<select class="form-control" name="via" id="via">
<option value="sms" selected> {Lang::T('via SMS')}</option>
<option value="wa"> {Lang::T('Via WhatsApp')}</option>
<option value="both"> {Lang::T('Via WhatsApp and SMS')}</option>
</select>
<option value="all" {if $via=='all' }selected{/if}>{Lang::T('All Channels')}</option>
<option value="inbox" {if $via=='inbox' }selected{/if}>{Lang::T('Inbox')}</option>
<option value="email" {if $via=='email' }selected{/if}>{Lang::T('Email')}</option>
<option value="sms" {if $via=='sms' }selected{/if}>{Lang::T('SMS')}</option>
<option value="wa" {if $via=='wa' }selected{/if}>{Lang::T('WhatsApp')}</option>
<option value="both" {if $via=='both' }selected{/if}>{Lang::T('SMS and WhatsApp')}
</option>
</select>
</div>
</div>
<div class="form-group" id="subject">
<label class="col-md-2 control-label">{Lang::T('Subject')}</label>
<div class="col-md-6">
<input type="text" class="form-control" name="subject" id="subject-content" value=""
placeholder="{Lang::T('Enter message subject here')}">
</div>
<p class="help-block col-md-4">
{Lang::T('You can also use the below placeholders here too')}.
</p>
</div>
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Message')}</label>
<div class="col-md-6">
@ -64,6 +78,33 @@
</div>
</div>
</div>
<script>
document.getElementById('via').addEventListener('change', function () {
const via = this.value;
const subject = document.getElementById('subject');
const subjectField = document.getElementById('subject-content');
subject.style.display = (via === 'all' || via === 'email' || via === 'inbox') ? 'block' : 'none';
switch (via) {
case 'all':
subjectField.placeholder = 'Enter a subject for all channels';
subjectField.required = true;
break;
case 'email':
subjectField.placeholder = 'Enter a subject for email';
subjectField.required = true;
break;
case 'inbox':
subjectField.placeholder = 'Enter a subject for inbox';
subjectField.required = true;
break;
default:
subjectField.placeholder = 'Enter message subject here';
subjectField.required = false;
break;
}
});
</script>
{include file="sections/footer.tpl"}