Use AJAX to load app list for selected account, fixes usually empty dialog for user run rights since they usually came from a group

This commit is contained in:
Nathan Gray 2014-04-30 15:20:32 +00:00
parent 5db89487a4
commit 7c5db56d61
3 changed files with 37 additions and 22 deletions

View File

@ -356,9 +356,6 @@ class admin_acl
//error_log(__METHOD__."() $n: ".array2string($row));
}
//error_log(__METHOD__."(".array2string($query).") returning ".$total);
// Get updated apps permission
$rows['acl_apps'] = $GLOBALS['egw']->acl->get_app_list_for_id('run', acl::READ, $query['account_id']);
return $total;
}
@ -391,6 +388,23 @@ class admin_acl
return true;
}
/**
* Get the list of applications allowed for the given user
*
* The list of applications is added to the json response
*
* @param int $account_id
*/
public static function ajax_get_app_list($account_id)
{
$list = array();
if(self::check_access((int)$account_id,'run',false))
{
$list = array_keys($GLOBALS['egw']->acl->get_user_applications((int)$account_id,false,false));
}
egw_json_response::get()->data($list);
}
/**
* Change (add, modify, delete) an ACL entry
*
@ -453,7 +467,6 @@ class admin_acl
$content = array();
$account_id = isset($_GET['account_id']) && (int)$_GET['account_id'] ?
(int)$_GET['account_id'] : $GLOBALS['egw_info']['user']['account_id'];
$acl_apps = $GLOBALS['egw']->acl->get_app_list_for_id('run', acl::READ, $account_id);
$content['nm'] = array(
'get_rows' => 'admin_acl::get_rows',
'no_cat' => true,
@ -472,8 +485,6 @@ class admin_acl
'location' => 'acl_rights',
'owner' => $account_id,
), array(), true),
// Client side is much easier if we send an array
'acl_apps' => $acl_apps ? $acl_apps : array()
);
$user = common::grab_owner_name($content['nm']['account_id']);
$sel_options = array(

View File

@ -389,6 +389,10 @@ app.classes.admin = AppJS.extend(
// Pre-set appname to currently selected
content.acl_appname = this.et2.getWidgetById('filter2').getValue()||"";
}
if(!content.acl_account)
{
content.acl_account = this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('account_id');
}
if(!content.acl_location)
{
content.acl_location = this.et2.getWidgetById('filter').getValue() == 'run' ? 'run' : null;
@ -396,7 +400,9 @@ app.classes.admin = AppJS.extend(
if(content.acl_location == 'run')
{
// These are the apps the account has access to
content.apps = this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('acl_apps')||[];
// Fetch current values from server
this.egw.json(className+'::ajax_get_app_list', [content.acl_account], function(data) {content.apps = data},this,false,this)
.sendRequest();
}
else
{
@ -407,10 +413,7 @@ app.classes.admin = AppJS.extend(
sel_options.acl_appname[app] = this.egw.lang(app);
}
}
if(!content.acl_account)
{
content.acl_account = this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('account_id');
}
}
if(content.acl_appname)
{
@ -436,6 +439,12 @@ app.classes.admin = AppJS.extend(
sel_options.acl_account = jQuery.extend({},sel_options.acl_account);
this.egw.link_title('home-accounts', content.acl_account, function(title) {sel_options.acl_account[content.acl_account] = title;});
}
if(content.acl_account != this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('account_id'))
{
var account = this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('account_id');
sel_options.acl_account[account] = 'loading';
this.egw.link_title('home-accounts', account, function(title) {sel_options.acl_account[account] = title;});
}
if(content.acl_location)
{
sel_options.acl_location = jQuery.extend({},sel_options.acl_location);
@ -448,6 +457,9 @@ app.classes.admin = AppJS.extend(
this.acl_dialog = null;
if(_button_id != et2_dialog.OK_BUTTON) return;
// Restore account if it's readonly in dialog
if(!_value.acl_account) _value.acl_account = content.acl_account;
// Only send the request if they entered everything
if(_value.acl_account && (_value.acl_appname && _value.acl_location || _value.apps))
{
@ -477,14 +489,6 @@ app.classes.admin = AppJS.extend(
}
}
// Update value in list
var list = this.et2.getWidgetById('nm').getArrayMgr('content').getEntry('acl_apps',true);
list.length = 0;
for(var app in _value.apps)
{
list.push(_value.apps[app]);
}
// Remove any removed
if(removed.length > 0)
{
@ -511,7 +515,7 @@ app.classes.admin = AppJS.extend(
* Change handler for ACL edit dialog application selectbox.
* Re-creates the dialog with the current values
*/
acl_change_application: function(input, widget)
acl_reopen_dialog: function(input, widget)
{
var content = {};
if(this.acl_dialog != null)

View File

@ -11,13 +11,13 @@
<row disabled="@acl_location=run" part="header">
<description value="Application"/>
<menulist>
<menupopup id="acl_appname" needed="1" onchange="app.admin.acl_change_application" options="Select one"/>
<menupopup id="acl_appname" needed="1" onchange="app.admin.acl_reopen_dialog" options="Select one"/>
</menulist>
</row>
<row part="header">
<description value="Data from" for="acl_account"/>
<menulist>
<menupopup type="select-account" id="acl_account" account_type="both" needed="1"/>
<menupopup type="select-account" id="acl_account" account_type="both" needed="1" onchange="app.admin.acl_reopen_dialog"/>
</menulist>
</row>
<row disabled="@acl_location=run" part="header">