Hi Ruslan,

> > 2. Unique attachment session: RT temporary stores attachments
> > in $session{'Attachments'} and deletes this on Display.html, Update.html,
> > Create.html, ModifyAll.html and Bulk.html. The problem is that if you
> start
> > a comment, attach a file and you open a ticket or start another comment,
> > etc.in another browser window or tab, your uploaded attachment will be
> > deleted from session. So later when you submit your comment there won't
> be
> > your previously attached file. This is annoying for a lot of users that's
> > why I create unique session variable in every related page to store the
> > attachments.
> > Note: I think it is impossible to implement this with Callbacks only. It
> > needs patching or overlaying some files.
>
> This is implemented in the repo and aimed at 4.2.
>

Good news. In that case I won't work on creating patches for this.


>  > 3. Multiple attach: there are flash solutions for multi-attach file but
> I
> > don't like flash. Fortunately in HTML5 you can create <input type="file">
> > with multiple attribute. Modern browsers support it and allow users to
> > select more than one file at once. I implement this feature on Update,
> > Create and ModifyAll pages. Users like this more than I previously
> supposed
> > and it was only a 20 minute work to implement. :)
> > Note: this will be another reason for IE users to change their browser :)
>
> What happens with browsers that don't support this feature? If those
> don't have problems and just allow users to upload one file then we
> can consider this for core.


It is backward compatible so you can upload one file without any problem
with IE or older FF, Safari, Chrome, etc.


> Do you care to send a patch against master branch?

Note that because of above change (2), code around attachments
> upload is different, but actually it's better as we concentrated it in
> one place.


Patch for master branch is attached.
IMPORTANT: I'm unable to test it but I hope it works well on this branch.


>  > 4. Attachment coloring and ordering: you can define categories in
> SiteConfig
> > and also colors for these categories. On Display page you can set
> category
> > for every file with one click. Files get the color of their categories.
> You
> > can also order attachments list by category (color), filename, creator,
> size
> > and date. There is a predefined category "hidden". With this you can
> hide an
> > attachment.
> > It's not my favorite improvement but this is very useful for companies
> work
> > on long projects with lot of files.
>
> Sounds like useful @Plugin.
>
> If you need new callbacks for any code then you can send patches.


Thanks, I think it will help me a lot to create Plugins.

--
Bekeny
Docca OutSource IT Ltd.
From ab86ab8277fa9ed49a4a791180558d4c1b0364ae Mon Sep 17 00:00:00 2001
From: Balint Bekeny <balint.bek...@docca.hu>
Date: Sun, 22 Jan 2012 20:54:15 +0100
Subject: [PATCH 1/2] "multiple" attribute added to input type="file"

---
 share/html/Ticket/Elements/AddAttachments |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/share/html/Ticket/Elements/AddAttachments b/share/html/Ticket/Elements/AddAttachments
index 0086858..8021bcb 100644
--- a/share/html/Ticket/Elements/AddAttachments
+++ b/share/html/Ticket/Elements/AddAttachments
@@ -56,6 +56,6 @@
 </tr>
 % } # end of if
 
-<tr><td class="label"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
+<tr><td class="label"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" multiple="multiple" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
 </td></tr>
 % $m->callback( %ARGS, CallbackName => 'End' );
-- 
1.7.2.5

From b421c45d917a41e8d98ae79bc6c9a26665fd0c81 Mon Sep 17 00:00:00 2001
From: Balint Bekeny <balint.bek...@docca.hu>
Date: Sun, 22 Jan 2012 21:30:12 +0100
Subject: [PATCH 2/2] handle multiple files attached

