mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
W.I.P restructuring of Notifications actions
This commit is contained in:
parent
670b74cf23
commit
c2a3c19124
@ -1050,25 +1050,9 @@ class calendar_boupdate extends calendar_bo
|
||||
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_popupdata('calendar', array(
|
||||
'event_id' => $event['id'],
|
||||
'user_id' => $userid
|
||||
));
|
||||
}
|
||||
$notification->set_popupmessage($subject."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n");
|
||||
|
@ -864,6 +864,37 @@ END:VALARM';
|
||||
'popup' => Link::get_registry('calendar', 'edit_popup')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to construct notifications actions
|
||||
*
|
||||
* @param type $params
|
||||
* @return type
|
||||
*/
|
||||
public static function notifications_actions ($params)
|
||||
{
|
||||
Api\Translation::add_app('calendar');
|
||||
return array(
|
||||
array(
|
||||
'id' => 'A',
|
||||
'caption' => lang('Accept'),
|
||||
'icon' => 'accepted',
|
||||
'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$params['data']['event_id'].','.$params['data']['user_id'].','.'"A"'.']).sendRequest(true);'
|
||||
),
|
||||
array(
|
||||
'id' => 'R',
|
||||
'caption' => lang('Reject'),
|
||||
'icon' => 'rejected',
|
||||
'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$params['data']['event_id'].','.$params['data']['user_id'].','.'"R"'.']).sendRequest(true);'
|
||||
),
|
||||
array(
|
||||
'id' => 'T',
|
||||
'caption' => lang('Tentative'),
|
||||
'icon' => 'tentative',
|
||||
'onExecute' => 'egw().json("calendar.calendar_uiforms.ajax_status",['.$params['data']['event_id'].','.$params['data']['user_id'].','.'"T"'.']).sendRequest(true);'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Not part of the class, since config hooks are still using the old style
|
||||
|
@ -46,6 +46,7 @@ $setup_info['calendar']['hooks']['export_limit'] = 'calendar_hooks::getAppExport
|
||||
$setup_info['calendar']['hooks']['acl_rights'] = 'calendar_hooks::acl_rights';
|
||||
$setup_info['calendar']['hooks']['categories'] = 'calendar_hooks::categories';
|
||||
$setup_info['calendar']['hooks']['mail_import'] = 'calendar_hooks::mail_import';
|
||||
$setup_info['calendar']['hooks']['notifications_actions'] = 'calendar_hooks::notifications_actions';
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['calendar']['depends'][] = array(
|
||||
|
@ -155,10 +155,10 @@ class notifications {
|
||||
protected $popup_links = array();
|
||||
|
||||
/**
|
||||
* array with objects of actions
|
||||
* array with objects of data
|
||||
* @var array
|
||||
*/
|
||||
protected $popup_actions = array();
|
||||
protected $popup_data = array();
|
||||
|
||||
/**
|
||||
* array with objects of attachments
|
||||
@ -327,7 +327,6 @@ 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 .= '<div data-actions='. json_encode($this->popup_actions).'></div>';
|
||||
$this->message_popup = $_message;
|
||||
return true;
|
||||
}
|
||||
@ -550,8 +549,9 @@ class notifications {
|
||||
{
|
||||
if (!empty($this->popupsubject)) $lsubject = $this->popupsubject;
|
||||
if ($this->popup_links) $llinks = $this->popup_links;
|
||||
if (is_array($this->popup_data)) $popup_data = $this->popup_data;
|
||||
}
|
||||
$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments);
|
||||
$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments, $popup_data);
|
||||
}
|
||||
catch (Exception $exception) {
|
||||
$backend_errors[] = $notification_backend.' failed: '.$exception->getMessage();
|
||||
@ -786,31 +786,20 @@ 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
|
||||
* Set popup data
|
||||
*
|
||||
* @param array $_actions
|
||||
* @param string $_appname
|
||||
* @param array $_data
|
||||
* @return boolean
|
||||
*/
|
||||
public function set_popupactions($_actions) {
|
||||
$this->popup_actions = array();
|
||||
foreach($_actions as $action) {
|
||||
if(is_array($action)) {
|
||||
$this->add_popupaction($action);
|
||||
}
|
||||
}
|
||||
public function set_popupdata($_appname, $_data) {
|
||||
$this->popup_data = array(
|
||||
'appname' => $_appname,
|
||||
'data' => $_data
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -185,6 +185,15 @@ class notifications_ajax {
|
||||
if ($rs->NumRows() > 0) {
|
||||
foreach ($rs as $notification) {
|
||||
$message = null;
|
||||
$data = json_decode($notification['notify_data'], true);
|
||||
if ($data['appname'])
|
||||
{
|
||||
$_actions = Api\Hooks::process (array(
|
||||
'location' => 'notifications_actions',
|
||||
'data' => $data['data']
|
||||
), $data['appname'], true);
|
||||
$actions = $_actions[$data['appname']];
|
||||
}
|
||||
if($browserNotify)
|
||||
{
|
||||
$message = $notification['notify_message'];
|
||||
@ -204,7 +213,8 @@ class notifications_ajax {
|
||||
$message3,
|
||||
$notification['notify_status'],
|
||||
$notification['notify_created'],
|
||||
new DateTime())
|
||||
new DateTime(),
|
||||
is_array($actions)?$actions:NULL)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -86,9 +86,12 @@ class notifications_email implements notifications_iface {
|
||||
* @param string $_subject
|
||||
* @param array $_links
|
||||
* @param array $_attachments
|
||||
* @param array $_data
|
||||
*/
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false)
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false)
|
||||
{
|
||||
unset ($_data);
|
||||
|
||||
$body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient);
|
||||
$body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n";
|
||||
|
||||
|
@ -33,6 +33,7 @@ interface notifications_iface {
|
||||
* @param string $_subject
|
||||
* @param array $_links
|
||||
* @param array $_attachments
|
||||
* @param array $_data
|
||||
*/
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false);
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false);
|
||||
}
|
||||
|
@ -91,10 +91,11 @@ class notifications_jpopup implements notifications_iface
|
||||
* @param string $_subject
|
||||
* @param array $_links
|
||||
* @param array $_attachments
|
||||
* @param array $_data
|
||||
*/
|
||||
public function send(array $_messages, $_subject=false, $_links=false, $_attachments=false)
|
||||
public function send(array $_messages, $_subject=false, $_links=false, $_attachments=false, $_data = false)
|
||||
{
|
||||
unset($_attachments); // not used
|
||||
unset($_attachments, $_data); // not used
|
||||
|
||||
$jmessage = array();
|
||||
|
||||
|
@ -99,8 +99,9 @@ class notifications_popup implements notifications_iface {
|
||||
* @param string $_subject
|
||||
* @param array $_links
|
||||
* @param array $_attachments
|
||||
* @param array $_data
|
||||
*/
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false)
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false)
|
||||
{
|
||||
unset($_attachments); // not used
|
||||
|
||||
@ -109,7 +110,7 @@ class notifications_popup implements notifications_iface {
|
||||
.(isset($_messages['popup'])&&!empty($_messages['popup'])?$_messages['popup']:$_messages['html'])
|
||||
.$this->render_links($_links);
|
||||
|
||||
$this->save( $message );
|
||||
$this->save($message, $_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,12 +118,14 @@ class notifications_popup implements notifications_iface {
|
||||
*
|
||||
* @param string $_message
|
||||
* @param array $_user_sessions
|
||||
* @param array $_data
|
||||
*/
|
||||
private function save( $_message ) {
|
||||
private function save($_message, $_data) {
|
||||
$result = $this->db->insert( self::_notification_table, array(
|
||||
'account_id' => $this->recipient->account_id,
|
||||
'notify_message' => $_message,
|
||||
'notify_type' => self::_type
|
||||
'notify_type' => self::_type,
|
||||
'notify_data' => is_array($_data) ? json_encode($_data) : NULL
|
||||
), false,__LINE__,__FILE__,self::_appname);
|
||||
if ($result === false) throw new Exception("Can't save notification into SQL table");
|
||||
}
|
||||
|
@ -101,10 +101,11 @@ class notifications_winpopup implements notifications_iface {
|
||||
* @param string $_subject
|
||||
* @param array $_links
|
||||
* @param array $_attachments
|
||||
* @param array $_data
|
||||
*/
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false)
|
||||
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false)
|
||||
{
|
||||
unset($_links, $_attachments); // not used
|
||||
unset($_links, $_attachments, $_data); // not used
|
||||
|
||||
$user_sessions = array();
|
||||
foreach (Api\Session::session_list(0, 'asc', 'session_dla', true) as $session) {
|
||||
|
@ -243,7 +243,7 @@
|
||||
}
|
||||
}
|
||||
).addClass('et2_link');
|
||||
if (notifymessages[id]['data'] && notifymessages[id]['data']['actions'])
|
||||
if (notifymessages[id]['data'] && notifymessages[id]['data']['actions'] && notifymessages[id]['data']['actions'].length > 0)
|
||||
{
|
||||
var $actions_container = jQuery(document.createElement('div')).addClass('egwpopup_actions_container');
|
||||
for(var action in notifymessages[id].data.actions)
|
||||
@ -322,7 +322,7 @@
|
||||
*/
|
||||
notifications.prototype.clickOnMessage = function (_node, _event){
|
||||
// Do not run the click handler if it's been already expanded
|
||||
if (_node[0].hasClass('egwpopup_expanded')) return;
|
||||
if (_node[0].hasClass('egwpopup_expanded') || jQuery(_event.target).hasClass('et2_button')) return;
|
||||
this.message_seen(_node, _event);
|
||||
var $node = jQuery(_node[0][0].cloneNode());
|
||||
if ($node)
|
||||
@ -432,7 +432,7 @@
|
||||
* @return undefined
|
||||
*/
|
||||
notifications.prototype.append = function(_id, _message, _browser_notify,
|
||||
_status, _created, _current) {
|
||||
_status, _created, _current, _actions) {
|
||||
var data = this.getData(_message);
|
||||
// Prevent the same thing popping up multiple times
|
||||
notifymessages[_id] = {
|
||||
@ -442,6 +442,7 @@
|
||||
created: _created,
|
||||
current: _current
|
||||
};
|
||||
if (_actions && _actions.length > 0) notifymessages[_id]['data']['actions'] = _actions;
|
||||
// Notification API
|
||||
if(_browser_notify && !_status)
|
||||
{
|
||||
@ -488,14 +489,12 @@
|
||||
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: {};
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,7 @@ if (!defined('NOTIFICATION_APP'))
|
||||
}
|
||||
|
||||
$setup_info[NOTIFICATION_APP]['name'] = NOTIFICATION_APP;
|
||||
$setup_info[NOTIFICATION_APP]['version'] = '17.1';
|
||||
$setup_info[NOTIFICATION_APP]['version'] = '17.1.001';
|
||||
$setup_info[NOTIFICATION_APP]['app_order'] = 1;
|
||||
$setup_info[NOTIFICATION_APP]['tables'] = array('egw_notificationpopup');
|
||||
$setup_info[NOTIFICATION_APP]['enable'] = 2;
|
||||
|
@ -17,7 +17,8 @@ $phpgw_baseline = array(
|
||||
'notify_message' => array('type' => 'varchar','precision' => '16384','comment' => 'notification message'),
|
||||
'notify_created' => array('type' => 'timestamp','meta' => 'timestamp','default' => 'current_timestamp','comment' => 'creation time of notification'),
|
||||
'notify_type' => array('type' => 'ascii','precision' => '32','comment' => 'notification type'),
|
||||
'notify_status' => array('type' => 'varchar','precision' => '32','comment' => 'notification status')
|
||||
'notify_status' => array('type' => 'varchar','precision' => '32','comment' => 'notification status'),
|
||||
'notify_data' => array('type' => 'varchar','precision' => '4096','comment' => 'notification data')
|
||||
),
|
||||
'pk' => array('notify_id'),
|
||||
'fk' => array(),
|
||||
|
@ -137,3 +137,14 @@ function notifications_upgrade16_1()
|
||||
|
||||
return $GLOBALS['setup_info']['notifications']['currentver'] = '17.1';
|
||||
}
|
||||
|
||||
function notifications_upgrade17_1()
|
||||
{
|
||||
$GLOBALS['egw_setup']->oProc->AddColumn('egw_notificationpopup','notify_data',array(
|
||||
'type' => 'varchar',
|
||||
'precision' => '4096',
|
||||
'comment' => 'notification actions'
|
||||
));
|
||||
|
||||
return $GLOBALS['setup_info']['notifications']['currentver'] = '17.1.001';
|
||||
}
|
Loading…
Reference in New Issue
Block a user