Added onclik con notification toasts
Former-commit-id: 7d0c7a7cc9dacc0e52c7f362a3301ed87a7205d3
This commit is contained in:
parent
36dd59b250
commit
325f5e8775
|
@ -197,7 +197,6 @@ config_check();
|
|||
if (!isset($_GET['refr'])) {
|
||||
$_GET['refr'] = null;
|
||||
}
|
||||
|
||||
$select = db_process_sql("SELECT autorefresh_white_list,time_autorefresh FROM tusuario WHERE id_user = '".$config['id_user']."'");
|
||||
$autorefresh_list = json_decode($select[0]['autorefresh_white_list']);
|
||||
|
||||
|
@ -398,8 +397,37 @@ config_check();
|
|||
}
|
||||
|
||||
function click_on_notification_toast(event) {
|
||||
// TODO action.
|
||||
document.getElementById(event.target.id).remove();
|
||||
var match = /notification-toast-id-([0-9]+)/.exec(event.target.id);
|
||||
if (!match) {
|
||||
console.error(
|
||||
"Cannot handle toast click event. Id not valid: ",
|
||||
event.target.id
|
||||
);
|
||||
return;
|
||||
}
|
||||
jQuery.post ("ajax.php",
|
||||
{
|
||||
"page" : "godmode/setup/setup_notifications",
|
||||
"mark_notification_as_read" : 1,
|
||||
"message": match[1]
|
||||
},
|
||||
function (data, status) {
|
||||
console.log(data.url)
|
||||
if (!data.result) {
|
||||
console.error("Cannot redirect to URL.");
|
||||
return;
|
||||
}
|
||||
window.location.replace(data.url);
|
||||
document.getElementById(event.target.id).remove();
|
||||
},
|
||||
"json"
|
||||
)
|
||||
.fail(function(xhr, textStatus, errorThrown){
|
||||
console.error(
|
||||
"Failed onclik event on toast. Error: ",
|
||||
xhr.responseText
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function print_toast(title, subtitle, severity, id, onclick) {
|
||||
|
@ -471,17 +499,19 @@ config_check();
|
|||
ball_wrapper.innerHTML = new_ball;
|
||||
|
||||
// Add the new toasts.
|
||||
data.new_notifications.forEach(function(ele) {
|
||||
toast_wrapper.appendChild(
|
||||
print_toast(
|
||||
ele.description,
|
||||
ele.mensaje,
|
||||
ele.criticity,
|
||||
'notification-toast-id-' + ele.id_mensaje,
|
||||
'click_on_notification_toast(event)'
|
||||
)
|
||||
);
|
||||
});
|
||||
if (Array.isArray(data.new_notifications)) {
|
||||
data.new_notifications.forEach(function(ele) {
|
||||
toast_wrapper.appendChild(
|
||||
print_toast(
|
||||
ele.description,
|
||||
ele.mensaje,
|
||||
ele.criticity,
|
||||
'notification-toast-id-' + ele.id_mensaje,
|
||||
'click_on_notification_toast(event)'
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
"json"
|
||||
)
|
||||
|
|
|
@ -125,6 +125,30 @@ if (get_parameter('check_new_notifications', 0)) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (get_parameter('mark_notification_as_read', 0)) {
|
||||
hd("asdfe", true);
|
||||
$message = (int) get_parameter('message', 0);
|
||||
messages_process_read($message);
|
||||
// TODO check read.
|
||||
$url = messages_get_url($message);
|
||||
hd("asdfe 2" . $url, true);
|
||||
// Return false if cannot get the URL.
|
||||
if ($url === false) {
|
||||
echo json_encode(['result' => false]);
|
||||
return;
|
||||
}
|
||||
hd("asdfe 03", true);
|
||||
|
||||
// If there is new messages, get the info.
|
||||
echo json_encode(
|
||||
[
|
||||
'result' => true,
|
||||
'url' => $url,
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Notification table. It is just a wrapper.
|
||||
$table_content = new StdClass();
|
||||
$table_content->data = [];
|
||||
|
|
|
@ -215,7 +215,6 @@ function messages_process_read(
|
|||
bool $read=true
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Check if user has grants to read the message.
|
||||
if (check_notification_readable($message_id) === false) {
|
||||
return false;
|
||||
|
@ -560,3 +559,28 @@ function messages_get_overview_sent(
|
|||
$order
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the URL of a message. If field in db is null, it returs a link to
|
||||
* messages view.
|
||||
*
|
||||
* @param integer $message_id Message id to get URL.
|
||||
*
|
||||
* @return mixed False if fails. A string with URL otherwise.
|
||||
*/
|
||||
function messages_get_url($message_id)
|
||||
{
|
||||
$messages = messages_get_message($message_id);
|
||||
if ($messages === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return URL stored if is set in database.
|
||||
if (isset($messages['url'])) {
|
||||
return $messages['url'];
|
||||
}
|
||||
|
||||
// Return the message direction.
|
||||
return ui_get_full_url('index.php?sec=message_list&sec2=operation/messages/message_edit&read_message=1&id_message='.$message_id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue