Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
// Global settings for overLIB.
2
ol_fgcolor = '#FFFFCC';
3
ol_textsize = '2';
4
ol_width = 300;
5
ol_height= 150;
6
 
7
// Codestriker XMLHttpRequest object that is used.
8
var cs_request;
9
 
10
// Reference to status element.
11
var cs_status_element;
12
 
13
// Handle to the popup window.
14
var windowHandle = '';
15
 
16
function myOpen(url,name)
17
{
18
    windowHandle = window.open(url,name,
19
	  		       'toolbar=no,width=800,height=600,status=yes,scrollbars=yes,resizable=yes,menubar=no');
20
    // Indicate who initiated this operation.
21
    windowHandle.opener = window;
22
 
23
    windowHandle.focus();
24
}
25
 
26
// Retrieve the value of a cookie by name.
27
function getCookie(name)
28
{
29
   var regexp = new RegExp(name + "=([^;]+)");
30
   var value = regexp.exec(document.cookie);
31
   return (value != null) ? value[1] : null;
32
}
33
 
34
// Set the value of the cookie to the specific value.
35
function setCookie(name, value, expirySeconds)
36
{
37
   if (!expirySeconds) {
38
       // Default to one hour
39
       expirySeconds = 60 * 60;
40
   }
41
 
42
   var now = new Date();
43
   var expiry = new Date(now.getTime() + (expirySeconds * 1000))
44
   document.cookie = name + "=" + value +
45
                     "; expires=" + expiry.toGMTString() +
46
                     "; path=" + document.location.pathname;
47
}
48
 
49
// Edit open function.  Name is kept short to reduce output size.
50
function eo(fn,line,newfile)
51
{
52
    add_comment_tooltip(fn,line,newfile);
53
}
54
 
55
function gotoAnchor(anchor, reload)
56
{
57
    if (anchor == "" || opener == null) return;
58
 
59
    var index = opener.location.href.lastIndexOf("#");
60
    if (index != -1) {
61
	opener.location.href =
62
	    opener.location.href.substr(0, index) + "#" + anchor;
63
    }
64
    else {
65
        opener.location.href += "#" + anchor;
66
    }
67
 
68
    if (reload) opener.location.reload(reload);
69
    opener.focus();
70
}
71
 
72
// Called by a body onload handler for the view topic page, to tooltip
73
// the comment associated with an anchor that has comments made
74
// against it.
75
function view_topic_on_load_handler()
76
{
77
    // If the URL loaded contains an anchor, check if there is a comment
78
    // associated with it.
79
    var anchor = window.location.hash;
80
    if (anchor != null) {
81
        // Remove the leading # character.
82
        anchor = anchor.substr(1);
83
        var comment_number = comment_hash[anchor];
84
        if (comment_number != null) {
85
            // We have a comment on this line, bring up the tooltip.
86
            overlib(comment_text[comment_number], STICKY, DRAGGABLE,
87
                    FIXX, getEltPageLeft(getElt('c' + comment_number)),
88
                    FIXY, getEltPageTop(getElt('c' + comment_number)));
89
        }
90
    }
91
}
92
 
