2013-07-01 19:07:07 +02:00
/ * *
* EGroupware - Admin - Javascript UI
*
* @ link http : //www.egroupware.org
* @ package filemanager
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
2014-03-28 17:56:35 +01:00
* @ copyright ( c ) 2013 - 14 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2013-07-01 19:07:07 +02:00
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ version $Id$
* /
/ * *
* UI for Admin
2013-11-04 21:54:23 +01:00
*
2013-07-01 19:07:07 +02:00
* @ augments AppJS
* /
2013-11-04 21:54:23 +01:00
app . classes . admin = AppJS . extend (
2014-03-27 20:00:52 +01:00
/ * *
* @ lends app . classes . admin
* /
2013-07-01 19:07:07 +02:00
{
appname : 'admin' ,
2013-07-03 18:27:18 +02:00
/ * *
2014-04-02 00:51:26 +02:00
* reference to iframe
2014-03-27 20:00:52 +01:00
*
* { et2 _iframe }
2013-07-03 18:27:18 +02:00
* /
iframe : null ,
2013-07-01 19:07:07 +02:00
2014-04-02 16:32:52 +02:00
/ * *
* reference to nextmatch
*
* { et2 _extension _nextmatch }
* /
nm : null ,
2014-04-23 18:45:51 +02:00
/ * *
* Reference to ACL edit dialog ( not the list )
* /
acl _dialog : null ,
2013-07-01 19:07:07 +02:00
/ * *
* Constructor
2013-11-04 21:54:23 +01:00
*
2014-03-27 20:00:52 +01:00
* @ memberOf app . classes . admin
2013-07-01 19:07:07 +02:00
* /
2013-11-04 21:54:23 +01:00
init : function ( )
2013-07-01 19:07:07 +02:00
{
// call parent
this . _super . apply ( this , arguments ) ;
} ,
2013-11-04 21:54:23 +01:00
2013-07-01 19:07:07 +02:00
/ * *
* Destructor
* /
destroy : function ( )
{
2014-02-05 23:31:46 +01:00
this . iframe = null ;
2014-04-23 18:45:51 +02:00
this . nm = null ;
this . acl _dialog = null ;
2014-02-17 16:00:06 +01:00
2013-07-01 19:07:07 +02:00
// call parent
this . _super . apply ( this , arguments ) ;
} ,
2013-11-04 21:54:23 +01:00
2013-07-01 19:07:07 +02:00
/ * *
* This function is called when the etemplate2 object is loaded
* and ready . If you must store a reference to the et2 object ,
* make sure to clean it up in destroy ( ) .
*
2014-02-17 16:00:06 +01:00
* @ param { etemplate2 } _et2
* @ param { string } _name name of template loaded
2013-07-01 19:07:07 +02:00
* /
2014-02-17 16:00:06 +01:00
et2 _ready : function ( _et2 , _name )
2013-07-01 19:07:07 +02:00
{
// call parent
this . _super . apply ( this , arguments ) ;
2014-02-17 16:00:06 +01:00
switch ( _name )
2013-08-01 13:44:44 +02:00
{
2014-02-17 16:00:06 +01:00
case 'admin.index' :
var iframe = this . iframe = this . et2 . getWidgetById ( 'iframe' ) ;
2014-04-02 00:51:26 +02:00
this . nm = this . et2 . getWidgetById ( 'nm' ) ;
2014-02-17 16:00:06 +01:00
if ( iframe )
{
var self = this ;
jQuery ( iframe . getDOMNode ( ) ) . off ( 'load.admin' )
. bind ( 'load.admin' , function ( ) {
self . _hide _navbar . call ( self ) ;
}
) ;
// Register app refresh now that iframe is available
register _app _refresh ( 'admin' , jQuery . proxy ( this . refresh , this ) ) ;
2013-12-23 18:24:40 +01:00
}
2014-02-17 16:00:06 +01:00
break ;
case 'admin.categories.index' :
break ;
2013-08-01 13:44:44 +02:00
}
2013-07-03 18:27:18 +02:00
} ,
2013-11-04 21:54:23 +01:00
2014-04-02 16:32:52 +02:00
/ * *
* Show given url in ( visible ) iframe or nextmatch with accounts ( ! _url )
*
* @ param { string } [ _url = ] url to show in iframe or nothing for showing
* /
load : function ( _url )
{
if ( _url )
{
this . iframe . set _src ( _url ) ;
}
2014-04-02 21:04:37 +02:00
else
{
this . egw . app _header ( '' ) ;
}
2014-04-02 16:32:52 +02:00
this . iframe . set _disabled ( ! _url ) ;
this . nm . set _disabled ( ! ! _url ) ;
} ,
2014-02-06 17:55:38 +01:00
/ * *
* Special handling for egw _refresh ( ) in admin , to refresh the iframe when
* the framework detects a simple refresh can be used ( same URL ) .
*
* All parameters ignored .
*
* @ param { string } _msg Message to display
* @ param { string } _app Application being refreshed , should be 'admin'
* @ param { string } _id Unique record ID .
2014-02-17 16:00:06 +01:00
* @ param { string } _type Type of refresh . Either 'edit' , 'delete' ,
2014-02-06 17:55:38 +01:00
* 'add' or null
* /
refresh : function ( _msg , _app , _id , _type )
{
2014-03-18 19:31:52 +01:00
var refresh _done = false ;
2014-03-19 16:24:54 +01:00
// group deleted, added or updated
if ( _app === 'admin' && _id < 0 )
{
var tree = this . et2 . getWidgetById ( 'tree' ) ;
switch ( _type )
{
case 'delete' :
tree . deleteItem ( '/groups/' + _id , false ) ;
break ;
2014-03-28 17:56:35 +01:00
default : // add, update, edit, null
2014-03-19 16:24:54 +01:00
tree . refreshItem ( '/groups' ) ;
break ;
}
}
2014-02-27 19:48:48 +01:00
// Try for intelligent et2 refresh inside iframe
2014-03-18 19:31:52 +01:00
var node = _app && _id && this . iframe ? this . iframe . getDOMNode ( this . iframe ) : null ;
if ( node && node . contentWindow && node . contentWindow . etemplate2 )
2014-02-27 19:48:48 +01:00
{
var templates = node . contentWindow . etemplate2 . getByApplication ( 'admin' ) ;
for ( var i = 0 ; i < templates . length ; i ++ )
{
templates [ i ] . refresh ( _msg , _app , _id , _type ) ;
2014-03-18 19:31:52 +01:00
refresh _done = true ;
2014-02-27 19:48:48 +01:00
}
}
2014-03-18 19:31:52 +01:00
// update of account list eg. from addressbook.edit
if ( ! refresh _done && _app == 'admin' && _id )
{
var templates = etemplate2 . getByApplication ( 'admin' ) ;
for ( var i = 0 ; i < templates . length ; i ++ )
{
templates [ i ] . refresh ( _msg , _app , _id , _type ) ;
refresh _done = true ;
}
}
// update iframe
if ( ! refresh _done && framework )
2014-02-27 19:48:48 +01:00
{
2014-03-18 19:31:52 +01:00
var app = framework . getApplicationByName ( _app ) ;
if ( app && app . browser && app . browser . currentLocation )
{
this . linkHandler ( app . browser . currentLocation ) ;
}
2014-02-27 19:48:48 +01:00
}
2014-02-06 17:55:38 +01:00
} ,
2013-08-01 13:44:44 +02:00
/ * *
* Hide navbar for idots template
2013-11-04 21:54:23 +01:00
*
2013-08-01 13:44:44 +02:00
* Just a hack for old idots , not neccesary for jdots
* /
_hide _navbar : function ( )
{
var document = this . iframe . getDOMNode ( ) . contentDocument ;
2013-11-04 21:54:23 +01:00
2014-02-17 16:00:06 +01:00
if ( ! document ) return ; // nothing we can do ...
2013-10-15 18:53:43 +02:00
// set white background, as transparent one lets account-list show through
document . getElementsByTagName ( 'body' ) [ 0 ] . style . backgroundColor = 'white' ;
2013-11-04 21:54:23 +01:00
2013-08-01 13:44:44 +02:00
// hide navbar elements
var ids2hide = [ 'divLogo' , 'topmenu' , 'divAppIconBar' , 'divStatusBar' , 'tdSidebox' , 'divAppboxHeader' ] ;
for ( var i = 0 ; i < ids2hide . length ; ++ i )
{
var elem = document . getElementById ( ids2hide [ i ] ) ;
if ( elem ) elem . style . display = 'none' ;
}
} ,
2013-11-04 21:54:23 +01:00
2013-07-03 18:27:18 +02:00
/ * *
* Set location of iframe for given _action and _sender ( row )
2013-11-04 21:54:23 +01:00
*
2013-07-03 18:27:18 +02:00
* @ param _action
* @ param _senders
* /
iframe _location : function ( _action , _senders )
{
var id = _senders [ 0 ] . id . split ( '::' ) ;
var url = _action . data . url . replace ( /(%24|\$)id/ , id [ 1 ] ) ;
2014-04-02 16:32:52 +02:00
this . load ( url ) ;
2013-07-01 19:07:07 +02:00
} ,
2013-11-04 21:54:23 +01:00
2013-10-15 18:53:43 +02:00
/ * *
* Link hander for jDots template to just reload our iframe , instead of reloading whole admin app
2013-11-04 21:54:23 +01:00
*
2013-10-15 18:53:43 +02:00
* @ param _url
* @ return boolean true , if linkHandler took care of link , false otherwise
* /
linkHandler : function ( _url )
{
2014-02-17 16:00:06 +01:00
var matches = _url . match ( /menuaction=admin.admin_ui.index.*&load=([^&]+)/ ) ;
if ( _url != 'about:blank' && ( this . iframe != null && ! _url . match ( 'menuaction=admin.admin_ui.index' ) || matches ) )
2013-10-15 18:53:43 +02:00
{
if ( matches )
{
_url = _url . replace ( /menuaction=admin.admin_ui.index/ , 'menuaction=' + matches [ 1 ] ) . replace ( /&(ajax=true|load=[^&]+)/g , '' ) ;
}
2014-04-02 16:32:52 +02:00
this . load ( _url ) ;
2013-10-15 18:53:43 +02:00
return true ;
}
// can not load our own index page, has to be done by framework
return false ;
} ,
2013-11-04 21:54:23 +01:00
2013-07-01 19:07:07 +02:00
/ * *
* Run an admin module / onclick callback for tree
2013-11-04 21:54:23 +01:00
*
2014-02-17 16:00:06 +01:00
* @ param { string } _id id of clicked node
* @ param { et2 _tree } _widget reference to tree widget
2013-07-01 19:07:07 +02:00
* /
run : function ( _id , _widget )
{
var link = _widget . getUserData ( _id , 'link' ) ;
2013-11-04 21:54:23 +01:00
2013-07-03 18:27:18 +02:00
if ( _id == '/accounts' || _id . substr ( 0 , 8 ) == '/groups/' )
{
2014-04-02 16:32:52 +02:00
this . load ( ) ;
2013-07-03 18:27:18 +02:00
var parts = _id . split ( '/' ) ;
2013-08-01 13:44:44 +02:00
this . et2 . getWidgetById ( 'nm' ) . applyFilters ( { filter : parts [ 2 ] ? parts [ 2 ] : '' , search : '' } ) ;
2013-07-03 18:27:18 +02:00
}
else if ( typeof link == 'undefined' )
2013-07-01 19:07:07 +02:00
{
2013-11-04 21:54:23 +01:00
_widget . openItem ( _id , 'toggle' ) ;
2013-07-01 19:07:07 +02:00
}
else if ( link [ 0 ] == '/' || link . substr ( 0 , 4 ) == 'http' )
{
2014-04-02 16:32:52 +02:00
this . load ( link + ( link . match ( /\?/ ) ? '&' : '?' ) + 'nonavbar=1' ) ;
2013-07-01 19:07:07 +02:00
}
else if ( link . substr ( 0 , 11 ) == 'javascript:' )
{
eval ( link . substr ( 11 ) ) ;
}
2013-07-31 16:01:12 +02:00
} ,
2013-11-04 21:54:23 +01:00
2013-07-31 16:01:12 +02:00
/ * *
* View , edit or delete a group callback for tree
2013-11-04 21:54:23 +01:00
*
2014-02-17 16:00:06 +01:00
* @ param { object } _action egwAction
* @ param { array } _senders egwActionObject _senders [ 0 ] . id holds id
2013-07-31 16:01:12 +02:00
* /
group : function ( _action , _senders )
{
switch ( _action . id )
{
case 'view' :
this . run ( _senders [ 0 ] . id , this . et2 . getWidgetById ( 'tree' ) ) ;
break ;
2013-11-04 21:54:23 +01:00
2014-03-19 16:24:54 +01:00
case 'delete' :
var account _id = _senders [ 0 ] . id . split ( '/' ) [ 2 ] ;
this . egw . json ( 'admin_account::ajax_delete_group' , [ account _id ] ) . sendRequest ( ) ;
break ;
2014-03-27 20:00:52 +01:00
default :
if ( ! _action . data . url )
{
alert ( 'Missing url in action ' + _action . id + '!' ) ;
break ;
}
var url = _action . data . url . replace ( '$id' , _senders [ 0 ] . id . split ( '/' ) [ 2 ] ) ;
if ( url [ 0 ] != '/' && url . substr ( 0 , 4 ) != 'http' )
{
url = this . egw . link ( '/index.php' , url ) ;
}
if ( _action . data . popup )
{
this . egw . open _link ( url , '_blank' , _action . data . popup ) ;
}
else
{
2014-04-02 16:32:52 +02:00
this . load ( url ) ;
2014-03-27 20:00:52 +01:00
}
break ;
2013-07-31 16:01:12 +02:00
}
} ,
2013-11-04 21:54:23 +01:00
2013-07-31 16:01:12 +02:00
/ * *
2013-08-27 19:58:38 +02:00
* Modify an ACL entry
2013-11-04 21:54:23 +01:00
*
2014-02-17 16:00:06 +01:00
* @ param { object } _action egwAction
* @ param { array } _senders egwActionObject _senders [ 0 ] . id holds the id "admin::app:account:location"
2013-07-31 16:01:12 +02:00
* /
2013-08-27 19:58:38 +02:00
acl : function ( _action , _senders )
2013-07-31 16:01:12 +02:00
{
2013-08-27 19:58:38 +02:00
var ids = [ ] ;
for ( var i = 0 ; i < _senders . length ; ++ i )
{
2014-03-12 13:49:28 +01:00
ids . push ( _senders [ i ] . id . split ( '::' ) . pop ( ) ) ; // remove "admin::" prefix
2013-08-27 19:58:38 +02:00
}
2014-04-23 18:45:51 +02:00
// For edit, set some data from the list since it's already there
var content = _senders [ 0 ] . id ? jQuery . extend ( { } , egw . dataGetUIDdata ( _senders [ 0 ] . id ) . data ) : { } ;
switch ( _action . id )
{
case 'delete' :
var app = egw . app _name ( ) ; // can be either admin or preferences!
if ( app != 'admin' ) app = 'preferences' ;
var className = app + '_acl' ;
var request = egw . json ( className + '::ajax_change_acl' , [ ids ] , this . _acl _callback , this , false , this )
. sendRequest ( ) ;
break ;
case 'add' :
// No content, even if they clicked on a row
// Defaults set by _acl_content() based on nm values
content = { } ;
// Fall through
case 'edit' :
this . _acl _dialog ( content ) ;
break ;
}
} ,
/ * *
* Create the ACL edit dialog , including defaults & fetching what can be found
*
* @ param content List of content for the dialog template
* @ param sel _options optional select options
* /
_acl _dialog : function ( content , sel _options )
{
if ( typeof content == 'undefined' ) content = { } ;
// Determine which application we're running as
2014-03-12 13:49:28 +01:00
var app = egw . app _name ( ) ; // can be either admin or preferences!
2014-03-12 14:50:16 +01:00
if ( app != 'admin' ) app = 'preferences' ;
2014-03-12 13:49:28 +01:00
var className = app + '_acl' ;
2014-04-23 18:45:51 +02:00
var acl _rights = { } ;
var readonlys = { acl : { } } ;
2013-08-27 19:58:38 +02:00
2014-04-02 20:32:52 +02:00
// Select options are already here, just pull them and pass along
2014-04-23 18:45:51 +02:00
sel _options = jQuery . extend ( { } , this . et2 . getArrayMgr ( 'sel_options' ) . data || { } , {
2014-04-02 20:32:52 +02:00
'apps' : this . et2 . getArrayMgr ( 'sel_options' ) . getEntry ( 'acl_appname' )
2014-04-23 18:45:51 +02:00
} , sel _options ) ;
2014-04-02 20:32:52 +02:00
2014-04-23 18:45:51 +02:00
// Some defaults
if ( this . et2 && this . et2 . getWidgetById ( 'nm' ) )
2014-04-02 20:32:52 +02:00
{
2014-04-23 18:45:51 +02:00
// This is which checkboxes are available for each app
var acl _rights = this . et2 . getWidgetById ( 'nm' ) . getArrayMgr ( 'content' ) . getEntry ( 'acl_rights' ) || { } ;
if ( ! content . acl _appname )
{
// Pre-set appname to currently selected
content . acl _appname = this . et2 . getWidgetById ( 'filter2' ) . getValue ( ) || "" ;
}
2014-04-30 17:20:32 +02:00
if ( ! content . acl _account )
{
content . acl _account = this . et2 . getWidgetById ( 'nm' ) . getArrayMgr ( 'content' ) . getEntry ( 'account_id' ) ;
}
2014-04-23 18:45:51 +02:00
if ( ! content . acl _location )
{
2014-04-28 18:19:39 +02:00
content . acl _location = this . et2 . getWidgetById ( 'filter' ) . getValue ( ) == 'run' ? 'run' : null ;
}
if ( content . acl _location == 'run' )
{
// These are the apps the account has access to
2014-04-30 17:20:32 +02:00
// 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 ( ) ;
2014-04-28 18:19:39 +02:00
}
else
{
// Restrict application selectbox to only apps that support ACL
sel _options . acl _appname = { } ;
for ( var app in acl _rights )
{
sel _options . acl _appname [ app ] = this . egw . lang ( app ) ;
}
2014-04-23 18:45:51 +02:00
}
2014-04-30 17:20:32 +02:00
2014-04-02 20:32:52 +02:00
}
if ( content . acl _appname )
{
2014-04-23 21:09:28 +02:00
// Load checkboxes & their values
2014-04-02 21:28:57 +02:00
content . acl _rights = content . acl _rights ? parseInt ( content . acl _rights ) : null ;
2014-04-02 20:32:52 +02:00
jQuery . extend ( content , { acl : [ ] , right : [ ] , label : [ ] } ) ;
for ( var right in acl _rights [ content . acl _appname ] )
{
2014-04-23 21:09:28 +02:00
// only user himself is allowed to grant private (16) rights
2014-04-23 18:45:51 +02:00
if ( right == '16' && content [ 'acl_account' ] != egw . user ( 'account_id' ) )
{
readonlys . acl [ content . acl . length ] = true ;
}
2014-04-02 20:32:52 +02:00
content . acl . push ( content . acl _rights & right ) ;
content . right . push ( right ) ;
content . label . push ( egw . lang ( acl _rights [ content . acl _appname ] [ right ] ) ) ;
}
2014-04-23 21:09:28 +02:00
}
// Make sure selected values are there
if ( content . acl _account )
{
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 ; } ) ;
}
2014-04-30 17:20:32 +02:00
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 ; } ) ;
}
2014-04-23 21:09:28 +02:00
if ( content . acl _location )
{
sel _options . acl _location = jQuery . extend ( { } , sel _options . acl _location ) ;
this . egw . link _title ( 'home-accounts' , content . acl _location , function ( title ) { sel _options . acl _location [ content . acl _location ] = title ; } ) ;
2014-04-02 20:32:52 +02:00
}
2014-04-02 21:04:37 +02:00
2014-04-23 18:45:51 +02:00
// Create the dialog
this . acl _dialog = et2 _createWidget ( "dialog" , {
callback : jQuery . proxy ( function ( _button _id , _value ) {
this . acl _dialog = null ;
if ( _button _id != et2 _dialog . OK _BUTTON ) return ;
2014-04-30 17:20:32 +02:00
// Restore account if it's readonly in dialog
if ( ! _value . acl _account ) _value . acl _account = content . acl _account ;
2014-04-23 18:45:51 +02:00
// Only send the request if they entered everything
2014-04-28 19:40:25 +02:00
if ( _value . acl _account && ( _value . acl _appname && _value . acl _location || _value . apps ) )
2014-04-23 18:45:51 +02:00
{
var id = _value . acl _appname + ':' + _value . acl _account + ':' + _value . acl _location ;
var rights = 0 ;
for ( var i in _value . acl )
{
rights += parseInt ( _value . acl [ i ] ) ;
}
2014-04-28 19:40:25 +02:00
if ( _value . apps && ! _value . acl _appname )
{
id = [ ] ;
rights = 1 ;
var removed = [ ] ;
// Loop through all apps, remove the ones with no permission
for ( var app in sel _options . apps )
{
var run _id = app + ":" + _value . acl _account + ":run" ;
if ( _value . apps . indexOf ( app ) < 0 && content . apps . indexOf ( app ) >= 0 )
{
removed . push ( run _id ) ;
}
else if ( _value . apps . indexOf ( app ) >= 0 && content . apps . indexOf ( app ) < 0 )
{
id . push ( run _id )
}
}
// Remove any removed
if ( removed . length > 0 )
{
this . egw . json ( className + '::ajax_change_acl' , [ removed , 0 ] , this . _acl _callback , this , false , this )
. sendRequest ( ) ;
}
}
2014-04-23 18:45:51 +02:00
this . egw . json ( className + '::ajax_change_acl' , [ id , rights ] , this . _acl _callback , this , false , this )
. sendRequest ( ) ;
}
} , this ) ,
title : egw . lang ( 'Access control' ) ,
buttons : et2 _dialog . BUTTONS _OK _CANCEL ,
value : {
content : content ,
sel _options : sel _options ,
readonlys : readonlys
} ,
template : egw . webserverUrl + '/admin/templates/default/acl.edit.xet'
} , et2 _dialog . _create _parent ( app ) ) ;
} ,
/ * *
* Change handler for ACL edit dialog application selectbox .
* Re - creates the dialog with the current values
* /
2014-04-30 17:20:32 +02:00
acl _reopen _dialog : function ( input , widget )
2014-04-23 18:45:51 +02:00
{
var content = { } ;
if ( this . acl _dialog != null )
2013-08-27 19:58:38 +02:00
{
2014-04-23 18:45:51 +02:00
content = this . acl _dialog . get _value ( ) || { } ;
2013-11-04 21:54:23 +01:00
2014-04-23 18:45:51 +02:00
// Destroy the dialog
this . acl _dialog . free ( ) ;
this . acl _dialog = null ;
2013-08-27 19:58:38 +02:00
}
2014-04-23 18:45:51 +02:00
// Re-open the dialog
this . _acl _dialog ( content ) ;
2013-08-27 19:58:38 +02:00
} ,
2013-11-04 21:54:23 +01:00
2013-08-27 19:58:38 +02:00
/ * *
* Callback called on successfull call of serverside ACL handling
2013-11-04 21:54:23 +01:00
*
2014-02-17 16:00:06 +01:00
* @ param { object } _data returned from server
2013-08-27 19:58:38 +02:00
* /
_acl _callback : function ( _data )
{
window . egw _refresh ( _data . msg , this . appname , _data . ids , _data . type ) ;
2013-07-31 16:01:12 +02:00
} ,
2014-01-16 17:21:17 +01:00
/ * *
* Check to see if admin has taken away access to a category
*
* @ @ param { widget } button add / apply pressed button
* /
check _owner : function ( button ) {
var select _owner = this . et2 . getWidgetById ( 'owner' ) ;
2014-01-28 11:48:23 +01:00
var diff = [ ] ;
2014-02-17 16:00:06 +01:00
2014-01-16 17:21:17 +01:00
if ( typeof select _owner != 'undefined' )
{
var owner = select _owner . get _value ( ) ;
}
if ( typeof owner != 'object' )
{
owner = [ owner ] ;
}
// No owner probably means selectbox is read-only, so no need to check
if ( owner == null ) return true ;
var all _users = owner . indexOf ( '0' ) >= 0 ;
// If they checked all users, uncheck the others
if ( all _users ) {
select _owner . set _value ( [ '0' ] ) ;
return true ;
}
// Find out what changed
2014-01-28 11:48:23 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . getEntry ( 'owner' ) ;
if ( content )
{
var cat _original _owner = content . split ( "," ) ;
var selected _groups = select _owner . get _value ( ) . toString ( ) ;
2014-02-17 16:00:06 +01:00
2014-01-28 11:48:23 +01:00
for ( var i = 0 ; i < cat _original _owner . length ; i ++ )
{
2014-01-28 12:13:48 +01:00
if ( selected _groups . search ( cat _original _owner [ i ] ) < 0 )
2014-01-28 11:48:23 +01:00
{
diff . push ( cat _original _owner [ i ] ) ;
}
}
2014-02-17 16:00:06 +01:00
2014-01-28 12:13:48 +01:00
if ( diff . length > 0 )
2014-01-28 11:48:23 +01:00
{
var removed _cat _label = jQuery . map ( select _owner . options . select _options , function ( val , i )
2014-03-27 20:00:52 +01:00
{
for ( var j = 0 ; j <= diff . length ; j ++ )
{
if ( diff [ j ] == val . value )
{
return val . label ;
}
}
} ) ;
2014-01-16 17:21:17 +01:00
2014-01-28 11:48:23 +01:00
// Somebody will lose permission, give warning.
if ( removed _cat _label )
{
var msg = this . egw . lang ( 'Removing access for groups may cause problems for data in this category. Are you sure? Users in these groups may no longer have access:' ) ;
return et2 _dialog . confirm ( button , msg + removed _cat _label . join ( ',' ) ) ;
}
}
2014-01-16 17:21:17 +01:00
}
return true ;
} ,
/ * *
* Show icon based on icon - selectbox , hide placeholder ( broken image ) , if no icon selected
*
* @ param { widget } widget select box widget
* /
change _icon : function ( widget )
{
var img = widget . getRoot ( ) . getWidgetById ( 'icon_url' ) ;
if ( img )
{
img . set _src ( widget . getValue ( ) ) ;
}
2014-03-18 19:31:52 +01:00
} ,
/ * *
* Add / edit an account
*
* @ param { object } _action egwAction
* @ param { array } _senders egwActionObject _senders [ 0 ] . id holds account _id
* /
account : function ( _action , _senders )
{
var params = jQuery . extend ( { } , this . egw . link _get _registry ( 'addressbook' , 'edit' ) ) ;
var popup = this . egw . link _get _registry ( 'addressbook' , 'edit_popup' ) ;
if ( _action . id == 'add' )
{
params . owner = '0' ;
}
else
{
2014-04-03 10:36:15 +02:00
params . account _id = _senders [ 0 ] . id . split ( '::' ) . pop ( ) ; // get last :: separated part
2014-03-18 19:31:52 +01:00
}
this . egw . open _link ( this . egw . link ( '/index.php' , params ) , 'admin' , popup ) ;
2014-02-17 16:00:06 +01:00
}
2013-07-01 19:07:07 +02:00
} ) ;