[rt-commit] [svn] r488 - in rt/branches: . autrijus-3.1/html/Admin/Groups autrijus-3.1/html/Admin/Users autrijus-3.1/html/CustomFieldValue autrijus-3.1/html/Elements autrijus-3.1/lib/RT autrijus-3.1/lib/RT/Interface

autrijus at fsck.com autrijus at fsck.com
Sun Mar 7 08:59:45 EST 2004


Author: autrijus
Date: Sun Mar  7 08:59:44 2004
New Revision: 488

Added:
   rt/branches/autrijus-3.1/html/CustomFieldValue/
   rt/branches/autrijus-3.1/html/CustomFieldValue/dhandler
Modified:
   rt/branches/   (props changed)
   rt/branches/autrijus-3.1/html/Admin/Groups/Modify.html
   rt/branches/autrijus-3.1/html/Admin/Users/Modify.html
   rt/branches/autrijus-3.1/html/Elements/EditCustomFieldBinary
   rt/branches/autrijus-3.1/html/Elements/EditCustomFieldImage
   rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm
   rt/branches/autrijus-3.1/lib/RT/ObjectCustomFieldValue_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/Record.pm
Log:
* file OCVF upload works.
* it is now possible to download OCFVs.


Modified: rt/branches/autrijus-3.1/html/Admin/Groups/Modify.html
==============================================================================
--- rt/branches/autrijus-3.1/html/Admin/Groups/Modify.html	(original)
+++ rt/branches/autrijus-3.1/html/Admin/Groups/Modify.html	Sun Mar  7 08:59:44 2004
@@ -31,7 +31,7 @@
 
 
 
