[Rt-commit] rt branch, 4.2/pluggable-cf-types, updated. rt-4.0.0rc6-139-g3d436a0
Chia-liang Kao
clkao at bestpractical.com
Wed Mar 23 10:19:45 EDT 2011
The branch, 4.2/pluggable-cf-types has been updated
via 3d436a06ced452c2dd51c5bf0dafa2c11fd8baa3 (commit)
via b923f961f6b630cdefeb919c256722fc837f49b7 (commit)
via 1c1bebeca15c09a22ad3acf32ca8af4d4af83446 (commit)
via 566f53b139f195d818cace0cd7eac6b5b712166d (commit)
from 779a12a3f6025b8afa6b93c19ca9e81cb77e1757 (commit)
Summary of changes:
lib/RT/CustomField.pm | 13 +++
lib/RT/CustomField/Type/ImageWithCaption.pm | 26 +++++
lib/RT/Interface/Web.pm | 101 +++++++++++++-------
...mFieldImage => EditCustomFieldImageWithCaption} | 2 +
...mFieldImage => ShowCustomFieldImageWithCaption} | 0
5 files changed, 109 insertions(+), 33 deletions(-)
create mode 100644 lib/RT/CustomField/Type/ImageWithCaption.pm
copy share/html/Elements/{EditCustomFieldImage => EditCustomFieldImageWithCaption} (95%)
copy share/html/Elements/{ShowCustomFieldImage => ShowCustomFieldImageWithCaption} (100%)
- Log -----------------------------------------------------------------
commit 566f53b139f195d818cace0cd7eac6b5b712166d
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Mar 23 20:59:31 2011 +0800
Refactor Interface::Web::CreateTicket's CF handling to be per-CF based
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index a2527c3..e17f539 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1285,6 +1285,7 @@ sub CreateTicket {
: ( $ARGS{'AttachTickets'} ) );
}
+ my %ticket_cfs;
foreach my $arg ( keys %ARGS ) {
next if $arg =~ /-(?:Magic|Category)$/;
@@ -1294,41 +1295,22 @@ sub CreateTicket {
# Object-RT::Ticket--CustomField-3-Values
elsif ( $arg =~ /^Object-RT::Ticket--CustomField-(\d+)/ ) {
- my $cfid = $1;
-
- my $cf = RT::CustomField->new( $session{'CurrentUser'} );
- $cf->Load($cfid);
- unless ( $cf->id ) {
- $RT::Logger->error( "Couldn't load custom field #" . $cfid );
- next;
- }
-
- if ( $arg =~ /-Upload$/ ) {
- $create_args{"CustomField-$cfid"} = _UploadedFile($arg);
- next;
- }
+ $ticket_cfs{$1} = 1;
+ }
+ }
- my $type = $cf->Type;
+ for my $cfid (sort keys %ticket_cfs) {
+ my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->Load($cfid);
+ unless ( $cf->id ) {
+ $RT::Logger->error( "Couldn't load custom field #" . $cfid );
+ next;
+ }
- my @values = ();
- if ( ref $ARGS{$arg} eq 'ARRAY' ) {
- @values = @{ $ARGS{$arg} };
- } elsif ( $type =~ /text/i ) {
- @values = ( $ARGS{$arg} );
- } else {
- no warnings 'uninitialized';
- @values = split /\r*\n/, $ARGS{$arg};
- }
- @values = grep length, map {
- s/\r+\n/\n/g;
- s/^\s+//;
- s/\s+$//;
- $_;
- }
- grep defined, @values;
+ my %web_args = map { $_ => $ARGS{$_} }
+ grep { /^Object-RT::Ticket--CustomField-$cfid-/ } keys %ARGS;
- $create_args{"CustomField-$cfid"} = \@values;
- }
+ _FillCreateArgsFromWebArgs($cf, \%web_args, \%create_args);
}
# turn new link lists into arrays, and pass in the proper arguments
@@ -1360,6 +1342,39 @@ sub CreateTicket {
}
+sub _FillCreateArgsFromWebArgs {
+ my ($cf, $web_args, $create_args) = @_;
+
+ my $key = "CustomField-".$cf->Id;
+ for my $arg (keys %$web_args) {
+ next if $arg =~ /-(?:Magic|Category)$/;
+ if ( $arg =~ /-Upload$/ ) {
+ $create_args->{$key} = _UploadedFile($arg);
+ next;
+ }
+
+ my $type = $cf->Type;
+
+ my @values = ();
+ if ( ref $web_args->{$arg} eq 'ARRAY' ) {
+ @values = @{ $web_args->{$arg} };
+ } elsif ( $type =~ /text/i ) {
+ @values = ( $web_args->{$arg} );
+ } else {
+ no warnings 'uninitialized';
+ @values = split /\r*\n/, $web_args->{$arg};
+ }
+ @values = grep length, map {
+ s/\r+\n/\n/g;
+ s/^\s+//;
+ s/\s+$//;
+ $_;
+ } grep defined, @values;
+
+ $create_args->{$key} = \@values;
+ }
+}
+
=head2 LoadTicket id
commit 1c1bebeca15c09a22ad3acf32ca8af4d4af83446
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Mar 23 21:22:28 2011 +0800
trim input name prefix for _FillCreateArgsFromWebArgs, and retreive upload for web_args earlier.
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index e17f539..d2d1a21 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1307,8 +1307,12 @@ sub CreateTicket {
next;
}
- my %web_args = map { $_ => $ARGS{$_} }
- grep { /^Object-RT::Ticket--CustomField-$cfid-/ } keys %ARGS;
+ my %web_args =
+ map { /^Object-RT::Ticket--CustomField-$cfid-(\w+)$/
+ ? ( $1 => $1 eq 'Upload' ? scalar $m->cgi_object->upload($_)
+ : $ARGS{$_} )
+ : ()
+ } keys %ARGS;
_FillCreateArgsFromWebArgs($cf, \%web_args, \%create_args);
}
@@ -1347,9 +1351,10 @@ sub _FillCreateArgsFromWebArgs {
my $key = "CustomField-".$cf->Id;
for my $arg (keys %$web_args) {
- next if $arg =~ /-(?:Magic|Category)$/;
- if ( $arg =~ /-Upload$/ ) {
- $create_args->{$key} = _UploadedFile($arg);
+ next if $arg =~ /^(?:Magic|Category)$/;
+ if ( $arg eq 'Upload' ) {
+ $create_args->{$key} = _UploadedFileArgs($web_args->{$arg})
+ if $web_args->{$arg};
next;
}
@@ -2524,6 +2529,13 @@ sub _UploadedFile {
my $arg = shift;
my $cgi_object = $m->cgi_object;
my $fh = $cgi_object->upload($arg) or return undef;
+
+ return _UploadedFileArgs($fh);
+}
+
+sub _UploadedFileArgs {
+ my $fh = shift;
+ my $cgi_object = $m->cgi_object;
my $upload_info = $cgi_object->uploadInfo($fh);
my $filename = "$fh";
commit b923f961f6b630cdefeb919c256722fc837f49b7
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Mar 23 21:38:31 2011 +0800
cf typeclass hook: CreateArgsFromWebArgs
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index d2d1a21..14584df 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1350,6 +1350,14 @@ sub _FillCreateArgsFromWebArgs {
my ($cf, $web_args, $create_args) = @_;
my $key = "CustomField-".$cf->Id;
+
+ my $class = $cf->GetTypeClass;
+
+ if ($class && $class->can('CreateArgsFromWebArgs')) {
+ $create_args->{$key} = $class->CreateArgsFromWebArgs($cf, $web_args);
+ return;
+ }
+
for my $arg (keys %$web_args) {
next if $arg =~ /^(?:Magic|Category)$/;
if ( $arg eq 'Upload' ) {
commit 3d436a06ced452c2dd51c5bf0dafa2c11fd8baa3
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Mar 23 22:17:40 2011 +0800
ImageWithCaption cf type.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 86129a7..27b4b8f 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -243,6 +243,19 @@ __PACKAGE__->RegisterType(
},
);
+__PACKAGE__->RegisterType(
+ ImageWithCaption => {
+ sort_order => 55,
+ selection_type => 0,
+ labels => [
+ 'Upload multiple images with caption', # loc
+ 'Upload one image with caption', # loc
+ 'Upload up to [_1] images with caption', # loc
+ ],
+ class => 'RT::CustomField::Type::ImageWithCaption',
+ }
+);
+
__PACKAGE__->AddRights(%$RIGHTS);
__PACKAGE__->AddRightCategories(%$RIGHT_CATEGORIES);
diff --git a/lib/RT/CustomField/Type/ImageWithCaption.pm b/lib/RT/CustomField/Type/ImageWithCaption.pm
new file mode 100644
index 0000000..bff4b10
--- /dev/null
+++ b/lib/RT/CustomField/Type/ImageWithCaption.pm
@@ -0,0 +1,26 @@
+package RT::CustomField::Type::ImageWithCaption;
+use strict;
+use warnings;
+
+sub CanonicalizeForCreate {
+ my ($self, $cf, $args) = @_;
+
+ return wantarray ? (1) : 1;
+}
+
+sub Stringify {
+ my ($self, $ocfv) = @_;
+ my $content = $ocfv->_Value('Content');
+
+ return $content
+}
+
+sub CreateArgsFromWebArgs {
+ my ($self, $cf, $web_args) = @_;
+
+ my $args = HTML::Mason::Commands::_UploadedFileArgs($web_args->{Upload});
+ $args->{Value} = $web_args->{Value}; # override value over filename from upload
+ return $args;
+}
+
+1;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 14584df..5f730ee 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2170,7 +2170,7 @@ sub _ProcessObjectCustomFieldUpdates {
next if defined $args{'ARGS'}->{'Values'} && length $args{'ARGS'}->{'Values'};
# "Empty" values does not mean anything for Image and Binary fields
- next if $cf_type =~ /^(?:Image|Binary)$/;
+ next if $cf_type =~ /^(?:Image|Binary|ImageWithCaption)$/;
$arg = 'Values';
$args{'ARGS'}->{'Values'} = undef;
diff --git a/share/html/Elements/EditCustomFieldImageWithCaption b/share/html/Elements/EditCustomFieldImageWithCaption
new file mode 100644
index 0000000..318f098
--- /dev/null
+++ b/share/html/Elements/EditCustomFieldImageWithCaption
@@ -0,0 +1,64 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# 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.
+%#
+%# 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 Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+% while ($Values and my $value = $Values->Next ) {
+<input type="checkbox" class="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><& ShowCustomFieldImage, Object => $value &>
+<br />
+% }
+% if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
+<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload" class="CF-<%$CustomField->id%>-Edit" />
+<br />
+Caption: <input type="text" name="<%$NamePrefix%><%$CustomField->Id%>-Value" class="CF-<%$CustomField->id%>-Edit" />
+% }
+<%ARGS>
+$Object => undef
+$CustomField => undef
+$NamePrefix => undef
+$Default => undef
+$Values => undef
+$MaxValues => undef
+</%ARGS>
diff --git a/share/html/Elements/ShowCustomFieldImageWithCaption b/share/html/Elements/ShowCustomFieldImageWithCaption
new file mode 100644
index 0000000..3d22e5c
--- /dev/null
+++ b/share/html/Elements/ShowCustomFieldImageWithCaption
@@ -0,0 +1,53 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# 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.
+%#
+%# 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 Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+% my $url = RT->Config->Get('WebPath') . "/Download/CustomFieldValue/".$Object->Id.'/'.$Object->Content;
+<a href="<% $url %>"><% $Object->Content %></a>
+<img type="<% $Object->ContentType %>" height="64" src="<% $url %>" align="middle" />
+<%ARGS>
+$Object
+</%ARGS>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list