Subversion Repositories DevTools

Rev

Rev 1293 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

[% USE AutomagicLinks %]
[% USE JavascriptEscape %]
[% USE StringObfuscator %]

<SCRIPT type="text/javascript">

// Store the form data in a browser cookie.
function save_form_data() {
   var form = document.add_comment;
   var contents = '';
   contents +=       escape(form.comments.value);
   contents += '&' + escape(form.email.value);
   contents += '&' + escape(form.comment_cc.value);
   setCookie('codestriker_add_comment_form_data', contents, 30);
}

// Load the form data from a browser cookie.
function load_form_data() {
   var cookie = getCookie('codestriker_add_comment_form_data');
   if (cookie == null || cookie == '') return null;

   // Delete the cookie (so that it doesn't persist between different
   // comment pages).
   setCookie('codestriker_add_comment_form_data', '', 1);

   return cookie.split('&');
}

// Set the form field from the values present in the cookie.
function set_form_fields() {
   var field_comments   = '';
   var field_email      = '[% email %]';
   var field_comment_cc = '';

   var fields = load_form_data();
   if (fields != null) {
      field_comments   = unescape(fields[0]);
      field_email      = unescape(fields[1]);
      field_comment_cc = unescape(fields[2]);
   }

   // Now set the form elements below if the values are available.
   if (field_comments != null) {
      document.add_comment.comments.value = field_comments;
   }
   if (field_email != null) {
      document.add_comment.email.value = field_email;
   }
   if (field_comment_cc != null) {
      document.add_comment.comment_cc.value = field_comment_cc;
   }
}

// Called when the form is submitted to ensure the metric dropdowns are set
// as well as the comment field.
function verify() {
  // Check the form field has a comment in it.
  if (document.add_comment.comments.value == '') {
      alert('No comment has been entered.');
      return false;
  }

  // Check the metrics have been set.
  var index;
  var value;
  [% FOREACH metric = metrics %]
      index = document.add_comment.comment_state_metric_[% metric.name %].options.selectedIndex;
      if (index == -1) {
          alert('Metric [% metric.name %] has not been specified.');
          return false;
      }
      value = document.add_comment.comment_state_metric_[% metric.name %].options[index].value;
      if (value == 'Select Value') {
          alert('Metric [% metric.name %] has not been specified.');
          return false;
      }

  [% END %]

  // If we reached here, then all metrics have been set.
  return true;
}

// Check if a specific reviewer can be added to the cc field, assuming
// it isn't present already.
function add_other_reviewer(reviewer) {
    if (document.add_comment.comment_cc.value != "") {
        var addresses = new Array();
        if (document.add_comment.comment_cc.value.split) {
            addresses = document.add_comment.comment_cc.value.split(/[\s,]+/);
        }
        var found = 0;
        for (var i = 0; i < addresses.length; i++) {
          if (addresses[i] == reviewer) {
            found = 1;
            break;
          }
        }
        if (reviewer == document.add_comment.email.value) {
          found = 1;
        }
        if (found == 0) {
            document.add_comment.comment_cc.value += ", " + reviewer;
        }
    } else {
        document.add_comment.comment_cc.value = reviewer;
    }
}

// Called when the "add other reviewers" link is pressed, which adds all
// reviewers to the Cc: field.
function add_other_reviewers() {
  [% FOREACH reviewer = reviewers %]
    add_other_reviewer("[% reviewer | $JavascriptEscape | $StringObfuscator %]");
  [% END %]
}
</Script>

