]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1383268 - Add attachments to new-bug
authorSebastin Santy <sebastinssanty@gmail.com>
Fri, 28 Jul 2017 20:34:41 +0000 (02:04 +0530)
committerDylan William Hardison <dylan@hardison.net>
Fri, 28 Jul 2017 20:34:41 +0000 (13:34 -0700)
extensions/BugModal/web/new_bug.css
extensions/BugModal/web/new_bug.js
new_bug.cgi
template/en/default/bug/new_bug.html.tmpl

index a96083d81d44bdd8c0c1b23147b51142c096d623..8a161bb9ac01fd77fd404cee811b16f59b9c6bc3 100644 (file)
     padding: 8px;
 }
 
+#reset {
+    padding: 1.5px 8px;
+}
+
 .new-bug-container {
     display: flex;
     display: -webkit-flex;
@@ -41,6 +45,7 @@
     flex: 6 1 30px;
     margin:5px;
 }
-input, label {
-    display: block; !important
+
+.file-container {
+    padding: 8px;
 }
index 9da5abce93e03e72a6c17ceb21ec63536da2b0c2..32dbe4783df33a68a85eae6ec2754ec96c15b3e4 100644 (file)
@@ -105,5 +105,21 @@ $(document).ready(function() {
                 this.form.submit()
             }
         });
+
+    $('#data').on("change", function () {
+        if (!$('#data').val()) {
+            return
+        } else {
+            document.getElementById('reset').style.display = "inline-block";
+            $("#description").prop('required',true);
+        }
+    });
+    $('#reset')
+        .click(function(event) {
+            event.preventDefault();
+            document.getElementById('data').value = "";
+            document.getElementById('reset').style.display = "none";
+            $("#description").prop('required',false);
+        });
     
 });
index 7f35f9ebc2b4730f2c8eec47bef471f61728be99..6a62d0dcb45030136dd6ec806ee152bb9e4b61aa 100644 (file)
@@ -45,6 +45,8 @@ my $user = Bugzilla->login(LOGIN_REQUIRED);
 my $cgi      = Bugzilla->cgi;
 my $template = Bugzilla->template;
 my $vars     = {};
+my $dbh      = Bugzilla->dbh;
+
 
 unless ($user->in_group('new-bug-testers')) {
     print $cgi->redirect(correct_urlbase());
@@ -70,6 +72,34 @@ if (lc($cgi->request_method) eq 'post') {
             });
      delete_token($token);
 
+     my $data_fh = $cgi->upload('data');
+
+     if ($data_fh) {
+         my $content_type = Bugzilla::Attachment::get_content_type();
+         my $attachment;
+
+         my $error_mode_cache = Bugzilla->error_mode;
+         Bugzilla->error_mode(ERROR_MODE_DIE);
+         my $timestamp = $dbh->selectrow_array(
+             'SELECT creation_ts FROM bugs WHERE bug_id = ?', undef, $new_bug->bug_id);
+         eval {
+             $attachment = Bugzilla::Attachment->create(
+                 {bug           => $new_bug,
+                  creation_ts   => $timestamp,
+                  data          => $data_fh,
+                  description   => scalar $cgi->param('description'),
+                  filename      => $data_fh,
+                  ispatch       => 0,
+                  isprivate     => 0,
+                  mimetype      => $content_type,
+                 });
+         };
+         Bugzilla->error_mode($error_mode_cache);
+         unless ($attachment) {
+            $vars->{'message'} = 'attachment_creation_failed';
+         }
+     }
+
      my $recipients = { changer => $user };
      my $bug_sent = Bugzilla::BugMail::Send($new_bug->bug_id, $recipients);
      $bug_sent->{type} = 'created';
index b1367788da3bfa1e895e5798f607407204b6efe2..a8d51414251fbe79aa23d58b44d622890537ac4c 100644 (file)
@@ -18,7 +18,7 @@
 
 [% IF user.id %]
   <div style="display: none" id="xhr-error"></div>
-  <form name="newbugform" id="newbugform" method="post" action="new_bug.cgi">
+  <form name="newbugform" id="newbugform" method="post" action="new_bug.cgi" enctype="multipart/form-data">
     <input type="hidden" value="[% issue_hash_token(['new_bug']) FILTER html %]" name="token">
     <div class="new-bug-container">
       <div class="new-bug">
           [% INCLUDE bug_modal/common_new_comment.html.tmpl disable_cols=1 %]
           [% END %]
           [% WRAPPER bug_modal/module.html.tmpl title = "Attach a File" collapsed = 1 %]
-            <p>Coming Soon.</p>
+          <div class="file-container">
+            <input type="file" style="display: inline-block;" id="data" name="data" size="50" >
+            <button id="reset" style="display: none;">Reset</button>
+          </div>
+            <label for="description" style="display: inline-block;">Description:</label>
+            <input type="text" id="description" name="description" class="required"
+           size="60" maxlength="200" style="display: inline-block;">
+           <input type="radio" id="autodetect"
+       name="contenttypemethod" value="autodetect" checked="checked" style="display:none">
           [% END %]
           <button type="submit" id="create-btn" class="create-btn major">Submit</button>
         </div>