|
|
@@ -707,38 +707,10 @@ function tblMsgsLoadMoreRows(n) {
|
|
|
}
|
|
|
|
|
|
public function _testViewMsg($msg) {
|
|
|
- /* $msg = {_raw: {A_RECORD_CREATE_AUTHOR: "plabudda",
|
|
|
- A_RECORD_CREATE_DATE: "2015-10-26 12:20:05",
|
|
|
- A_RECORD_DELETE_AUTHOR: "",
|
|
|
- A_RECORD_DELETE_DATE: null,
|
|
|
- A_RECORD_UPDATE_AUTHOR: "plabudda",
|
|
|
- A_RECORD_UPDATE_DATE: "2015-11-02 12:44:59",
|
|
|
- A_STATUS: "NORMAL",
|
|
|
- ID: "67",
|
|
|
- actionExecutedTime: "2015-11-02 12:44:59",
|
|
|
- actionNotes: "",
|
|
|
- app_className: "TableMsgs",
|
|
|
- msg: "test Y",
|
|
|
- msgType: "info",
|
|
|
- uiTargetName: "TEST_PERMS.31",
|
|
|
- uiTargetType: "default_db_table_record",
|
|
|
- userTargetName: "plabudda",
|
|
|
- userTargetType: "user"}
|
|
|
- _read: true,
|
|
|
- idRow: "31",
|
|
|
- message: "test Y",
|
|
|
- tblName: "TEST_PERMS",
|
|
|
- type: "info",
|
|
|
- usrLogin: "plabudda"} */
|
|
|
- $message = new stdClass();
|
|
|
- $message->id = $msg['_raw']->ID;
|
|
|
- $message->idThread = $msg['_raw']->ID;// TODO: ID_THREAD
|
|
|
- $message->idReplyTo = $msg['_raw']->ID;// TODO: ID_REPLY_TO
|
|
|
- $message->message = $msg['_raw']->msg;
|
|
|
- $message->type = $msg['_raw']->msgType;
|
|
|
- $message->author = $msg['_raw']->A_RECORD_CREATE_AUTHOR;
|
|
|
- $message->created = $msg['_raw']->A_RECORD_CREATE_DATE;
|
|
|
- $message->_read = $msg['_read'];
|
|
|
+ $uiTargetName = $msg['_raw']->uiTargetName;
|
|
|
+ $uiTargetType = $msg['_raw']->uiTargetType;
|
|
|
+ $replyLink = "index.php?_route=UserMsgs&_task=reply&uiTargetName={$uiTargetName}&uiTargetType={$uiTargetType}";
|
|
|
+ $message = $this->_convertMessageToJson($msg['_raw']);
|
|
|
$messageList = array($message);
|
|
|
?>
|
|
|
<link rel="stylesheet" href="./stuff/widget-select.css">
|
|
|
@@ -778,31 +750,28 @@ function frmTestSubmit(frm) {
|
|
|
msgs: <?php echo json_encode($messageList); ?>,
|
|
|
fetchMessages: (function() {
|
|
|
var _msgsXhr = null;
|
|
|
- return function(input, callback) {
|
|
|
+ return function(reqData, callback) {
|
|
|
if (_msgsXhr && _msgsXhr.state() === 'pending') {
|
|
|
_msgsXhr.abort();
|
|
|
_msgsXhr = null;
|
|
|
}
|
|
|
_msgsXhr = $.ajax({
|
|
|
url: 'index.php?_route=UserMsgs&_task=getMessagesById&id=<?php echo $message->id; ?>',
|
|
|
+ data: reqData,
|
|
|
dataType: 'json'
|
|
|
});
|
|
|
_msgsXhr.done(function(data, textStatus, jqXHR) {
|
|
|
- if (data && data.length > 0) {
|
|
|
- var options = [];
|
|
|
- data.forEach(function(item) {
|
|
|
- options.push({value: item.id, label: item.name});
|
|
|
- });
|
|
|
- callback(null, {options: options});
|
|
|
+ if (data && data.msgs && data.msgs.length > 0) {
|
|
|
+ callback(null, {msgs: data.msgs});
|
|
|
} else {
|
|
|
- callback(null, {options: []});//"Error no data!");
|
|
|
+ callback(null, {msgs: []});//"Error no data!");
|
|
|
}
|
|
|
});
|
|
|
_msgsXhr.fail(function() {
|
|
|
callback(null, {options: []});//"Error no data!");
|
|
|
});
|
|
|
_msgsXhr.always(function() {
|
|
|
- _userXhr = null;
|
|
|
+ _msgsXhr = null;
|
|
|
});
|
|
|
};
|
|
|
})(),
|
|
|
@@ -868,22 +837,31 @@ function frmTestSubmit(frm) {
|
|
|
})(),
|
|
|
saveReply: function(data, callback) {
|
|
|
console.log('#widget-msg-tree/MsgThread::saveReply: data:', data, 'callback', callback);
|
|
|
- // TODO: send data
|
|
|
- setTimeout(function() {
|
|
|
- console.log('#widget-msg-tree/MsgThread::saveReply: after 500ms data:', data, 'callback', callback);
|
|
|
- var newId = 1000 + (testNewRecordCounter++),
|
|
|
- newRecord = {
|
|
|
- id: newId,
|
|
|
- author: 'test13',
|
|
|
- created: '2015-10-22 10:36:52',
|
|
|
- to: 'plabudda',
|
|
|
- metaInfo: 'do plabudda',
|
|
|
- message: 'test added newId('+newId+')'
|
|
|
- }
|
|
|
- ;
|
|
|
- //callback(null, {message: 'Nie udało się zapisać wiadomości', type: 'danger'});
|
|
|
- callback(null, {message: 'Saved', type: 'success', record: newRecord});
|
|
|
- }, 500);
|
|
|
+ $.ajax({
|
|
|
+ url: '<?php echo $replyLink; ?>',
|
|
|
+ method: 'POST',
|
|
|
+ data: data,
|
|
|
+ dataType: 'json'
|
|
|
+ })
|
|
|
+ .done(function(data, textStatus, jqXHR) {
|
|
|
+ var returnData = {message: '', type: 'danger'};
|
|
|
+ if (data && data.record) {
|
|
|
+ returnData.msg = data.msg || 'Wysłano wiadomość';
|
|
|
+ returnData.record = data.record;
|
|
|
+ returnData.type = 'success';
|
|
|
+ } else if (data.validateErrors) {
|
|
|
+ returnData.msg = data.msg || 'Wystąpiły błędy w formularzu';
|
|
|
+ returnData.type = 'warning';
|
|
|
+ returnData.validateErrors = data.validateErrors;
|
|
|
+ } else {
|
|
|
+ returnData.msg = data.msg || 'Nie udało się wysłać wiadomości!';
|
|
|
+ returnData.type = 'danger';
|
|
|
+ }
|
|
|
+ callback(null, returnData);
|
|
|
+ })
|
|
|
+ .fail(function() {
|
|
|
+ callback(null, {message: 'Nie udało się wysłać wiadomości!', type: 'danger'});
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
// jQuery("#widget-msg-tree").on('change', function(e, data) {
|
|
|
@@ -893,8 +871,119 @@ function frmTestSubmit(frm) {
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
+ public function _convertMessageToJson($rawMsg) {
|
|
|
+ /* $msg = {_raw: {A_RECORD_CREATE_AUTHOR: "plabudda",
|
|
|
+ A_RECORD_CREATE_DATE: "2015-10-26 12:20:05",
|
|
|
+ A_RECORD_DELETE_AUTHOR: "",
|
|
|
+ A_RECORD_DELETE_DATE: null,
|
|
|
+ A_RECORD_UPDATE_AUTHOR: "plabudda",
|
|
|
+ A_RECORD_UPDATE_DATE: "2015-11-02 12:44:59",
|
|
|
+ A_STATUS: "NORMAL",
|
|
|
+ ID: "67",
|
|
|
+ actionExecutedTime: "2015-11-02 12:44:59",
|
|
|
+ actionNotes: "",
|
|
|
+ app_className: "TableMsgs",
|
|
|
+ msg: "test Y",
|
|
|
+ msgType: "info",
|
|
|
+ uiTargetName: "TEST_PERMS.31",
|
|
|
+ uiTargetType: "default_db_table_record",
|
|
|
+ userTargetName: "plabudda",
|
|
|
+ userTargetType: "user"}
|
|
|
+ _read: true,
|
|
|
+ idRow: "31",
|
|
|
+ message: "test Y",
|
|
|
+ tblName: "TEST_PERMS",
|
|
|
+ type: "info",
|
|
|
+ usrLogin: "plabudda"} */
|
|
|
+ $message = new stdClass();
|
|
|
+ $message->id = $rawMsg->ID;
|
|
|
+ $message->idThread = $rawMsg->idThread;// TODO: ID_THREAD
|
|
|
+ $message->idReplyTo = $rawMsg->idReplyTo;// TODO: ID_REPLY_TO
|
|
|
+ $message->message = $rawMsg->msg;
|
|
|
+ $message->type = $rawMsg->msgType;
|
|
|
+ $message->to = $rawMsg->userTargetName;
|
|
|
+ $message->toType = $rawMsg->userTargetType;
|
|
|
+ $message->author = $rawMsg->A_RECORD_CREATE_AUTHOR;
|
|
|
+ $message->created = $rawMsg->A_RECORD_CREATE_DATE;
|
|
|
+ $message->_read = false;//TODO: $msg['_read'];
|
|
|
+ return $message;
|
|
|
+ }
|
|
|
+
|
|
|
public function getMessagesByIdAction() {
|
|
|
+ try {
|
|
|
+ $id = V::get('id', '', $_GET, 'int');
|
|
|
+ $idLastMsg = V::get('idLastMsg', '', $_GET, 'int');
|
|
|
+ if ($id <= 0) throw new Exception("Wrong param id!");
|
|
|
+
|
|
|
+ $sqlLimit = 10;// TODO: 100?
|
|
|
+ $ds = DB::getDataSource();
|
|
|
+ $sql = "
|
|
|
+ select m.*
|
|
|
+ from `CRM_UI_MSGS` m
|
|
|
+ where m.`idThread` = {$id}
|
|
|
+ and m.`ID` > {$idLastMsg}
|
|
|
+ limit {$sqlLimit}
|
|
|
+ ";
|
|
|
+ $moreMsgs = $ds->getListByQuery($sql);
|
|
|
+
|
|
|
+ $response = new stdClass();
|
|
|
+ $response->msg = "Nowe wiadomości";
|
|
|
+ $response->type = 'success';
|
|
|
+ $response->msgs = array();
|
|
|
+ foreach ($moreMsgs as $msg) {
|
|
|
+ $response->msgs[] = $this->_convertMessageToJson($msg);
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $response = new stdClass();
|
|
|
+ $response->msg = "Wystąpiły błędy: " . $e->getMessage();
|
|
|
+ $response->type = 'danger';
|
|
|
+ }
|
|
|
+ echo json_encode($response);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function replyAction() {
|
|
|
+ try {
|
|
|
+ $uiTargetType = V::get('uiTargetType', '', $_GET);
|
|
|
+ $uiTargetName = V::get('uiTargetName', '', $_GET);
|
|
|
+ $response = $this->_reply($uiTargetType, $uiTargetName, $_POST);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $response = new stdClass();
|
|
|
+ $response->msg = "Wystąpiły błędy: " . $e->getMessage();
|
|
|
+ $response->type = 'danger';
|
|
|
+ }
|
|
|
+ echo json_encode($response);
|
|
|
+ }
|
|
|
|
|
|
+ public function _reply($uiTargetType, $uiTargetName, $args) {
|
|
|
+ $ds = DB::getDataSource();
|
|
|
+ $newMsg = array();
|
|
|
+ $newMsg['idReplyTo'] = V::get('idReplyTo', '', $args, 'int');
|
|
|
+ $newMsg['msg'] = V::get('message', '', $args);
|
|
|
+ $newMsg['msgType'] = V::get('msgType', 'info', $args);
|
|
|
+ $newMsg['userTargetType'] = V::get('toType', '', $args);
|
|
|
+ $newMsg['userTargetName'] = V::get('to', '', $args);
|
|
|
+ $newMsg['A_RECORD_CREATE_DATE'] = 'NOW()';
|
|
|
+ $newMsg['A_RECORD_CREATE_AUTHOR'] = User::getLogin();
|
|
|
+ $newMsg['app_className'] = 'TableMsgs';
|
|
|
+ //DBG::_(true, true, "newMsg", $newMsg, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+
|
|
|
+ if ($newMsg['idReplyTo'] <= 0) throw new Exception("Wrong id reply to msg");
|
|
|
+ $parentMsg = $ds->getById('CRM_UI_MSGS', $newMsg['idReplyTo']);
|
|
|
+ if (!$parentMsg) throw new Exception("Nie znaleziono wiadomości");
|
|
|
+
|
|
|
+ $newMsg['idThread'] = ($parentMsg->idThread > 0)? $parentMsg->idThread : $parentMsg->ID;
|
|
|
+ $newMsg['uiTargetType'] = $uiTargetType;// TODO:? $parentMsg->uiTargetType
|
|
|
+ $newMsg['uiTargetName'] = $uiTargetName;// TODO:? $parentMsg->uiTargetName
|
|
|
+
|
|
|
+ $insertedId = $ds->insert('CRM_UI_MSGS', $newMsg);
|
|
|
+ if (!$insertedId) throw new Exception("Nie udało się utworzyć rekordu");
|
|
|
+ $msgAdded = $ds->getById('CRM_UI_MSGS', $insertedId);
|
|
|
+
|
|
|
+ $response = new stdClass();
|
|
|
+ $response->msg = "Wysłano wiadomość";
|
|
|
+ $response->type = 'success';
|
|
|
+ $response->record = $msgAdded;
|
|
|
+ return $response;
|
|
|
}
|
|
|
|
|
|
public function removeMsgAction() {
|