[%# Screen for the add comment form. #%]

[% PROCESS header.html.tmpl displaymenu = 0 version = version help = "x504.html#ADD-COMMENT" %]

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr class="tlh">
    <td>Topic title: <b>[% topic_title | html_entity %]</b>.</td>
    <td align=right>[% document_creation_time | html_entity %]</td>
</tr>
</table>

<P>

<FORM NAME="add_comment" METHOD="POST" onSubmit="return verify();" ENCTYPE="application/x-www-form-urlencoded">
 <INPUT TYPE="hidden" NAME="action" VALUE="submit_comment">
 <INPUT TYPE="hidden" NAME="line" VALUE="[% line %]">
 <INPUT TYPE="hidden" NAME="topic" VALUE="[% topic %]">
 <INPUT TYPE="hidden" NAME="mode" VALUE="[% mode %]">
 <INPUT TYPE="hidden" NAME="a" VALUE="[% anchor %]">
 <INPUT TYPE="hidden" NAME="fn" VALUE="[% fn %]">
 <INPUT TYPE="hidden" NAME="new" VALUE="[% new %]">

 Enter new comment:<BR>
 <TEXTAREA NAME="comments" ROWS=13 COLS=75 WRAP="hard"></TEXTAREA>

 [% IF metrics != '' %]
   <P>
   <TABLE>
     [% FOREACH metric = metrics %]
     [% IF loop.index() % 4 == 0 %]
     <TR>
     [% END %]
       <TD ALIGN="right">[% metric.name %]:</TD>
       <TD ALIGN="left">
         <SELECT NAME="comment_state_metric_[% metric.name %]">
           [% IF metric.current_value == '' %]

             [% IF metric.default_value == '' %]
               <OPTION VALUE="Select Value">&lt;Select Value&gt;</OPTION>
             [% END %]
             [% FOREACH value = metric.values %]
               <OPTION [% IF value == metric.default_value %]SELECTED[% END %] VALUE="[% value %]">[% value %]</OPTION>
             [% END %]

           [% ELSE %]

             [% SET found_current_value = 0 %]
             [% FOREACH value = metric.values %]

               [% IF value == metric.current_value %]
                 <OPTION SELECTED VALUE="[% value %]">[% value %]</OPTION>
                 [% SET found_current_value = 1 %]
               [% ELSE %]
                 <OPTION VALUE="[% value %]">[% value %]</OPTION>
               [% END %]
             [% END %]

             [% IF found_current_value == 0 %]
               [%# Old metric data value no longer in config. #%]

               <OPTION VALUE="[% metric.current_value %]">[% metric.current_value %]</OPTION>
             [% END %]

           [% END %]
         </SELECT>
         &nbsp;&nbsp;&nbsp;&nbsp;
       </TD>
     [% IF loop.index() % 4 == 3 || loop.last() %]
     </TR>
     [% END %]
     [% END %]
   </TABLE>
 [% END %]

 <P>

 <TABLE>
 <TR>
  <TD>Your email address: </TD>
  <TD>
    <INPUT TYPE="text" NAME="email" SIZE=50 MAXLENGTH=100>
  </TD>
  <TD></TD>
 </TR>
 <TR>
  <TD>Cc: <FONT SIZE="-1"><A HREF="javascript:add_other_reviewers();">(add other reviewers)</A></FONT> </TD>
  <TD>
     <INPUT TYPE="text" NAME="comment_cc" SIZE=50 MAXLENGTH=150>
  </TD>
  <TD><INPUT TYPE="submit" NAME="submit" VALUE="Submit" ONCLICK="if (opener != null) opener.focus()"></TD>
 </TR>
 </TABLE>

 
</FORM>

[%# Display a list of comments #%]

<TABLE CELLPADDING="1" CELLSPACING="1" BORDER="0" width="100%">
[% FOREACH comment = comments %]
[% FLUSH IF loop.count() % 10 == 1 %]

[% IF loop.count() == 1 %]
<TR CLASS="comments"><TD><B>Comments:</B></TD></TR>
<TR CLASS="commentb"><TD>&nbsp;</TD></TR>
[% END %]

<TR CLASS="commenth">
<TD>
[% IF comment.line != '' %]
<A HREF="[% comment.lineurl %]" NAME="[% comment.linename %]">
[% comment.line %]</A>
[% END %]

[% comment.author | html_entity %]&nbsp;[% comment.date | html_entity %]
</TD>
</TR>
<TR CLASS="commentb">
<TD>
<PRE>[% comment.data | html_entity | $AutomagicLinks %]</PRE></TD>
</TR>
[% END %]
</TABLE>

[% IF context != '' %]
<hr>
<P>Context: (<A onClick="save_form_data()" HREF="[% inc_context_url %]">increase</A> | <A onClick="save_form_data()" HREF="[% dec_context_url %]">decrease)</A>
[% context %]
[% END %]

<SCRIPT type="text/javascript">
  // Now that the form has loaded, set the form fields.
  set_form_fields();
</SCRIPT>

[% PROCESS trailer.html.tmpl %]

</BODY>
</HTML>