Working on incorporating the API into the page

merge-requests/60/head
Mike Koch 7 years ago
parent 6e72662a1b
commit 6b05ee31ab

@ -4,6 +4,7 @@ define('IN_SCRIPT', 1);
define('HESK_PATH', '../');
define('PAGE_TITLE', 'ADMIN_CUSTOM_NAV_ELEMENTS');
define('MFH_PAGE_LAYOUT', 'TOP_ONLY');
define('EXTRA_JS', '<script src="'.HESK_PATH.'internal-api/js/manage-custom-nav-elements.js"></script>');
/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
@ -18,12 +19,6 @@ hesk_isLoggedIn();
//hesk_checkPermission('can_man_custom_nav');
// Are we saving?
if (isset($_POST['action'])) {
if ($_POST['action'] == 'save') {
save();
}
}
/* Print header */
require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
@ -68,113 +63,38 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
if (hesk_dbNumRows($customElementsRs) === 0) {
echo '<tr><td colspan="6">No custom navigation elements</td></tr>';
}
<tbody id="table-body">
while ($row = hesk_dbFetchAssoc($customElementsRs)):
$localizedTextRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "custom_nav_element_to_text`
WHERE `nav_element_id` = " . intval($row['id']));
$languageText = array();
while ($textRow = hesk_dbFetchAssoc($localizedTextRs)) {
$languageText[$textRow['language']] = $textRow;
} ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td>
<ul class="list-unstyled">
<?php foreach ($languageText as $key => $value): ?>
<li>
<b><?php echo $key; ?>: </b>
<?php echo $value['text']; ?>
</li>
<?php endforeach; ?>
</ul>
</td>
<td>
<ul class="list-unstyled">
<?php
if ($row['place'] == 0) {
foreach ($languageText as $key => $value): ?>
<li>
<b><?php echo $key; ?>: </b>
<?php echo $value['subtext']; ?>
</li>
<?php endforeach;
} else {
echo '-';
} ?>
</ul>
</td>
<td>
<?php if ($row['image_url'] !== null) {
echo $row['image_url'];
} else {
echo '<i class="' . $row['font_icon'] . '"></i>';
} ?>
</td>
<td>
<?php if ($row['place'] == 0) {
echo 'Homepage - Block';
} elseif ($row['place'] == 1) {
echo 'Customer Navbar';
} elseif ($row['place'] == 2) {
echo 'Staff Navbar';
} else {
echo 'INVALID!!';
} ?>
</td>
<td>
<a href="manage_custom_nav_elements.php?edit=<?php echo $row['id'];?>">
<i class="fa fa-pencil icon-link orange"
data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i>
</a>
<a href="manage_custom_nav_elements.php?delete=<?php echo $row['id']; ?>">
<i class="fa fa-times icon-link red"
data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i>
</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
if ($showEditPanel):
?>
<div class="box">
<div class="box-header with-border">
<h1 class="box-title">
Edit Custom Navigation Menu Element
</h1>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i>
</button>
</div>
</div>
<div class="box-body">
<form action="manage_custom_nav_elements.php" method="post">
</form>
</div>
</div>
<?php endif; ?>
</section>
</div>
<section id="table-row-template" style="display: none">
<tr>
<td data-property="id"></td>
<td data-property="text"></td>
<td data-property="subtext"></td>
<td data-property="icon-url"></td>
<td data-property="place"></td>
<td data-property="action"></td>
<p style="display: none" id="lang_edit"><?php echo $hesklang['edit']; ?></p>
<p style="display: none" id="lang_delete"><?php echo $hesklang['delete']; ?></p>
<script type="text/html" id="nav-element-template">
<tr id="nav-element-template">
<td><span data-property="id"></span></td>
<td><span>
<ul data-property="text" class="list-unstyled"></ul>
</span></td>
<td><span data-property="subtext"></span></td>
<td><span data-property="image-or-font"></span></td>
<td><span data-property="place"></span></td>
<td>
<a href="#" data-action="edit">
<i class="fa fa-pencil icon-link orange"
data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i>
</a>
<a href="#" data-action="delete">
<i class="fa fa-times icon-link red"
data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i>
</a>
</td>
</tr>
</section>
</script>
<?php
require_once(HESK_PATH . 'inc/footer.inc.php');

@ -7,6 +7,13 @@ use BusinessLogic\Exceptions\InternalUseOnlyException;
use BusinessLogic\Helpers;
abstract class InternalApiController {
static function staticCheckForInternalUseOnly() {
$tokenHeader = Helpers::getHeader('X-AUTH-TOKEN');
if ($tokenHeader !== null && trim($tokenHeader) !== '') {
throw new InternalUseOnlyException();
}
}
function checkForInternalUseOnly() {
$tokenHeader = Helpers::getHeader('X-AUTH-TOKEN');
if ($tokenHeader !== null && trim($tokenHeader) !== '') {

@ -13,7 +13,7 @@ class CustomNavElementController extends InternalApiController {
static function getAll() {
global $applicationContext, $hesk_settings;
self::checkForInternalUseOnly();
self::staticCheckForInternalUseOnly();
/* @var $handler CustomNavElementHandler */
$handler = $applicationContext->get[CustomNavElementHandler::class];

@ -0,0 +1,50 @@
$(document).ready(function() {
var heskUrl = $('#heskUrl').text();
var places = [];
places[1] = 'Homepage - Block';
places[2] = 'Customer Navigation';
places[3] = 'Staff Navigation';
$.ajax({
method: 'GET',
url: heskUrl + '/api/v1-internal/custom-navigation/all',
headers: { 'X-Internal-Call': true },
success: function(data) {
$.each(data, function() {
var $template = $($('#nav-element-template').html());
//var $template = $(template);
console.log($template);
$template.find('span[data-property="id"]').text(this.id);
if (this.imageUrl === null) {
$template.find('span[data-property="image-or-font"]').html('<i class="' + escape(this.fontIcon) + '"></i>');
} else {
$template.find('span[data-property="image-or-font"]').text(this.imageUrl);
}
$template.find('span[data-property="place"]').text(places[this.place]);
var text = '';
$.each(this.text, function(key, value) {
text += '<li><b>' + escape(key) + ':</b> ' + escape(value) + '</li>';
});
$template.find('ul[data-property="text"]').html(text);
$.each(this.subtext, function() {
console.log(this);
});
$('#table-body').append($template);
});
},
error: function(data) {
console.error(data);
}
});
});
function escape(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
Loading…
Cancel
Save