Commit ef4aa1aa authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(management) Reorganize column classes

Showing with 210 additions and 122 deletions
+210 -122
...@@ -207,7 +207,7 @@ class managementListing ...@@ -207,7 +207,7 @@ class managementListing
new ObjectTypeColumn(), new ObjectTypeColumn(),
new LinkColumn('sn', 'Last name'), new LinkColumn('sn', 'Last name'),
new LinkColumn('givenName', 'First name'), new LinkColumn('givenName', 'First name'),
new StringColumn('uid', 'Login'), new Column('uid', 'Login'),
new PropertiesColumn(NULL, 'Properties'), new PropertiesColumn(NULL, 'Properties'),
new ActionsColumn(NULL, 'Actions'), new ActionsColumn(NULL, 'Actions'),
); );
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Column showing the actions available on the object
*/
class ActionsColumn extends Column
{
function isSortable()
{
return FALSE;
}
function getRowClasses(ListingEntry $entry)
{
return $this->parent->parent->getActionRowClasses($entry);
}
function renderCell(ListingEntry $entry)
{
return $this->parent->parent->renderActionColumn($entry);
}
}
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/*! /*!
* \brief Column base class * \brief Column base class
*/ */
class StringColumn class Column
{ {
protected $attribute; protected $attribute;
protected $label; protected $label;
...@@ -161,123 +161,3 @@ class StringColumn ...@@ -161,123 +161,3 @@ class StringColumn
} }
} }
} }
class LinkColumn extends StringColumn
{
function renderCell(ListingEntry $entry)
{
$attribute = $this->attribute;
if (isset($this->templateAttribute) && $entry->isTemplate()) {
$attribute = $this->templateAttribute;
}
if (isset($entry[$attribute])) {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8').'</a>';
} else {
return '&nbsp;';
}
}
}
class ObjectTypeColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function renderCell(ListingEntry $entry)
{
if ($entry->isTemplate()) {
$infos = objects::infos($entry->getTemplatedType());
return '<img title="'.$entry->dn.'" src="'.htmlentities('geticon.php?context=devices&icon=template&size=16', ENT_COMPAT, 'UTF-8').'" alt="'.sprintf(_('%s template'), $infos['name']).'"/>';
} elseif ($entry->type) {
$infos = objects::infos($entry->type);
return '<img title="'.$entry->dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>';
} else {
return '&nbsp;';
}
}
}
class ActionsColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function getRowClasses(ListingEntry $entry)
{
return $this->parent->parent->getActionRowClasses($entry);
}
function renderCell(ListingEntry $entry)
{
return $this->parent->parent->renderActionColumn($entry);
}
}
class PropertiesColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function fillNeededAttributes(array &$attrs)
{
$attrs['objectClass'] = '*';
}
function renderCell(ListingEntry $entry)
{
global $config;
$infos = objects::infos($entry->getTemplatedType());
static $tabs = array();
if (empty($tabs[$entry->type])) {
$tabs[$entry->type] = array();
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
if ($plug['CLASS'] == $infos['mainTab']) {
continue;
}
if (class_available($plug['CLASS'])) {
$name = $plug['CLASS'];
$tabs[$entry->type][$name] = new $name('new');
}
}
}
/* Main tab is always there */
$pInfos = pluglist::pluginInfos($infos['mainTab']);
$result = '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>';
if (!empty($entry)) {
if ($entry->isTemplate()) {
$attrs = $entry->getTemplatedFields();
} else {
$attrs = $entry;
}
foreach ($tabs[$entry->type] as $class => $tab) {
if ($tab->is_this_account($attrs)) {
$pInfos = pluglist::pluginInfos($class);
if (isset($pInfos['plSmallIcon'])) {
$result .= '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$class.'_'.$entry->row.'"/>';
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for');
}
} else {
$result .= '<img src="images/empty.png" alt="" class="optional '.$class.'"/>';
}
}
}
return $result;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Column rendering a link to edit the object
*/
class LinkColumn extends Column
{
function renderCell(ListingEntry $entry)
{
$attribute = $this->attribute;
if (isset($this->templateAttribute) && $entry->isTemplate()) {
$attribute = $this->templateAttribute;
}
if (isset($entry[$attribute])) {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8').'</a>';
} else {
return '&nbsp;';
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Column showing the icon of the objectType
*/
class ObjectTypeColumn extends Column
{
function isSortable()
{
return FALSE;
}
function renderCell(ListingEntry $entry)
{
if ($entry->isTemplate()) {
$infos = objects::infos($entry->getTemplatedType());
return '<img title="'.$entry->dn.'" src="'.htmlentities('geticon.php?context=devices&icon=template&size=16', ENT_COMPAT, 'UTF-8').'" alt="'.sprintf(_('%s template'), $infos['name']).'"/>';
} elseif ($entry->type) {
$infos = objects::infos($entry->type);
return '<img title="'.$entry->dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>';
} else {
return '&nbsp;';
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Column showing the activated tabs of the object
*/
class PropertiesColumn extends Column
{
function isSortable()
{
return FALSE;
}
function fillNeededAttributes(array &$attrs)
{
$attrs['objectClass'] = '*';
}
function renderCell(ListingEntry $entry)
{
global $config;
$infos = objects::infos($entry->getTemplatedType());
static $tabs = array();
if (empty($tabs[$entry->type])) {
$tabs[$entry->type] = array();
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
if ($plug['CLASS'] == $infos['mainTab']) {
continue;
}
if (class_available($plug['CLASS'])) {
$name = $plug['CLASS'];
$tabs[$entry->type][$name] = new $name('new');
}
}
}
/* Main tab is always there */
$pInfos = pluglist::pluginInfos($infos['mainTab']);
$result = '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>';
if (!empty($entry)) {
if ($entry->isTemplate()) {
$attrs = $entry->getTemplatedFields();
} else {
$attrs = $entry;
}
foreach ($tabs[$entry->type] as $class => $tab) {
if ($tab->is_this_account($attrs)) {
$pInfos = pluglist::pluginInfos($class);
if (isset($pInfos['plSmallIcon'])) {
$result .= '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$class.'_'.$entry->row.'"/>';
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for');
}
} else {
$result .= '<img src="images/empty.png" alt="" class="optional '.$class.'"/>';
}
}
}
return $result;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment