Message button
This commit is contained in:
parent
771832c6e4
commit
9d7ae24701
|
|
@ -1057,6 +1057,32 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
|||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> SendOrderNotification(int orderId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return Json(new { success = false, message = "Az üzenet nem lehet üres" });
|
||||
}
|
||||
|
||||
var orderDto = await _dbContext.OrderDtos.GetByIdAsync(orderId, true);
|
||||
await _sendToClient.SendMeasuringNotification("Módosult a rendelés, mérjétek újra!", orderDto);
|
||||
return Json(new { success = true, message = "Üzenet sikeresen elküldve" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
_logger.Error($"Error sending notification for order {orderId}", ex);
|
||||
|
||||
return Json(new { success = false, message = $"Hiba történt: {ex.Message}" });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,44 @@
|
|||
@using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders
|
||||
@model OrderAttributesModel
|
||||
|
||||
<!-- InnVoice Management Section -->
|
||||
<!-- Order Subsection -->
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-header">
|
||||
<h4><i class="fas fa-cogs"></i> Üzenet küldése</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<div class="col-md-12">
|
||||
<label for="notificationMessage">Üzenet szövege:</label>
|
||||
<textarea id="notificationMessage" class="form-control" rows="3" placeholder="Írja be az üzenetet..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-md-12">
|
||||
<div id="notificationStatus" class="alert" style="display: none;">
|
||||
<i class="fas fa-info-circle"></i> <span id="notificationStatusMessage"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-md-12 text-right">
|
||||
<button type="button" id="sendNotificationBtn" class="btn btn-primary">
|
||||
<i class="fas fa-paper-plane"></i> Üzenet küldése
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
|
||||
<div class="col-12 col-md-6">
|
||||
<div class="card card-default mb-3">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-file-invoice"></i>
|
||||
Megrendelés beállítások
|
||||
|
|
@ -415,5 +447,76 @@
|
|||
updateInvoiceButtons();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var sendNotificationUrl = '/Admin/CustomOrder/SendOrderNotification';
|
||||
|
||||
// Send Notification
|
||||
$("#sendNotificationBtn").click(function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
var message = $("#notificationMessage").val().trim();
|
||||
|
||||
if (!message) {
|
||||
showNotificationStatus("Kérjük, adjon meg egy üzenetet!", "warning");
|
||||
return false;
|
||||
}
|
||||
|
||||
var btn = $(this);
|
||||
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Küldés...');
|
||||
|
||||
showNotificationStatus("Üzenet küldése folyamatban...", "info");
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: sendNotificationUrl,
|
||||
data: {
|
||||
orderId: @Model.OrderId,
|
||||
message: message,
|
||||
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
console.log("Notification Response:", response);
|
||||
btn.prop("disabled", false).html('<i class="fas fa-paper-plane"></i> Üzenet küldése');
|
||||
|
||||
if (response.success) {
|
||||
showNotificationStatus("Üzenet sikeresen elküldve!", "success");
|
||||
$("#notificationMessage").val(""); // Clear the textbox
|
||||
} else {
|
||||
showNotificationStatus("Hiba: " + (response.message || "Ismeretlen hiba"), "danger");
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Notification AJAX Error:", xhr, status, error);
|
||||
btn.prop("disabled", false).html('<i class="fas fa-paper-plane"></i> Üzenet küldése');
|
||||
|
||||
var errorMessage = "Hiba az üzenet küldése közben";
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
errorMessage = xhr.responseJSON.message;
|
||||
} else if (xhr.responseText) {
|
||||
try {
|
||||
var errorObj = JSON.parse(xhr.responseText);
|
||||
errorMessage = errorObj.message || errorMessage;
|
||||
} catch (e) {
|
||||
errorMessage = "Hiba: " + xhr.status + " - " + xhr.statusText;
|
||||
}
|
||||
}
|
||||
showNotificationStatus(errorMessage, "danger");
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
function showNotificationStatus(message, type) {
|
||||
var statusDiv = $("#notificationStatus");
|
||||
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
||||
.addClass("alert-" + type);
|
||||
$("#notificationStatusMessage").text(message);
|
||||
statusDiv.show();
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in New Issue