[Codestriker-commits] CVS update: codestriker/template/en/default submitnewcomment.html.tmpl
Brought to you by:
sits
|
From: <si...@us...> - 2005-02-24 09:41:26
|
Created Codestriker topic at: http://codestriker.sourceforge.net/cgi-bin/codestriker.pl?topic=947327&action=view User: sits Date: 05/02/24 01:41:02 Modified: html codestriker.js lib/Codestriker/Http Render.pm Response.pm template/en/default submitnewcomment.html.tmpl Log: Now generate the add comment window all via javascript, so that the backend is not required at all. Once the user enters in the comment, of course this is posted to the server. The add comment window is suitable simplified, since the actual topic text is visible in front of the reviewer. We could possibly position the window in a more optimised fashion rather than the middle of the screen, but that can come later. Index: codestriker.js =================================================================== RCS file: /cvsroot/codestriker/codestriker/html/codestriker.js,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- codestriker.js 23 Feb 2005 00:03:17 -0000 1.4 +++ codestriker.js 24 Feb 2005 09:40:58 -0000 1.5 @@ -59,18 +59,204 @@ } } +// Create the HTML necessary for adding a comment. +function add_comment_html(file, line, new_value) +{ + // Get the location of the codestriker URL. + var l = top.location; + var url = l.protocol + '//' + l.host + l.pathname; + + // Create the initial form, with the appropriate hidden fields. + var html = '<html><body bgcolor="#eeeeee">\n' + + '<form name="add_comment" method="POST" ' + + 'action="' + url + '" ' + + 'onSubmit="return top.verify();" ' + + 'enctype="application/x-www-form-urlencoded">\n' + + '<input type="hidden" name="action" value="submit_comment">\n' + + '<input type="hidden" name="line" value="' + line + '">\n' + + '<input type="hidden" name="topic" value="' + cs_topicid + '">\n' + + '<input type="hidden" name="fn" value="' + file + '">\n' + + '<input type="hidden" name="new" value="' + new_value + '">\n' + + '<textarea name="comments" rows="5" cols="50" wrap="hard">\n' + + '</textarea>\n'; + + // Now add in the metric dropdowns. + if (top.cs_metric_data.length > 0) { + html += '<p><table>\n'; + } + for (var i = 0; i < top.cs_metric_data.length; i++) { + if (i % 2 == 0) { + html += '<tr>\n'; + } + html += '<td align="right">' + top.cs_metric_data[i].name + ':</td>\n'; + html += '<td align="left">\n'; + html += '<select name="comment_state_metric_' + + top.cs_metric_data[i].name + '">\n'; + + // Check if a value has been selected for this metric. + var key = file + '|' + line + '|' + new_value; + var comment_number = top.comment_hash[key]; + var current_value = null; + if (comment_number != null && + top.comment_metrics[comment_number] != null) { + current_value = + top.comment_metrics[comment_number][top.cs_metric_data[i].name]; + } + if (current_value == null) { + // If there is no default value defined, create an empty setting. + if (top.cs_metric_data[i].default_value == null) { + html += '<option value="Select Value">' + + '<Select Value></option>\n'; + } + for (var j = 0; j < top.cs_metric_data[i].values.length; j++) { + html += '<option '; + var value = top.cs_metric_data[i].values[j]; + if (value == top.cs_metric_data[i].default_value) { + html += 'selected '; + } + html += 'value="' + value + '">' + value + '</option>\n'; + } + } + else { + // This metric does have a current value selected. + var found_current_value = 0; + for (var j = 0; j < top.cs_metric_data[i].values.length; j++) { + var value = top.cs_metric_data[i].values[j]; + if (value == current_value) { + html += '<option selected value="' + value + '">' + + value + '</option>\n'; + found_current_value = 1; + } + else { + html += '<option value="' + value + '">' + value + + '</option>\n'; + } + } + + // Check if the current value was found, and if not, it must + // represent an old metric value no longer represented in the + // configuration file. + if (found_current_value == 0) { + html += '<option value="' + current_value + '">' + + current_value + '</option>\n'; + } + } + html += '</select>\n'; + html += ' </td>\n'; + if (i % 2 == 1 || i == top.cs_metric_data.length-1) { + html += '</tr>\n'; + } + } + if (top.cs_metric_data.length > 0) { + html += '</table>\n'; + } + + // Now add in the email address, CC and submit buttons. + html += '<p><table><tr>\n' + + '<td>Your email address: </td>\n' + + '<td>' + + '<input type="text" name="email" size="35" maxlength="100" ' + + 'value="' + cs_email + '">\n' + + '</td><td></td></tr><tr>' + + '<td>Cc: <font size="-1">' + + '<a href="javascript:top.add_other_reviewers();">' + + '(add other reviewers)</a></font> </td>' + + '<td>' + + '<input type="text" name="comment_cc" size="35" ' + + 'maxlength="150"></td>\n' + + '<td><input type="submit" name="submit" value="Submit"></td>' + + '</tr></table></form></body></html>\n'; + + // Return the generated html. + return html; +} + +// Verify that a comment is ready to be shipped out. +function verify() +{ + // Get a reference to the comment form. + var comment_form = top.comment_frame.document.add_comment; + + // Check that the comment field has a comment entered in it. + if (comment_form.comments.value == '') { + alert('No comment has been entered.'); + return false; + } + + // Check that the email field has an email address in it. + if (comment_form.email.value == '') { + alert('No email address has been entered.'); + return false; + } + + // Check that the metrics have been set. + for (var i = 0; i < top.cs_metric_data.length; i++) { + var metric_name = top.cs_metric_data[i].name; + var name = 'comment_state_metric_' + metric_name; + var index = comment_form.elements[name].options.selectedIndex; + if (index == -1) { + alert('Metric "' + metric_name + '" has not been specified.'); + return false; + } + + var value = comment_form.elements[name].options[index].value; + if (value == 'Select Value') { + alert('Metric "' + metric_name + '" has not been specified.'); + return false; + } + } + + // If we reached here, then all metrics have been set. + return true; +} + +// Add all the other reviews into the Cc field of the comment frame. +function add_other_reviewers() +{ + // Get a reference to the comment form. + var comment_form = top.comment_frame.document.add_comment; + + // Find out who the reviewers are for this review. + var reviewers = top.topic_reviewers.split(/[\s,]+/); + + // Now check each reviewer to see if it can be added into the Cc field. + for (var i = 0; i < reviewers.length; i++) { + // Get the value of the Cc field and check if the reviewer is present. + var cc_addresses = comment_form.comment_cc.value.split(/[\s,]+/); + var found = 0; + for (var j = 0; j < cc_addresses.length; j++) { + if (reviewers[i] == cc_addresses[j]) { + found = 1; + break; + } + } + + // Also check if the reviewer is already in the email field. + if (reviewers[i] == comment_form.email.value) { + found = 1; + } + + // If not found, append it to the Cc field. + if (found == 0) { + if (comment_form.comment_cc.value != '') { + comment_form.comment_cc.value += ', '; + } + comment_form.comment_cc.value += reviewers[i]; + } + } +} + + // Create a new tooltip window which contains an iframe used for adding // a comment to the topic. function add_comment_tooltip(file, line, new_value) { - var l = window.location; - var url = l.protocol + '//' + l.host + l.pathname + '?' + - 'fn=' + file + '&line=' + line + '&new=' + new_value + - '&topic=' + cs_topicid + '&action=edit'; var html = '<a href="javascript:hideElt(getElt(\'overDiv\')); void(0);">' + 'Close</a><p>' + - '<iframe width="660" height="520" src="' + url + '">' + + '<iframe width="480" height="300" name="comment_frame" ' + + 'src="javascript:top.add_comment_html(' + + file + ',' + line + ',' + new_value + ');">' + 'Can\'t view iframe</iframe>'; - overlib(html, STICKY, DRAGGABLE, ALTCUT, CENTERPOPUP, WIDTH, 660, - HEIGHT, 520); + overlib(html, STICKY, DRAGGABLE, ALTCUT, CENTERPOPUP, WIDTH, 480, + HEIGHT, 300); } Index: Render.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Render.pm,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- Render.pm 22 Feb 2005 10:14:32 -0000 1.47 +++ Render.pm 24 Feb 2005 09:41:01 -0000 1.48 @@ -154,9 +154,13 @@ # Precompute the overlib HTML for each comment location. print "\n<script language=\"JavaScript\" type=\"text/javascript\">\n"; + # Add the reviewers for the review here. + print " var topic_reviewers = '" . $topic_obj->{reviewers} . "';\n"; + # Now record all the comments made so far in the topic. print " var comment_text = new Array();\n"; print " var comment_hash = new Array();\n"; + print " var comment_metrics = new Array();\n"; my $index; for ($index = 0; $index <= $#comment_locations; $index++) { @@ -242,6 +246,17 @@ print " comment_text[$index] = '$overlib_html';\n"; print " comment_hash['" . $comment_locations[$index] . "'] = $index;\n"; + + # Store the current metric values for this comment. + print " comment_metrics[$index] = new Array();\n"; + my $comment_metrics = $comments[0]->{metrics}; + foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) { + my $value = $comment_metrics->{$metric_config->{name}}; + $value = "" unless defined $value; + print " comment_metrics[${index}]['" . + $metric_config->{name} . "'] = '" . $value . "';\n"; + } + } print "</script>\n"; Index: Response.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Response.pm,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- Response.pm 22 Feb 2005 10:14:36 -0000 1.27 +++ Response.pm 24 Feb 2005 09:41:01 -0000 1.28 @@ -240,6 +240,29 @@ print " var cs_load_anchor = '$load_anchor';\n"; print " var cs_reload = $reload;\n"; print " var cs_topicid = $topic;\n" if defined $topic && $topic ne ""; + print " var cs_email = '$email';\n" if defined $email; + + # Now output all of the comment metric information. + print " var cs_metric_data = new Array();\n"; + my $i = 0; + foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) { + print " cs_metric_data[$i] = new Object();\n"; + print " cs_metric_data[$i].name = '" . + $metric_config->{name} . "';\n"; + print " cs_metric_data[$i].values = new Array();\n"; + my $j = 0; + foreach my $value (@{ $metric_config->{values} }) { + print " cs_metric_data[$i].values[$j] = '$value';\n"; + $j++; + } + if (defined $metric_config->{default_value}) { + print " cs_metric_data[$i].default_value = '" . + $metric_config->{default_value} . "';\n"; + } + $i++; + } + + print "</script>\n"; # Write an HTML comment indicating if response was sent compressed or not. Index: submitnewcomment.html.tmpl =================================================================== RCS file: /cvsroot/codestriker/codestriker/template/en/default/submitnewcomment.html.tmpl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- submitnewcomment.html.tmpl 21 Feb 2005 11:25:31 -0000 1.5 +++ submitnewcomment.html.tmpl 24 Feb 2005 09:41:01 -0000 1.6 @@ -1,20 +1,7 @@ [%# Screen for the submit comment confirmation screen. #%] -[% PROCESS header.html.tmpl version = version displaymenu = 1 - closehead = 1 help="" %] - -<H2>Comment submitted</H2> -<P> -<PRE>[% comment | html_entity %] -</PRE><P> - -[%# Display a simple form for closing the comment popup window #%] -<FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded"> -<INPUT TYPE="submit" NAME=".submit" VALUE="Close" - ONCLICK="window.close()"> -</FORM> - -[% PROCESS trailer.html.tmpl %] - -</BODY> -</HTML> +</head> +<body bgcolor="#eeeeee"> +<h2>Comment submitted</h2> +</body> +</html> |