From 479a557381d4b0d42b83031db9e1930cf78c709e Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 23 May 2017 16:54:20 +0200 Subject: [PATCH] WIP of Notifications system: - Add actions for notification messages - Fix on message click handler - Implement appointment request actions for calendar notifications --- calendar/inc/class.calendar_boupdate.inc.php | 29 +++++++++++- notifications/inc/class.notifications.inc.php | 44 +++++++++++++++++-- notifications/js/notificationajaxpopup.js | 19 +++++++- pixelegg/css/mobile.css | 15 +++++++ pixelegg/css/pixelegg.css | 15 +++++++ pixelegg/less/layout_messages.less | 15 +++++++ pixelegg/mobile/fw_mobile.css | 15 +++++++ 7 files changed, 146 insertions(+), 6 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index 9d02e0d7dc..074c7cf756 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1045,8 +1045,33 @@ class calendar_boupdate extends calendar_bo } // popup notifiactions: set subject, different message (without separator) and (always) links $notification->set_popupsubject($subject); - $notification->set_popupmessage($notify_body."\n\n".$details['description']."\n\n".$details_body); - $notification->set_popuplinks(array($details['link_arr'])); + + if ($method =='REQUEST') + { + // Add ACCEPT|REHECT|TENTATIVE actions + $notification->set_popupactions(array( + array( + 'id' => 'A', + 'caption' => lang('Accept'), + 'icon' => 'accepted', + 'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$event['id'].','.$userid.','.'"A"'.']).sendRequest(true);' + ), + array( + 'id' => 'R', + 'caption' => lang('Reject'), + 'icon' => 'rejected', + 'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$event['id'].','.$userid.','.'"R"'.']).sendRequest(true);' + ), + array( + 'id' => 'T', + 'caption' => lang('Tentative'), + 'icon' => 'tentative', + 'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$event['id'].','.$userid.','.'"T"'.']).sendRequest(true);' + ) + )); + } + $notification->set_popupmessage($response."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n"); + $notification->set_popuplinks(array($details['link_arr']+array('app'=>'calendar'))); if(is_array($attachment)) { $notification->set_attachments(array($attachment)); } $notification->send(); diff --git a/notifications/inc/class.notifications.inc.php b/notifications/inc/class.notifications.inc.php index b2fc37a555..ad97d201c8 100644 --- a/notifications/inc/class.notifications.inc.php +++ b/notifications/inc/class.notifications.inc.php @@ -154,6 +154,12 @@ final class notifications { */ private $popup_links = array(); + /** + * array with objects of actions + * @var array + */ + private $popup_actions = array(); + /** * array with objects of attachments * @var array @@ -315,6 +321,7 @@ final class notifications { public function set_popupmessage($_message) { //popup requires html if(strlen($_message) == strlen(strip_tags($_message))) $_message = self::plain2html($_message); + if ($this->popup_actions) $_message .= '
'; $this->message_popup = $_message; return true; } @@ -343,7 +350,7 @@ final class notifications { $this->popup_links = array(); // clear array if set foreach($_links as $link) { if(is_array($link)) { - $this->add_popuplink($link['text'], $link['view'], $link['popup']); + $this->add_popuplink($link['text'], $link['view'], $link['popup'], $link['app']); } } return true; @@ -376,12 +383,15 @@ final class notifications { * @param string $_text a descriptive text for the link * @param array $_view all params needed to view the link (name => value pairs) * @param string $_popup if link can be viewed in a popup something like '300x200' otherwise false + * @param string $_app application name */ - public function add_popuplink($_text, $_view, $_popup = false) { + public function add_popuplink($_text, $_view, $_popup = false, $_app = '') { if(!$_view || !$_text) { return false; } - $this->popup_links[] = (object)array( 'text' => $_text, + $this->popup_links[] = (object)array( + 'text' => $_text, 'view' => $_view, 'popup' => $_popup, + 'app' => $_app ); return true; } @@ -767,4 +777,32 @@ final class notifications { } } } + + /** + * Add action button to popup message + * @param array $_action + * + * @return boolean + */ + public function add_popupaction($_action) { + if(!is_array($_action)) { return false; } + $this->popup_actions[] = (object)$_action; + return true; + } + + /** + * Set popup actions + * + * @param array $_actions + * @return boolean + */ + public function set_popupactions($_actions) { + $this->popup_actions = array(); + foreach($_actions as $action) { + if(is_array($action)) { + $this->add_popupaction($action); + } + } + return true; + } } diff --git a/notifications/js/notificationajaxpopup.js b/notifications/js/notificationajaxpopup.js index 1c09c2f0d2..cf679bf488 100644 --- a/notifications/js/notificationajaxpopup.js +++ b/notifications/js/notificationajaxpopup.js @@ -106,6 +106,21 @@ } } ).addClass('et2_link'); + if (notifymessages[show]['data'] && notifymessages[show]['data']['actions']) + { + var $actions_container = jQuery(document.createElement('div')).addClass('egwpopup_actions_container'); + for(var action in notifymessages[show].data.actions) + { + var func = new Function(notifymessages[show].data.actions[action].onExecute); + jQuery(document.createElement('button')) + .addClass('et2_button') + .css({'background-image':'url('+egw.image(notifymessages[show].data.actions[action].icon,notifymessages[show].data.app)+')'}) + .text(notifymessages[show].data.actions[action].caption) + .click(jQuery.proxy(func,this)) + .prependTo($actions_container); + } + $actions_container.prependTo($message); + } $egwpopup_list.append($message); // bind click handler after the message container is attached $message.click(jQuery.proxy(this.clickOnMessage, this,[$message])); @@ -131,7 +146,7 @@ notifications.prototype.clickOnMessage = function (_node, _event){ _event.stopPropagation(); this.message_seen(_node, _event); - if (_event.target.classList.contains('link')) return; + if (_node[0][0] !=_event.target) return; var egwpopup_message = _node[0]; var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,''); if (notifymessages[id]['data']) @@ -293,12 +308,14 @@ notifications.prototype.getData = function (_message) { var dom = jQuery(document.createElement('div')).html(_message);; var link = dom.find('div[data-id],div[data-url]'); + var actions = dom.find('div[data-actions]'); var data = { message: dom.text(), title: link.text(), icon: link.find('img').attr('src') }; jQuery.extend(data,link.data()); + if (actions.data()) jQuery.extend(data,actions.data()); return typeof data == 'object'? data: {}; }; diff --git a/pixelegg/css/mobile.css b/pixelegg/css/mobile.css index f1ef8b2dea..2ff0542043 100644 --- a/pixelegg/css/mobile.css +++ b/pixelegg/css/mobile.css @@ -3568,6 +3568,21 @@ td.lettersearch { #egwpopup #egwpopup_list .egwpopup_message:hover { background-color: rgba(103, 159, 210, 0.2); } +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container { + border-bottom: 1px solid silver; + padding-bottom: 5px; + text-align: center; +} +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container > button { + height: 24px; + width: 90px; + border: none; + background: #e6e6e6; + background-size: 16px; + background-position: 12px center; + background-repeat: no-repeat; + padding-left: 26px; +} #egwpopup #egwpopup_list .egwpopup_message_seen .egwpopup_mark { cursor: auto; background: none; diff --git a/pixelegg/css/pixelegg.css b/pixelegg/css/pixelegg.css index 6d0c587737..bd7129d3eb 100644 --- a/pixelegg/css/pixelegg.css +++ b/pixelegg/css/pixelegg.css @@ -3557,6 +3557,21 @@ td.lettersearch { #egwpopup #egwpopup_list .egwpopup_message:hover { background-color: rgba(103, 159, 210, 0.2); } +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container { + border-bottom: 1px solid silver; + padding-bottom: 5px; + text-align: center; +} +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container > button { + height: 24px; + width: 90px; + border: none; + background: #e6e6e6; + background-size: 16px; + background-position: 12px center; + background-repeat: no-repeat; + padding-left: 26px; +} #egwpopup #egwpopup_list .egwpopup_message_seen .egwpopup_mark { cursor: auto; background: none; diff --git a/pixelegg/less/layout_messages.less b/pixelegg/less/layout_messages.less index 5a34cd5a01..9b77e6fe67 100755 --- a/pixelegg/less/layout_messages.less +++ b/pixelegg/less/layout_messages.less @@ -86,6 +86,21 @@ &:hover { background-color: rgba(103, 159, 210, 0.2); } + .egwpopup_actions_container { + border-bottom: 1px solid silver; + padding-bottom: 5px; + text-align: center; + } + .egwpopup_actions_container>button { + height: 24px; + width: 90px; + border: none; + background: #e6e6e6; + background-size: 16px; + background-position: 12px center; + background-repeat: no-repeat; + padding-left: 26px; + } } .egwpopup_message_seen { .egwpopup_mark {cursor: auto;background:none;border-color: #666c6e;} diff --git a/pixelegg/mobile/fw_mobile.css b/pixelegg/mobile/fw_mobile.css index dfabfbc730..4c3ff69261 100644 --- a/pixelegg/mobile/fw_mobile.css +++ b/pixelegg/mobile/fw_mobile.css @@ -3579,6 +3579,21 @@ td.lettersearch { #egwpopup #egwpopup_list .egwpopup_message:hover { background-color: rgba(103, 159, 210, 0.2); } +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container { + border-bottom: 1px solid silver; + padding-bottom: 5px; + text-align: center; +} +#egwpopup #egwpopup_list .egwpopup_message .egwpopup_actions_container > button { + height: 24px; + width: 90px; + border: none; + background: #e6e6e6; + background-size: 16px; + background-position: 12px center; + background-repeat: no-repeat; + padding-left: 26px; +} #egwpopup #egwpopup_list .egwpopup_message_seen .egwpopup_mark { cursor: auto; background: none;