Bug 138596 - add preview for too long comments
git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@1865 6955db30-a419-402b-8a0d-67ecbb4d7f56master
parent
6c7355da56
commit
62c781c123
|
@ -30,6 +30,8 @@ use Bugzilla::User;
|
|||
use Bugzilla::Util;
|
||||
use Bugzilla::Template;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
###############################
|
||||
#### Initialization ####
|
||||
###############################
|
||||
|
@ -92,7 +94,6 @@ sub preload {
|
|||
###############################
|
||||
|
||||
sub already_wrapped { return $_[0]->{'already_wrapped'}; }
|
||||
sub body { return $_[0]->{'thetext'}; }
|
||||
sub bug_id { return $_[0]->{'bug_id'}; }
|
||||
sub creation_ts { return $_[0]->{'bug_when'}; }
|
||||
sub is_private { return $_[0]->{'isprivate'}; }
|
||||
|
@ -101,6 +102,21 @@ sub type { return $_[0]->{'type'}; }
|
|||
sub extra_data { return $_[0]->{'extra_data'} }
|
||||
sub who { return $_[0]->{'who'}; }
|
||||
|
||||
sub body
|
||||
{
|
||||
my ($self, $preview) = @_;
|
||||
$preview = 0 if !$preview;
|
||||
if ($preview && !$self->check_length)
|
||||
{
|
||||
my $max_lines = Bugzilla->params->{preview_comment_lines} - 1;
|
||||
my $line_length = Bugzilla->params->{comment_line_length} - 1;
|
||||
my $result = $self->{'thetext'};
|
||||
$result =~ s/^((?>[^\n]{0,$line_length}.){0,$max_lines}(?>[^\n]{0,$line_length}\s)).*$/\1.../s;
|
||||
return $result;
|
||||
}
|
||||
return $_[0]->{'thetext'};
|
||||
}
|
||||
|
||||
sub bug {
|
||||
my $self = shift;
|
||||
require Bugzilla::Bug;
|
||||
|
@ -134,6 +150,7 @@ sub author {
|
|||
sub body_full {
|
||||
my ($self, $params) = @_;
|
||||
$params ||= {};
|
||||
my $preview = $params->{preview} ? $params->{preview} : 0;
|
||||
my $template = Bugzilla->template_inner;
|
||||
my $body;
|
||||
my $t = $self->type;
|
||||
|
@ -146,17 +163,36 @@ sub body_full {
|
|||
$body =~ s/^X//;
|
||||
}
|
||||
else {
|
||||
$body = $self->body;
|
||||
$body = $self->body($preview);
|
||||
}
|
||||
if (!$params->{is_bugmail}) {
|
||||
$body = Bugzilla::Template::quoteUrls($body, $self->bug_id, $self);
|
||||
}
|
||||
if ($params->{wrap}) {
|
||||
$body = wrap_comment($body);
|
||||
if (!$preview && !($self->check_length))
|
||||
{
|
||||
$params->{preview} = 1;
|
||||
my $new_body;
|
||||
$template->process("bug/comment-preview-text.html.tmpl",
|
||||
{ preview => $self->body_full($params), body => $body, id => $self->id }, \$new_body)
|
||||
|| ThrowTemplateError($template->error());
|
||||
$body = $new_body;
|
||||
}
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
sub check_length
|
||||
{
|
||||
my $self = shift;
|
||||
my $test = $self->{'thetext'};
|
||||
my $line_length = Bugzilla->params->{comment_line_length};
|
||||
my $length = $test =~ s/([^\n]{$line_length}|\n)/$1/g;
|
||||
$length = 0 if !$length;
|
||||
return $length <= Bugzilla->params->{preview_comment_lines};
|
||||
}
|
||||
|
||||
############
|
||||
# Mutators #
|
||||
############
|
||||
|
|
|
@ -197,6 +197,20 @@ sub get_param_list {
|
|||
type => 'b',
|
||||
default => 0,
|
||||
},
|
||||
|
||||
{
|
||||
name => 'comment_line_length',
|
||||
type => 't',
|
||||
default => '80',
|
||||
checker => \&check_numeric
|
||||
},
|
||||
|
||||
{
|
||||
name => 'preview_comment_lines',
|
||||
type => 't',
|
||||
default => '30',
|
||||
checker => \&check_numeric
|
||||
},
|
||||
);
|
||||
return @param_list;
|
||||
}
|
||||
|
|
22
js/bug.js
22
js/bug.js
|
@ -49,6 +49,28 @@ function showhide_comment(comment_id, show)
|
|||
addClass(comment, 'collapsed');
|
||||
}
|
||||
|
||||
function showhide_comment_preview(comment_id)
|
||||
{
|
||||
var link = document.getElementById('comment-preview-link-' + comment_id);
|
||||
var preview = document.getElementById('comment-preview-' + comment_id);
|
||||
var body = document.getElementById('comment-body-' + comment_id);
|
||||
var show = link.className.match(new RegExp(/\bshown\b/))
|
||||
if (show)
|
||||
{
|
||||
preview.style.display = 'block';
|
||||
body.style.display = 'none';
|
||||
removeClass(link, "shown");
|
||||
}
|
||||
else
|
||||
{
|
||||
preview.style.display = 'none';
|
||||
body.style.display = 'block';
|
||||
addClass(link, "shown");
|
||||
}
|
||||
link.innerHTML = (!show ? "Hide" : "Show") + " full text";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mark comment as worktime-only or normal
|
||||
function toggle_wtonly(id, initial_wtonly, img)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<div id="comment-preview-[% id %]">[% preview %]</div>
|
||||
<div id="comment-body-[% id %]" style="display:none;">[% body %]</div>
|
||||
<p style="text-align: right">
|
||||
<a href="javascript:void(0)" id="comment-preview-link-[% id %]" onclick="return showhide_comment_preview([% id %])">Show full text</a>
|
||||
</p>
|
|
@ -75,4 +75,8 @@
|
|||
clear_requests_on_close => "Clear all unanswered flag requests when changing bug status to CLOSED",
|
||||
|
||||
unauth_bug_details => "Show product name to the user in Unauthorized message if he doesn't have access to bug.",
|
||||
|
||||
comment_line_length => "Symbols in one \"line\" whithout linebreaks.",
|
||||
|
||||
preview_comment_lines => "If comment's count of lines (one line is <comment_line_length> symbols or linebreaked line) is greater this value preview of text is shown.",
|
||||
} %]
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#%]
|
||||
|
||||
[% IF comment.type == constants.CMT_DUPE_OF %]
|
||||
X[% comment.body %]
|
||||
X[% comment.body(preview) %]
|
||||
|
||||
*** This [% terms.bug %] has been marked as a duplicate of [% terms.bug %] [%+ comment.extra_data %] ***
|
||||
[% ELSIF comment.type == constants.CMT_HAS_DUPE %]
|
||||
|
@ -39,7 +39,7 @@ X[% comment.body %]
|
|||
[% ELSIF comment.type == constants.CMT_POPULAR_VOTES %]
|
||||
*** This [% terms.bug %] has been confirmed by popular vote. ***
|
||||
[% ELSIF comment.type == constants.CMT_MOVED_TO %]
|
||||
X[% comment.body %]
|
||||
X[% comment.body(preview) %]
|
||||
|
||||
[%+ terms.Bug %] moved to [% Param("move-to-url") %].
|
||||
If the move succeeded, [% comment.extra_data %] will receive a mail containing
|
||||
|
@ -53,7 +53,7 @@ Created attachment [% comment.extra_data %]
|
|||
[% END %]
|
||||
[%+ comment.attachment.description %]
|
||||
|
||||
[%+ comment.body %]
|
||||
[%+ comment.body(preview) %]
|
||||
[% ELSIF comment.type == constants.CMT_ATTACHMENT_UPDATED %]
|
||||
Comment on attachment [% comment.extra_data %]
|
||||
[% IF is_bugmail %]
|
||||
|
@ -61,5 +61,5 @@ Comment on attachment [% comment.extra_data %]
|
|||
[% END %]
|
||||
[%+ comment.attachment.description %]
|
||||
|
||||
[%+ comment.body %]
|
||||
[%+ comment.body(preview) %]
|
||||
[% END %]
|
||||
|
|
Loading…
Reference in New Issue