93
// Create the HTML necessary for adding a comment.
94
function add_comment_html(file, line, new_value)
95
{
96
    // Get the location of the codestriker URL.
97
    var l = top.location;
98
    var url = l.protocol + '//' + l.host + l.pathname;
99
 
100
    // Create the hidden error span, and the initial form, with the
101
    // appropriate hidden fields.
102
    var html = '<html><head>' +
103
            '<link rel="stylesheet" type="text/css" ' +
104
            '      href="' + cs_css + '"/>\n' +
105
            '<script src="' + cs_xbdhtml_js + '" type="text/javascript"></script>\n' +
106
            '</head>\n' +
107
            '<body bgcolor="#eeeeee">\n' +
108
            '<span class="hidden" id="statusField">&nbsp;</span>\n' +
109
	    '<form name="add_comment" method="POST" ' +
110
            'action="' + url + '" ' +
111
            'onSubmit="return top.verify(document.add_comment, getElt(\'statusField\'));" ' +
112
            'enctype="application/x-www-form-urlencoded">\n' +
113
	    '<input type="hidden" name="action" value="submit_comment">\n' +
114
	    '<input type="hidden" name="line" value="' + line + '">\n' +
115
	    '<input type="hidden" name="topic" value="' + cs_topicid + '">\n' +
116
	    '<input type="hidden" name="fn" value="' + file + '">\n' +
117
	    '<input type="hidden" name="newval" value="' + new_value + '">\n' +
118
	    '<textarea name="comments" rows="5" cols="50" wrap="hard">\n' +
119
	    '</textarea>\n';
120
 
121
    // Now add in the metric dropdowns.
122
    if (top.cs_metric_data.length > 0) {
123
        html += '<p><table>\n';
124
    }
125
    for (var i = 0; i < top.cs_metric_data.length; i++) {
126
        if (i % 2 == 0) {
127
            html += '<tr>\n';
128
        }
129
        html += '<td align="right">' + top.cs_metric_data[i].name + ':</td>\n';
130
        html += '<td align="left">\n';
131
        html += '<select name="comment_state_metric_' +
132
		top.cs_metric_data[i].name + '">\n';
133
 
134
	// Check if a value has been selected for this metric.
135
	var key = file + '|' + line + '|' + new_value;
136
	var comment_number = comment_hash[key];
137
        var current_value = null;
138
        if (comment_number != null &&
139
            comment_metrics[comment_number] != null) {
140
            current_value = 
141
               comment_metrics[comment_number][top.cs_metric_data[i].name];
142
        }
143
        if (current_value == null) {
144
	    // If there is no default value defined, create an empty setting.
145
	    if (top.cs_metric_data[i].default_value == null) {
146
                html += '<option value="Select Value">' +
147
		        '&lt;Select Value&gt;</option>\n';
148
            }
149
	    for (var j = 0; j < top.cs_metric_data[i].values.length; j++) {
150
                html += '<option ';
151
                var value = top.cs_metric_data[i].values[j];
152
                if (value == top.cs_metric_data[i].default_value) {
153
                    html += 'selected ';
154
                }
155
                html += 'value="' + value + '">' + value + '</option>\n';
156
            }
157
        }
158
        else {
159
            // This metric does have a current value selected.
160
            var found_current_value = 0;
161
	    for (var j = 0; j < top.cs_metric_data[i].values.length; j++) {
162
                var value = top.cs_metric_data[i].values[j];
163
                if (value == current_value) {
164
                    html += '<option selected value="' + value + '">' +
165
                            value + '</option>\n';
166
                    found_current_value = 1;
167
                }
168
                else {
169
                    html += '<option value="' + value + '">' + value +
170
                            '</option>\n';
171
                }
172
            }
173
 
174
            // Check if the current value was found, and if not, it must
175
            // represent an old metric value no longer represented in the
176
            // configuration file.
177
            if (found_current_value == 0) {
178
                html += '<option value="' + current_value + '">' +
179
                        current_value + '</option>\n';
180
            }
181
       }
182
       html += '</select>\n';
183
       html += '&nbsp;&nbsp;&nbsp;&nbsp;</td>\n';
184
       if (i % 2 == 1 || i == top.cs_metric_data.length-1) {
185
           html += '</tr>\n';
186
       }
187
    }
188
    if (top.cs_metric_data.length > 0) {
189
        html += '</table>\n';
190
    }
191
 
192
    // Now add in the email address, CC and submit buttons.
193
    html += '<p><table><tr>\n' +
194
            '<td>Your email address: </td>\n' +
195
            '<td>' +
196
            '<input type="text" name="email" size="25" maxlength="100" ' +
197
                   'value="' + cs_email + '">\n' +
198
            '</td><td></td></tr><tr>' +
199
	    '<td>Cc: <font size="-1">' +
200
            '<a href="javascript:top.add_other_reviewers(document.add_comment);">' +
201
            '(add other reviewers)</a></font> </td>' +
202
            '<td>' +
203
	    '<input type="text" name="comment_cc" size="25" ' +
204
                    'maxlength="1024"></td>\n' +
205
            '<td><input type="submit" name="submit" value="Submit"></td>' +
206
            '</tr></table></form></body></html>\n';
207
 
208
    // Return the generated html.
209
    return html;
210
}
211
 
