Class ::xowiki::includelet::personal-notification-messages (public)
::xotcl::Class ::xowiki::includelet::personal-notification-messages
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::xowiki::includelet {}
::nsf::object::alloc ::xotcl::Class ::xowiki::includelet::personal-notification-messages {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object}
::xowiki::includelet::personal-notification-messages proc message_dismiss {-notification_id:integer -user_id:integer -ts:integer} {
nsv_dict unset inclass_exam $notification_id $user_id $ts
}
::xowiki::includelet::personal-notification-messages proc modal_message_dialog {-to_user_id:integer,1..n,required {-title "#xowiki.Send_message_to#"} {-adpicon pencil}} {
if {[::template::CSS toolkit] eq "bootstrap5"} {
set data_attribute "data-bs"
set close_button_label ""
set before_close "<h4 class='modal-title' id='configurationModalTitle'>$title</h4>"
set after_close ""
} else {
set data_attribute "data"
set close_button_label {<span aria-hidden="true">&
set before_close ""
set after_close "<h4 class='modal-title' id='configurationModalTitle'>$title</h4>"
}
if {[llength $to_user_id] == 1} {
set id dialog-msg-$to_user_id
set to_user_name [::xo::get_user_name $to_user_id]
} else {
set id dialog-msg-all
set to_user_name " [llength $to_user_id] #xowiki.Participants#"
}
append title " " $to_user_name
foreach to_user_id $to_user_id {
append input_fields [subst {<input type="hidden" name="to_user_id" value="$to_user_id">}]
}
set btnDefault [::template::CSS class btn-default]
return [list link [subst {
<a href="#$id" title="$title" role="button" $data_attribute-toggle="modal" $data_attribute-keyboard="false">
<adp:icon name="$adpicon" aria-hidden="true"></span>
}] dialog [subst {
<div class="modal fade" id='$id' tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<form role="form" class="form-vertical" method="post" action="">
<div class="modal-content">
<div class="modal-header">
$before_close<adp:button type="button" class="close" data-dismiss="modal" aria-label="Close">$close_button_label
</adp:button>$after_close
</div><!-- modal-header -->
<div class="modal-body">
<div class="form-group">
<label for="msg"><adp:icon name="$adpicon">
<input class="form-control" id="msg" name="msg" placeholder="#xowiki.Enter_message#" required autofocus>
</div>
<div class="form-group">
<label class="radio-inline" for="option1">
<input id="option1" name="urgency" value="info" type="radio">
<label class="radio-inline" for="option2">
<input id="option2" name="urgency" value="warning" type="radio" checked>
<label class="radio-inline" for="option3">
<input id="option3" name="urgency" value="danger" type="radio">
</div> <!--form-group-->
$input_fields
</div><!--modal-body-->
<div class="modal-footer">
<adp:button type="button" class="btn btn-default" data-dismiss="modal">
<adp:button type="submit" class="btn btn-default submit" data-id="$id" data-dismiss="modal">
</div>
</div>
</form>
</div><!--modal-dialog-->
</div><!--modal-->
}]]
}
::xowiki::includelet::personal-notification-messages proc get_messages_response {-notification_id:integer -user_id:integer} {
if {[nsv_dict exists inclass_exam $notification_id $user_id]} {
set msgs [nsv_dict get inclass_exam $notification_id $user_id]
} else {
set msgs {}
}
set json {}
foreach {ts msgDict} $msgs {
set msg [string map {\" {\"} \n {<br>}} [dict get $msgDict msg]]
set from [string map {\" {\"} \n {<br>}} [::xo::get_user_name [dict get $msgDict from]]]
set urgency [string map {\" {\"} \n {<br>}} [dict get $msgDict urgency]]
lappend json [subst -nobackslash {{"text": "$msg","ts":$ts,"from":"$from","urgency":"$urgency"}}]
}
return [subst {\[[join $json ,]\]}]
}
::xowiki::includelet::personal-notification-messages proc message_add {-notification_id:integer -to_user_id:integer,1..n -payload:required} {
foreach to_user_id $to_user_id {
nsv_dict set inclass_exam $notification_id $to_user_id [clock microseconds] $payload
}
}
::xowiki::includelet::personal-notification-messages proc modal_message_dialog_register_submit -url:required {
template::add_body_script -script [subst {
document.querySelectorAll('div.modal form .submit').forEach(function(e) {
e.addEventListener('click', function(ev){
ev.preventDefault();
//console.log(ev.target.dataset.id);
var form = document.querySelector('#' + ev.target.dataset.id + ' form');
var data = new FormData(form);
var xhttp = new XMLHttpRequest();
xhttp.open('POST', '$url', true);
xhttp.onload = function () {
//console.log(this.responseText);
};
xhttp.send(data);
});});
}]
}
::xowiki::includelet::personal-notification-messages instproc render {} {
return {
<div id='personal-notification-messages'>
</div>
}
}
::xowiki::includelet::personal-notification-messages instproc initialize {} {
:get_parameters
if {[::template::CSS toolkit] eq "bootstrap5"} {
set data_attribute "data-bs"
set close_button_label ""
} else {
set data_attribute "data"
set close_button_label {<span aria-hidden="true">&
}
template::add_body_script -script [subst {
var inclass_exam_messages_ts = \[\];
var inclass_exam_dismiss_handler = function (ev) {
var ts = ev.target.dataset.ts;
var xhttp = new XMLHttpRequest();
xhttp.open("GET", '$url_dismiss&ts=' + ts, true);
xhttp.send();
};
var inclass_exam_get_data = function () {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", '$url_poll', true);
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//console.log(xhttp.responseText);
var data_array = JSON.parse(xhttp.responseText);
var el = document.querySelector('#personal-notification-messages');
var block = '';
data_array.forEach(function(data) {
if (data.text != "" && typeof data.text !== "undefined" ) {
if (inclass_exam_messages_ts.indexOf(data.ts) == -1) {
var alert = 'alert-' + data.urgency;
block = '<div class="alert ' + alert + ' alert-dismissible" style="width:50%">'
+ '<button id="ts' + data.ts + '" data-ts="' + data.ts + '" href="#" class="[::template::CSS class close]" '
+ '$data_attribute-dismiss="alert" aria-label="close">$close_button_label</button>'
+ '<strong>' + data.from +':</strong> <span>' + data.text + '</span>'
+ '</div>';
inclass_exam_messages_ts.push(data.ts);
}
}
if (block != '') {
el.innerHTML += block;
}
});
document.querySelectorAll('button.[::template::CSS class close]').forEach(function(e) {
//console.log('register dismiss handler ts '+ e.dataset.ts);
e.removeEventListener('click', inclass_exam_dismiss_handler);
e.addEventListener('click', inclass_exam_dismiss_handler);
});
}
};
xhttp.send();
};
inclass_exam_get_data();
(function poll() {
setTimeout(function() {
inclass_exam_get_data();
poll();
}, $poll_interval);
})();
}]
}
::xowiki::includelet::personal-notification-messages instparametercmd __decoration
::xowiki::includelet::personal-notification-messages instparametercmd parameter_declaration
::nsf::relation::set ::xowiki::includelet::personal-notification-messages superclass ::xowiki::Includelet
::nx::slotObj -container slot ::xowiki::includelet::personal-notification-messages
::xowiki::includelet::personal-notification-messages::slot eval {set :__parameter {
{__decoration plain}
{parameter_declaration {
{-url_poll ""}
{-url_dismiss ""}
{-poll_interval 5000}
}}
}}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::includelet::personal-notification-messages::slot::parameter_declaration {set :accessor public
set :configurable true
set :convert false
set :default {
{-url_poll ""}
{-url_dismiss ""}
{-poll_interval 5000}
}
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::includelet::personal-notification-messages
set :incremental 0
set :manager ::xowiki::includelet::personal-notification-messages::slot::parameter_declaration
set :methodname parameter_declaration
set :multiplicity 1..1
set :name parameter_declaration
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::includelet::personal-notification-messages::slot::__decoration {set :accessor public
set :configurable true
set :convert false
set :default plain
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::includelet::personal-notification-messages
set :incremental 0
set :manager ::xowiki::includelet::personal-notification-messages::slot::__decoration
set :methodname __decoration
set :multiplicity 1..1
set :name __decoration
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]