Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -145,6 +145,15 @@ class Controller extends DispatcherController
|
||||
|
||||
$tree = new Tree( $this->url, $nodeClass::$nodeTitle, array( $this, '_getRoots' ), array( $this, '_getRow' ), array( $this, '_getRowParentId' ), array( $this, '_getChildren' ), array( $this, '_getRootButtons' ), TRUE, $this->lockParents, $this->protectRoots, $this->_getRootsPerPage(), array( $this, '_getTotalRoots' ) );
|
||||
Output::i()->output .= $tree;
|
||||
|
||||
if( IPS::classUsesTrait( $nodeClass, Grouping::class ) )
|
||||
{
|
||||
Output::i()->sidebar['actions']['groups'] = [
|
||||
'icon' => 'folder-open',
|
||||
'title' => 'node_groups',
|
||||
'link' => $this->url->setQueryString( 'do', 'nodeGroups' )
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1691,4 +1700,187 @@ class Controller extends DispatcherController
|
||||
{
|
||||
return $node->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Node Groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function nodeGroups() : void
|
||||
{
|
||||
$nodeClass = $this->nodeClass;
|
||||
|
||||
$tree = new Tree(
|
||||
$this->url->setQueryString( 'do', 'nodeGroups' ),
|
||||
NodeGroup::$nodeTitle,
|
||||
array( $this, '_getNodeGroupRoots' ),
|
||||
array( $this, '_getNodeGroupRow' ),
|
||||
null,
|
||||
null,
|
||||
function(){
|
||||
return [
|
||||
'add' => [
|
||||
'icon' => 'plus',
|
||||
'title' => 'new_node_group',
|
||||
'link' => $this->url->setQueryString( 'do', 'nodeGroupForm' ),
|
||||
'data' => [ 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'new_node_group' ) ]
|
||||
]
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
/* Figure out the header blurb */
|
||||
try
|
||||
{
|
||||
$langStringPlural = Member::loggedIn()->language()->get( '__defart_nodegroup__' . $nodeClass->application . '_pl' );
|
||||
$langString = Member::loggedIn()->language()->get( '__defart_nodegroup__' . $nodeClass->application );
|
||||
}
|
||||
catch( \Exception )
|
||||
{
|
||||
$langStringPlural = Member::loggedIn()->language()->get( '__defart_nodegroup__core_pl' );
|
||||
$langString = Member::loggedIn()->language()->get( '__defart_nodegroup__core' );
|
||||
}
|
||||
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( NodeGroup::$nodeTitle );
|
||||
Output::i()->breadcrumb[] = [ $this->url, $this->title ];
|
||||
Output::i()->breadcrumb[] = [ null, Member::loggedIn()->language()->addToStack( NodeGroup::$nodeTitle ) ];
|
||||
Output::i()->output = Theme::i()->getTemplate( 'forms','core' )->blurb( Member::loggedIn()->language()->addToStack( 'node_groups_header_desc', null, [ 'sprintf' => [ $langStringPlural, $langString ] ] ) );
|
||||
Output::i()->output .= $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all node groups for this node class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getNodeGroupRoots() : array
|
||||
{
|
||||
$roots = [];
|
||||
foreach( NodeGroup::roots() as $node )
|
||||
{
|
||||
if( $node->class == $this->nodeClass )
|
||||
{
|
||||
$roots[ $node->_id ] = $this->_getNodeGroupRow( $node );
|
||||
}
|
||||
}
|
||||
return $roots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted node group row
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return string
|
||||
*/
|
||||
public function _getNodeGroupRow( mixed $id ) : string
|
||||
{
|
||||
if ( $id instanceof Model)
|
||||
{
|
||||
$node = $id;
|
||||
$id = $node->_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = NodeGroup::load( $id );
|
||||
}
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
Output::i()->error( 'node_error', '2S101/P', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
$buttons = [
|
||||
'edit' => [
|
||||
'icon' => 'pencil',
|
||||
'title' => 'edit',
|
||||
'link' => $this->url->setQueryString( [ 'do' => 'nodeGroupForm', 'id' => $node->_id ] ),
|
||||
'data' => [ 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'edit' ) ]
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'delete',
|
||||
'link' => $this->url->setQueryString( [ 'do' => 'nodeGroupDelete', 'id' => $node->_id ] )->csrf(),
|
||||
'data' => [ 'delete' => '' ]
|
||||
]
|
||||
];
|
||||
|
||||
return Theme::i()->getTemplate( 'trees', 'core' )->row(
|
||||
$this->url->setQueryString( 'do', 'nodeGroups' ),
|
||||
$id,
|
||||
static::nodeTitle( $node ),
|
||||
false,
|
||||
$buttons
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit a node group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function nodeGroupForm() : void
|
||||
{
|
||||
$group = null;
|
||||
if( isset( Request::i()->id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$group = NodeGroup::load( Request::i()->id );
|
||||
if( $group->class != $this->nodeClass )
|
||||
{
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch( OutOfRangeException ){}
|
||||
}
|
||||
|
||||
if( $group === null )
|
||||
{
|
||||
$group = new NodeGroup;
|
||||
$group->class = $this->nodeClass;
|
||||
}
|
||||
|
||||
$form = new Form;
|
||||
$group->form( $form );
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$group->saveForm( $group->formatFormValues( $values ) );
|
||||
|
||||
Output::i()->redirect( $this->url->setQueryString( 'do', 'nodeGroups' ) );
|
||||
}
|
||||
|
||||
/* Appify the language strings */
|
||||
try
|
||||
{
|
||||
$langString = Member::loggedIn()->language()->get( '__defart_nodegroup__' . $this->nodeClass->application );
|
||||
}
|
||||
catch( \Exception )
|
||||
{
|
||||
$langString = Member::loggedIn()->language()->get( '__defart_nodegroup__core' );
|
||||
}
|
||||
|
||||
Member::loggedIn()->language()->words['node_group_name_desc'] = Member::loggedIn()->language()->addToStack( 'node_group_name__desc', null, [ 'sprintf' => [ $langString ] ] );
|
||||
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a node group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function nodeGroupDelete() : void
|
||||
{
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
try
|
||||
{
|
||||
NodeGroup::load( Request::i()->id )->delete();
|
||||
}
|
||||
catch( OutOfRangeException ){}
|
||||
|
||||
Output::i()->redirect( $this->url->setQueryString( 'do', 'nodeGroups' ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user