-<FORM ACTION="<%$RT::WebPath%>/Admin/Groups/Modify.html" METHOD=POST>
+<FORM ACTION="<%$RT::WebPath%>/Admin/Groups/Modify.html" METHOD=POST ENCTYPE="multipart/form-data">
 
 %unless ($Group->Id) {
 <INPUT TYPE=HIDDEN NAME=id VALUE="new">

Modified: rt/branches/autrijus-3.1/html/Admin/Users/Modify.html
==============================================================================
--- rt/branches/autrijus-3.1/html/Admin/Users/Modify.html	(original)
+++ rt/branches/autrijus-3.1/html/Admin/Users/Modify.html	Sun Mar  7 08:59:44 2004
@@ -30,7 +30,7 @@
 
 <& /Elements/ListActions, actions => \@results &>
 
-<FORM ACTION="<%$RT::WebPath%>/Admin/Users/Modify.html" METHOD=POST>
+<FORM ACTION="<%$RT::WebPath%>/Admin/Users/Modify.html" METHOD=POST ENCTYPE="multipart/form-data">
 %if ($Create) {
 <INPUT TYPE=HIDDEN NAME=id VALUE="new">
 % } else {

Added: rt/branches/autrijus-3.1/html/CustomFieldValue/dhandler
==============================================================================
--- (empty file)
+++ rt/branches/autrijus-3.1/html/CustomFieldValue/dhandler	Sun Mar  7 08:59:44 2004
@@ -0,0 +1,53 @@
+%# BEGIN LICENSE BLOCK
+%# 
+%# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
+%# 
+%# (Except where explictly superceded by other copyright notices)
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work 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.
+%# 
+%# Unless otherwise specified, all modifications, corrections or
+%# extensions to this work which alter its source code become the
+%# property of Best Practical Solutions, LLC when submitted for
+%# inclusion in the work.
+%# 
+%# 
+%# END LICENSE BLOCK
+<%perl>
+my $id;
+my $arg = $m->dhandler_arg;                # get rest of path
+if ($arg =~ /^(\d+)\//) {
+    $id = $1;
+}
+else {
+    Abort("Corrupted customfieldvalue URL.");
+}
+my $OCFV = RT::ObjectCustomFieldValue->new($session{'CurrentUser'});
+$OCFV->Load($id) || Abort("OCFV '$id' could not be loaded");
+
+unless ($OCFV->id) {
+    Abort("Bad OCFV id. Couldn't find OCFV '$id'\n");
+}
+
+my $content_type = $OCFV->ContentType || 'text/plain';
+    
+unless ($RT::TrustHTMLAttachments) {
+    $content_type = 'text/plain' if ($content_type =~ /^text\/html/i);
+}
+
+$r->content_type( $content_type );
+$m->clear_buffer();
+$m->out($OCFV->LargeContent);
+$m->abort; 
+</%perl>
+<%attr>
+AutoFlush => 0
+</%attr>

Modified: rt/branches/autrijus-3.1/html/Elements/EditCustomFieldBinary
==============================================================================
--- rt/branches/autrijus-3.1/html/Elements/EditCustomFieldBinary	(original)
+++ rt/branches/autrijus-3.1/html/Elements/EditCustomFieldBinary	Sun Mar  7 08:59:44 2004
@@ -23,10 +23,10 @@
 %# END LICENSE BLOCK
 % while (my $value = $Values->Next ) {
 %# XXX - let user download the file(s) here?
-<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValues" value="<% $value->Id %>"><% $value->Content %><br>
+<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" value="<% $value->Id %>"><a href="/CustomFieldValue/<% $value->Id %>/<% $value->Content %>"><% $value->Content %></a><br>
 % }
-% if (!$MaxValues or $Values->Count >= $MaxValues) {
-<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Value">
+% if (!$MaxValues or $Values->Count < $MaxValues) {
+<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload">
 % }
 <%ARGS>
 $Object => undef

Modified: rt/branches/autrijus-3.1/html/Elements/EditCustomFieldImage
==============================================================================
--- rt/branches/autrijus-3.1/html/Elements/EditCustomFieldImage	(original)
+++ rt/branches/autrijus-3.1/html/Elements/EditCustomFieldImage	Sun Mar  7 08:59:44 2004
@@ -22,11 +22,11 @@
 %# 
 %# END LICENSE BLOCK
 % while (my $value = $Values->Next ) {
-%# XXX - display thumbnails or full images?
-<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValues" value="<% $value->Id %>"><% $value->Content %><br>
+%# XXX - let user download the file(s) here?
+<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" value="<% $value->Id %>"><a href="/CustomFieldValue/<% $value->Id %>/<% $value->Content %>"><% $value->Content %></a><br>
 % }
 % if (!$MaxValues or $Values->Count < $MaxValues) {
-<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Value">
+<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload">
 % }
 <%ARGS>
 $Object => undef

Modified: rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm	Sun Mar  7 08:59:44 2004
@@ -773,6 +773,8 @@
 	my $self = shift;
 	my %args = ( Object => undef,
                  Content => undef,
+		 LargeContent => undef,
+		 ContentType => undef,
 		     @_ );
 	my $obj = $args{'Object'} or return;
 
@@ -780,6 +782,8 @@
 	my $val = $newval->Create(ObjectType => ref($obj),
 	                    ObjectId => $obj->Id,
                             Content => $args{'Content'},
+                            LargeContent => $args{'LargeContent'},
+                            ContentType => $args{'ContentType'},
                             CustomField => $self->Id);
 
     return($val);
@@ -798,15 +802,25 @@
 =cut
 
 sub DeleteValueForObject {
-	my $self = shift;
-	my %args = ( Object => undef,
+    my $self = shift;
+    my %args = ( Object => undef,
                  Content => undef,
+                 Id => undef,
 		     @_ );
 
-	my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
-    $oldval->LoadByObjectContentAndCustomField (Object => $args{'Object'}, 
-                                                Content =>  $args{'Content'}, 
-                                                CustomField => $self->Id );
+    my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
+
+    if (my $id = $args{'Id'}) {
+	$oldval->Load($id);
+    }
+    else {
+	$oldval->LoadByObjectContentAndCustomField(
+	    Object => $args{'Object'}, 
+	    Content =>  $args{'Content'}, 
+	    CustomField => $self->Id
+	);
+    }
+
     # check ot make sure we found it
     unless ($oldval->Id) {
         return(0, $self->loc("Custom field value [_1] could not be found for custom field [_2]", $args{'Content'}, $self->Name));

Modified: rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm	Sun Mar  7 08:59:44 2004
@@ -1166,12 +1166,35 @@
 			    push ( @results, $msg );
 			}
 		    }
+		    elsif ( $arg =~ /-Upload$/ ) {
+			my $cgi_object = $m->cgi_object;
+			my $fh = $cgi_object->upload($arg) or next;
+			my $upload_info = $cgi_object->uploadInfo($fh);
+			my $filename = "$fh";
+			$filename =~ s#^.*[\\/]##;
+			my ( $val, $msg ) = $Object->AddCustomFieldValue(
+			    Field => $cf,
+			    Value => $filename,
+			    LargeContent => do { local $/; scalar <$fh> },
+			    ContentType => $upload_info->{'Content-Type'},
+			);
+		    }
 		    elsif ( $arg =~ /-DeleteValues$/ ) {
 			foreach my $value (@values) {
 			    next unless length($value);
 			    my ( $val, $msg ) = $Object->DeleteCustomFieldValue(
 				Field => $cf,
 				Value => $value
+			    );
+			    push ( @results, $msg );
+			}
+		    }
+		    elsif ( $arg =~ /-DeleteValueIds$/ ) {
+			foreach my $value (@values) {
+			    next unless length($value);
+			    my ( $val, $msg ) = $Object->DeleteCustomFieldValue(
+				Field => $cf,
+				ValueId => $value,
 			    );
 			    push ( @results, $msg );
 			}

Modified: rt/branches/autrijus-3.1/lib/RT/ObjectCustomFieldValue_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/ObjectCustomFieldValue_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/ObjectCustomFieldValue_Overlay.pm	Sun Mar  7 08:59:44 2004
@@ -68,4 +68,9 @@
     
 }
 
+sub Delete {
+    my $self = shift;
+    $self->SetCurrent(0);
+}
+
 1;

Modified: rt/branches/autrijus-3.1/lib/RT/Record.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Record.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Record.pm	Sun Mar  7 08:59:44 2004
@@ -791,7 +791,9 @@
 
         my ( $new_value_id, $value_msg ) = $cf->AddValueForObject(
             Object  => $self,
-            Content => $args{'Value'}
+            Content => $args{'Value'},
+            LargeContent => $args{'LargeContent'},
+            ContentType => $args{'ContenType'},
         );
 
         unless ($new_value_id) {
@@ -836,7 +838,9 @@
     else {
         my ( $new_value_id ) = $cf->AddValueForObject(
             Object  => $self,
-            Content => $args{'Value'}
+            Content => $args{'Value'},
+            LargeContent => $args{'LargeContent'},
+            ContentType => $args{'ContenType'},
         );
 
         unless ($new_value_id) {
@@ -879,6 +883,7 @@
     my %args = (
         Field => undef,
         Value => undef,
+	ValueId => undef,
         @_);
 
 #    XXX - normalise CF related ACLs... ask obra!
@@ -898,7 +903,11 @@
     }
 
 
-     my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $args{'Value'});
+     my ($val, $msg) = $cf->DeleteValueForObject(
+	 Object => $self,
+	 Id => $args{'ValueId'},
+	 Content => $args{'Value'},
+     );
      unless ($val) { 
             return (0,$msg);
      }



More information about the Rt-commit mailing list