diff --git a/admin/service_messages.php b/admin/service_messages.php
index c60d7b58..93ad7a5c 100644
--- a/admin/service_messages.php
+++ b/admin/service_messages.php
@@ -214,6 +214,48 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
+
diff --git a/install/migrations/v330/UpdateExistingServiceMessagesLocations.php b/install/migrations/v330/UpdateExistingServiceMessagesLocations.php
new file mode 100644
index 00000000..899909dc
--- /dev/null
+++ b/install/migrations/v330/UpdateExistingServiceMessagesLocations.php
@@ -0,0 +1,19 @@
+executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "mfh_service_message_to_location` (`service_message_id`, `location`)
+ SELECT `id`, '" . hesk_dbEscape(ServiceMessageLocation::CUSTOMER_HOME) . "' FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages`");
+ }
+
+ function innerDown($hesk_settings) {
+ $this->executeQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "mfh_service_message_to_location`
+ WHERE `service_message_id` IN (SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages`)");
+ }
+}
\ No newline at end of file
diff --git a/internal-api/js/service-messages.js b/internal-api/js/service-messages.js
index 050c864a..ebe79766 100644
--- a/internal-api/js/service-messages.js
+++ b/internal-api/js/service-messages.js
@@ -137,7 +137,8 @@ function bindEditModal() {
$(document).on('click', '[data-action="edit"]', function() {
var element = serviceMessages[$(this).parent().parent().find('[data-property="id"]').data('value')];
var $modal = $('#service-message-modal');
- $modal.find('#preview-pane').html('');
+ $modal.find('#preview-pane').html('').end()
+ .find('input[name="location[]"]').prop('checked', false);
$modal.find('#edit-label').show();
$modal.find('#create-label').hide();
@@ -150,6 +151,10 @@ function bindEditModal() {
.find('input[name="order"]').val(element.order).end();
setIcon(element.icon);
+ $.each(element.locations, function() {
+ $modal.find('input[name="location[]"][value="' + this + '"]').prop('checked', 'checked');
+ });
+
if ($('input[name="kb_wysiwyg"]').val() === "1") {
tinyMCE.get('content').setContent(element.message);
} else {
@@ -171,7 +176,8 @@ function bindCreateModal() {
.find('input[name="title"]').val('').end()
.find('input[name="id"]').val(-1).end()
.find('input[name="order"]').val('').end()
- .find('#preview-pane').html('').end();
+ .find('#preview-pane').html('').end()
+ .find('input[name="location[]"]').prop('checked', false);
setIcon('');
if ($('input[name="kb_wysiwyg"]').val() === "1") {
@@ -198,13 +204,21 @@ function bindFormSubmit() {
styles[3] = "NOTICE";
styles[4] = "ERROR";
+ var domLocations = $modal.find('input[name="location[]"]:checked');
+
+ var locations = [];
+ $.each(domLocations, function() {
+ locations.push($(this).val());
+ });
+
var data = {
icon: $modal.find('input[name="icon"]').val(),
title: $modal.find('input[name="title"]').val(),
message: getMessage(),
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()
+ order: $modal.find('input[name="order"]').val(),
+ locations: locations
};
var url = heskUrl + 'api/index.php/v1/service-messages/';