[Rt-commit] [svn] r1946 - in rt/branches/3.3-TESTING: . html/Ticket/Elements lib/RT

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Sun Nov 28 22:25:21 EST 2004


Author: jesse
Date: Sun Nov 28 22:25:19 2004
New Revision: 1946

Modified:
   rt/branches/3.3-TESTING/   (props changed)
   rt/branches/3.3-TESTING/html/Ticket/Elements/EditCustomField
   rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
Log:
 r9432 at tinbook:  jesse | 2004-11-29T03:26:44.094679Z
 Custom field API backward-compatibility improvements


Modified: rt/branches/3.3-TESTING/html/Ticket/Elements/EditCustomField
==============================================================================
--- rt/branches/3.3-TESTING/html/Ticket/Elements/EditCustomField	(original)
+++ rt/branches/3.3-TESTING/html/Ticket/Elements/EditCustomField	Sun Nov 28 22:25:19 2004
@@ -43,57 +43,13 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-% my $Values;
-<input type="hidden" name="<%$NamePrefix%><%$CustomField->Id%>-Values-Magic" value="1">
-% if ($TicketObj) {
-%          $Values  = $TicketObj->CustomFieldValues($CustomField->id);
-% }
-% if ($CustomField->Type eq 'FreeformSingle') {
-      <input name="<%$NamePrefix%><%$CustomField->Id%>-Value"
-        size="<%$Cols%>"
-% if ($TicketObj) {
-          value="<%$Values->Count ? $Values->First->Content : ''%>"
-% } elsif ($Default) {
-          value="<%$Default ? $Default : ''%>"
-% }
->
-% } elsif ($CustomField->Type eq 'FreeformMultiple') {
-% my $content;
-% if ($TicketObj) {
-%          while (my $value = $Values->Next ) {
-%                 $content .= "\n" . $value->Content;
-%           }
-% } elsif ($Default) {
-          value="<%$Default ? $Default : ''%>"
-%  }
-<textarea cols=<%$Cols%> rows=<%$Rows%> name="<%$NamePrefix%><%$CustomField->Id%>-Values"><%$content%></textarea>
-% } elsif ($CustomField->Type =~ /^Select/) {
-      <select name="<%$NamePrefix%><%$CustomField->Id%>-Values"
-        size="<%$Rows%>"
-        <%$CustomField->Type eq 'SelectMultiple' && 'MULTIPLE'%>>
-% my $CustomFieldValues = $CustomField->Values();
-% my $selected;
-% while (my $value = $CustomFieldValues->Next) {
-        <option value="<%$value->Name%>" 
-% if ($TicketObj) {
-            <% $Values->HasEntry($value->Name) && ($selected = 1) && 'SELECTED' %>
-% } elsif ($Default) {
-            <% ($Default eq $value->Name) && ($selected = 1) && 'SELECTED' %>
-% }
-            ><% $value->Name%></option>
-% }
-        <option value="" <% !$selected && 'SELECTED' %>><&|/l&>(no value)</&></option>
-      </select>
-% }
-<%ARGS>
-$TicketObj => undef
-$CustomField => undef
-$NamePrefix => undef
-$Rows => 5
-$Cols=> 15
-$Default => undef
-</%ARGS>
 <%init>
-use Carp;
-$RT::Logger->error("Ticket/Elements/EditCustomField is deprecated in RT 3.4 and will be removed.\n". Carp::longmess);
+
+# RT 3.2 API compatibility glue
+
+$RT::Logger->debug("Ticket/Elements/EditCustomField is deprecated in RT 3.4 and will be removed in 3.6.");
+
+$ARGS{'NamePrefix'} =~ s/^Ticket-/Object-RT::Ticket-/;
+$ARGS{'NamePrefix'} =~ s/^CustomField-/Object-RT::Ticket--CustomField-/;
+$m->comp('/Elements/EditCustomField', %ARGS, Object=> $ARGS{'TicketObj'});
 </%init>

Modified: rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm	Sun Nov 28 22:25:19 2004
@@ -193,19 +193,28 @@
 }
 
 
-# {{{ sub LoadByNameAndQueue
+# {{{ sub LoadByName
 
-=head2  LoadByNameAndQueue (Queue => QUEUEID, Name => NAME)
+=head2  LoadByName (Queue => QUEUEID, Name => NAME)
 
-Loads the Custom field named NAME for Queue QUEUE. If QUEUE is 0,
-loads a global custom field
+Loads the Custom field named NAME.
+
+If a Queue parameter is specified, only look for ticket custom fields tied to that Queue.
+
+If the Queue parameter is '0', look for global ticket custom fields.
+
+If no queue parameter is specified, look for any and all custom fields with this name.
+
+BUG/TODO, this won't let you specify that you only want user or group CFs.
 
 =cut
 
 # Compatibility for API change after 3.0 beta 1
-*LoadNameAndQueue = \&LoadByNameAndQueue;
+*LoadNameAndQueue = \&LoadByName;
+# Change after 3.4 beta.
+*LoadByNameAndQueue = \&LoadByName;
 
-sub LoadByNameAndQueue {
+sub LoadByName {
     my $self = shift;
     my %args = (
         Queue => undef,
@@ -213,21 +222,33 @@
         @_,
     );
 
-    if ($args{'Queue'} =~ /\D/) {
+    # if we're looking for a queue by name, make it a number
+    if  (defined $args{'Queue'}  &&  $args{'Queue'} !~ /^\d+$/) {
 	my $QueueObj = RT::Queue->new($self->CurrentUser);
 	$QueueObj->Load($args{'Queue'});
 	$args{'Queue'} = $QueueObj->Id;
     }
 
-    # XXX - really naive implementation.  Slow.
+    # XXX - really naive implementation.  Slow. - not really. still just one query
 
     my $CFs = RT::CustomFields->new($self->CurrentUser);
+
     $CFs->Limit( FIELD => 'Name', VALUE => $args{'Name'} );
-    $CFs->LimitToQueue( $args{'Queue'} );
-    $CFs->RowsPerPage(1);
+    # Don't limit to queue if queue is 0.  Trying to do so breaks
+    # RT::Group type CFs.
+    if (defined $args{'Queue'}) {
+	$CFs->LimitToQueue( $args{'Queue'} );
+    }
+
+    # When loading by name, it's ok if they're disabled. That's not a big deal.
+    $CFs->{'find_disabled_rows'}=1;
 
-    my $CF = $CFs->First or return;
-    return $self->Load($CF->Id);
+    # We only want one entry.
+    $CFs->RowsPerPage(1);
+    unless ($CFs->First->id) {
+        return(0, $self->loc('Custom field not found'));
+    }
+    return($self->Load($CFs->First->id));
 
 }
 


More information about the Rt-commit mailing list