From 5f60df7ebbe44fb4ec9b239a4c78259a61a6c847 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 27 Oct 2014 18:43:03 +0000 Subject: [PATCH] Distribution list UI: - Context menu and nextmatch Add new list now both set the owner based on selected addressbook (previously were different) - If no selected addressbook, they now use preferred default addressbook - Added context menu to rename selected addressbook --- addressbook/inc/class.addressbook_ui.inc.php | 46 +++++++++++++++++-- addressbook/js/app.js | 48 ++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 4182521266..d43b67f7e1 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -250,10 +250,10 @@ class addressbook_ui extends addressbook_bo } $sel_options['cat_id'] = array('' => lang('all'), '0' => lang('None')); - // Delete list action depends on permissions + // Edit and delete list actions depends on permissions if($this->get_lists(EGW_ACL_EDIT)) { - $content['nm']['placeholder_actions'][] = 'delete_list'; + $content['nm']['placeholder_actions']+= array('rename_list','delete_list'); } // Search parameter passed in @@ -482,6 +482,14 @@ class addressbook_ui extends addressbook_bo 'fieldId' => 'exec[nm][filter2]', 'fieldValue' => '!', // enable if list != '' ), + 'rename_list' => array( + 'caption' => 'Rename selected distribution list', + 'icon' => 'edit', + 'enabled' => 'javaScript:app.addressbook.nm_compare_field', + 'fieldId' => 'exec[nm][filter2]', + 'fieldValue' => '!', // enable if list != '' + 'onExecute' => 'javaScript:app.addressbook.rename_list' + ), 'delete_list' => array( 'caption' => 'Delete selected distribution list!', 'confirm' => 'Delete selected distribution list!', @@ -879,6 +887,38 @@ window.egw_LAB.wait(function() { } + /** + * Rename an existing email list + * + * @param int $list_id + * @param string $new_name + * @return boolean|string + */ + function ajax_rename_list($list_id, $new_name) + { + // Check for valid list & permissions + if (!$list_id) + { + egw_json_response::get()->apply('egw.message',lang('You need to select a distribution list'),'error'); + return; + } + else if (!$this->check_list((int)$list_id, EGW_ACL_EDIT, $GLOBALS['egw_info']['user']['account_id'])) + { + egw_json_response::get()->apply('egw.message', array( lang('Insufficent rights to edit this list!'),'error')); + return; + } + + // Rename + $list = $this->read_list((int)$list_id); + $list['list_name'] = $new_name; + + $this->add_list(array('list_id' => (int)$list_id), $list['list_owner'],array(),$list); + + egw_json_response::get()->apply('egw.message', array( lang('Distribution list renamed'),'success')); + // Success, just update selectbox to new value + egw_json_response::get()->data("true"); + } + /** * apply an action to multiple contacts * @@ -989,7 +1029,7 @@ window.egw_LAB.wait(function() { egw_session::appsession($session_name,'addressbook',$query); } return false; - + case 'document': if (!$document) $document = $this->prefs['default_document']; $document_merge = new addressbook_merge(); diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 8cf0529b0e..123df7fdfe 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -446,6 +446,11 @@ app.classes.addressbook = AppJS.extend( add_new_list: function(owner) { + if(!owner || typeof owner == 'object') + { + var filter = this.et2.getWidgetById('filter'); + owner = filter.getValue()||egw.preference('add_default','addressbook'); + } var name = window.prompt(this.egw.lang('Name for the distribution list')); if (name) { @@ -456,6 +461,49 @@ app.classes.addressbook = AppJS.extend( } }, + /** + * Rename the current distribution list selected in the nextmatch filter2 + * + * @param {egwAction} action Action selected in context menu (rename) + * @param {egwActionObject[]} selected The selected row(s). Not used for this. + */ + rename_list: function(action, selected) + { + var lists = this.et2.getWidgetById('filter2'); + var list = lists.getValue() || 0; + var value = null; + for(var i = 0; i < lists.options.select_options.length; i++) + { + if(lists.options.select_options[i].value == list) + { + value = lists.options.select_options[i]; + } + } + et2_dialog.show_prompt( + function(button, name) { + if(button == et2_dialog.OK_BUTTON) + { + egw.json('addressbook.addressbook_ui.ajax_rename_list',[list, name], + function(result) + { + if(typeof result == 'object') return; // This response not for us + debugger; + // Update list + if(result) + { + value.label = name; + lists.set_select_options(lists.options.select_options); + } + } + ).sendRequest(true); + } + }, + this.egw.lang('Name for the distribution list'), + this.egw.lang('Rename list'), + value.label + ); + }, + filter2_onchange: function() { var filter2 = this.et2.getWidgetById('filter2');