]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1294478 - Move JSON serialization out of the templates and into perl to improve...
authorKalpesh Krishna <kalpeshk2011@gmail.com>
Mon, 29 Aug 2016 17:22:51 +0000 (13:22 -0400)
committerDylan William Hardison <dylan@hardison.net>
Mon, 29 Aug 2016 17:22:51 +0000 (13:22 -0400)
enter_bug.cgi
template/en/default/bug/create/create.html.tmpl

index afaffd752f8d65a36a635a44c240a5a362bbf0dd..697b6c8df8ebec3a895e82b7751ce1dcaa5370ef 100755 (executable)
@@ -52,6 +52,7 @@ use Bugzilla::Token;
 use Bugzilla::Field;
 use Bugzilla::Status;
 use Bugzilla::UserAgent;
+use JSON::XS qw(encode_json);
 
 my $user = Bugzilla->login(LOGIN_REQUIRED);
 
@@ -438,7 +439,33 @@ my $format = $template->get_format("bug/create/create",
                                    scalar $cgi->param('format'), 
                                    scalar $cgi->param('ctype'));
 
+my %data;
+my $count = 0;
+foreach my $c (@{ $product->components }) {
+    next if not $c->is_active;
+    $data{components}[$count]    = $c->name;
+    $data{comp_desc}[$count]     = $c->description;
+    $data{initialowners}[$count] = $c->default_assignee->login;
+    my @flag_list;
+    foreach my $f (@{ $c->flag_types->{bug} }) {
+        push @flag_list, $f->id;
+    }
+    foreach my $f (@{ $c->flag_types->{attachment} }) {
+        push @flag_list, $f->id;
+    }
+    $data{flags}[$count] = join(',', @flag_list);
+    $count++;
+    if (Bugzilla->params->{'useqacontact'}) {
+        $data{initialqacontacts}[$count] = $c->default_qa_contact->login;
+    }
+    my @initial_cc_list;
+    foreach my $cc_user (@{ $c->initial_cc }) {
+        push @initial_cc_list, $cc_user->login;
+    }
+    $data{initialccs}[$count] = join(', ', @initial_cc_list);
+}
+$vars->{data} = encode_json(\%data);
 print $cgi->header($format->{'ctype'});
 $template->process($format->{'template'}, $vars)
-  || ThrowTemplateError($template->error());          
+  || ThrowTemplateError($template->error());
 
index ba5d082732107da5e988c8a59a3651b7fc536beb..4103c16dc4ec0c80c89222664a86afba99609f94 100644 (file)
@@ -63,43 +63,17 @@ function initCrashSignatureField() {
                       'cf_crash_signature_action', 'cf_crash_signature');
   [% END %]
 }
-
-var initialowners = new Array([% product.components.size %]);
+var data = JSON.parse('[% data FILTER js %]');
+var initialowners = data["initialowners"];
 var last_initialowner;
-var initialccs = new Array([% product.components.size %]);
-var components = new Array([% product.components.size %]);
-var comp_desc = new Array([% product.components.size %]);
-var flags = new Array([% product.components.size %]);
+var initialccs = data["initialccs"];
+var components = data["components"];
+var comp_desc = data["comp_desc"];
+var flags = data["flags"];
 [% IF Param("useqacontact") %]
-    var initialqacontacts = new Array([% product.components.size %]);
+    var initialqacontacts = data["initialqacontacts"];
     var last_initialqacontact;
 [% END %]
-[% count = 0 %]
-[%- FOREACH c = product.components %]
-    [% NEXT IF NOT c.is_active %]
-    components[[% count %]] = "[% c.name FILTER js %]";
-    comp_desc[[% count %]] = "[% c.description FILTER html_light FILTER js %]";
-    initialowners[[% count %]] = "[% c.default_assignee.login FILTER js %]";
-    [% flag_list = [] %]
-    [% FOREACH f = c.flag_types.bug %]
-      [% flag_list.push(f.id) %]
-    [% END %]
-    [% FOREACH f = c.flag_types.attachment %]
-      [% flag_list.push(f.id) %]
-    [% END %]
-    flags[[% count %]] = [[% flag_list.join(",") FILTER js %]];
-    [% IF Param("useqacontact") %]
-        initialqacontacts[[% count %]] = "[% c.default_qa_contact.login FILTER js %]";
-    [% END %]
-
-    [% SET initial_cc_list = [] %]
-    [% FOREACH cc_user = c.initial_cc %]
-      [% initial_cc_list.push(cc_user.login) %]
-    [% END %]
-    initialccs[[% count %]] = "[% initial_cc_list.join(', ') FILTER js %]";
-
-    [% count = count + 1 %]
-[%- END %]
 
 function set_assign_to() {
     // Based on the selected component, fill the "Assign To:" field