Toggle buttons (#2071)

This commit is contained in:
Christophe Maudoux 2020-02-09 18:40:43 +01:00
parent ef01060c54
commit 73a0ec9dc6
24 changed files with 94 additions and 33 deletions

View File

@ -172,6 +172,7 @@ sub defaultValues {
'notificationServerPOST' => 1,
'notificationServerSentAttributes' =>
'uid reference date title subtitle text check',
'notificationsMaxRetrieve' => 3,
'notificationStorage' => 'File',
'notificationStorageOptions' => {
'dirName' => '/var/lib/lemonldap-ng/notifications'

View File

@ -1888,6 +1888,10 @@ qr/^(?:\*\.)?(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][
'default' => 0,
'type' => 'bool'
},
'notificationsMaxRetrieve' => {
'default' => 3,
'type' => 'int'
},
'notificationStorage' => {
'default' => 'File',
'type' => 'PerlModule'

View File

@ -1140,6 +1140,11 @@ sub attributes {
type => 'bool',
documentation => 'Notifications explorer activation',
},
notificationsMaxRetrieve => {
default => 3,
type => 'int',
documentation => 'Max number of displayed notifications',
},
notificationServer => {
default => 0,
type => 'bool',

View File

@ -53,10 +53,11 @@ my @notManagedAttributes = (
# Other ini-only prms
'configStorage', 'status', 'localStorageOptions', 'localStorage',
'max2FDevices', 'max2FDevicesNameLength', 'checkTime',
'mySessionAuthorizedRWKeys', 'handlerInternalCache',
'handlerServiceTokenTTL', 'impersonationPrefix', 'pdataDomain',
'forceGlobalStorageUpgradeOTT', 'forceGlobalStorageIssuerOTT'
'max2FDevices', 'max2FDevicesNameLength', 'checkTime',
'mySessionAuthorizedRWKeys', 'handlerInternalCache',
'handlerServiceTokenTTL', 'impersonationPrefix', 'pdataDomain',
'forceGlobalStorageUpgradeOTT', 'forceGlobalStorageIssuerOTT',
'notificationsMaxRetrieve'
);
# Words used either as attribute name and node title

View File

@ -39,10 +39,13 @@ has module => ( is => 'rw' );
sub init {
my ($self) = @_;
# Declare new route
# Declare new routes
$self->addUnauthRoute( notifback => 'getNotifBack', [ 'POST', 'GET' ] );
$self->addAuthRoute( notifback => 'getNotifBack', ['POST'] )
->addAuthRoute( mynotifs => { '*' => 'myNotifs' }, ['GET'] );
$self->addAuthRoute( notifback => 'getNotifBack', ['POST'] );
$self->addAuthRouteWithRedirect(
mynotifications => { '*' => 'myNotifs' },
['GET']
) if $self->conf->{notificationsExplorer};
if ( $self->conf->{notificationServer} ) {
$self->logger->debug('Notification server enable');
@ -205,9 +208,10 @@ sub retrieveNotifs {
];
@$_notifications = sort {
$a->{reference} cmp $b->{reference}
or $a->{epoch} <=> $b->{epoch}
$b->{epoch} <=> $a->{epoch}
or $a->{reference} cmp $b->{reference}
} @$_notifications;
splice @$_notifications, $self->conf->{notificationsMaxRetrieve};
$self->logger->debug(
scalar @$_notifications . " accepted notifications found" );

View File

@ -16,35 +16,48 @@ displayError = (j, status, err) ->
console.log 'Returned error', res
setMsg res, 'warning'
# Delete function (launched by "view" button)
viewNotif = (notif, epoch) ->
toggle = (button, verif) ->
if verif
$("#myNotification").attr('hidden', 'true')
button.removeClass 'btn-danger'
button.addClass 'btn-success'
else
$("#myNotification").removeAttr('hidden')
$(".btn-danger").each ->
$(this).removeClass 'btn-danger'
$(this).addClass 'btn-success'
button.removeClass 'btn-success'
button.addClass 'btn-danger'
# viewNotif function (launched by "verify" button)
viewNotif = (notif, epoch, button) ->
console.log 'Ref:', notif, 'epoch:', epoch
if notif and epoch
console.log 'Send AJAX request'
$.ajax
type: "GET"
url: "#{portal}mynotifs/#{notif}"
url: "#{portal}mynotifications/#{notif}"
data:
epoch: epoch
dataType: 'json'
#error: displayError
error: displayError
success: (resp) ->
if resp.result
console.log 'Notification:', resp.notification
toggle button, 0
$('#displayNotif').html resp.notification
$("#myNotification").removeAttr('hidden')
$('#notifRef').text(notif)
myDate = new Date(epoch * 1000)
$('#notifEpoch').text(myDate.toLocaleString())
else setMsg 'notificationNotFound', 'warning'
#error: displayError
else setMsg 'notificationRetreiveFailed', 'warning'
# Register "click" events
$(document).ready ->
#$("#myNotification").hide()
$('body').on 'click', '.btn-success', () -> viewNotif ( $(this).attr 'notif' ), ( $(this).attr 'epoch' )
$('#goback').attr 'href', portal
$(".data-epoch").each ->
myDate = new Date($(this).text() * 1000)
$(this).text(myDate.toLocaleString())
$('#goback').attr 'href', portal
$('body').on 'click', '.btn-success', () -> viewNotif ( $(this).attr 'notif' ), ( $(this).attr 'epoch' ), $(this)
$('body').on 'click', '.btn-danger', () -> toggle $(this), 1

View File

@ -5,7 +5,7 @@ LemonLDAP::NG Notifications script
*/
(function() {
var displayError, setMsg, viewNotif;
var displayError, setMsg, toggle, viewNotif;
setMsg = function(msg, level) {
$('#msg').html(window.translate(msg));
@ -27,23 +27,40 @@ LemonLDAP::NG Notifications script
}
};
viewNotif = function(notif, epoch) {
toggle = function(button, verif) {
if (verif) {
$("#myNotification").attr('hidden', 'true');
button.removeClass('btn-danger');
return button.addClass('btn-success');
} else {
$("#myNotification").removeAttr('hidden');
$(".btn-danger").each(function() {
$(this).removeClass('btn-danger');
return $(this).addClass('btn-success');
});
button.removeClass('btn-success');
return button.addClass('btn-danger');
}
};
viewNotif = function(notif, epoch, button) {
console.log('Ref:', notif, 'epoch:', epoch);
if (notif && epoch) {
console.log('Send AJAX request');
return $.ajax({
type: "GET",
url: portal + "mynotifs/" + notif,
url: portal + "mynotifications/" + notif,
data: {
epoch: epoch
},
dataType: 'json',
error: displayError,
success: function(resp) {
var myDate;
if (resp.result) {
console.log('Notification:', resp.notification);
toggle(button, 0);
$('#displayNotif').html(resp.notification);
$("#myNotification").removeAttr('hidden');
$('#notifRef').text(notif);
myDate = new Date(epoch * 1000);
return $('#notifEpoch').text(myDate.toLocaleString());
@ -58,15 +75,18 @@ LemonLDAP::NG Notifications script
};
$(document).ready(function() {
$('body').on('click', '.btn-success', function() {
return viewNotif($(this).attr('notif'), $(this).attr('epoch'));
});
$('#goback').attr('href', portal);
return $(".data-epoch").each(function() {
$(".data-epoch").each(function() {
var myDate;
myDate = new Date($(this).text() * 1000);
return $(this).text(myDate.toLocaleString());
});
$('#goback').attr('href', portal);
$('body').on('click', '.btn-success', function() {
return viewNotif($(this).attr('notif'), $(this).attr('epoch'), $(this));
});
return $('body').on('click', '.btn-danger', function() {
return toggle($(this), 1);
});
});
}).call(this);

View File

@ -1 +1 @@
(function(){var i,t;i=function(t,e){return $("#msg").html(window.translate(t)),$("#color").removeClass("message-positive message-warning alert-success alert-warning"),$("#color").addClass("message-"+e),"positive"===e&&(e="success"),$("#color").addClass("alert-"+e)},t=function(o,n){return console.log("Ref:",o,"epoch:",n),o&&n?(console.log("Send AJAX request"),$.ajax({type:"GET",url:portal+"mynotifs/"+o,data:{epoch:n},dataType:"json",success:function(t){var e;return t.result?(console.log("Notification:",t.notification),$("#displayNotif").html(t.notification),$("#myNotification").removeAttr("hidden"),$("#notifRef").text(o),e=new Date(1e3*n),$("#notifEpoch").text(e.toLocaleString())):i("notificationNotFound","warning")}})):i("notificationRetreiveFailed","warning")},$(document).ready(function(){return $("body").on("click",".btn-success",function(){return t($(this).attr("notif"),$(this).attr("epoch"))}),$("#goback").attr("href",portal),$(".data-epoch").each(function(){var t;return t=new Date(1e3*$(this).text()),$(this).text(t.toLocaleString())})})}).call(this);
(function(){var t,s,a,e;s=function(t,e){return $("#msg").html(window.translate(t)),$("#color").removeClass("message-positive message-warning alert-success alert-warning"),$("#color").addClass("message-"+e),"positive"===e&&(e="success"),$("#color").addClass("alert-"+e)},t=function(t,e,n){var o;if(console.log("Error",n),(o=JSON.parse(t.responseText))&&o.error)return console.log("Returned error",o),s(o,"warning")},a=function(t,e){return e?($("#myNotification").attr("hidden","true"),t.removeClass("btn-danger"),t.addClass("btn-success")):($("#myNotification").removeAttr("hidden"),$(".btn-danger").each(function(){return $(this).removeClass("btn-danger"),$(this).addClass("btn-success")}),t.removeClass("btn-success"),t.addClass("btn-danger"))},e=function(n,o,r){return console.log("Ref:",n,"epoch:",o),n&&o?(console.log("Send AJAX request"),$.ajax({type:"GET",url:portal+"mynotifications/"+n,data:{epoch:o},dataType:"json",error:t,success:function(t){var e;return t.result?(console.log("Notification:",t.notification),a(r,0),$("#displayNotif").html(t.notification),$("#notifRef").text(n),e=new Date(1e3*o),$("#notifEpoch").text(e.toLocaleString())):s("notificationNotFound","warning")}})):s("notificationRetreiveFailed","warning")},$(document).ready(function(){return $(".data-epoch").each(function(){var t;return t=new Date(1e3*$(this).text()),$(this).text(t.toLocaleString())}),$("#goback").attr("href",portal),$("body").on("click",".btn-success",function(){return e($(this).attr("notif"),$(this).attr("epoch"),$(this))}),$("body").on("click",".btn-danger",function(){return a($(this),1)})})}).call(this);

View File

@ -1 +1 @@
{"version":3,"sources":["lemonldap-ng-portal/site/htdocs/static/common/js/notifications.js"],"names":["setMsg","viewNotif","msg","level","$","html","window","translate","removeClass","addClass","notif","epoch","console","log","ajax","type","url","portal","data","dataType","success","resp","myDate","result","notification","removeAttr","text","Date","toLocaleString","document","ready","on","this","attr","each","call"],"mappings":"CAMA,WACE,IAAkBA,EAAQC,EAE1BD,EAAS,SAASE,EAAKC,GAOrB,OANAC,EAAE,QAAQC,KAAKC,OAAOC,UAAUL,IAChCE,EAAE,UAAUI,YAAY,gEACxBJ,EAAE,UAAUK,SAAS,WAAaN,GACpB,aAAVA,IACFA,EAAQ,WAEHC,EAAE,UAAUK,SAAS,SAAWN,IAazCF,EAAY,SAASS,EAAOC,GAE1B,OADAC,QAAQC,IAAI,OAAQH,EAAO,SAAUC,GACjCD,GAASC,GACXC,QAAQC,IAAI,qBACLT,EAAEU,KAAK,CACZC,KAAM,MACNC,IAAKC,OAAS,YAAcP,EAC5BQ,KAAM,CACJP,MAAOA,GAETQ,SAAU,OACVC,QAAS,SAASC,GAChB,IAAIC,EACJ,OAAID,EAAKE,QACPX,QAAQC,IAAI,gBAAiBQ,EAAKG,cAClCpB,EAAE,iBAAiBC,KAAKgB,EAAKG,cAC7BpB,EAAE,mBAAmBqB,WAAW,UAChCrB,EAAE,aAAasB,KAAKhB,GACpBY,EAAS,IAAIK,KAAa,IAARhB,GACXP,EAAE,eAAesB,KAAKJ,EAAOM,mBAE7B5B,EAAO,uBAAwB,eAKrCA,EAAO,6BAA8B,YAIhDI,EAAEyB,UAAUC,MAAM,WAKhB,OAJA1B,EAAE,QAAQ2B,GAAG,QAAS,eAAgB,WACpC,OAAO9B,EAAUG,EAAE4B,MAAMC,KAAK,SAAU7B,EAAE4B,MAAMC,KAAK,YAEvD7B,EAAE,WAAW6B,KAAK,OAAQhB,QACnBb,EAAE,eAAe8B,KAAK,WAC3B,IAAIZ,EAEJ,OADAA,EAAS,IAAIK,KAAsB,IAAjBvB,EAAE4B,MAAMN,QACnBtB,EAAE4B,MAAMN,KAAKJ,EAAOM,wBAI9BO,KAAKH"}
{"version":3,"sources":["lemonldap-ng-portal/site/htdocs/static/common/js/notifications.js"],"names":["displayError","setMsg","toggle","viewNotif","msg","level","$","html","window","translate","removeClass","addClass","j","status","err","res","console","log","JSON","parse","responseText","error","button","verif","attr","removeAttr","each","this","notif","epoch","ajax","type","url","portal","data","dataType","success","resp","myDate","result","notification","text","Date","toLocaleString","document","ready","on","call"],"mappings":"CAMA,WACE,IAAIA,EAAcC,EAAQC,EAAQC,EAElCF,EAAS,SAASG,EAAKC,GAOrB,OANAC,EAAE,QAAQC,KAAKC,OAAOC,UAAUL,IAChCE,EAAE,UAAUI,YAAY,gEACxBJ,EAAE,UAAUK,SAAS,WAAaN,GACpB,aAAVA,IACFA,EAAQ,WAEHC,EAAE,UAAUK,SAAS,SAAWN,IAGzCL,EAAe,SAASY,EAAGC,EAAQC,GACjC,IAAIC,EAGJ,GAFAC,QAAQC,IAAI,QAASH,IACrBC,EAAMG,KAAKC,MAAMP,EAAEQ,gBACRL,EAAIM,MAEb,OADAL,QAAQC,IAAI,iBAAkBF,GACvBd,EAAOc,EAAK,YAIvBb,EAAS,SAASoB,EAAQC,GACxB,OAAIA,GACFjB,EAAE,mBAAmBkB,KAAK,SAAU,QACpCF,EAAOZ,YAAY,cACZY,EAAOX,SAAS,iBAEvBL,EAAE,mBA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د",
"info":"معلومات",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"ID",
"imSure":"Ich bin sicher",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"I'm sure",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"GRUPOS SSO",
"headers":"ENCABEZADOS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"Estoy seguro",
"info":"Información",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"Olen varma",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"GROUPES SSO",
"headers":"ENTETES",
"hello":"Bonjour",
"hide":"Masquer",
"id":"Id",
"imSure":"Je suis sûr",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"GRUPPI SSO",
"headers":"INTESTAZIONI",
"hello":"Salve",
"hide":"Hide",
"id":"Id",
"imSure":"Sono sicuro",
"info":"Informazioni",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"I'm sure",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"I'm sure",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"I'm sure",
"info":"Information",

View File

@ -166,6 +166,7 @@
"groups_sso":"TOA GRUPLARI",
"headers":"BAŞLIKLAR",
"hello":"Merhaba",
"hide":"Hide",
"id":"ID",
"imSure":"Eminim",
"info":"Bilgi",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"Tôi chắc chắn",
"info":"Thông tin",

View File

@ -166,6 +166,7 @@
"groups_sso":"SSO GROUPS",
"headers":"HEADERS",
"hello":"Hello",
"hide":"Hide",
"id":"Id",
"imSure":"我确认",
"info":"信息",

View File

@ -80,7 +80,7 @@
</a></li>
</TMPL_IF>
<TMPL_IF NAME="notifsExplorer">
<li class="dropdown-item"><a href="/mynotifs" class="nav-link">
<li class="dropdown-item"><a href="/mynotifications" class="nav-link">
<img src="<TMPL_VAR NAME="STATIC_PREFIX">common/icons/notifsExplorer.png" width="20" height="20" alt="notificationsExplorer" />
<span trspan="notificationsExplorer">notificationsExplorer</span>
</a></li>

View File

@ -10,8 +10,8 @@
<table class="table table-hover">
<thead>
<tr>
<th><span trspan="reference">Reference</span></th>
<th><span trspan="date">Date</span></th>
<th><span trspan="reference">Reference</span></th>
<th>
<TMPL_IF NAME="ACTION">
<span trspan="action">Action</span>
@ -22,8 +22,8 @@
<tbody>
<TMPL_LOOP NAME="NOTIFICATIONS">
<tr id='delete-<TMPL_VAR NAME="epoch">'>
<td class="align-middle"><TMPL_VAR NAME="reference"></td>
<td class="data-epoch"><TMPL_VAR NAME="epoch"></td>
<td class="align-middle"><TMPL_VAR NAME="reference"></td>
<td>
<TMPL_IF NAME="DISPLAY">
<span notif='<TMPL_VAR NAME="reference">' epoch='<TMPL_VAR NAME="epoch">' class="btn btn-success" role="button">
@ -41,7 +41,7 @@
<div class="card mb-3 border-info" id='myNotification' hidden>
<div class="card-header text-white bg-info">
<h3 class="card-title"><span trspan="reference">Reference</span>: <span id="notifRef"></span> / <span trspan="validationDate">Validation date</span>: <span id="notifEpoch"></span></h3>
<h3 class="card-title"><span trspan="validationDate">Validation date</span>: <span id="notifEpoch"></span> - <span trspan="reference">Reference</span>: <span id="notifRef"></span></h3>
</div>
<div class="card-body">
<div class="form">