From 6adec1971061d39addf0886755bf341e1457f32b Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 20 Dec 2016 08:47:33 -0700 Subject: [PATCH] Add selected contacts to new distribution list when you create it via context menu --- addressbook/inc/class.addressbook_ui.inc.php | 7 ++++++- addressbook/js/app.js | 22 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 2c5c8951ad..52f1259009 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -937,9 +937,10 @@ window.egw_LAB.wait(function() { * @param int $list_id ID of existing list, or 0 for a new one * @param string $new_name List name * @param int $_owner List owner, or empty for current user + * @param string[] [$contacts] List of contacts to add to the array * @return boolean|string */ - function ajax_set_list($list_id, $new_name, $_owner = false) + function ajax_set_list($list_id, $new_name, $_owner = false, $contacts = array()) { // Set owner to current user, if not set $owner = $_owner ? $_owner : $GLOBALS['egw_info']['user']['account_id']; @@ -974,6 +975,10 @@ window.egw_LAB.wait(function() { $new_id = $this->add_list(array('list_id' => (int)$list_id), $list['list_owner'],array(),$list); + if($contacts) + { + $this->add2list($contacts,$new_id); + } Api\Json\Response::get()->apply('egw.message', array( $new_id == $list_id ? lang('Distribution list renamed') : lang('List created'), 'success' diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 1e235fc51c..371151cba3 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -556,7 +556,13 @@ app.classes.addressbook = AppJS.extend( } }, - add_new_list: function(owner) + /** + * Add a new mailing list. If any contacts are selected, they will be added. + * + * @param {egwAction} owner + * @param {egwActionObject[]} selected + */ + add_new_list: function(owner, selected) { if(!owner || typeof owner == 'object') { @@ -564,11 +570,23 @@ app.classes.addressbook = AppJS.extend( owner = filter.getValue()||egw.preference('add_default','addressbook'); } var lists = this.et2.getWidgetById('filter2'); + var contacts = []; + if(selected && selected.length) + { + for(var i = 0; i < selected.length; i++) + { + // Remove UID prefix for just contact_id + var ids = selected[i].id.split('::'); + ids.shift(); + ids = ids.join('::'); + contacts.push(ids); + } + } et2_dialog.show_prompt( function(button, name) { if(button == et2_dialog.OK_BUTTON) { - egw.json('addressbook.addressbook_ui.ajax_set_list',[0, name, owner], + egw.json('addressbook.addressbook_ui.ajax_set_list',[0, name, owner, contacts], function(result) { if(typeof result == 'object') return; // This response not for us