Skip to content

Commit

Permalink
Merge pull request #2271 from department-of-veterans-affairs/bugfix/t…
Browse files Browse the repository at this point in the history
…emplate-editor

Leaf 4208 - Resolve issue related to incorrect "custom" designation
  • Loading branch information
Pelentan authored Jan 23, 2024
2 parents 2b8ad18 + 5831312 commit 95e5488
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 59 deletions.
14 changes: 4 additions & 10 deletions LEAF_Request_Portal/admin/templates/mod_templates.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -890,34 +890,28 @@
type: 'GET',
url: '../api/template/custom',
dataType: 'json',
success: function (result) {
success: function (customTemplates) {
let template_excluded = 'import_from_webHR.tpl';
let res_array = $.parseJSON(result);
let buffer = '<ul class="leaf-ul">';
let filesMobile = '<h3>Template Files:</h3><div class="template_select_container"><select class="templateFiles">';
if (res_array.status['code'] === 2) {
if (Array.isArray(customTemplates)) {
for (let i in res) {
if (res[i] === template_excluded) {
// Will skip the excluded template, until further notice.
continue;
}
if (result.includes(res[i])) {
let custom = '';
if (customTemplates.includes(res[i])) {
custom = '<span class=\'custom_file\' style=\'color: red; font-size: .75em\'>(custom)</span>';
} else {
custom = '';
}
let file = res[i].replace('.tpl', '');
buffer += '<li><div class="template_files"><a href="#" data-file="' + res[i] + '">' + file + '</a> ' + custom + '</div></li>';
filesMobile += '<option value="' + res[i] + '">' + file + ' ' + custom + '</option>';
}
} else if (res_array.status['code'] === 4) {
buffer += '<li><div class="template_files">' + res_array.status['message'] + '</div></li>';
filesMobile += '<select><option>' + res_array.status['message'] + '</option></select>';
} else {
buffer += '<li>Internal error occurred, if this persists contact your Primary Admin.</li>';
}
Expand Down
10 changes: 3 additions & 7 deletions LEAF_Request_Portal/admin/templates/mod_templates_email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1263,16 +1263,15 @@
type: 'GET',
url: '../api/emailTemplates/custom',
dataType: 'json',
success: function (result) {
let res_array = $.parseJSON(result);
success: function (customTemplates) {
let buffer = '<ul class="leaf-ul">';
let filesMobile = '<h3>Template Files:</h3><div class="template_select_container"><select class="templateFiles">';
if (res_array.status['code'] === 2) {
if (Array.isArray(customTemplates)) {
for (let i in res) {
let custom = '';
if (result.includes(res[i].fileName)) {
if (customTemplates.includes(res[i].fileName)) {
custom = '<span class=\'custom_file\' style=\'color: red; font-size: .75em\'>(custom)</span>';
}
Expand All @@ -1291,9 +1290,6 @@
filesMobile += '</select></div>';
buffer += '</ul>';
} else if (res_array.status['code'] === 4) {
buffer += '<li>' + res_array.status['message'] + '</li>';
filesMobile += '<select><option>' + res_array.status['message'] + '</option></select>';
} else {
buffer += '<li>Internal error occurred. If this persists, contact your Primary Admin.</li>';
filesMobile += '<div>Internal error occurred. If this persists, contact your Primary Admin.</div>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function get($act)
});

$this->index['GET']->register('emailTemplates/custom', function ($args) use ($emailTemplate) {
$return_value = $emailTemplate->getCustomEmailTemplateList();

return json_encode($return_value);
return $emailTemplate->getCustomEmailTemplateList();
});

$this->index['GET']->register('emailTemplates/[text]', function ($args) use ($emailTemplate) {
Expand Down
4 changes: 1 addition & 3 deletions LEAF_Request_Portal/api/controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public function get($act)
});

$this->index['GET']->register('template/custom', function ($args) use ($template) {
$return_value = $template->getCustomTemplateList();

return json_encode($return_value);
return $template->getCustomTemplateList();
});

$this->index['GET']->register('template/[text]', function ($args) use ($template) {
Expand Down
26 changes: 8 additions & 18 deletions LEAF_Request_Portal/sources/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,38 +132,28 @@ public function getEmailAndSubjectTemplateList()
}

/**
* @return array
* getCustomEmailTemplateList retrieves a list of custom email templates
* @return array of templates
* @return string error message
*
* Created at: 6/6/2023, 1:40:09 PM (America/New_York)
*/
public function getCustomEmailTemplateList(): array
public function getCustomEmailTemplateList(): array|string
{
$return_value = [];

if (!$this->login->checkGroup(1)) {
$return_value = array(
'status' => array(
'code' => 4,
'message' => 'Admin access required'
)
);
return 'Admin access required';
}

$list = scandir('../templates/email/custom_override');
$out = array();

foreach ($list as $item) {
if (preg_match('/.tpl$/', $item)) {
$out[] = $item;
$return_value[] = $item;
}
}

$return_value = array(
'status' => array(
'code' => 2,
'message' => ''
),
'data' => $out
);

return $return_value;
}

Expand Down
27 changes: 9 additions & 18 deletions LEAF_Request_Portal/sources/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,29 @@ public function getTemplateList()
}

/**
* @return array
* getCustomTemplateList retrieves a list of custom templates
* @return array of templates
* @return string error message
*
* Created at: 5/24/2023, 10:22:51 AM (America/New_York)
*/
public function getCustomTemplateList(): array
public function getCustomTemplateList(): array|string
{
$return_value = [];

if (!$this->login->checkGroup(1))
{
$return_value = array(
'status' => array(
'code' => 4,
'message' => 'Admin access required'
)
);
return 'Admin access required';
}

$list = scandir('../templates/custom_override');
$out = array();

foreach ($list as $item) {
if (preg_match('/.tpl$/', $item)) {
$out['success'][] = $item;
$return_value[] = $item;
}
}

$return_value = array(
'status' => array(
'code' => 2,
'message' => ''
),
'data' => $out
);

return $return_value;
}

Expand Down

0 comments on commit 95e5488

Please sign in to comment.