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 >
* @ copyright ( c ) 2013 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ 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 (
2013-07-01 19:07:07 +02:00
{
appname : 'admin' ,
2013-07-03 18:27:18 +02:00
/ * *
* reference to splitter
* /
splitter : null ,
/ * *
* reference to splitter
* /
iframe : null ,
2013-07-01 19:07:07 +02:00
/ * *
* Constructor
2013-11-04 21:54:23 +01:00
*
2013-07-01 19:07:07 +02:00
* @ memberOf app . filemanager
* /
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 ( )
{
// 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 ( ) .
*
* @ param _et2 etemplate2 Newly ready object
* /
et2 _ready : function ( _et2 )
{
// call parent
this . _super . apply ( this , arguments ) ;
2013-08-01 13:44:44 +02:00
var iframe = this . iframe = this . et2 . getWidgetById ( 'iframe' ) ;
2013-11-04 21:54:23 +01:00
if ( iframe )
2013-08-01 13:44:44 +02:00
{
var self = this ;
2013-12-23 18:24:40 +01:00
jQuery ( iframe . getDOMNode ( ) ) . off ( 'load.admin' )
. bind ( 'load.admin' , function ( ) {
self . _hide _navbar . call ( self ) ;
self . splitter . dock ( ) ;
self . splitter . resize ( ) ;
}
) ;
2013-08-01 13:44:44 +02:00
}
2013-10-15 18:53:43 +02:00
this . splitter = this . et2 . getWidgetById ( 'splitter' ) ;
2013-07-03 18:27:18 +02:00
} ,
2013-11-04 21:54:23 +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
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 ] ) ;
this . iframe . set _src ( 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 )
{
var matches ;
if ( ! _url . match ( 'menuaction=admin.admin_ui.index' ) ||
( matches = _url . match ( /menuaction=admin.admin_ui.index.*&load=([^&]+)/ ) ) )
{
if ( matches )
{
_url = _url . replace ( /menuaction=admin.admin_ui.index/ , 'menuaction=' + matches [ 1 ] ) . replace ( /&(ajax=true|load=[^&]+)/g , '' ) ;
}
this . iframe . set _src ( _url ) ;
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
*
2013-07-01 19:07:07 +02:00
* @ param string _id id of clicked node
* @ param et2 _tree _widget reference to tree widget
* /
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/' )
{
this . splitter . undock ( ) ;
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' )
{
2013-07-03 18:27:18 +02:00
this . splitter . dock ( ) ;
2013-10-15 18:53:43 +02:00
this . iframe . set _src ( 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
*
2013-07-31 16:01:12 +02:00
* @ param Object _action egwAction
* @ param Object _senders egwActionObject _senders [ 0 ] . id holds id
* /
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
2013-07-31 16:01:12 +02:00
case 'edit' :
case 'delete' :
this . splitter . dock ( ) ;
2013-11-04 21:54:23 +01:00
this . iframe . set _src ( egw . link ( '/index.php' , {
menuaction : _action . id == 'edit' ? 'admin.uiaccounts.edit_group' : 'admin.uiaccounts.delete_group' ,
2013-07-31 16:01:12 +02:00
account _id : _senders [ 0 ] . id . split ( '/' ) [ 2 ]
} ) ) ;
break ;
2013-08-26 20:25:43 +02:00
case 'acl' :
this . splitter . dock ( ) ;
2013-11-04 21:54:23 +01:00
this . iframe . set _src ( egw . link ( '/index.php' , {
menuaction : 'admin.admin_acl.index' ,
2013-08-26 20:25:43 +02:00
account _id : _senders [ 0 ] . id . split ( '/' ) [ 2 ]
} ) ) ;
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
*
2013-07-31 16:01:12 +02:00
* @ param Object _action egwAction
2013-08-28 14:52:47 +02:00
* @ param Object _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 )
{
ids . push ( _senders [ i ] . id . substr ( 7 ) ) ; // remove "admin::" prefix
}
switch ( _action . id )
{
case 'delete' :
2013-09-10 21:45:08 +02:00
var request = egw . json ( 'admin_acl::ajax_change_acl' , [ ids ] , this . _acl _callback , this , false , this )
. sendRequest ( ) ;
2013-08-27 19:58:38 +02:00
break ;
2013-11-04 21:54:23 +01:00
2013-08-27 19:58:38 +02:00
case 'edit' :
2013-08-28 14:52:47 +02:00
// need to specify window to get correct opener, as admin has multiple windows open!
egw ( 'admin' , window ) . open _link ( egw . link ( '/index.php' , {
2013-08-27 19:58:38 +02:00
menuaction : 'admin.admin_acl.acl' ,
id : ids [ 0 ] ,
} ) , 'acl' , '300x300' ) ;
break ;
case 'add' :
2013-08-28 14:52:47 +02:00
var current = ids [ 0 ] . split ( ':' ) ;
egw ( 'admin' , window ) . open _link ( egw . link ( '/index.php' , {
2013-08-27 19:58:38 +02:00
menuaction : 'admin.admin_acl.acl' ,
2013-08-28 14:52:47 +02:00
app : current [ 0 ] ,
account : current [ 1 ]
2013-08-27 19:58:38 +02:00
} ) , 'acl' , '250x250' ) ;
break ;
}
} ,
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
*
2013-08-27 19:58:38 +02:00
* @ param string _data returned from server
* /
_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' ) ;
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
var cat _original _owner = this . et2 . getArrayMgr ( 'content' ) . getEntry ( 'owner' ) . split ( "," ) ;
var new _cat _label = jQuery . map ( select _owner . options . select _options , function ( val , i )
{
for ( j = 0 ; j <= cat _original _owner . length ; j ++ )
{
if ( cat _original _owner [ j ] == val . value )
{
return val . label ;
}
}
} ) ;
// Somebody will lose permission, give warning.
if ( new _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 + new _cat _label . join ( ',' ) ) ;
}
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 ( ) ) ;
}
} ,
2013-07-01 19:07:07 +02:00
} ) ;