[Rt-commit] r2889 - in rt/branches/CHALDEA-EXPERIMENTAL:
html/Admin/CustomFields html/Admin/Elements lib/RT lib/t/regression
autrijus at bestpractical.com
autrijus at bestpractical.com
Wed May 18 08:18:59 EDT 2005
Author: autrijus
Date: Wed May 18 08:18:58 2005
New Revision: 2889
Added:
rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_combo_cascade.t
Modified:
rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/AddCustomFieldValue
rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/EditCustomFieldValues
rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
Log:
* Refactor Cascaded type back to apply to all Select-ish custom fields,
by introducing a "Category" member field for a CFV.
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/CustomFields/Modify.html Wed May 18 08:18:58 2005
@@ -171,7 +171,7 @@
# Update any existing values
my $values = $CustomFieldObj->ValuesObj;
while (my $value = $values->Next) {
- foreach my $attr qw(Name Description SortOrder) {
+ foreach my $attr qw(Name Description SortOrder Category) {
my $param = $paramtag.$value->Id."-".$attr;
if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param})) {
@@ -190,7 +190,8 @@
if ($ARGS{$paramtag."new-Name"}) {
my ($id, $msg) = $CustomFieldObj->AddValue ( Name => $ARGS{$paramtag."new-Name"},
Description => $ARGS{$paramtag."new-Description"},
- SortOrder => $ARGS{$paramtag."new-SortOrder"});
+ SortOrder => $ARGS{$paramtag."new-SortOrder"},
+ Category => $ARGS{$paramtag."new-Category"});
push (@results, $msg);
}
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/AddCustomFieldValue
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/AddCustomFieldValue (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/AddCustomFieldValue Wed May 18 08:18:58 2005
@@ -56,6 +56,10 @@
<TD><small>
<&|/l&>Description</&>:<br>
<input type="text" size=50 name="CustomField-<%$CustomField->Id%>-Value-new-Description">
+</TD>
+<TD><small>
+<&|/l&>Category</&>:<br>
+<input type="text" size=10 name="CustomField-<%$CustomField->Id%>-Value-new-Category">
</TD></TR>
</TABLE>
Modified: rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/EditCustomFieldValues
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/EditCustomFieldValues (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/html/Admin/Elements/EditCustomFieldValues Wed May 18 08:18:58 2005
@@ -71,6 +71,11 @@
<input type="text" size=50 name="CustomField-<%$CustomField->Id%>-Value-<%$value->Id%>-Description" value="<%$value->Description%>">
</font>
</td>
+<td>
+<font size="-1">
+<input type="text" size=50 name="CustomField-<%$CustomField->Id%>-Value-<%$value->Id%>-Category" value="<%$value->Category%>">
+</font>
+</td>
</tr>
% }
</table>
Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm Wed May 18 08:18:58 2005
@@ -90,11 +90,6 @@
'Combobox: Select or enter one value', # loc
'Combobox: Select or enter up to [_1] values', # loc
],
- Cascaded => [
- 'Cascaded: Select multiple cascaded values', # loc
- 'Cascaded: Select one cascaded value', # loc
- 'Cascaded: Select up to [_1] cascaded values', # loc
- ],
);
@@ -201,6 +196,12 @@
}
$args{'LookupType'} = 'RT::Queue-RT::Ticket';
}
+
+ my ($ok, $msg) = $self->_IsValidRegex($args{'Pattern'});
+ if (!$ok) {
+ return (0, $self->loc("Invalid pattern: [_1]", $msg));
+ }
+
my $rv = $self->SUPER::Create(
Name => $args{'Name'},
Type => $args{'Type'},
@@ -563,6 +564,22 @@
# }}}
+# {{{ IsSelectionType
+
+=head2 IsSelectionType
+
+Retuns a boolean value indicating whether the C<Values> method makes sense
+to this Custom Field.
+
+=cut
+
+sub IsSelectionType {
+ my $self = shift;
+ $self->Type =~ /(?:Select|Combobox)/;
+}
+
+# }}}
+
=head2 FriendlyType [TYPE, MAX_VALUES]
@@ -634,6 +651,51 @@
$self->SUPER::SetType($type);
}
+=head2 SetPattern STRING
+
+Takes a single string representing a regular expression. Performs basic
+validation on that regex, and sets the C<Pattern> field for the CF if it
+is valid.
+
+=cut
+
+sub SetPattern {
+ my $self = shift;
+ my $regex = shift;
+
+ my ($ok, $msg) = $self->_IsValidRegex($regex);
+ if ($ok) {
+ return $self->SUPER::SetPattern($regex);
+ }
+ else {
+ return (0, $self->loc("Invalid pattern: [_1]", $msg));
+ }
+}
+
+=head2 _IsValidRegex(Str $regex) returns (Bool $success, Str $msg)
+
+Tests if the string contains an invalid regex.
+
+=cut
+
+sub _IsValidRegex {
+ my $self = shift;
+ my $regex = shift or return (1, 'valid');
+
+ local $^W; local $@;
+ $SIG{__DIE__} = sub { 1 };
+ $SIG{__WARN__} = sub { 1 };
+
+ if (eval { qr/$regex/; 1 }) {
+ return (1, 'valid');
+ }
+
+ my $err = $@;
+ $err =~ s{[,;].*}{}; # strip debug info from error
+ chomp $err;
+ return (0, $err);
+}
+
# {{{ SingleValue
=head2 SingleValue
@@ -804,7 +866,7 @@
sub TypeComposites {
my $self = shift;
- return grep !/Text-0/, map { ("$_-1", "$_-0") } $self->Types;
+ return grep !/(?:[Tt]ext|Combobox)-0/, map { ("$_-1", "$_-0") } $self->Types;
}
=head2 LookupTypes
@@ -946,6 +1008,10 @@
return ( 0, $self->loc('Permission Denied') );
}
+ unless ( $self->_MatchPattern($args{Content}) ) {
+ return ( 0, $self->loc('Invalid input') );
+ }
+
$RT::Handle->BeginTransaction;
my $current_values = $self->ValuesForObject($obj);
@@ -994,6 +1060,15 @@
}
+sub _MatchPattern {
+ my $self = shift;
+ my $regex = $self->Pattern;
+
+ return 1 if !length($regex);
+ return ($_[0] =~ $regex);
+}
+
+
# }}}
# {{{ DeleteValueForObject
Added: rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_combo_cascade.t
==============================================================================
--- (empty file)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_combo_cascade.t Wed May 18 08:18:58 2005
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More qw/no_plan/;
+
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+sub fail_ok {
+ my ($cond, $msg) = @_;
+ ok(!$cond, "This should fail: $msg");
+}
+
+sub new (*) {
+ my $class = shift;
+ return $class->new($RT::SystemUser);
+}
+
+my $q = new(RT::Queue);
+ok($q->Create(Name => "CF-Pattern-".$$));
+
+my $cf = new(RT::CustomField);
+my @cf_args = (Name => $q->Name, Type => 'Combobox', Queue => $q->id);
+
+ok($cf->Create(@cf_args));
+
+# Set some CFVs with Category markers
+
+my $t = new(RT::Ticket);
+my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test');
+ok($id,$msg);
+
+sub cnt { $cf->Values->Count };
+sub add { $cf->AddValue(Field => $cf->id, Value => $_[0], Category => $_[1]) };
+
+ok(add('value1', '1. Category A'));
+is(cnt(), 1, "Value filled");
+ok(add('value2'));
+is(cnt(), 2, "Value filled");
+ok(add('value3', '1.1. A-sub one'));
+is(cnt(), 3, "Value filled");
+ok(add('value4', '1.2. A-sub two'));
+is(cnt(), 4, "Value filled");
+ok(add('value5', ''));
+is(cnt(), 5, "Value filled");
+
+is($cf->Values->First->Category('1. Category A'), '1. Category A');
+
+1;
More information about the Rt-commit
mailing list