Remove full list reload when adding a new distribution list, using ajax instead.

This commit is contained in:
Nathan Gray 2014-10-28 19:50:19 +00:00
parent 02fbe1ef41
commit 235a847cff
2 changed files with 52 additions and 21 deletions

View File

@ -890,35 +890,47 @@ window.egw_LAB.wait(function() {
}
/**
* Rename an existing email list
* Create or rename an existing email list
*
* @param int $list_id
* @param string $new_name
* @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
* @return boolean|string
*/
function ajax_rename_list($list_id, $new_name)
function ajax_set_list($list_id, $new_name, $owner = false)
{
// Set owner to current user, if not set
$owner = $owner ? $owner : $GLOBALS['egw_info']['user']['account_id'];
// Check for valid list & permissions
if (!$list_id)
if(!(int)$list_id && !$this->check_list(null,EGW_ACL_ADD|EGW_ACL_EDIT,$owner))
{
egw_json_response::get()->apply('egw.message',lang('You need to select a distribution list'),'error');
egw_json_response::get()->apply('egw.message', array( lang('List creation failed, no rights!'),'error'));
return;
}
else if (!$this->check_list((int)$list_id, EGW_ACL_EDIT, $GLOBALS['egw_info']['user']['account_id']))
if ((int)$list_id && !$this->check_list((int)$list_id, EGW_ACL_EDIT, $owner))
{
egw_json_response::get()->apply('egw.message', array( lang('Insufficent rights to edit this list!'),'error'));
return;
}
$list = array('list_owner' => $owner);
// Rename
$list = $this->read_list((int)$list_id);
if($list_id)
{
$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);
$new_id = $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'));
egw_json_response::get()->apply('egw.message', array(
$new_id == $list_id ? lang('Distribution list renamed') : lang('List created'),
'success'
));
// Success, just update selectbox to new value
egw_json_response::get()->data("true");
egw_json_response::get()->data($new_id == $list_id ? "true" : $new_id);
}
/**

View File

@ -451,19 +451,39 @@ app.classes.addressbook = AppJS.extend(
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)
{
egw.open('','addressbook', 'list', {
'add_list': name,
'owner': owner
},'_self');
}
var lists = this.et2.getWidgetById('filter2');
et2_dialog.show_prompt(
function(button, name) {
if(button == et2_dialog.OK_BUTTON)
{
egw.json('addressbook.addressbook_ui.ajax_set_list',[0, name, owner],
function(result)
{
if(typeof result == 'object') return; // This response not for us
// Update list
if(result)
{
lists.options.select_options.unshift({value:result,label:name});
lists.set_select_options(lists.options.select_options);
// Set to new list so they can see it easily
lists.set_value(result);
}
}
).sendRequest(true);
}
},
this.egw.lang('Name for the distribution list'),
this.egw.lang('Add a new list...')
);
},
/**
* Rename the current distribution list selected in the nextmatch filter2
*
* Differences from add_new_list are in the dialog, parameters sent, and how the
* response is dealt with
*
* @param {egwAction} action Action selected in context menu (rename)
* @param {egwActionObject[]} selected The selected row(s). Not used for this.
*/
@ -483,11 +503,10 @@ app.classes.addressbook = AppJS.extend(
function(button, name) {
if(button == et2_dialog.OK_BUTTON)
{
egw.json('addressbook.addressbook_ui.ajax_rename_list',[list, name],
egw.json('addressbook.addressbook_ui.ajax_set_list',[list, name],
function(result)
{
if(typeof result == 'object') return; // This response not for us
debugger;
// Update list
if(result)
{