Hello,
I have send major updates for the network addresses management.
However, I have several few minor suggestions that can enhance the
current SVN release.
As attached, you will find the "svn diff" patch of some files :
* commontreedropdown.class.php : I suggest to use a specific
specialisation regarding the current class to define the completename of
the CommonTreeDropDown class. That may be usefull when the class have to
show another complete name than the default one (for instance, a
complete internet domain name should be represented with dot notations).
* db.function.php : the management of getPlural and getSingular may be
surprising. Actually, with the previous solution, we had to worry of
the last rules that add or remove the final 's'. (we had to append a
specific 's' in special cases). In the version I suggest, we count the
number of replacement that have been done. If there is at least one
replacement, then it means the current rule is the good one. So, we
don't have to continue. Thus, we don't have to worry about the following
cases.
* dropdown class : I think there can be drop downs that don't allow
users to append elements. So I propose to add a "can_create" parameter
(same way than the "comments" parameter).
KR
Damien Touraine
--
--------------------------------------------------------------------
Damien TOURAINE - Ingénieur de Recherche CNRS, LIMSI-CNRS
Groupe de RV&A "VENISE", (http://www.limsi.fr/venise/)
Bat. 508, Universite Paris-Sud 91403 Orsay cedex - +33 1 69 85 81 64
--------------------------------------------------------------------
Index: current/inc/commontreedropdown.class.php
===================================================================
--- current/inc/commontreedropdown.class.php (revision 14980)
+++ current/inc/commontreedropdown.class.php (working copy)
@@ -77,6 +77,9 @@
return false;
}
+ function getCompleteNameFromParents($parentCompleteName, $thisName) {
+ return addslashes($parentCompleteName) . " > " . $thisName;
+ }
function prepareInputForAdd($input) {
@@ -87,8 +90,9 @@
&& $parent->getFromDB($input[$this->getForeignKeyField()])) {
$input['level'] = $parent->fields['level']+1;
- $input['completename'] = addslashes($parent->fields['completename'])
. " > " .
- $input['name'];
+ // Sometimes (internet address), the complete name may be different ...
+ $input['completename'] =
$this->getCompleteNameFromParents($parent->fields['completename'],
+
$input['name']);
} else {
$input[$this->getForeignKeyField()] = 0;
$input['level'] = 1;
Index: current/inc/db.function.php
===================================================================
--- current/inc/db.function.php (revision 14980)
+++ current/inc/db.function.php (working copy)
@@ -190,11 +190,13 @@
'ch$' =>'ches',
'sh$' =>'shes',
'x$' =>'xes',
- '([^s])$' => '\1s', // Add at the end if not exists
- 'eds$' => 'ed'); // case table without plural (ex.
imported)
+ 'ed$' => 'ed', // case table without plural (ex.
imported)
+ '([^s])$' => '\1s'); // Add at the end if not exists
foreach ($rules as $singular => $plural) {
- $string = preg_replace("/$singular/", "$plural", $string);
+ $string = preg_replace("/$singular/", "$plural", $string, -1, $count);
+ if ($count > 0)
+ break;
}
return $string;
}
@@ -209,17 +211,19 @@
function getSingular($string) {
$rules = array(//'plural' => 'singular'
- 'ches$' => 'ch',
- 'shes$' => 'sh',
- 'ss$' => 'sss', // Case like address : add triple ss to
be cut at the end
- 'sses$' => 'sss', // Case like addresses : add triple ss
to be cut at the end
- 'ias$' => 'iass', // Case like alias : add double ss to be
cut at the end
- '([aeiou])ses$' => '\1ss', // Case like aliases : add
double ss to be cut at the end
- 'ies$' => 'y', // special case : category
- 's$' => ''); // Add at the end if not exists
+ 'ches$' => 'ch',
+ 'shes$' => 'sh',
+ 'sses$' => 'ss', // Case like addresses
+ '([aeiou])ses$' => '\1s', // Case like aliases
+ 'ss$' => 'ss', // Special case (addresses) when
getSingular is called on already singular form
+ 'ias$' => 'ias', // Special case (aliases) when
getSingular is called on already singular form
+ 'ies$' => 'y', // special case : category
+ 's$' => ''); // Add at the end if not exists
foreach ($rules as $plural => $singular) {
- $string = preg_replace("/$plural/", "$singular", $string);
+ $string = preg_replace("/$plural/", "$singular", $string, -1, $count);
+ if ($count > 0)
+ break;
}
return $string;
}
Index: current/inc/dropdown.class.php
===================================================================
--- current/inc/dropdown.class.php (revision 14980)
+++ current/inc/dropdown.class.php (working copy)
@@ -55,6 +55,7 @@
* - rand : integer / already computed rand value
* - condition : string / aditional SQL condition to limit display
* - displaywith : array / array of field to display with request
+ * - can_create : boolean / is it possible to create an entity ?
*
* @param $itemtype itemtype used for create dropdown
* @param $options possible options
@@ -80,6 +81,7 @@
$params['used'] = array();
$params['toadd'] = array();
$params['auto_submit'] = 0;
+ $params['can_create'] = true;
$params['condition'] = '';
$params['rand'] = mt_rand();
$params['displaywith'] = array();
@@ -202,8 +204,9 @@
showToolTip($comment,$options_tooltip);
if (($item instanceof CommonDropdown)
- && $item->canCreate()
- && !isset($_GET['popup'])) {
+ && $item->canCreate()
+ && !isset($_GET['popup'])
+ && $params['can_create']) {
echo "<img alt='' title=\"".$LANG['buttons'][8]."\"
src='".$CFG_GLPI["root_doc"].
"/pics/add_dropdown.png' style='cursor:pointer;
margin-left:2px;'
_______________________________________________
Glpi-dev mailing list
Glpi-dev@gna.org
https://mail.gna.org/listinfo/glpi-dev