All operations except for preview are working
This commit is contained in:
parent
d897fa2a4b
commit
3e7f000630
@ -247,6 +247,10 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
|
||||
<i class="fa fa-times-circle"></i>
|
||||
<span><?php echo $hesklang['cancel']; ?></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary preview-button">
|
||||
<i class="fa fa-search"></i>
|
||||
<span><?php echo $hesklang['sm_preview']; ?></span>
|
||||
</button>
|
||||
<button type="submit" class="btn btn-success save-button">
|
||||
<i class="fa fa-check-circle"></i>
|
||||
<span><?php echo $hesklang['save']; ?></span>
|
||||
@ -262,6 +266,13 @@ echo mfh_get_hidden_fields_for_language(array(
|
||||
'sm_published',
|
||||
'sm_draft',
|
||||
'no_sm',
|
||||
'sm_added',
|
||||
'sm_mdf',
|
||||
'error_saving_updating_sm',
|
||||
'sm_deleted',
|
||||
'error_deleting_sm',
|
||||
'error_sorting_categories',
|
||||
'error_retrieving_sm',
|
||||
));
|
||||
|
||||
echo '<script>var users = [];';
|
||||
|
@ -81,14 +81,14 @@ class ServiceMessageHandler extends \BaseClass {
|
||||
$serviceMessages = $this->serviceMessageGateway->getServiceMessages($heskSettings);
|
||||
$serviceMessage = null;
|
||||
foreach ($serviceMessages as $innerServiceMessage) {
|
||||
if ($innerServiceMessage->id === intval($id)) {
|
||||
if (intval($innerServiceMessage->id) === intval($id)) {
|
||||
$serviceMessage = $innerServiceMessage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($serviceMessage === null) {
|
||||
throw new \BaseException("Could not find category with ID {$id}!");
|
||||
throw new \BaseException("Could not find service message with ID {$id}!");
|
||||
}
|
||||
|
||||
if ($direction === Direction::UP) {
|
||||
|
@ -29,14 +29,16 @@ class ServiceMessagesController extends \BaseClass {
|
||||
return output($element, 201);
|
||||
}
|
||||
|
||||
function put() {
|
||||
function put($id) {
|
||||
global $applicationContext, $hesk_settings;
|
||||
|
||||
/* @var $handler ServiceMessageHandler */
|
||||
$handler = $applicationContext->get(ServiceMessageHandler::clazz());
|
||||
|
||||
$data = JsonRetriever::getJsonData();
|
||||
$element = $handler->editServiceMessage($this->buildElementModel($data, null, false), $hesk_settings);
|
||||
$serviceMessage = $this->buildElementModel($data, null, false);
|
||||
$serviceMessage->id = $id;
|
||||
$element = $handler->editServiceMessage($serviceMessage, $hesk_settings);
|
||||
|
||||
return output($element);
|
||||
}
|
||||
@ -61,7 +63,6 @@ class ServiceMessagesController extends \BaseClass {
|
||||
$serviceMessage = new ServiceMessage();
|
||||
|
||||
if (!$creating) {
|
||||
$serviceMessage->id = $data['id'];
|
||||
$serviceMessage->order = $data['order'];
|
||||
}
|
||||
|
||||
@ -77,4 +78,13 @@ class ServiceMessagesController extends \BaseClass {
|
||||
|
||||
return $serviceMessage;
|
||||
}
|
||||
|
||||
static function sort($id, $direction) {
|
||||
global $applicationContext, $hesk_settings;
|
||||
|
||||
/* @var $handler ServiceMessageHandler */
|
||||
$handler = $applicationContext->get(ServiceMessageHandler::clazz());
|
||||
|
||||
$handler->sortServiceMessage(intval($id), $direction, $hesk_settings);
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
|
||||
$serviceMessages = array();
|
||||
|
||||
$rs = hesk_dbQuery("SELECT * FROM `". hesk_dbEscape($heskSettings['db_pfix']) . "service_messages` ORDER BY `id`");
|
||||
$rs = hesk_dbQuery("SELECT * FROM `". hesk_dbEscape($heskSettings['db_pfix']) . "service_messages` ORDER BY `order`");
|
||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||
$serviceMessage = new ServiceMessage();
|
||||
$serviceMessage->id = $row['id'];
|
||||
@ -88,14 +88,14 @@ class ServiceMessagesGateway extends CommonDao {
|
||||
`message` = '" . hesk_dbEscape($serviceMessage->message) . "',
|
||||
`style` = '" . intval($style) . "',
|
||||
`type` = " . intval($type) . ",
|
||||
`icon` = '" . hesk_dbEscape($serviceMessage->icon) . "'
|
||||
`icon` = '" . hesk_dbEscape($serviceMessage->icon) . "',
|
||||
`order` = " . intval($serviceMessage->order) . "
|
||||
WHERE `id` = " . intval($serviceMessage->id));
|
||||
|
||||
$otherFieldsRs = hesk_dbQuery("SELECT `dt`, `author`, `order` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||
WHERE `id` = " . intval($serviceMessage->id));
|
||||
$otherFields = hesk_dbFetchAssoc($otherFieldsRs);
|
||||
|
||||
$serviceMessage->order = intval($otherFields['order']);
|
||||
$serviceMessage->createdBy = intval($otherFields['author']);
|
||||
$serviceMessage->dateCreated = $otherFields['dt'];
|
||||
|
||||
|
@ -204,12 +204,12 @@ Link::all(array(
|
||||
'/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()),
|
||||
// Service Messages
|
||||
'/v1/service-messages' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz(),
|
||||
array(RequestMethod::GET, RequestMethod::POST, RequestMethod::PUT),
|
||||
array(RequestMethod::GET, RequestMethod::POST),
|
||||
SecurityHandler::INTERNAL_OR_AUTH_TOKEN),
|
||||
'/v1/service-messages/{i}' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz(),
|
||||
array(RequestMethod::DELETE),
|
||||
array(RequestMethod::PUT, RequestMethod::DELETE),
|
||||
SecurityHandler::INTERNAL_OR_AUTH_TOKEN),
|
||||
'/v1/service-messages/{i}/sort/{s}' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz() . '::sort',
|
||||
'/v1-internal/service-messages/{i}/sort/{s}' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz() . '::sort',
|
||||
array(RequestMethod::POST),
|
||||
SecurityHandler::INTERNAL),
|
||||
|
||||
|
@ -14,6 +14,7 @@ $(document).ready(function() {
|
||||
bindDeleteButton();
|
||||
bindCreateModal();
|
||||
bindSortButtons();
|
||||
bindPreview();
|
||||
});
|
||||
|
||||
|
||||
@ -215,19 +216,16 @@ function bindFormSubmit() {
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
success: function(data) {
|
||||
var format = undefined;
|
||||
if (categoryId === -1) {
|
||||
format = mfhLang.html('cat_name_added');
|
||||
mfhAlert.success(format.replace('%s', data.name));
|
||||
if (serviceMessageId === -1) {
|
||||
mfhAlert.success(mfhLang.text('sm_added'));
|
||||
} else {
|
||||
format = mfhLang.html('category_updated');
|
||||
mfhAlert.success(format.replace('%s', data.name));
|
||||
mfhAlert.success(mfhLang.text('sm_mdf'));
|
||||
}
|
||||
$modal.modal('hide');
|
||||
loadTable();
|
||||
},
|
||||
error: function(data) {
|
||||
mfhAlert.errorWithLog(mfhLang.text('error_saving_updating_category'), data.responseJSON);
|
||||
mfhAlert.errorWithLog(mfhLang.text('error_saving_updating_sm'), data.responseJSON);
|
||||
console.error(data);
|
||||
},
|
||||
complete: function(data) {
|
||||
@ -243,55 +241,38 @@ function bindDeleteButton() {
|
||||
$('#overlay').show();
|
||||
|
||||
var heskUrl = $('p#hesk-path').text();
|
||||
var element = categories[$(this).parent().parent().find('[data-property="id"]').text()];
|
||||
var element = serviceMessages[$(this).parent().parent().find('[data-property="id"]').data('value')];
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: heskUrl + 'api/index.php/v1/categories/' + element.id,
|
||||
url: heskUrl + 'api/index.php/v1/service-messages/' + element.id,
|
||||
headers: {
|
||||
'X-Internal-Call': true,
|
||||
'X-HTTP-Method-Override': 'DELETE'
|
||||
},
|
||||
success: function() {
|
||||
mfhAlert.success(mfhLang.text('cat_removed'));
|
||||
mfhAlert.success(mfhLang.text('sm_deleted'));
|
||||
loadTable();
|
||||
},
|
||||
error: function(data) {
|
||||
$('#overlay').hide();
|
||||
mfhAlert.errorWithLog(mfhLang.text('error_deleting_category'), data.responseJSON);
|
||||
mfhAlert.errorWithLog(mfhLang.text('error_deleting_sm'), data.responseJSON);
|
||||
console.error(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindGenerateLinkModal() {
|
||||
var $modal = $('#generate-link-modal');
|
||||
|
||||
$modal.find('.input-group-addon').click(function() {
|
||||
clipboard.copy($modal.find('input[type="text"]').val());
|
||||
mfhAlert.success(mfhLang.text('copied_to_clipboard'));
|
||||
});
|
||||
|
||||
$(document).on('click', '[data-property="generate-link"] i.fa-code', function () {
|
||||
var heskUrl = $('p#hesk-url').text();
|
||||
|
||||
var url = heskUrl + '/index.php?a=add&catid=' + $(this).parent().data('category-id');
|
||||
|
||||
$modal.find('input[type="text"]').val(url).end().modal('show');
|
||||
});
|
||||
}
|
||||
|
||||
function bindSortButtons() {
|
||||
$(document).on('click', '[data-action="sort"]', function() {
|
||||
$('#overlay').show();
|
||||
var heskUrl = $('p#hesk-path').text();
|
||||
var direction = $(this).data('direction');
|
||||
var element = categories[$(this).parent().parent().parent().find('[data-property="id"]').text()];
|
||||
var element = serviceMessages[$(this).parent().parent().parent().find('[data-property="id"]').data('value')];
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: heskUrl + 'api/index.php/v1-internal/categories/' + element.id + '/sort/' + direction,
|
||||
url: heskUrl + 'api/index.php/v1-internal/service-messages/' + element.id + '/sort/' + direction,
|
||||
headers: { 'X-Internal-Call': true },
|
||||
success: function() {
|
||||
loadTable();
|
||||
@ -303,4 +284,20 @@ function bindSortButtons() {
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function bindPreview() {
|
||||
$('#preview-button').click(function() {
|
||||
var $modal = $('#service-message-modal');
|
||||
var data = {
|
||||
icon: $modal.find('input[name="icon"]').val(),
|
||||
title: $modal.find('input[name="title"]').val(),
|
||||
message: tinyMCE.get('content').getContent(),
|
||||
published: $modal.find('input[name="type"]:checked').val() === "0",
|
||||
style: styles[$modal.find('input[name="style"]:checked').val()],
|
||||
order: $modal.find('input[name="order"]').val()
|
||||
};
|
||||
|
||||
getServiceMessagePreview(data.icon, data.title, data.message, data.style);
|
||||
});
|
||||
}
|
@ -2217,6 +2217,9 @@ $hesklang['audit_unlinked_ticket'] = '%s unlinked ticket %s';
|
||||
|
||||
// Added or modified in Mods for HESK 3.3.0
|
||||
$hesklang['error_retrieving_sm'] = 'An error occurred retrieving service messages!';
|
||||
$hesklang['error_saving_updating_sm'] = 'An error occurred creating / saving the service message!';
|
||||
$hesklang['error_deleting_sm'] = 'An error occurred when trying to delete the service message.';
|
||||
$hesklang['error_sorting_sm'] = 'An error occurred sorting service messages!';
|
||||
|
||||
// DO NOT CHANGE BELOW
|
||||
if (!defined('IN_SCRIPT')) die('PHP syntax OK!');
|
||||
|
Loading…
x
Reference in New Issue
Block a user