mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 08:34:29 +00:00
- Added new public method setMessageRead to system/messages/MessageClient
- system/Recipient_model methods getReceivedMessages and getSentMessages now retrieve person_id from tbl_msg_status - Added new public method setMessageRead to CL/Messages_model - Improved code in public/js/messaging/read.js
This commit is contained in:
+91
-37
@@ -2,35 +2,108 @@
|
||||
// List all personal messages, used by view system/messages/ajaxRead
|
||||
// ***********************************************************************
|
||||
|
||||
//
|
||||
// Global variable that contains tha tabulator instance
|
||||
var tableMessageLst;
|
||||
|
||||
/**
|
||||
*
|
||||
* Use DialogLib to display a Generic error
|
||||
*/
|
||||
function genericError()
|
||||
function readMessagesGenericError()
|
||||
{
|
||||
FHC_DialogLib.alertError("An error occurred while retrieving message, contact the website administrator");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets all the received messages
|
||||
*/
|
||||
function getReceivedMessages()
|
||||
{
|
||||
_getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listReceivedMessages');
|
||||
_getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listReceivedMessages");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets all the sent messages
|
||||
*/
|
||||
function getSentMessages()
|
||||
{
|
||||
_getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + '/listSentMessages');
|
||||
_getMessages(FHC_JS_DATA_STORAGE_OBJECT.called_path + "/listSentMessages");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Change the TinyMCE content
|
||||
*/
|
||||
function changeTinyMCE(row)
|
||||
{
|
||||
tinyMCE.get("readMessagePanel").setContent(row.getData().body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on Tabulator row click event
|
||||
* - If a clicked message is unread thes is set as read
|
||||
* - Change the TinyMCE content with the clicked message body
|
||||
*/
|
||||
function rowClick(e, row)
|
||||
{
|
||||
// If the message is unread
|
||||
if (row.getData().status == "0")
|
||||
{
|
||||
FHC_AjaxClient.ajaxCallPost(
|
||||
FHC_JS_DATA_STORAGE_OBJECT.called_path + "/setMessageRead",
|
||||
{
|
||||
message_id: row.getData().message_id,
|
||||
statusPersonId: row.getData().statusPersonId
|
||||
},
|
||||
{
|
||||
successCallback: function(data, textStatus, jqXHR) {
|
||||
|
||||
if (FHC_AjaxClient.isSuccess(data))
|
||||
{
|
||||
rowFormatter(row, "normal");
|
||||
}
|
||||
else
|
||||
{
|
||||
readMessagesGenericError();
|
||||
}
|
||||
},
|
||||
errorCallback: readMessagesGenericError,
|
||||
veilTimeout: 300
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
changeTinyMCE(row); // Change TinyMCE content
|
||||
}
|
||||
|
||||
/**
|
||||
* Radio button click event to switch between received and sent messages
|
||||
*/
|
||||
function toggleMessages()
|
||||
{
|
||||
//
|
||||
if ($(this)[0].className.search("active") == -1)
|
||||
{
|
||||
$(this)[0].id == "r" ? getReceivedMessages() : getSentMessages();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats tabulator rows
|
||||
*/
|
||||
function rowFormatter(row, fontWeight = 700)
|
||||
{
|
||||
if (row.getData().status == "0")
|
||||
{
|
||||
var cells = row.getElement().childNodes;
|
||||
|
||||
for (var i = 0; i < cells.length; i++)
|
||||
{
|
||||
cells[i].style.fontWeight = fontWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get received/sent messages and change tabulator content
|
||||
*/
|
||||
function _getMessages(getMessagesURL)
|
||||
{
|
||||
@@ -48,42 +121,22 @@ function _getMessages(getMessagesURL)
|
||||
}
|
||||
catch (syntaxError)
|
||||
{
|
||||
genericError();
|
||||
readMessagesGenericError();
|
||||
}
|
||||
}
|
||||
},
|
||||
errorCallback: genericError,
|
||||
errorCallback: readMessagesGenericError,
|
||||
veilTimeout: 300
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function changeTinyMCE(e, row)
|
||||
{
|
||||
tinyMCE.get("readMessagePanel").setContent(row._row.data.body);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function toggleMessages()
|
||||
{
|
||||
//
|
||||
if ($(this)[0].className.search('active') == -1)
|
||||
{
|
||||
$(this)[0].id == 'r' ? getReceivedMessages() : getSentMessages();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Start!
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
|
||||
//
|
||||
// TinyMCE initialization
|
||||
tinymce.init({
|
||||
selector: "#readMessagePanel",
|
||||
plugins: "autoresize",
|
||||
@@ -95,7 +148,7 @@ $(document).ready(function () {
|
||||
autoresize_bottom_margin: 0
|
||||
});
|
||||
|
||||
//
|
||||
// Tabulator initialization
|
||||
tableMessageLst = new Tabulator("#lstMessagesPanel", {
|
||||
height: "400px",
|
||||
pagination: "local",
|
||||
@@ -105,13 +158,14 @@ $(document).ready(function () {
|
||||
{title: "To", field: "to", width: 400},
|
||||
{title: "Date", field: "sent", sorter: "datetime", width: 150}
|
||||
],
|
||||
rowClick: changeTinyMCE
|
||||
rowClick: rowClick,
|
||||
rowFormatter: rowFormatter
|
||||
});
|
||||
|
||||
//
|
||||
$('.toggleMessages .btn').click(toggleMessages);
|
||||
// Bind radio buttons click event with toggleMessages function
|
||||
$(".toggleMessages .btn").click(toggleMessages);
|
||||
|
||||
//
|
||||
// First retrieve the received message and populate the tabulator
|
||||
getReceivedMessages();
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user