212
// Verify that a comment is ready to be shipped out.
213
function verify(comment_form, status_field)
214
{
215
    // Set the global status element so it can be updated when
216
    // the request is being sent and received.
217
    top.cs_status_element = status_field;
218
 
219
    // Check that the comment field has a comment entered in it.
220
    if (comment_form.comments.value == '') {
221
        alert('No comment has been entered.');
222
        return false;
223
    }
224
 
225
    // Check that the email field has an email address in it.
226
    if (comment_form.email.value == '') {
227
        alert('No email address has been entered.');
228
        return false;
229
    }
230
 
231
    // Check that the metrics have been set.
232
    for (var i = 0; i < top.cs_metric_data.length; i++) {
233
        var metric_name = top.cs_metric_data[i].name;
234
        var name = 'comment_state_metric_' + metric_name;
235
        var index = comment_form.elements[name].options.selectedIndex;
236
        if (index == -1) {
237
            alert('Metric "' + metric_name + '" has not been specified.');
238
            return false;
239
        }
240
 
241
        var value = comment_form.elements[name].options[index].value;
242
        if (value == 'Select Value') {
243
            alert('Metric "' + metric_name + '" has not been specified.');
244
	    return false;
245
        }
246
    }
247
 
248
    // Make sure the email field is stored into the Codestriker
249
    // cookie, so that it is remembered for the next add comment tooltip.
250
    var cookie = getCookie('codestriker_cookie');
251
    cs_email = comment_form.email.value;
252
    var email_value = encodeURIComponent(cs_email);
253
    if (cookie == null || cookie == '') {
254
        cookie = 'email&' + email_value;
255
    }
256
    else if (cookie.match(/[&^]email&[^&]+/)) {
257
        // Email field is already in cookie.
258
        cookie = cookie.replace(/([&^])email&([^&]+)/, "$1email&" + email_value);
259
    } else {
260
        // Tack the email field onto the end.
261
        cookie += '&email&' + email_value;
262
    }
263
    setCookie('codestriker_cookie', cookie, 10 * 356 * 24 * 60 * 60);
264
 
265
    // If we reached here, then all metrics have been set.  Send the 
266
    // request as an XMLHttpRequest, and return false so the browser
267
    // does nothing else.
268
    var params = 'action=submit_comment';
269
    params += '&line=' + encodeURIComponent(comment_form.line.value);
270
    params += '&topic=' + encodeURIComponent(comment_form.topic.value);
271
    params += '&fn=' + encodeURIComponent(comment_form.fn.value);
272
    params += '&new=' + encodeURIComponent(comment_form.newval.value);
273
    params += '&comments=' + encodeURIComponent(comment_form.comments.value);
274
    params += '&email=' + encodeURIComponent(comment_form.email.value);
275
    params += '&comment_cc=' + encodeURIComponent(comment_form.comment_cc.value);
276
    params += '&format=xml';
277
 
278
    for (var i = 0; i < top.cs_metric_data.length; i++) {
279
        var comment_param =
280
            encodeURIComponent('comment_state_metric_' + top.cs_metric_data[i].name);
281
        params += '&' + comment_param + '=' +
282
                  encodeURIComponent(eval('comment_form.' + comment_param + '.value'));
283
    }
284
 
285
    setStatusText('Submitting comment...');
286
 
287
    postXMLDoc(params);
288
    return false;
289
}
290
 
291
// Add all the other reviews into the Cc field of the comment frame.
292
function add_other_reviewers(comment_form)
293
{
294
    // Find out who the reviewers are for this review.
295
    var reviewers = topic_reviewers.split(/[\s,]+/);
296
 
297
    // Now check each reviewer to see if it can be added into the Cc field.
298
    for (var i = 0; i < reviewers.length; i++) {
299
        // Get the value of the Cc field and check if the reviewer is present.
300
        var cc_addresses = comment_form.comment_cc.value.split(/[\s,]+/);
301
        var found = 0;
302
        for (var j = 0; j < cc_addresses.length; j++) {
303
            if (reviewers[i] == cc_addresses[j]) {
304
                found = 1;
305
                break;
306
            }
307
        }
308
 
309
        // Also check if the reviewer is already in the email field.
310
        if (reviewers[i] == comment_form.email.value) {
311
            found = 1;
312
        }
313
 
314
        // If not found, append it to the Cc field.
315
        if (found == 0) {
316
            if (comment_form.comment_cc.value != '') {
317
                comment_form.comment_cc.value += ', ';
318
            }
319
            comment_form.comment_cc.value += reviewers[i];
320
        }
321
    }
322
}
323
 
