Add event id + notification UI improvemenets BT#16386

pull/3057/head
Julio 6 years ago
parent 87e6bac4b7
commit df1ee89672
  1. 63
      main/inc/lib/NotificationEvent.php
  2. 1
      main/install/configuration.dist.php
  3. 8
      main/notification_event/add.php
  4. 3
      main/notification_event/edit.php
  5. 57
      main/template/default/layout/notification.tpl
  6. 2
      plugin/justification/Justification.php

@ -12,6 +12,7 @@ class NotificationEvent extends Model
'persistent',
'day_diff',
'event_type',
'event_id',
];
const ACCOUNT_EXPIRATION = 1;
@ -43,15 +44,67 @@ class NotificationEvent extends Model
];
}
public function getForm(FormValidator $form)
public function getForm(FormValidator $form, $data = [])
{
$options = $this->getEventsForSelect();
$form->addSelect('event_type', get_lang('EventType'), $options);
$form->freeze('event_type');
$eventType = $data['event_type'];
switch ($eventType) {
case self::JUSTIFICATION_EXPIRATION:
$plugin = Justification::create();
$list = $plugin->getList();
$list = array_column($list, 'name', 'id');
$form->addSelect('event_id', get_lang('JustificationType'), $list);
break;
default:
break;
}
$form->freeze('event_id');
$form->addText('title', get_lang('Title'));
$form->addTextarea('content', get_lang('Content'));
$form->addText('link', get_lang('Link'), false);
$form->addCheckBox('persistent', get_lang('Persistent'));
$form->addNumeric('day_diff', get_lang('DayDiff'), false);
return $form;
}
public function getAddForm(FormValidator $form)
{
$options = $this->getEventsForSelect();
$form->addSelect('event_type', get_lang('EventType'), $options);
$eventType = $form->getSubmitValue('event_type');
$form->addSelect(
'event_type',
get_lang('EventType'),
$options,
['placeholder' => get_lang('SelectAnOption'), 'onchange' => 'document.add.submit()']
);
if (!empty($eventType)) {
$form->freeze('event_type');
$form->addText('title', get_lang('Title'));
$form->addTextarea('content', get_lang('Content'));
$form->addText('link', get_lang('Link'), false);
$form->addCheckBox('persistent', get_lang('Persistent'));
$form->addNumeric('day_diff', get_lang('DayDiff'), false);
switch ($eventType) {
case self::JUSTIFICATION_EXPIRATION:
$plugin = Justification::create();
$list = $plugin->getList();
$list = array_column($list, 'name', 'id');
$form->addSelect('event_id', get_lang('JustificationType'), $list);
break;
default:
break;
}
$form->addButtonSave(get_lang('Save'));
}
return $form;
}
@ -80,6 +133,7 @@ class NotificationEvent extends Model
foreach ($events as $event) {
$days = (int) $event['day_diff'];
$checkIsRead = $event['persistent'] == 0 ? true : false;
$eventItemId = $event['event_id'];
switch ($event['event_type']) {
case self::ACCOUNT_EXPIRATION:
@ -112,6 +166,11 @@ class NotificationEvent extends Model
if (empty($userJustification['date_validity'])) {
continue;
}
if ($eventItemId != $userJustification['justification_document_id']) {
continue;
}
$showNotification = $this->showNotification($userJustification['date_validity'], $days);
$id = 'id_'.self::JUSTIFICATION_EXPIRATION.'_event_'.$event['id'].'_'.$userJustification['id'];

@ -1351,6 +1351,7 @@ id INT unsigned NOT NULL auto_increment PRIMARY KEY,
day_diff INT,
event_type VARCHAR(255)
);
ALTER TABLE notification_event ADD COLUMN event_id INT NULL;
*/
// create new user text extra field called 'notification_event' to save the persistent settings.
// $_configuration['notification_event'] = false;

@ -13,14 +13,12 @@ $fields = [];
$manager = new NotificationEvent();
$form = new FormValidator('add');
$form = $manager->getForm($form);
$form = $manager->getAddForm($form);
$form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
if (isset($_POST) && isset($_POST['title']) && $form->validate()) {
$values = $form->getSubmitValues();
$manager->save($values);
Display::addFlash(get_lang('Saved'));
Display::addFlash(Display::return_message(get_lang('Saved')));
$url = api_get_path(WEB_CODE_PATH).'notification_event/list.php?';
header('Location: '.$url);
exit;

@ -16,12 +16,11 @@ if (empty($id)) {
$manager = new NotificationEvent();
$notification = $manager->get($id);
$tpl = new Template($tool);
$fields = [];
$form = new FormValidator('edit', 'post', api_get_self().'?id='.$id);
$form = $manager->getForm($form);
$form = $manager->getForm($form, $notification);
$form->setDefaults($notification);
$form->addButtonSave(get_lang('Update'));

@ -161,6 +161,34 @@
appNotifications.badgeLoadingMask(false);
});
},
loadNotificationArray: function () {
$('#notificationsContainer').html("");
var closeLink = '<div class="notification-read"><i class="fa fa-times" aria-hidden="true"></i></div>';
for (i = 0; i < count; i++) {
if (notifications[i]) {
var template = $('#notificationTemplate').html();
template = template.replace("{id}", notifications[i].id);
template = template.replace("{link}", notifications[i].link);
template = template.replace("{title}", notifications[i].title);
template = template.replace("{content}", notifications[i].content);
template = template.replace("{event_text}", notifications[i].event_text);
if (notifications[i].persistent == 1) {
template = template.replace("{close_link}", '');
} else {
template = template.replace("{close_link}", closeLink);
}
$('#notificationsContainer').append(template);
}
}
$('.notification-read').on('click', function (event) {
appNotifications.markAsRead(event, $(this));
});
appNotifications.loadingMask(false);
$("#notifications-dropdown").prop("disabled", false);
},
load: function () {
appNotifications.loadingMask(true);
$('#notificationsContainer').html("");
@ -188,30 +216,7 @@
});
setTimeout(function () {
var closeLink = '<div class="notification-read"><i class="fa fa-times" aria-hidden="true"></i></div>';
for (i = 0; i < count; i++) {
if (notifications[i]) {
var template = $('#notificationTemplate').html();
template = template.replace("{id}", notifications[i].id);
template = template.replace("{link}", notifications[i].link);
template = template.replace("{title}", notifications[i].title);
template = template.replace("{content}", notifications[i].content);
template = template.replace("{event_text}", notifications[i].event_text);
if (notifications[i].persistent == 1) {
template = template.replace("{close_link}", '');
} else {
template = template.replace("{close_link}", closeLink);
}
$('#notificationsContainer').append(template);
}
}
$('.notification-read').on('click', function (event) {
appNotifications.markAsRead(event, $(this));
});
appNotifications.loadingMask(false);
$("#notifications-dropdown").prop("disabled", false);
appNotifications.loadNotificationArray();
}, 1000);
},
markAsRead: function (event, elem) {
@ -227,6 +232,7 @@
$.ajax({
url: '{{ _p.web_main }}inc/ajax/message.ajax.php?a=mark_notification_as_read&id='+notificationId,
success: function (data) {
console.log(notifications);
notifications = $.grep(notifications, function(value) {
if (notificationId == value.id) {
return false;
@ -238,7 +244,8 @@
count--;
console.log('count : ' + count);
appNotifications.loadAll();
//appNotifications.loadAll();
appNotifications.loadNotificationArray();
}
});
},

@ -57,7 +57,7 @@ class Justification extends Plugin
public function getList()
{
$sql = 'SELECT * FROM justification_document ';
$sql = 'SELECT * FROM justification_document ORDER BY name ';
$query = Database::query($sql);
return Database::store_result($query, 'ASSOC');

Loading…
Cancel
Save