---
 lib/RT/Interface/Web.pm          |   17 +++++++++--------
 share/html/Search/Bulk.html      |   21 +++++++++++++--------
 share/html/Ticket/Create.html    |   23 ++++++++++++++---------
 share/html/Ticket/ModifyAll.html |   23 ++++++++++++++---------
 share/html/Ticket/Update.html    |   23 ++++++++++++++---------
 5 files changed, 64 insertions(+), 43 deletions(-)

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index eefaab5..9c1c7cf 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1678,12 +1678,13 @@ sub MakeMIMEEntity {
 
     #TODO document what else this takes.
     my %args = (
-        Subject             => undef,
-        From                => undef,
-        Cc                  => undef,
-        Body                => undef,
-        AttachmentFieldName => undef,
-        Type                => undef,
+        Subject              => undef,
+        From                 => undef,
+        Cc                   => undef,
+        Body                 => undef,
+        AttachmentFieldName  => undef,
+        AttachmentFilehandle => undef,
+        Type                 => undef,
         @_,
     );
     my $Message = MIME::Entity->build(
@@ -1705,10 +1706,10 @@ sub MakeMIMEEntity {
         );
     }
 
-    if ( $args{'AttachmentFieldName'} ) {
+    if ( $args{'AttachmentFieldName'} || $args{'AttachmentFilehandle'} ) {
 
         my $cgi_object = $m->cgi_object;
-        my $filehandle = $cgi_object->upload( $args{'AttachmentFieldName'} );
+        my $filehandle = ( $args{'AttachmentFieldName'} ? $cgi_object->upload( $args{'AttachmentFieldName'} ) : $args{'AttachmentFilehandle'} );
         if ( defined $filehandle && length $filehandle ) {
 
             my ( @content, $buffer );
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index d39c24c..3dbc823 100755
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -238,15 +238,20 @@ foreach my $key (keys %ARGS) {
 
 # store the uploaded attachment in session
 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
+    my $cgi_object = $m->cgi_object;
+    if ( my @filehandle = $cgi_object->upload('Attach') ) {
+      foreach my $afh (@filehandle)  {
+        my $attachment = MakeMIMEEntity(
+          AttachmentFilehandle => $afh
+        );
+
+        my $file_path = Encode::decode_utf8("$afh");
+        $session{'Attachments'} = {
+          %{$session{'Attachments'} || {}},
+          $file_path => $attachment,
+        };
+      }
+    }
 }
 
 # delete temporary storage entry to make WebUI clean
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index d41c090..c9d52ec 100755
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -382,15 +382,20 @@ foreach my $key (keys %ARGS) {
 
 # store the uploaded attachment in session
 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-	$file_path => $attachment,
-    };
+    my $cgi_object = $m->cgi_object;
+    if ( my @filehandle = $cgi_object->upload('Attach') ) {
+      foreach my $afh (@filehandle)  {
+        my $attachment = MakeMIMEEntity(
+          AttachmentFilehandle => $afh
+        );
+
+        my $file_path = Encode::decode_utf8("$afh");
+        $session{'Attachments'} = {
+          %{$session{'Attachments'} || {}},
+          $file_path => $attachment,
+        };
+      }
+    }
 }
 
 # delete temporary storage entry to make WebUI clean
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 8619cd5..af68431 100755
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -162,15 +162,20 @@ foreach my $key (keys %ARGS) {
 
 # store the uploaded attachment in session
 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
+    my $cgi_object = $m->cgi_object;
+    if ( my @filehandle = $cgi_object->upload('Attach') ) {
+      foreach my $afh (@filehandle)  {
+        my $attachment = MakeMIMEEntity(
+          AttachmentFilehandle => $afh
+        );
+
+        my $file_path = Encode::decode_utf8("$afh");
+        $session{'Attachments'} = {
+          %{$session{'Attachments'} || {}},
+          $file_path => $attachment,
+        };
+      }
+    }
 }
 
 # delete temporary storage entry to make WebUI clean
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 672d8ab..7340426 100755
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -252,15 +252,20 @@ foreach my $key (keys %ARGS) {
 
 # store the uploaded attachment in session
 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
+    my $cgi_object = $m->cgi_object;
+    if ( my @filehandle = $cgi_object->upload('Attach') ) {
+      foreach my $afh (@filehandle)  {
+        my $attachment = MakeMIMEEntity(
+          AttachmentFilehandle => $afh
+        );
+
+        my $file_path = Encode::decode_utf8("$afh");
+        $session{'Attachments'} = {
+          %{$session{'Attachments'} || {}},
+          $file_path => $attachment,
+        };
+      }
+    }
 }
 
 # delete temporary storage entry to make WebUI clean
-- 
1.7.2.5

--------
RT Training Sessions (http://bestpractical.com/services/training.html)
* Boston — March 5 & 6, 2012

Reply via email to