324
 
325
// Create a new tooltip window which contains the html used for adding
326
// a comment to the topic.
327
function add_comment_tooltip(file, line, new_value)
328
{
329
    var html = '<a href="javascript:hideElt(getElt(\'overDiv\')); void(0);">' +
330
               'Close</a><p>' +
331
               '<iframe width="480" height="300" name="comment_frame" ' +
332
               'src="javascript:top.add_comment_html(' +
333
               file + ',' + line + ',' + new_value + ');">' +
334
                'This browser is not supported.  Please use ' +
335
                'a modern browser, such as Firefox or IE which ' +
336
                'supports iframes.</iframe>';
337
    overlib(html, STICKY, DRAGGABLE, ALTCUT, CENTERPOPUP, WIDTH, 480,
338
            HEIGHT, 300);
339
}
340
 
341
// Create a new tooltip window which creates a sticky, draggable
342
// window with a close link.
343
function create_window(text)
344
{
345
    var html = '<a href="javascript:hideElt(getElt(\'overDiv\')); void(0);">' +
346
               'Close</a><p>' + text;
347
    overlib(html, STICKY, DRAGGABLE, ALTCUT, CENTERPOPUP);
348
}
349
 
350
// Function for posting to Codestriker using the XMLHttpRequest object.
351
function postXMLDoc(params)
352
{
353
    // Generate the basic Codestriker URL.
354
    var l = top.location;
355
    var url = l.protocol + '//' + l.host + l.pathname;
356
 
357
    // Check for Mozilla/Safari.
358
    if (window.XMLHttpRequest) {
359
        cs_request = new XMLHttpRequest();
360
    }
361
    // Check for IE.
362
    else if (window.ActiveXObject) {
363
        cs_request = new ActiveXObject("Microsoft.XMLHTTP");
364
    }
365
 
366
    // If the request object was created, generate the request.
367
    if (cs_request) {
368
        cs_request.onreadystatechange = top.processReqChange;
369
        cs_request.open("POST", url, true);
370
        cs_request.setRequestHeader("Content-Type",
371
                                    "application/x-www-form-urlencoded");
372
        cs_request.send(params);
373
    }
374
}
375
 
376
// Function for updating the status text in the add comment tooltip.
377
function setStatusText(newStatusText)
378
{
379
    cs_status_element.className = 'error';
380
    if (is.ie) {
381
        cs_status_element.innerText = newStatusText;
382
    }
383
    else {
384
        var newStatusTextNode = document.createTextNode(newStatusText);
385
        cs_status_element.replaceChild(newStatusTextNode, cs_status_element.childNodes[0]);
386
    }
387
}
388
 
389
// Function for handling state changes to the request object.
390
function processReqChange()
391
{
392
    // Only check for completed requests.
393
    if (cs_request.readyState == 4) {
394
        if (cs_request.status == 200) {
395
            var response = top.cs_request.responseXML.documentElement;
396
            result = response.getElementsByTagName('result')[0].firstChild.data;
397
            if (result == 'OK') {
398
                // Hide the popup if the comment was successful.
399
                hideElt(getElt('overDiv'));
400
            }
401
            else {
402
                // An error occurred, show this in the tooltip, and leave
403
                // it up.
404
                setStatusText(result);
405
            }
406
        }
407
        else {
408
            alert("There was a problem retrieving the XML data:\n" +
409
                  cs_request.statusText);
410
        }
411
    }
412
    else if (cs_request.readyState == 3) {
413
        setStatusText('Receiving response...');
414
    }
415
    else if (cs_request.readyState == 2) {
416
        setStatusText('Request sent...');
417
    }
418
}
419