[Codestriker-commits] CVS update: codestriker/template/en/default submitnewcomment.html.tmpl
Brought to you by:
sits
|
From: <si...@us...> - 2005-05-05 09:35:52
|
Created Codestriker topic at: http://codestriker.sourceforge.net/cgi-bin/codestriker.pl?topic=46167&action=view User: sits Date: 05/05/05 02:35:28 Modified: html codestriker.css codestriker.js lib/Codestriker/Action SubmitNewComment.pm lib/Codestriker/Http Input.pm Response.pm template/en/default submitnewcomment.html.tmpl Log: Comment tooltip now uses XMLHttpRequest object rather than using an iframe. Modified SubmitNewCommentAction so that it can send an XML reply, if that is what the format parameter requested. The tooltip is dragged by Control-LeftMouseButton. This needed to be changed otherwise text could not be entered into the comment fields. There may be a way of have a "Drag" link, which can activate the drag, as on my Linux box, the window manage grabs the Control-LeftMouseButton event, and drags the entire browser window! Index: codestriker.css =================================================================== RCS file: /cvsroot/codestriker/codestriker/html/codestriker.css,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- codestriker.css 17 Feb 2005 21:29:33 -0000 1.11 +++ codestriker.css 5 May 2005 09:35:25 -0000 1.12 @@ -141,3 +141,6 @@ TD.space {background-color: #eeeeee} A.tab {text-decoration: none} +/* Styles for error field in comment posting tooltip. */ +span.hidden {display: none} +span.error {display: inline; color: red} Index: codestriker.js =================================================================== RCS file: /cvsroot/codestriker/codestriker/html/codestriker.js,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- codestriker.js 24 Feb 2005 09:44:33 -0000 1.6 +++ codestriker.js 5 May 2005 09:35:25 -0000 1.7 @@ -52,7 +52,7 @@ var comment_number = comment_hash[anchor]; if (comment_number != null) { // We have a comment on this line, bring up the tooltip. - overlib(comment_text[comment_number], STICKY, DRAGGABLE, ALTCUT, + overlib(comment_text[comment_number], STICKY, DRAGGABLE, FIXX, getEltPageLeft(getElt('c' + comment_number)), FIXY, getEltPageTop(getElt('c' + comment_number))); } @@ -63,55 +63,57 @@ function add_comment_html(file, line, new_value) { // Get the location of the codestriker URL. - var l = top.location; + var l = 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' + + // Create the hidden error span, and the initial form, with the + // appropriate hidden fields. + var html = + '<span class="hidden" id="statusField"> </span>\n' + '<form name="add_comment" method="POST" ' + 'action="' + url + '" ' + - 'onSubmit="return top.verify();" ' + + 'onSubmit="return 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' + + '<input type="hidden" name="newval" 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) { + if (cs_metric_data.length > 0) { html += '<p><table>\n'; } - for (var i = 0; i < top.cs_metric_data.length; i++) { + for (var i = 0; i < 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="right">' + 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'; + 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 comment_number = comment_hash[key]; var current_value = null; if (comment_number != null && - top.comment_metrics[comment_number] != null) { + comment_metrics[comment_number] != null) { current_value = - top.comment_metrics[comment_number][top.cs_metric_data[i].name]; + comment_metrics[comment_number][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) { + if (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++) { + for (var j = 0; j < 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) { + var value = cs_metric_data[i].values[j]; + if (value == cs_metric_data[i].default_value) { html += 'selected '; } html += 'value="' + value + '">' + value + '</option>\n'; @@ -120,8 +122,8 @@ 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]; + for (var j = 0; j < cs_metric_data[i].values.length; j++) { + var value = cs_metric_data[i].values[j]; if (value == current_value) { html += '<option selected value="' + value + '">' + value + '</option>\n'; @@ -143,11 +145,11 @@ } html += '</select>\n'; html += ' </td>\n'; - if (i % 2 == 1 || i == top.cs_metric_data.length-1) { + if (i % 2 == 1 || i == cs_metric_data.length-1) { html += '</tr>\n'; } } - if (top.cs_metric_data.length > 0) { + if (cs_metric_data.length > 0) { html += '</table>\n'; } @@ -159,13 +161,13 @@ 'value="' + cs_email + '">\n' + '</td><td></td></tr><tr>' + '<td>Cc: <font size="-1">' + - '<a href="javascript:top.add_other_reviewers();">' + + '<a href="javascript:add_other_reviewers();">' + '(add other reviewers)</a></font> </td>' + '<td>' + '<input type="text" name="comment_cc" size="25" ' + 'maxlength="150"></td>\n' + '<td><input type="submit" name="submit" value="Submit"></td>' + - '</tr></table></form></body></html>\n'; + '</tr></table></form>\n'; // Return the generated html. return html; @@ -175,7 +177,7 @@ function verify() { // Get a reference to the comment form. - var comment_form = top.comment_frame.document.add_comment; + var comment_form = document.add_comment; // Check that the comment field has a comment entered in it. if (comment_form.comments.value == '') { @@ -190,8 +192,8 @@ } // 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; + for (var i = 0; i < cs_metric_data.length; i++) { + var metric_name = cs_metric_data[i].name; var name = 'comment_state_metric_' + metric_name; var index = comment_form.elements[name].options.selectedIndex; if (index == -1) { @@ -206,18 +208,37 @@ } } - // If we reached here, then all metrics have been set. - return true; + // If we reached here, then all metrics have been set. Send the + // request as an XMLHttpRequest, and return false so the browser + // does nothing else. + var params = 'action=submit_comment'; + params += '&line=' + escape(comment_form.line.value); + params += '&topic=' + escape(comment_form.topic.value); + params += '&fn=' + escape(comment_form.fn.value); + params += '&new=' + escape(comment_form.newval.value); + params += '&comments=' + escape(comment_form.comments.value); + params += '&email=' + escape(comment_form.email.value); + params += '&comment_cc=' + escape(comment_form.comment_cc.value); + params += '&format=xml'; + + for (var i = 0; i < cs_metric_data.length; i++) { + var comment_param = + escape('comment_state_metric_' + cs_metric_data[i].name); + params += '&' + comment_param + '=' + + escape(eval('comment_form.' + comment_param + '.value')); + } + postXMLDoc(params); + return false; } // 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; + var comment_form = document.add_comment; // Find out who the reviewers are for this review. - var reviewers = top.topic_reviewers.split(/[\s,]+/); + var reviewers = 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++) { @@ -247,16 +268,81 @@ } -// Create a new tooltip window which contains an iframe used for adding +// Create a new tooltip window which contains the html used for adding // a comment to the topic. function add_comment_tooltip(file, line, new_value) { var html = '<a href="javascript:hideElt(getElt(\'overDiv\')); void(0);">' + 'Close</a><p>' + - '<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, 480, - HEIGHT, 300); + add_comment_html(file,line,new_value); + overlib(html, STICKY, DRAGGABLE, CENTERPOPUP); } + +// Codestriker XMLHttpRequest object that is used. +var cs_request; + +// Function for posting to Codestriker using the XMLHttpRequest object. +function postXMLDoc(params) +{ + // Generate the basic Codestriker URL. + var l = location; + var url = l.protocol + '//' + l.host + l.pathname; + + // Check for Mozilla/Safari. + if (window.XMLHttpRequest) { + cs_request = new XMLHttpRequest(); + } + // Check for IE. + else if (window.ActiveXObject) { + cs_request = new ActiveXObject("Microsoft.XMLHTTP"); + } + + // If the request object was created, generate the request. + if (cs_request) { + cs_request.onreadystatechange = processReqChange; + cs_request.open("POST", url, true); + cs_request.setRequestHeader("Content-Type", + "application/x-www-form-urlencoded"); + cs_request.send(params); + } +} + +// Function for updating the status text in the add comment tooltip. +function setStatusText(newStatusText) +{ + var statusElt = document.getElementById('statusField'); + statusElt.className = 'error'; + var newStatusTextNode = document.createTextNode(newStatusText); + statusElt.replaceChild(newStatusTextNode, statusElt.childNodes[0]); +} + +// Function for handling state changes to the request object. +function processReqChange() +{ + // Only check for completed requests. + if (cs_request.readyState == 4) { + if (cs_request.status == 200) { + var response = cs_request.responseXML.documentElement; + result = response.getElementsByTagName('result')[0].firstChild.data; + if (result == 'OK') { + // Hide the popup if the comment was successful. + hideElt(getElt('overDiv')); + } + else { + // An error occurred, show this in the tooltip, and leave + // it up. + setStatusText(result); + } + } + else { + alert("There was a problem retrieving the XML data:\n" + + cs_request.statusText); + } + } + else if (cs_request.readyState == 3) { + setStatusText('Receiving response...'); + } + else if (cs_request.readyState == 2) { + setStatusText('Request sent...'); + } +} \ No newline at end of file Index: SubmitNewComment.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitNewComment.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SubmitNewComment.pm 1 Mar 2005 10:12:49 -0000 1.6 +++ SubmitNewComment.pm 5 May 2005 09:35:26 -0000 1.7 @@ -34,6 +34,7 @@ my $cc = $http_input->get('comment_cc'); my $mode = $http_input->get('mode'); my $anchor = $http_input->get('a'); + my $format = $http_input->get('format'); # Check that the fields have been filled appropriately. if ($comments eq "" || !defined $comments) { @@ -71,31 +72,41 @@ if ( $listener_response ne '') { $http_response->error($listener_response); } - - # Display a simple screen indicating that the comment has been registered. - # Clicking the Close button simply dismisses the edit popup. Leaving it - # up will ensure the next editing topic will be handled quickly, as the - # overhead of bringing up a new window is removed. - my $reload = $query->param('submit') eq 'Submit+Refresh' ? 1 : 0; - $http_response->generate_header(topic=>$topic, - topic_title=>"Comment Submitted: $topic->{title}", - email=>$email, - repository=>$topic->{repository}, - load_anchor=>$anchor, - reload=>$reload, cache=>0); + + if (defined $format && $format eq "xml") { + print $query->header(-content_type=>'text/xml'); + print "<?xml version=\"1.0\" encoding=\"UTF-8\" " . + "standalone=\"yes\"?>\n"; + print "<response><method>submitnewcomment</method>" . + "<result>OK</result></response>\n"; + } else { + # Display a simple screen indicating that the comment has been + # registered. Clicking the Close button simply dismisses the + # edit popup. Leaving it # up will ensure the next editing + # topic will be handled quickly, as the # overhead of bringing + # up a new window is removed. + my $reload = $query->param('submit') eq 'Submit+Refresh' ? 1 : 0; + $http_response->generate_header(topic=>$topic, + topic_title=>"Comment Submitted: " . + "$topic->{title}", + email=>$email, + repository=>$topic->{repository}, + load_anchor=>$anchor, + reload=>$reload, cache=>0); - my $view_topic_url = $url_builder->view_url($topicid, $line, $mode); - my $view_comments_url = $url_builder->view_comments_url($topicid); + my $view_topic_url = $url_builder->view_url($topicid, $line, $mode); + my $view_comments_url = $url_builder->view_comments_url($topicid); - my $vars = {}; - $vars->{'view_topic_url'} = $view_topic_url; - $vars->{'view_comments_url'} = $view_comments_url; - $vars->{'comment'} = $comments; - - my $template = Codestriker::Http::Template->new("submitnewcomment"); - $template->process($vars); + my $vars = {}; + $vars->{'view_topic_url'} = $view_topic_url; + $vars->{'view_comments_url'} = $view_comments_url; + $vars->{'comment'} = $comments; + + my $template = Codestriker::Http::Template->new("submitnewcomment"); + $template->process($vars); - $http_response->generate_footer(); + $http_response->generate_footer(); + } } # Given a topic and topic line number, try to determine the line Index: Input.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Input.pm,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- Input.pm 3 Nov 2004 20:48:33 -0000 1.41 +++ Input.pm 5 May 2005 09:35:27 -0000 1.42 @@ -102,7 +102,7 @@ $self->{end_tag} = $query->param('end_tag'); $self->{module} = $query->param('module'); $self->{topic_sort_change} = $query->param('topic_sort_change'); - $self->{content} = $query->param('content'); + $self->{format} = $query->param('format'); $self->{obsoletes} = $query->param('obsoletes'); my @selected_topics = $query->param('selected_topics'); $self->{selected_topics} = \@selected_topics; @@ -124,7 +124,7 @@ $self->{project_description} = "" if ! defined $self->{project_description}; $self->{project_state} = "" if ! defined $self->{project_state}; $self->{topic_sort_change} = "" if ! defined $self->{topic_sort_change}; - $self->{content} = "html" if ! defined $self->{content}; + $self->{format} = "html" if ! defined $self->{format}; $self->{obsoletes} = "" if ! defined $self->{obsoletes}; $self->{default_to_head} = 0 if ! defined $self->{default_to_head}; Index: Response.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Response.pm,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- Response.pm 1 Mar 2005 10:12:53 -0000 1.29 +++ Response.pm 5 May 2005 09:35:27 -0000 1.30 @@ -22,6 +22,8 @@ my $self = {}; $self->{header_generated} = 0; $self->{query} = $query; + $self->{format} = $query->param('format'); + $self->{action} = $query->param('action'); return bless $self, $type; } @@ -440,15 +442,29 @@ my ($self, $error_message) = @_; my $query = $self->{query}; - if (! $self->{generated_header}) { - print $query->header, $query->start_html(-title=>'Codestriker error', - -bgcolor=>'white'); + + # Check if the expected format is XML. + if (defined $self->{format} && $self->{format} eq "xml") { + print $query->header(-content_type=>'text/xml'); + print "<?xml version=\"1.0\" encoding=\"UTF-8\" " . + "standalone=\"yes\"?>\n"; + print "<response><method>" . $self->{action} . "</method>" . + "<result>" . HTML::Entities::encode($error_message) . + "</result></response>\n"; } + else { + if (! $self->{generated_header}) { + print $query->header, + $query->start_html(-title=>'Codestriker error', + -bgcolor=>'white'); + } - print $query->p, "<FONT COLOR='red'>$error_message</FONT>", $query->p; - print $query->end_html(); + print $query->p, "<FONT COLOR='red'>$error_message</FONT>", $query->p; + print $query->end_html(); + + $self->generate_footer(); + } - $self->generate_footer(); exit; } Index: submitnewcomment.html.tmpl =================================================================== RCS file: /cvsroot/codestriker/codestriker/template/en/default/submitnewcomment.html.tmpl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- submitnewcomment.html.tmpl 24 Feb 2005 09:41:01 -0000 1.6 +++ submitnewcomment.html.tmpl 5 May 2005 09:35:27 -0000 1.7 @@ -1,7 +1,20 @@ [%# Screen for the submit comment confirmation screen. #%] -</head> -<body bgcolor="#eeeeee"> -<h2>Comment submitted</h2> -</body> -</html> +[% 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> |