summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2012-01-12 00:09:34 +0100
committerDave Lawrence <dlawrence@mozilla.com>2012-01-12 00:09:34 +0100
commitc39392747857dae64e90e174af7393e002dafad1 (patch)
tree9d1336ae72f3cc0aad2d31923e71708011c37c39
parente75d8cf78f93434f9f3394ab215e6eb5a28248ba (diff)
downloadbugzilla-c39392747857dae64e90e174af7393e002dafad1.tar.gz
bugzilla-c39392747857dae64e90e174af7393e002dafad1.tar.xz
Bug 714786: The FlagTypeComment extension should allow more than one flag to
have have comment text associated with it r=glob
-rw-r--r--extensions/FlagTypeComment/Extension.pm37
-rw-r--r--extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl10
-rw-r--r--extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl20
3 files changed, 33 insertions, 34 deletions
diff --git a/extensions/FlagTypeComment/Extension.pm b/extensions/FlagTypeComment/Extension.pm
index caa41adf0..b3089e993 100644
--- a/extensions/FlagTypeComment/Extension.pm
+++ b/extensions/FlagTypeComment/Extension.pm
@@ -80,7 +80,8 @@ sub _set_ftc_states {
my ($file, $vars) = @_;
my $dbh = Bugzilla->dbh;
- my $db_states;
+ my $ftc_flags;
+ my $db_result;
if ($file =~ /^admin\//) {
# admin
my $type = $vars->{'type'} || return;
@@ -96,11 +97,11 @@ sub _set_ftc_states {
} else {
return unless FLAGTYPE_COMMENT_ATTACHMENT_FLAGS;
}
- $db_states = $dbh->selectall_hashref(
+ $db_result = $dbh->selectall_arrayref(
"SELECT type_id AS flagtype, on_status AS state, comment AS text
- FROM flagtype_comments WHERE type_id=?",
- 'state',
- undef,
+ FROM flagtype_comments
+ WHERE type_id = ?",
+ { Slice => {} },
$id);
} else {
@@ -123,21 +124,21 @@ sub _set_ftc_states {
});
my $types = join(',', map { $_->id } @$flag_types);
- $db_states = $dbh->selectall_hashref(
+ my $states = "'" . join("','", FLAGTYPE_COMMENT_STATES) . "'";
+ $db_result = $dbh->selectall_arrayref(
"SELECT type_id AS flagtype, on_status AS state, comment AS text
- FROM flagtype_comments WHERE type_id IN ($types)",
- 'state');
+ FROM flagtype_comments
+ WHERE type_id IN ($types) AND on_status IN ($states)",
+ { Slice => {} });
}
- my @edit_states;
- foreach my $state (FLAGTYPE_COMMENT_STATES) {
- if (exists $db_states->{$state}) {
- push @edit_states, $db_states->{$state};
- } else {
- push @edit_states, { state => $state, text => '' };
- }
+ foreach my $row (@$db_result) {
+ $ftc_flags->{$row->{'flagtype'}} ||= {};
+ $ftc_flags->{$row->{'flagtype'}}{$row->{'state'}} = $row->{text};
}
- $vars->{'ftc_states'} = \@edit_states;
+
+ $vars->{'ftc_states'} = [ FLAGTYPE_COMMENT_STATES ];
+ $vars->{'ftc_flags'} = $ftc_flags;
}
#########
@@ -159,9 +160,8 @@ sub _set_flagtypes {
my $input = Bugzilla->input_params;
my $dbh = Bugzilla->dbh;
- my $i = 0;
foreach my $state (FLAGTYPE_COMMENT_STATES) {
- my $text = $input->{"ftc_text_$i"} || '';
+ my $text = $input->{"ftc_${flagtype_id}_$state"} || '';
$text =~ s/\r\n/\n/g;
trick_taint($text);
@@ -190,7 +190,6 @@ sub _set_flagtypes {
undef,
$flagtype_id, $state);
}
- $i++;
}
}
diff --git a/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl b/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl
index 81484f17c..95c0cb283 100644
--- a/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl
+++ b/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl
@@ -20,7 +20,7 @@
# byron jones <glob@mozilla.com>
#%]
-[% IF ftc_states.size %]
+[% IF ftc_flags.keys.size %]
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function() {
var selects = YAHOO.util.Dom.getElementsByClassName('flag_select');
@@ -34,10 +34,10 @@
var state = ev.target.value;
var commentEl = document.getElementById('comment');
if (!commentEl) return;
- [% FOREACH state = ftc_states %]
- [% IF state.flagtype %]
- if ([% state.flagtype FILTER none %] == id && '[% state.state FILTER js %]' == state) {
- var text = '[% state.text FILTER js %]';
+ [% FOREACH type_id = ftc_flags.keys %]
+ [% FOREACH state = ftc_states %]
+ if ([% type_id FILTER none %] == id && '[% state FILTER js %]' == state) {
+ var text = '[% ftc_flags.$type_id.$state FILTER js %]';
var value = commentEl.value;
if (value == text) {
return;
diff --git a/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl b/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl
index 7f2c328af..71aaad424 100644
--- a/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl
+++ b/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl
@@ -27,15 +27,15 @@
</tr>
[% FOREACH state = ftc_states %]
- <tr>
- <td>&nbsp;</td>
- <td>
- for [% state.state FILTER html %]<br>
- <textarea
- id="ftc_text_[% loop.index FILTER none %]"
- name="ftc_text_[% loop.index FILTER none %]"
- cols="50" rows="2">[% state.text FILTER html %]</textarea>
- </td>
- </tr>
+ <tr>
+ <td>&nbsp;</td>
+ <td>
+ for [% state FILTER html %]<br>
+ <textarea
+ id="ftc_[% type.id FILTER html %]_[% state FILTER html %]"
+ name="ftc_[% type.id FILTER html %]_[% state FILTER html %]"
+ cols="50" rows="2">[% ftc_flags.${type.id}.$state FILTER html %]</textarea>
+ </td>
+ </tr>
[% END %]
[% END %]