From e74d21eaeb3bc4ba3a5521882815b6a6c6d45bcc Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Sat, 29 Jul 2017 02:04:41 +0530 Subject: Bug 1383268 - Add attachments to new-bug --- extensions/BugModal/web/new_bug.css | 9 +++++++-- extensions/BugModal/web/new_bug.js | 16 ++++++++++++++++ new_bug.cgi | 30 ++++++++++++++++++++++++++++++ template/en/default/bug/new_bug.html.tmpl | 12 ++++++++++-- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/extensions/BugModal/web/new_bug.css b/extensions/BugModal/web/new_bug.css index a96083d81..8a161bb9a 100644 --- a/extensions/BugModal/web/new_bug.css +++ b/extensions/BugModal/web/new_bug.css @@ -10,6 +10,10 @@ 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; } diff --git a/extensions/BugModal/web/new_bug.js b/extensions/BugModal/web/new_bug.js index 9da5abce9..32dbe4783 100644 --- a/extensions/BugModal/web/new_bug.js +++ b/extensions/BugModal/web/new_bug.js @@ -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); + }); }); diff --git a/new_bug.cgi b/new_bug.cgi index 7f35f9ebc..6a62d0dcb 100644 --- a/new_bug.cgi +++ b/new_bug.cgi @@ -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'; diff --git a/template/en/default/bug/new_bug.html.tmpl b/template/en/default/bug/new_bug.html.tmpl index b1367788d..a8d514142 100644 --- a/template/en/default/bug/new_bug.html.tmpl +++ b/template/en/default/bug/new_bug.html.tmpl @@ -18,7 +18,7 @@ [% IF user.id %] -
+
@@ -56,7 +56,15 @@ [% INCLUDE bug_modal/common_new_comment.html.tmpl disable_cols=1 %] [% END %] [% WRAPPER bug_modal/module.html.tmpl title = "Attach a File" collapsed = 1 %] -

Coming Soon.

+
+ + +
+ + + [% END %]
-- cgit v1.2.3-24-g4f1b