diff --git a/application/controllers/system/messages/MessageClient.php b/application/controllers/system/messages/MessageClient.php index f7bc760ad..a0cc5c518 100644 --- a/application/controllers/system/messages/MessageClient.php +++ b/application/controllers/system/messages/MessageClient.php @@ -18,6 +18,14 @@ class MessageClient extends FHC_Controller // Loads model CLMessagesModel which contains the GUI logic $this->load->model('CL/Messages_model', 'CLMessagesModel'); + + // Phrases used in loaded views + $this->loadPhrases( + array( + 'global', + 'ui' + ) + ); } /** @@ -38,6 +46,17 @@ class MessageClient extends FHC_Controller $this->load->view('system/messages/ajaxWrite', $this->CLMessagesModel->prepareAjaxWrite()); } + /** + * Starts the GUI used to reply to a received personal message + */ + public function writeReply() + { + $token = $this->input->get('token'); + + // Loads the view to reply to a message + $this->load->view('system/messages/ajaxWriteReply', $this->CLMessagesModel->prepareAjaxWriteReply($token)); + } + /** * Returns JSON that that contains all the received messages by the currently logged user */ @@ -66,6 +85,20 @@ class MessageClient extends FHC_Controller $this->outputJson($this->CLMessagesModel->sendToOrganisationUnit($receiverOU, $subject, $body)); } + /** + * Sends a message to an organisation unit + */ + public function sendMessageReply() + { + $receiver_id = $this->input->post('receiver_id'); + $relationmessage_id = $this->input->post('relationmessage_id'); + $token = $this->input->post('token'); + $subject = $this->input->post('subject'); + $body = $this->input->post('body'); + + $this->outputJson($this->CLMessagesModel->sendReply($receiver_id, $subject, $body, $relationmessage_id, $token)); + } + /** * Set a message as read */ diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 18b958e14..9224996c8 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -272,10 +272,17 @@ class MessageLib // If NOT found then insert the read status if (!$found) { + $uid = null; + if (!isEmptyString($messageTokenResult[0]->uid)) + { + $uid = $messageTokenResult[0]->uid; + } + $statusData = array( 'message_id' => getData($messageTokenResult)[0]->message_id, 'person_id' => getData($messageTokenResult)[0]->receiver_id, - 'status' => MSG_STATUS_READ + 'status' => MSG_STATUS_READ, + 'insertvon' => $uid ); $messageTokenResultIns = $this->_ci->MsgStatusModel->insert($statusData); @@ -383,6 +390,15 @@ class MessageLib // Starts database transaction $this->_ci->db->trans_start(false); + $this->_ci->load->model('person/Benutzer_model', 'BenutzerModel'); + + $uid = null; + $benutzerDB = $this->_ci->BenutzerModel->loadWhere(array('person_id' => $sender_id)); + if (hasData($benutzerDB)) + { + $uid = getData($benutzerDB)[0]->uid; + } + // Store message information in tbl_msg_message $messageData = array( 'person_id' => $sender_id, @@ -413,7 +429,8 @@ class MessageLib $statusData = array( 'message_id' => $messageId, 'person_id' => $receiver_id, - 'status' => MSG_STATUS_UNREAD + 'status' => MSG_STATUS_UNREAD, + 'insertvon' => $uid ); $saveMessageResult = $this->_ci->MsgStatusModel->insert($statusData); } @@ -511,7 +528,17 @@ class MessageLib if (isError($messageResult)) return $messageResult; // if an error occured then return it if (!hasData($messageResult)) return error('No data found with the given message id'); // if no data found then return an error - return $this->_sendNotice(getData($messageResult)); + $messages = getData($messageResult); + if (count($messages) == 1 && $messages[0]->receiver_id == $this->_ci->config->item(self::CFG_SYSTEM_PERSON_ID)) + { + $messages = $this->_ci->RecipientModel->getReceivedMessagesByOE( + $messages[0]->oe_kurzbz, + $this->_ci->config->item(MessageLib::CFG_OU_RECEIVERS), + self::EMAIL_KONTAKT_TYPE + ); + } + + return $this->_sendNotice($messages); } /** @@ -614,11 +641,13 @@ class MessageLib // Checks if sender is fine $sender = $this->_getSender($sender_id); if (!hasData($sender)) return $sender; + // Checks if the sender and receiver organisation unit are valid if (($receiversOU != null && !$this->_ouExists($receiversOU)) || ($senderOU != null && !$this->_ouExists($senderOU))) { return error('The given organisation unit is not valid', MSG_ERR_INVALID_OU); } + // Checks subjects if (isEmptyString($subject)) return error('The given subject is an empty string', MSG_ERR_INVALID_SUBJECT); // Checks body diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index e907022aa..7673a6d71 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -62,7 +62,8 @@ class Messages_model extends CI_Model $statusData = array( 'message_id' => $message_id, 'person_id' => $person_id, - 'status' => MSG_STATUS_READ + 'status' => MSG_STATUS_READ, + 'insertvon' => getAuthUID() ); return $this->MsgStatusModel->insert($statusData); // insert and return result @@ -83,25 +84,61 @@ class Messages_model extends CI_Model { foreach (getData($ouResult) as $ou) { - $ouOptions .= sprintf("\n".'', $ou->oe_kurzbz, $ou->bezeichnung); + $ouOptions .= sprintf( + "\n".'', + is_numeric($ou->prestudent_id) ? $ou->oe_kurzbz : 'infocenter', + $ou->bezeichnung + ); } } return array('organisationUnitOptions' => $ouOptions); } + /** + * Prepares data for the view system/messages/ajaxWriteReply + */ + public function prepareAjaxWriteReply($token) + { + if (isEmptyString($token)) show_error('The given token is not valid'); + + // Retrieves message using the given token + $messageResult = $this->MessageTokenModel->getMessageByToken($token); + if (isError($messageResult)) show_error('An error occurred while loading this page, please contact the site administrator'); + + if (hasData($messageResult)) + { + $message = getData($messageResult)[0]; // Found message data + + // Retrieves message sender information + $senderResult = $this->MessageTokenModel->getSenderData($message->sender_id); + if (isError($senderResult)) show_error('An error occurred while loading this page, please contact the site administrator'); + + if (hasData($senderResult)) + { + $sender = getData($senderResult)[0]; // Found sender data + + $replySubject = self::REPLY_SUBJECT_PREFIX.$message->subject; + $replyBody = $this->_getReplyBody($message->body, $sender->vorname, $sender->nachname, $message->sent); + + return array ( + 'receiver' => $sender->vorname.' '.$sender->nachname, // yep! the sender of the sent message is the receiver of the reply message + 'subject' => $replySubject, + 'body' => $replyBody, + 'receiver_id' => $message->sender_id, + 'relationmessage_id' => $message->message_id, + 'token' => $token + ); + } + } + } + /** * Prepares data for the view system/messages/ajaxRead * If everything is fine returns a list of received messages (objects) */ public function prepareAjaxReadReceived() { - // Name and surname of the logged user - $loggedUserName = getAuthFirstname().' '.getAuthSurname(); - - // If empty then use a hard coded one - if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; - // Retrieves received messages for the logged user and its organisation units $receivedMessagesResult = $this->RecipientModel->getReceivedMessages( getAuthPersonId(), @@ -127,6 +164,7 @@ class Messages_model extends CI_Model $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $receivedMessage->status; $jsonRecord->statusPersonId = $receivedMessage->statuspersonid; + $jsonRecord->token = $receivedMessage->token; $jsonArray[] = $jsonRecord; } @@ -143,12 +181,6 @@ class Messages_model extends CI_Model */ public function prepareAjaxReadSent() { - // Name and surname of the logged user - $loggedUserName = getAuthFirstname().' '.getAuthSurname(); - - // If empty then use a hard coded one - if (isEmptyString($loggedUserName)) $loggedUserName = 'Me'; - // Retrieves sent messages from the logged user $sentMessagesResult = $this->RecipientModel->getSentMessages(getAuthPersonId()); if (isError($sentMessagesResult)) return $sentMessagesResult; // If an error occurred return it @@ -164,11 +196,20 @@ class Messages_model extends CI_Model $jsonRecord->message_id = $sentMessage->message_id; $jsonRecord->subject = $sentMessage->subject; $jsonRecord->body = $sentMessage->body; - $jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname; $sentDate = new DateTime($sentMessage->sent); $jsonRecord->sent = $sentDate->format('d/m/Y H:i:s'); $jsonRecord->status = $sentMessage->status; $jsonRecord->statusPersonId = $sentMessage->statuspersonid; + $jsonRecord->token = $sentMessage->token; + + if ($sentMessage->person_id == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID)) + { + $jsonRecord->to = $sentMessage->sg; + } + else + { + $jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname; + } $jsonArray[] = $jsonRecord; } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index b4c756e52..b1ae9b8e9 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -529,13 +529,23 @@ class Prestudent_model extends DB_Model */ public function getOrganisationunitsByPersonId($person_id) { - $query = 'SELECT o.oe_kurzbz, o.bezeichnung + $query = 'SELECT o.oe_kurzbz, + sg.bezeichnung, + ps.prestudent_id FROM public.tbl_prestudent p - JOIN public.tbl_studiengang s USING(studiengang_kz) + JOIN public.tbl_studiengang sg USING(studiengang_kz) JOIN public.tbl_organisationseinheit o USING(oe_kurzbz) + LEFT JOIN ( + SELECT prestudent_id + FROM public.tbl_prestudentstatus + WHERE bestaetigtam IS NOT NULL + AND status_kurzbz = \'Interessent\' + ) ps USING(prestudent_id) WHERE p.person_id = ? - GROUP BY o.oe_kurzbz, o.bezeichnung - ORDER BY o.bezeichnung'; + GROUP BY o.oe_kurzbz, + sg.bezeichnung, + ps.prestudent_id + ORDER BY sg.bezeichnung'; return $this->execQuery($query, array($person_id)); } diff --git a/application/models/system/Recipient_model.php b/application/models/system/Recipient_model.php index 46cf0e36f..76a0bf435 100644 --- a/application/models/system/Recipient_model.php +++ b/application/models/system/Recipient_model.php @@ -57,11 +57,13 @@ class Recipient_model extends DB_Model m.oe_kurzbz, s.status, s.statusinfo, - s.insertamum as statusamum + s.insertamum as statusamum, + b.uid FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id) JOIN ( SELECT * FROM public.tbl_msg_status WHERE status < ? ORDER BY insertamum DESC, status DESC - ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id) + ) s ON (r.message_id = s.message_id AND r.person_id = s.person_id), + LEFT JOIN public.tbl_benutzer b USING(person_id) WHERE r.token = ? LIMIT 1'; @@ -217,7 +219,8 @@ class Recipient_model extends DB_Model mr.token, mm.subject, mm.body, - mr.sentinfo + mr.sentinfo, + mr.oe_kurzbz FROM public.tbl_msg_recipient mr INNER JOIN public.tbl_msg_message mm USING (message_id) LEFT JOIN ( SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? @@ -315,11 +318,12 @@ class Recipient_model extends DB_Model p.vorname, p.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + mr.token FROM public.tbl_msg_recipient mr JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id) - JOIN public.tbl_person p ON (p.person_id = mr.person_id) + JOIN public.tbl_person p ON (p.person_id = mm.person_id) WHERE mr.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -330,7 +334,8 @@ class Recipient_model extends DB_Model mr.sent, p.vorname, p.nachname, - ms.person_id + ms.person_id, + mr.token UNION -- Messages sent to a person that belongs to the recipient organisation unit SELECT mrou.message_id, @@ -341,14 +346,21 @@ class Recipient_model extends DB_Model pr.vorname, pr.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + mrou.token FROM public.tbl_person p JOIN public.tbl_benutzer b ON (b.person_id = p.person_id) - JOIN (SELECT uid, oe_kurzbz FROM public.tbl_benutzerfunktion WHERE funktion_kurzbz IN ?) bf ON (bf.uid = b.uid) + JOIN ( + SELECT uid, oe_kurzbz + FROM public.tbl_benutzerfunktion + WHERE (datum_von IS NULL OR datum_von <= NOW()) + AND (datum_bis IS NULL OR datum_bis >= NOW()) + AND funktion_kurzbz IN ? + ) bf ON (bf.uid = b.uid) JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) - JOIN public.tbl_person pr ON (pr.person_id = mrou.person_id) + JOIN public.tbl_person pr ON (pr.person_id = mm.person_id) WHERE p.person_id = ? AND mrou.sent IS NOT NULL AND mrou.sentinfo IS NULL @@ -359,12 +371,78 @@ class Recipient_model extends DB_Model mrou.sent, pr.vorname, pr.nachname, - ms.person_id + ms.person_id, + mrou.token ORDER BY sent DESC'; return $this->execQuery($sql, array($person_id, $functions, $person_id)); } + /** + * Gets only the recieved messages from an organisation unit where this person plays a role given by the parameter functions + */ + public function getReceivedMessagesByOE($oe_kurzbz, $functions, $kontaktType) + { + // Messages sent to a person that belongs to the recipient organisation unit + $sql = 'SELECT mm.message_id, + mm.subject, + mm.body, + mrou.person_id as receiver_id, + mrou.sentinfo, + mrou.token, + mrou.oe_kurzbz, + ks.kontakt as sender, + kr.kontakt as receiver, + mu.mitarbeiter_uid as employeeContact, + mb.mitarbeiter_uid as senderemployeeContact + FROM public.tbl_benutzer b + JOIN ( + SELECT uid, oe_kurzbz + FROM public.tbl_benutzerfunktion + WHERE (datum_von IS NULL OR datum_von <= NOW()) + AND (datum_bis IS NULL OR datum_bis >= NOW()) + AND funktion_kurzbz IN ? + ) bf ON (bf.uid = b.uid) + JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz) + JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id) + JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id) + JOIN public.tbl_person pr ON (pr.person_id = mm.person_id) + LEFT JOIN ( + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? + ) ks ON (ks.person_id = mm.person_id) + LEFT JOIN ( + SELECT person_id, kontakt FROM public.tbl_kontakt WHERE zustellung = true AND kontakttyp = ? + ) kr ON (kr.person_id = mrou.person_id) + LEFT JOIN ( + SELECT b.person_id, + m.mitarbeiter_uid + FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) + WHERE b.aktiv = TRUE + ) mu ON (mu.person_id = mrou.person_id) + LEFT JOIN ( + SELECT b.person_id, + m.mitarbeiter_uid + FROM public.tbl_benutzer b INNER JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid) + WHERE b.aktiv = TRUE + ) mb ON (mb.person_id = mm.person_id) + WHERE bf.oe_kurzbz = ? + AND mrou.sent IS NULL + AND mrou.sentinfo IS NOT NULL + GROUP BY mm.message_id, + mm.subject, + mm.body, + mrou.person_id, + mrou.sentinfo, + mrou.token, + mrou.oe_kurzbz, + ks.kontakt, + kr.kontakt, + mu.mitarbeiter_uid, + mb.mitarbeiter_uid'; + + return $this->execQuery($sql, array($functions, $kontaktType, $kontaktType, $oe_kurzbz)); + } + /** * Gets all the sent message by the given person */ @@ -375,14 +453,18 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mr.sent, + p.person_id, p.vorname, p.nachname, MAX(ms.status) AS status, - ms.person_id AS statusPersonId + ms.person_id AS statusPersonId, + sg.bezeichnung AS sg, + mr.token FROM public.tbl_msg_message mm JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id) JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND mr.person_id = mr.person_id) JOIN public.tbl_person p ON (p.person_id = mr.person_id) + LEFT JOIN public.tbl_studiengang sg ON (sg.oe_kurzbz = mr.oe_kurzbz) WHERE mm.person_id = ? AND mr.sent IS NOT NULL AND mr.sentinfo IS NULL @@ -391,9 +473,12 @@ class Recipient_model extends DB_Model mm.subject, mm.body, mr.sent, + p.person_id, p.vorname, p.nachname, - ms.person_id + ms.person_id, + sg.bezeichnung, + mr.token ORDER BY mr.sent DESC'; return $this->execQuery($sql, array($person_id)); diff --git a/application/views/system/messages/ajaxRead.php b/application/views/system/messages/ajaxRead.php index f5a733c74..1e4dbd187 100644 --- a/application/views/system/messages/ajaxRead.php +++ b/application/views/system/messages/ajaxRead.php @@ -1,34 +1,56 @@ -load->view( - 'templates/FHC-Header', - array( - 'title' => 'Read personal messages', - 'jquery' => true, - 'jqueryui' => true, - 'bootstrap' => true, - 'fontawesome' => true, - 'sbadmintemplate' => true, - 'momentjs' => true, - 'tabulator' => true, - 'ajaxlib' => true, - 'dialoglib' => true, - 'tinymce' => true, - 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), - 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') - ) - ); -?> - -
-
- - - - -
-
-
-
- - -load->view("templates/FHC-Footer"); ?> +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Read personal messages', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'momentjs' => true, + 'tabulator' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/read.js') + ) + ); +?> + + +
+ + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ + + +load->view("templates/FHC-Footer"); ?> diff --git a/application/views/system/messages/ajaxWriteReply.php b/application/views/system/messages/ajaxWriteReply.php new file mode 100644 index 000000000..25602271c --- /dev/null +++ b/application/views/system/messages/ajaxWriteReply.php @@ -0,0 +1,80 @@ +load->view( + 'templates/FHC-Header', + array( + 'title' => 'Reply to a message', + 'jquery' => true, + 'jqueryui' => true, + 'bootstrap' => true, + 'fontawesome' => true, + 'sbadmintemplate' => true, + 'ajaxlib' => true, + 'dialoglib' => true, + 'tinymce' => true, + 'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messaging/message.css'), + 'customJSs' => array('public/js/bootstrapper.js', 'public/js/messaging/writeReply.js') + ) + ); +?> + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+ +
+   +
+ + + +
+
+
+
+
+
+ + +
+
+
+
+
+ + + + + + +
+
+
+
+
+ + +load->view("templates/FHC-Footer"); ?> diff --git a/public/js/messaging/read.js b/public/js/messaging/read.js index c3b117636..cc463b3f7 100644 --- a/public/js/messaging/read.js +++ b/public/js/messaging/read.js @@ -4,6 +4,7 @@ // Global variable that contains tha tabulator instance var tableMessageLst; +var selectedToggleMessage = "received"; /** * Use DialogLib to display a Generic error @@ -40,7 +41,14 @@ function getSentMessages() */ function changeTinyMCE(row) { - tinyMCE.get("readMessagePanel").setContent(row.getData().body); + if (row == null) + { + tinyMCE.get("readMessagePanel").setContent(''); + } + else + { + tinyMCE.get("readMessagePanel").setContent(row.getData().body); + } } /** @@ -50,8 +58,8 @@ function changeTinyMCE(row) */ function rowClick(e, row) { - // If the message is unread - if (row.getData().status == "0") + // If in received mode and the message is not unread + if (selectedToggleMessage == "received" && row.getData().status == "0") { FHC_AjaxClient.ajaxCallPost( FHC_JS_DATA_STORAGE_OBJECT.called_path + "/setMessageRead", @@ -64,7 +72,8 @@ function rowClick(e, row) if (FHC_AjaxClient.isSuccess(data)) { - rowFormatter(row, "normal"); + rowFormatter(row, "normal"); // format row + row.getData().status = "1"; // update status to read } else { @@ -77,6 +86,12 @@ function rowClick(e, row) ); } + // If NOT in send mode + if (selectedToggleMessage == "received") + { + $("#replyMessage").show(); + } + changeTinyMCE(row); // Change TinyMCE content } @@ -85,8 +100,19 @@ function rowClick(e, row) */ function toggleMessages() { - $(this)[0].id == "received" ? getReceivedMessages() : getSentMessages(); + if ($(this)[0].id == "received") + { + selectedToggleMessage = "received"; + getReceivedMessages(); + } + else + { + selectedToggleMessage = "send"; + $("#replyMessage").hide(); + getSentMessages(); + } + changeTinyMCE(null); // clean tinymce tableMessageLst.redraw(); // redraw table after its content is changed } @@ -119,13 +145,19 @@ function _getMessages(getMessagesURL) if (FHC_AjaxClient.hasData(data)) { - var messages = FHC_AjaxClient.getData(data); + var messages = null; + + try + { + messages = JSON.parse(FHC_AjaxClient.getData(data)); + } + catch (syntaxError) {} if ($.isArray(messages)) { try { - tableMessageLst.replaceData(JSON.parse()); + tableMessageLst.replaceData(messages); } catch (syntaxError) { @@ -141,10 +173,39 @@ function _getMessages(getMessagesURL) } /** - * Start! + * Open new tab/window to write a new message + */ +function writeNewMessage() +{ + window.open("write", "_blank"); +} + +/** + * Open new tab/window to reply to a received message + */ +function replyMessage() +{ + var selectedMessages = tableMessageLst.getSelectedData(); + + if ($.isArray(selectedMessages)) + { + var selectedMessage = selectedMessages[0]; + + window.open("writeReply?token=" + selectedMessage.token, "_blank"); + } + else // + { + FHC_DialogLib.alertInfo("Please select a message"); + } +} + +/** + * Start me up! */ $(document).ready(function () { + $("#replyMessage").hide(); + // TinyMCE initialization tinymce.init({ selector: "#readMessagePanel", @@ -153,14 +214,15 @@ $(document).ready(function () { toolbar: false, statusbar: false, readonly: 1, - autoresize_min_height: 200, + autoresize_min_height: 300, autoresize_bottom_margin: 0 }); // Tabulator initialization tableMessageLst = new Tabulator("#lstMessagesPanel", { - height: "400px", + height: "270px", layout: "fitColumns", + selectable: 1, layoutColumnsOnNewData: true, columns: [ {title: "Subject", field: "subject", responsive: 0}, @@ -175,6 +237,12 @@ $(document).ready(function () { // Bind radio buttons click event with toggleMessages function $("#toggleMessages input").click(toggleMessages); + // Bind write a new message button + $("#writeMessage").click(writeNewMessage); + + // Bind reply to a message button + $("#replyMessage").click(replyMessage); + // First retrieve the received message and populate the tabulator getReceivedMessages(); diff --git a/public/js/messaging/writeReply.js b/public/js/messaging/writeReply.js new file mode 100644 index 000000000..aeb13dc2c --- /dev/null +++ b/public/js/messaging/writeReply.js @@ -0,0 +1,48 @@ +// **************************************************************************************** +// Write a reply to a received message, used by view system/messages/ajaxWriteReply +// **************************************************************************************** + +/** + * + */ +function sendReply() +{ + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + '/sendMessageReply', + { + receiver_id: $('#receiver_id').val(), + relationmessage_id: $('#relationmessage_id').val(), + token: $('#token').val(), + subject: $('#subject').html(), + body: tinyMCE.get("body").getContent() + }, + { + successCallback: function(data, textStatus, jqXHR) { + + FHC_DialogLib.alertSuccess("Message sent succesfully"); + }, + errorCallback: function() { + FHC_DialogLib.alertError("Error"); + }, + veilTimeout: 300 + } + ); +} + +/** + * + */ +$(document).ready(function () { + + // + tinymce.init({ + selector: "#body", + plugins: "autoresize", + autoresize_min_height: 150, + autoresize_max_height: 600, + autoresize_bottom_margin: 10 + }); + + $('#sendButton').click(sendReply); + +});