1 | Nitrate.TestRuns = {}; |
||
2 | Nitrate.TestRuns.Details = {}; |
||
3 | Nitrate.TestRuns.Execute = {} |
||
4 | Nitrate.TestRuns.AssignCase = {} |
||
5 | |||
6 | |||
7 | function toggleDiv(link, divId) { |
||
8 | var link = jQ(link); |
||
9 | var div = jQ('#' + divId); |
||
10 | var show = 'Show All'; |
||
11 | var hide = 'Hide All'; |
||
12 | div.toggle(); |
||
13 | var text = link.html(); |
||
14 | if (text !== show) { |
||
15 | link.html(show); |
||
16 | } else { |
||
17 | link.html(hide); |
||
18 | } |
||
19 | } |
||
20 | |||
21 | |||
22 | Nitrate.TestRuns.Details.on_load = function() { |
||
23 | setAddTagAutocomplete(); |
||
24 | |||
25 | // Observe the interface buttons |
||
26 | jQ('#id_check_all_button').bind('click', function(e) { |
||
27 | toggleAllCheckBoxes(this, 'id_table_cases', 'case_run'); |
||
28 | }); |
||
29 | |||
30 | if (jQ('#id_check_box_highlight').attr('checked')) { |
||
31 | jQ('.mine').addClass('highlight'); |
||
32 | } |
||
33 | |||
34 | jQ('#id_check_box_highlight').bind('click', function(e) { |
||
35 | e = jQ('.mine'); |
||
36 | this.checked && e.addClass('highlight') || e.removeClass('highlight'); |
||
37 | }); |
||
38 | |||
39 | jQ('#id_blind_all_link').bind('click', function(e) { |
||
40 | if (!jQ('td[id^="id_loading_"]').length) { |
||
41 | jQ(this).removeClass('locked'); |
||
42 | } |
||
43 | if (jQ(this).is('.locked')) { |
||
44 | //To disable the 'expand all' until all case runs are expanded. |
||
45 | return false; |
||
46 | } else { |
||
47 | jQ(this).addClass('locked'); |
||
48 | var element = jQ(this).children(); |
||
49 | if (element.is('.collapse-all')) { |
||
50 | this.title = "Collapse all cases"; |
||
51 | blinddownAllCases(element[0]); |
||
52 | } else { |
||
53 | this.title = "Expand all cases"; |
||
54 | blindupAllCases(element[0]); |
||
55 | } |
||
56 | } |
||
57 | }); |
||
58 | |||
59 | // Observe the case run toggle and the comment form |
||
60 | var toggle_case_run = function(e) { |
||
61 | var c = jQ(this).parent(); // Container |
||
62 | var c_container = c.next(); // Content Containers |
||
63 | var case_id = c.find('input[name="case"]')[0].value; |
||
64 | var case_run_id = c.find('input[name="case_run"]')[0].value; |
||
65 | var case_text_version = c.find('input[name="case_text_version"]')[0].value; |
||
66 | var type = 'case_run'; |
||
67 | var callback = function(t) { |
||
68 | // Observe the update case run stauts/comment form |
||
69 | c_container.parent().find('.update_form') |
||
70 | .unbind('submit').bind('submit', updateCaseRunStatus); |
||
71 | |||
72 | // Observe the delete comment form |
||
73 | var refresh_case = function(t) { |
||
74 | constructCaseRunZone(c_container[0], c[0], case_id); |
||
75 | }; |
||
76 | |||
77 | var rc_callback = function(e) { |
||
78 | e.stopPropagation(); |
||
79 | e.preventDefault(); |
||
80 | if (!window.confirm(default_messages.confirm.remove_comment)) { |
||
81 | return false; |
||
82 | } |
||
83 | removeComment(this, refresh_case); |
||
84 | }; |
||
85 | c_container.parent().find('.form_comment') |
||
86 | .unbind('submit').bind('submit', rc_callback); |
||
87 | c_container.find('.js-status-button').bind('click', function() { |
||
88 | this.form.value.value = jQ(this).data('formvalue'); |
||
89 | }); |
||
90 | c_container.find('.js-show-comments').bind('click', function() { |
||
91 | toggleDiv(this, jQ(this).data('param')); |
||
92 | }); |
||
93 | c_container.find('.js-show-changelog').bind('click', function() { |
||
94 | toggleDiv(this, jQ(this).data('param')); |
||
95 | }); |
||
96 | c_container.find('.js-file-caserun-bug').bind('click', function(){ |
||
97 | var params = jQ(this).data('params'); |
||
98 | fileCaseRunBug(params[0], c[0], c_container[0], params[1], params[2]); |
||
99 | }); |
||
100 | c_container.find('.js-add-testlog').bind('click', function(){ |
||
101 | var params = jQ(this).data('params'); |
||
102 | addLinkToTestExecution(this, params[0], [params[1]]); |
||
103 | }); |
||
104 | c_container.find('.js-remove-testlog').bind('click', function(){ |
||
105 | var button = this; |
||
106 | jsonRPC('TestExecution.remove_link', [{pk: $(button).data('param')}], function(result) { |
||
107 | button.parentNode.remove(); |
||
108 | }); |
||
109 | }); |
||
110 | }; |
||
111 | |||
112 | toggleTestExecutionPane({ |
||
113 | 'callback': callback, |
||
114 | 'caseId': case_id, |
||
115 | 'caserunId': case_run_id, |
||
116 | 'caseTextVersion': case_text_version, |
||
117 | 'caserunRowContainer': c, |
||
118 | 'expandPaneContainer': c_container |
||
119 | }); |
||
120 | }; |
||
121 | jQ('.expandable').bind('click', toggle_case_run); |
||
122 | |||
123 | // Auto show the case run contents. |
||
124 | if (window.location.hash != '') { |
||
125 | fireEvent(jQ('a[href=\"' + window.location.hash + '\"]')[0], 'click'); |
||
126 | }; |
||
127 | |||
128 | // Filter Case-Run |
||
129 | if (jQ('#filter_case_run').length) { |
||
130 | jQ('#filter_case_run').bind('click',function(e){ |
||
131 | if (jQ('#id_filter').is(':hidden')){ |
||
132 | jQ('#id_filter').show(); |
||
133 | jQ(this).html(default_messages.link.hide_filter); |
||
134 | } else { |
||
135 | jQ('#id_filter').hide(); |
||
136 | jQ(this).html(default_messages.link.show_filter); |
||
137 | } |
||
138 | }); |
||
139 | } |
||
140 | //bind click to status btn |
||
141 | jQ('.btn_status').live('click', function() { |
||
142 | var from = jQ(this).siblings('.btn_status:disabled')[0].title; |
||
143 | var to = this.title; |
||
144 | if (jQ('span#' + to + ' a').text() === '0') { |
||
145 | var htmlstr = "[<a href='javascript:void(0)' onclick=\"showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], '" |
||
146 | + jQ(this).attr('crs_id')+"')\">0</a>]"; |
||
147 | jQ('span#' + to).html(htmlstr); |
||
148 | } |
||
149 | if (jQ('span#' + from + ' a').text() === '1') { |
||
150 | jQ('span#' + from).html("[<a>1</a>]"); |
||
151 | } |
||
152 | jQ('span#' + to + ' a').text(window.parseInt(jQ('span#' + to + ' a').text()) + 1); |
||
153 | jQ('span#' + from + ' a').text(window.parseInt(jQ('span#' + from + ' a').text()) - 1); |
||
154 | |||
155 | var caseRunCount = window.parseInt(jQ('span#TOTAL').next().text()) || 0; |
||
156 | var passedCaseRunCount = window.parseInt(jQ('span#PASSED a').text()) || 0; |
||
157 | var errorCaseRunCount = window.parseInt(jQ('span#ERROR a').text()) || 0; |
||
158 | var failedCaseRunCount = window.parseInt(jQ('span#FAILED a').text()) || 0; |
||
159 | var waivedCaseRunCount = window.parseInt(jQ('span#WAIVED a').text()) || 0; |
||
160 | var completePercent = 100 * ((passedCaseRunCount + errorCaseRunCount + failedCaseRunCount |
||
161 | + waivedCaseRunCount) / caseRunCount).toFixed(2); |
||
162 | var failedPercent = 100 * ((errorCaseRunCount + failedCaseRunCount) / (passedCaseRunCount |
||
163 | + errorCaseRunCount + failedCaseRunCount + waivedCaseRunCount)).toFixed(2); |
||
164 | |||
165 | jQ('span#complete_percent').text(completePercent); |
||
166 | jQ('div.progress-inner').attr('style', 'width:' + completePercent + '%'); |
||
167 | jQ('div.progress-failed').attr('style', 'width:' + failedPercent + '%'); |
||
168 | }); |
||
169 | |||
170 | jQ('#btn_clone').bind('click', function() { |
||
171 | postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases','case_run')); |
||
172 | }); |
||
173 | jQ('#btn_delete').bind('click', function() { |
||
174 | window.location.href = jQ(this).data('param'); |
||
175 | }); |
||
176 | |||
177 | bindJSRemoveTagButton(); |
||
178 | jQ('.js-add-tag').bind('click', function() { |
||
179 | addRunTag(jQ('.js-tag-ul')[0], jQ(this).data('param')); |
||
180 | }); |
||
181 | jQ('.js-set-running').bind('click', function() { |
||
182 | window.location.href = jQ(this).data('param') + '?finished=0'; |
||
183 | }); |
||
184 | jQ('.js-set-finished').bind('click', function() { |
||
185 | window.location.href = jQ(this).data('param') + '?finished=1'; |
||
186 | }); |
||
187 | jQ('.js-del-case').bind('click', function() { |
||
188 | delCaseRun(jQ(this).data('param')); |
||
189 | }); |
||
190 | jQ('.js-update-case').bind('click', function() { |
||
191 | postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases', 'case_run')); |
||
192 | }); |
||
193 | jQ('.js-change-assignee').bind('click', function() { |
||
194 | changeCaseRunAssignee(); |
||
195 | }); |
||
196 | jQ('.js-show-commentdialog').bind('click', function() { |
||
197 | showCommentForm(); |
||
198 | }); |
||
199 | |||
200 | $('.js-add-links').bind('click', function() { |
||
201 | bulkAddLinkToTestExecution(); |
||
202 | }); |
||
203 | |||
204 | jQ('.js-add-cc').bind('click', function() { |
||
205 | addRunCC(jQ(this).data('param'), jQ('.js-cc-ul')[0]); |
||
206 | }); |
||
207 | jQ('.js-remove-cc').bind('click', function() { |
||
208 | var params = jQ(this).data('params'); |
||
209 | removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]); |
||
210 | }); |
||
211 | jQ('.js-caserun-total').bind('click', function() { |
||
212 | showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], ''); |
||
213 | }); |
||
214 | jQ('.js-status-subtotal').bind('click', function() { |
||
215 | showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], jQ(this).data('param')); |
||
216 | }); |
||
217 | }; |
||
218 | |||
219 | Nitrate.TestRuns.AssignCase.on_load = function() { |
||
220 | if (jQ('#id_check_all_button').length) { |
||
221 | jQ('#id_check_all_button').bind('click', function(m) { |
||
222 | toggleAllCheckBoxes(this, 'id_table_cases', 'case'); |
||
223 | }); |
||
224 | } |
||
225 | |||
226 | jQ('input[name="case"]').bind('click', function(t) { |
||
227 | if (this.checked) { |
||
228 | jQ(this).closest('tr').addClass('selection_row'); |
||
229 | jQ(this).parent().siblings().eq(7).html('<div class="apply_icon"></div>'); |
||
230 | } else { |
||
231 | jQ(this).closest('tr').removeClass('selection_row'); |
||
232 | jQ(this).parent().siblings().eq(7).html(''); |
||
233 | } |
||
234 | }); |
||
235 | |||
236 | jQ('.js-how-assign-case').bind('click', function() { |
||
237 | jQ('#help_assign').show(); |
||
238 | }); |
||
239 | jQ('.js-close-how-assign').bind('click', function() { |
||
240 | jQ('#help_assign').hide(); |
||
241 | }); |
||
242 | jQ('.js-toggle-button, .js-case-summary').bind('click', function() { |
||
243 | toggleTestCaseContents(jQ(this).data('param')); |
||
244 | }); |
||
245 | }; |
||
246 | |||
247 | |||
248 | function updateRunStatus(object_pk, value, callback) { |
||
249 | jQ.ajax({ |
||
250 | 'url': '/runs/case-run-update-status/', |
||
251 | 'type': 'POST', |
||
252 | 'data': {'object_pk': object_pk, 'status_id': value }, |
||
253 | 'success': function (data, textStatus, jqXHR) { |
||
254 | callback(); |
||
255 | }, |
||
256 | 'error': function (jqXHR, textStatus, errorThrown) { |
||
257 | json_failure(jqXHR); |
||
258 | } |
||
259 | }); |
||
260 | } |
||
261 | |||
262 | var updateCaseRunStatus = function(e) { |
||
263 | e.stopPropagation(); |
||
264 | e.preventDefault(); |
||
265 | var container = jQ(this).parents().eq(3); |
||
266 | var parent = container.parent(); |
||
267 | var title = parent.prev(); |
||
268 | var link = title.find('.expandable')[0]; |
||
269 | var parameters = Nitrate.Utils.formSerialize(this); |
||
270 | var object_pk = parameters['object_pk']; |
||
271 | var value = parameters['value']; |
||
272 | |||
273 | // Callback when |
||
274 | var callback = function(t) { |
||
275 | // Update the contents |
||
276 | if (parameters['value'] != '') { |
||
277 | // Update the case run status icon |
||
278 | var crs = Nitrate.TestRuns.CaseRunStatus; |
||
279 | title.find('.icon_status').each(function(index) { |
||
280 | for (i in crs) { |
||
281 | if (typeof crs[i] === 'string' && jQ(this).is('.btn_' + crs[i])) { |
||
282 | jQ(this).removeClass('btn_' + crs[i]); |
||
283 | } |
||
284 | } |
||
285 | jQ(this).addClass('btn_' + Nitrate.TestRuns.CaseRunStatus[value - 1]); |
||
286 | }); |
||
287 | |||
288 | // Update related people |
||
289 | var usr = Nitrate.User; |
||
290 | title.find('.link_tested_by').each(function(i) { |
||
291 | jQ(this).html(usr.username); |
||
292 | }); |
||
293 | } |
||
294 | |||
295 | // Mark the case run to mine |
||
296 | if (!title.is('.mine')) { |
||
297 | title.addClass('mine'); |
||
298 | } |
||
299 | |||
300 | // Blind down next case |
||
301 | fireEvent(link, 'click'); |
||
302 | if (jQ('#id_check_box_auto_blinddown').attr('checked') && parameters['value'] != '') { |
||
303 | var next_title = parent.next(); |
||
304 | if (!next_title.length) { |
||
305 | return false; |
||
306 | } |
||
307 | if (next_title.next().is(':hidden')) { |
||
308 | fireEvent(next_title.find('.expandable')[0], 'click'); |
||
309 | } |
||
310 | } else { |
||
311 | fireEvent(link, 'click'); |
||
312 | } |
||
313 | }; |
||
314 | |||
315 | // Add comment |
||
316 | if (parameters['comment'] != '') { |
||
317 | // Reset the content to loading |
||
318 | var ajax_loading = getAjaxLoading(); |
||
319 | ajax_loading.id = 'id_loading_' + parameters['case_id']; |
||
320 | container.html(ajax_loading); |
||
321 | var c = jQ('<div>'); |
||
322 | if (parameters['value'] != '') { |
||
323 | submitComment(c[0], parameters); |
||
324 | } else { |
||
325 | submitComment(c[0], parameters, callback); |
||
326 | } |
||
327 | } |
||
328 | |||
329 | // Update the object when changing the status |
||
330 | if (parameters['value'] != '') { |
||
331 | // Reset the content to loading |
||
332 | var ajax_loading = getAjaxLoading(); |
||
333 | ajax_loading.id = 'id_loading_' + parameters['case_id']; |
||
334 | container.html(ajax_loading); |
||
335 | updateRunStatus([object_pk], value, callback); |
||
336 | } |
||
337 | }; |
||
338 | |||
339 | |||
340 | function constructCaseRunZone(container, title_container, case_id) { |
||
341 | var link = jQ(title_container).find('.expandable')[0]; |
||
342 | if (container) { |
||
343 | var td = jQ('<td>', {'id': 'id_loading_' + case_id, 'colspan': 12 }); |
||
344 | td.html(getAjaxLoading()); |
||
345 | jQ(container).html(td); |
||
346 | } |
||
347 | |||
348 | if (title_container) { |
||
349 | fireEvent(link, 'click'); |
||
350 | fireEvent(link, 'click'); |
||
351 | } |
||
352 | } |
||
353 | |||
354 | |||
355 | ////////////////////////////////////////////////////////////////////////////////////////////// |
||
356 | //////// AddIssueDialog Definition ////////////// |
||
357 | |||
358 | |||
359 | /* |
||
360 | * Dialog to allow user to add sort of issue keys to case run(s). |
||
361 | * |
||
362 | * Here, issue key is a general to whatever the issue tracker system is. |
||
363 | * |
||
364 | * options: |
||
365 | * @param extraFormHiddenData: used for providing extra data for specific AJAX request. |
||
366 | * @param onSubmit: callback function when user click Add button |
||
367 | * @param action: string - Add or Remove. Default is Add |
||
368 | */ |
||
369 | /* |
||
370 | * FIXME: which namespace is proper to hold this dialog class? |
||
371 | */ |
||
372 | function AddIssueDialog(options) { |
||
373 | this.onSubmit = options.onSubmit; |
||
374 | if (this.onSubmit !== undefined && typeof this.onSubmit !== "function") { |
||
375 | throw new Error("onSubmit should be a function object."); |
||
376 | } |
||
377 | this.extraFormHiddenData = options.extraFormHiddenData; |
||
378 | if (this.extraFormHiddenData !== undefined && typeof this.extraFormHiddenData !== "object") { |
||
379 | throw new Error("extraFormHiddenData sould be an object if present."); |
||
380 | } |
||
381 | |||
382 | this.action = options.action; |
||
383 | if (this.action === undefined) { |
||
384 | this.action = "Add"; |
||
385 | } |
||
386 | |||
387 | this.a = options.a; |
||
388 | if (this.a === undefined) { |
||
389 | this.a = this.action.toLowerCase(); |
||
390 | } |
||
391 | } |
||
392 | |||
393 | |||
394 | AddIssueDialog.prototype.show = function () { |
||
395 | var dialog = jQ("#dialog")[0]; |
||
396 | if (dialog == null) { |
||
397 | throw new Error("No HTML element with ID dialog. This should not happen in the runtime."); |
||
398 | } |
||
399 | |||
400 | var hiddenPart = []; |
||
401 | if (this.extraFormHiddenData !== undefined) { |
||
402 | for (var name_attr in this.extraFormHiddenData) { |
||
403 | hiddenPart.push({'name': name_attr, 'value': this.extraFormHiddenData[name_attr]}); |
||
404 | } |
||
405 | } |
||
406 | |||
407 | var template = Handlebars.compile(jQ("#add_issue_form_template").html()); |
||
408 | var context = { |
||
409 | 'hiddenFields': hiddenPart, |
||
410 | 'action_button_text': this.action, |
||
411 | 'a': this.a, |
||
412 | }; |
||
413 | |||
414 | jQ('#dialog').html(template(context)) |
||
415 | .find('.js-cancel-button').bind('click', function() { |
||
416 | jQ('#dialog').hide(); |
||
417 | }) |
||
418 | .end().show(); |
||
419 | |||
420 | this.form = jQ("#add_issue_form")[0]; |
||
421 | |||
422 | // Used for following event callbacks to ref this dialog's instance |
||
423 | var that = this; |
||
424 | |||
425 | // Set custom callback functions |
||
426 | if (this.onSubmit !== undefined) { |
||
427 | jQ(this.form).bind('submit', function (form_event) { |
||
428 | that.onSubmit(form_event, that); |
||
429 | }); |
||
430 | } |
||
431 | }; |
||
432 | |||
433 | AddIssueDialog.prototype.get_data = function () { |
||
434 | var form_data = Nitrate.Utils.formSerialize(this.form); |
||
435 | return form_data; |
||
436 | }; |
||
437 | |||
438 | //// end of AddIssueDialog definition ///////// |
||
439 | ///////////////////////////////////////////////////////////////////////////////////////////// |
||
440 | |||
441 | function fileCaseRunBug(run_id, title_container, container, case_id, case_run_id) { |
||
442 | var dialog = new AddIssueDialog({ |
||
443 | 'action': 'Report', |
||
444 | 'onSubmit': function (e, dialog) { |
||
445 | e.stopPropagation(); |
||
446 | e.preventDefault(); |
||
447 | |||
448 | var tracker_id = dialog.get_data()['bug_system_id']; |
||
449 | jsonRPC('Bug.report', [case_run_id, tracker_id], function(result) { |
||
450 | $('#dialog').hide(); |
||
451 | |||
452 | if (result.rc === 0) { |
||
453 | window.open(result.response, '_blank'); |
||
454 | } else { |
||
455 | window.alert(result.response); |
||
456 | } |
||
457 | }); |
||
458 | } |
||
459 | }); |
||
460 | |||
461 | dialog.show(); |
||
462 | } |
||
463 | |||
464 | |||
465 | function delCaseRun(run_id) { |
||
466 | if (window.confirm('Are you sure?')) { |
||
467 | const executions = $('#id_table_cases').find('input[name="case_run"]:checked'); |
||
468 | |||
469 | executions.each(function() { |
||
470 | var case_id = this.getAttribute('data-case_id'); |
||
471 | jsonRPC('TestRun.remove_case', [run_id, Number(case_id)], function () { |
||
472 | $(this).closest('tr').remove(); |
||
473 | }.bind(this)); |
||
474 | }); |
||
475 | } |
||
476 | } |
||
477 | |||
478 | |||
479 | // binds the remove buttons for all tags |
||
480 | function bindJSRemoveTagButton() { |
||
481 | $('.js-remove-tag').bind('click', function() { |
||
482 | var params = $(this).data('params'); |
||
483 | removeRunTag($('.js-tag-ul')[0], params[0], params[1]); |
||
484 | }); |
||
485 | } |
||
486 | |||
487 | |||
488 | // data is an array of id/name for tags |
||
489 | function updateTagContainer(container, data, run_id) { |
||
490 | var html = ''; |
||
491 | |||
492 | data.forEach(function(element) { |
||
493 | var li = '<li>' + element['name'] + |
||
494 | '<a href="#" class="js-remove-tag" data-params=\'["'+ run_id + '", "' + element['name'] + '"]\'>' + |
||
495 | ' <i class="fa fa-trash-o"></i>' + |
||
496 | '</a>' + |
||
497 | '</li>'; |
||
498 | html += li; |
||
499 | }); |
||
500 | |||
501 | $(container).html(html); |
||
502 | bindJSRemoveTagButton(); |
||
503 | } |
||
504 | |||
505 | |||
506 | function addRunTag(container, run_id) { |
||
507 | var tag_container = $('#id_tags'); |
||
508 | var tag = tag_container.val(); |
||
509 | |||
510 | if (!tag) { |
||
511 | return false; |
||
512 | } |
||
513 | |||
514 | var inner_callback = function(data) { |
||
515 | updateTagContainer(container, data, run_id); |
||
516 | tag_container.val(''); |
||
517 | } |
||
518 | jsonRPC('TestRun.add_tag', [run_id, tag], inner_callback); |
||
519 | } |
||
520 | |||
521 | function removeRunTag(container, run_id, tag) { |
||
522 | var inner_callback = function(data) { |
||
523 | updateTagContainer(container, data, run_id); |
||
524 | } |
||
525 | jsonRPC('TestRun.remove_tag', [run_id, tag], inner_callback); |
||
526 | } |
||
527 | |||
528 | function constructRunCC(container, run_id, parameters) { |
||
529 | var complete = function(t) { |
||
530 | jQ('.js-remove-cc').bind('click', function() { |
||
531 | var params = jQ(this).data('params'); |
||
532 | removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]); |
||
533 | }); |
||
534 | if (jQ('#message').length) { |
||
535 | window.alert(jQ('#message').html()); |
||
536 | return false; |
||
537 | } |
||
538 | }; |
||
539 | var url = '/runs/' + run_id + '/cc/'; |
||
540 | jQ.ajax({ |
||
541 | 'url': url, |
||
542 | 'type': 'GET', |
||
543 | 'data': parameters, |
||
544 | 'success': function (data, textStatus, jqXHR) { |
||
545 | jQ(container).html(data); |
||
546 | }, |
||
547 | 'complete': function() { |
||
548 | complete(); |
||
549 | } |
||
550 | }); |
||
551 | } |
||
552 | |||
553 | function addRunCC(run_id, container) { |
||
554 | var user = window.prompt('Please type new email or username for CC.'); |
||
555 | if (!user) { |
||
556 | return false; |
||
557 | } |
||
558 | var parameters = {'do': 'add', 'user': user}; |
||
559 | constructRunCC(container, run_id, parameters); |
||
560 | } |
||
561 | |||
562 | function removeRunCC(run_id, user, container) { |
||
563 | var c = window.confirm('Are you sure to delete this user from CC?'); |
||
564 | |||
565 | if (!c) { |
||
566 | return false; |
||
567 | } |
||
568 | |||
569 | var parameters = { 'do': 'remove', 'user': user }; |
||
570 | constructRunCC(container, run_id, parameters); |
||
571 | } |
||
572 | |||
573 | function changeCaseRunAssignee() { |
||
574 | var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]); |
||
575 | if (!runs.length) { |
||
576 | window.alert(default_messages.alert.no_case_selected); |
||
577 | return false; |
||
578 | } |
||
579 | |||
580 | var p = window.prompt('Please type new email or username for assignee'); |
||
581 | if (!p) { |
||
582 | return false; |
||
583 | } |
||
584 | |||
585 | jQ.ajax({ |
||
586 | 'url': '/runs/update-assignee/', |
||
587 | 'type': 'POST', |
||
588 | 'data': { ids: runs, assignee: p }, |
||
589 | 'success': function (data, textStatus, jqXHR) { |
||
590 | window.location.reload(); |
||
591 | }, |
||
592 | 'error': function (jqXHR, textStatus, errorThrown) { |
||
593 | json_failure(jqXHR); |
||
594 | } |
||
595 | }); |
||
596 | } |
||
597 | |||
598 | function serializeCaseRunFromInputList(table, name) { |
||
599 | var elements; |
||
600 | if (typeof table === 'string') { |
||
601 | elements = jQ('#' + table).parent().find('input[name="case_run"]:checked'); |
||
602 | } else { |
||
603 | elements = jQ(table).parent().find('input[name="case_run"]:checked'); |
||
604 | } |
||
605 | |||
606 | var returnobj_list = []; |
||
607 | elements.each(function(i) { |
||
608 | if (typeof this.value === 'string') { |
||
609 | returnobj_list.push(this.value); |
||
610 | } |
||
611 | }); |
||
612 | if (name) { |
||
613 | var returnobj = {}; |
||
614 | returnobj[name] = returnobj_list; |
||
615 | return returnobj; |
||
616 | } |
||
617 | |||
618 | return returnobj_list; |
||
619 | } |
||
620 | |||
621 | function serialzeCaseForm(form, table, serialized) { |
||
622 | if (typeof serialized !== 'boolean') { |
||
623 | var serialized = true; |
||
624 | } |
||
625 | var data; |
||
626 | if (serialized) { |
||
627 | data = Nitrate.Utils.formSerialize(form); |
||
628 | } else { |
||
629 | data = jQ(form).serialize(); |
||
630 | } |
||
631 | |||
632 | data['case_run'] = serializeCaseFromInputList(table); |
||
633 | return data; |
||
634 | } |
||
635 | |||
636 | function showCaseRunsWithSelectedStatus(form, status_id) { |
||
637 | form.status__pk.value = status_id; |
||
638 | fireEvent(jQ(form).find('input[type="submit"]')[0], 'click'); |
||
639 | } |
||
640 | |||
641 | function showCommentForm() { |
||
642 | var dialog = getDialog(); |
||
643 | var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]); |
||
644 | if (!runs.length) { |
||
645 | return window.alert(default_messages.alert.no_case_selected); |
||
646 | } |
||
647 | var template = Handlebars.compile(jQ("#batch_add_comment_to_caseruns_template").html()); |
||
648 | jQ(dialog).html(template()); |
||
649 | |||
650 | var commentText = jQ('#commentText'); |
||
651 | var commentsErr = jQ('#commentsErr'); |
||
652 | jQ('#btnComment').live('click', function() { |
||
653 | var error; |
||
654 | var comments = jQ.trim(commentText.val()); |
||
655 | if (!comments) { |
||
656 | error = 'No comments given.'; |
||
657 | } |
||
658 | if (error) { |
||
659 | commentsErr.html(error); |
||
660 | return false; |
||
661 | } |
||
662 | jQ.ajax({ |
||
663 | url: '/caserun/comment-many/', |
||
664 | data: {'comment': comments, 'run': runs.join()}, |
||
665 | dataType: 'json', |
||
666 | type: 'post', |
||
667 | success: function(res) { |
||
668 | if (res.rc == 0) { |
||
669 | reloadWindow(); |
||
670 | } else { |
||
671 | commentsErr.html(res.response); |
||
672 | return false; |
||
673 | } |
||
674 | } |
||
675 | }); |
||
676 | }); |
||
677 | jQ('#btnCancelComment').live('click', function(){ |
||
678 | jQ(dialog).hide(); |
||
679 | commentText.val(''); |
||
680 | }); |
||
681 | jQ(dialog).show(); |
||
682 | } |
||
683 | |||
684 | jQ(document).ready(function(){ |
||
685 | jQ('.btnBlueCaserun').mouseover(function() { |
||
686 | jQ(this).find('ul').show(); |
||
687 | }).mouseout(function() { |
||
688 | jQ(this).find('ul').hide(); |
||
689 | }); |
||
690 | jQ('ul.statusOptions a').click(function() { |
||
691 | var option = jQ(this).attr('value'); |
||
692 | var object_pks = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]); |
||
693 | if (option == '') { |
||
694 | return false; |
||
695 | } |
||
696 | if (!object_pks.length) { |
||
697 | window.alert(default_messages.alert.no_case_selected); |
||
698 | return false; |
||
699 | } |
||
700 | if (!window.confirm(default_messages.confirm.change_case_status)) { |
||
701 | return false; |
||
702 | } |
||
703 | updateRunStatus(object_pks, option, reloadWindow); |
||
704 | }); |
||
705 | }); |
||
706 | |||
707 | |||
708 | function bulkAddLinkToTestExecution() { |
||
709 | var execution_ids = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]); |
||
710 | if (!execution_ids.length) { |
||
711 | return window.alert(default_messages.alert.no_case_selected); |
||
712 | } |
||
713 | |||
714 | addLinkToTestExecution(null, null, execution_ids); |
||
715 | } |
||
716 | |||
717 | /* |
||
718 | * - sender: the Add link button, which is pressed to fire this event. |
||
719 | * - case_id: used for reloading TE details. In case of bulk actions this |
||
720 | * is null/undefined and the entire page is reloaded! |
||
721 | * - execution_ids: Array of TestExecution IDs to which the new link will be added |
||
722 | */ |
||
723 | function addLinkToTestExecution(sender, case_id, execution_ids) { |
||
724 | var dialog_p = jQ('#addlink_dialog'); |
||
725 | |||
726 | dialog_p.dialog('option', 'target_id', execution_ids); |
||
727 | dialog_p.dialog('option', 'case_id', case_id); |
||
728 | if (case_id) { |
||
729 | // These two options are used for reloading TestExecution when successfully. |
||
730 | var container = jQ(sender).parents('.case_content.hide')[0]; |
||
731 | dialog_p.dialog('option', 'container', container); |
||
732 | var title_container = jQ(container).prev()[0]; |
||
733 | dialog_p.dialog('option', 'title_container', title_container); |
||
734 | } |
||
735 | dialog_p.dialog('open'); |
||
736 | } |
||
737 | |||
738 | /* |
||
739 | * Initialize dialog for getting information about new link, which is attached |
||
740 | * to an arbitrary instance of TestExecution |
||
741 | */ |
||
742 | function initialize_addlink_dialog() { |
||
743 | var dialog_p = jQ('#addlink_dialog'); |
||
744 | |||
745 | dialog_p.dialog({ |
||
746 | autoOpen: false, |
||
747 | modal: true, |
||
748 | resizable: false, |
||
749 | height: 300, |
||
750 | width: 400, |
||
751 | open: function() { |
||
752 | jQ(this).unbind('submit').bind('submit', function (e) { |
||
753 | e.stopPropagation(); |
||
754 | e.preventDefault(); |
||
755 | jQ(this).dialog('widget').find('span:contains("OK")').click(); |
||
756 | }); |
||
757 | }, |
||
758 | buttons: { |
||
759 | "OK": function() { |
||
760 | var name = jQ('#testlog_name').attr('value'); |
||
761 | var url = jQ('#testlog_url').attr('value'); |
||
762 | var is_defect = $('#is_defect').is(':checked'); |
||
763 | var update_tracker = $('#update_tracker').is(':checked'); |
||
764 | var case_id = dialog_p.dialog('option', 'case_id'); |
||
765 | |||
766 | dialog_p.dialog('close'); |
||
767 | |||
768 | jQ(this).dialog('option', 'target_id').forEach(function(target_id) { |
||
769 | jsonRPC('TestExecution.add_link', [{ |
||
770 | execution_id: target_id, |
||
771 | name: name, |
||
772 | url: url, |
||
773 | is_defect: is_defect |
||
774 | }, update_tracker], function(result) { |
||
0 ignored issues
–
show
|
|||
775 | // when bulk adding links case_id will be undefined/null |
||
776 | if (case_id) { |
||
777 | if (is_defect) { |
||
778 | $('span#' + target_id + '_case_bug_count').addClass('have_bug'); |
||
779 | } |
||
780 | |||
781 | // Begin to construct case run area |
||
782 | var container = dialog_p.dialog('option', 'container'); |
||
783 | var title_container = dialog_p.dialog('option', 'title_container'); |
||
784 | constructCaseRunZone(container, title_container, case_id); |
||
785 | } |
||
786 | }); |
||
787 | }); |
||
788 | |||
789 | // reload entire page if adding in bulk |
||
790 | if (!case_id) { |
||
791 | window.location.reload(true); |
||
792 | } |
||
793 | }, |
||
794 | "Cancel": function() { |
||
795 | jQ(this).dialog('close'); |
||
796 | } |
||
797 | }, |
||
798 | beforeClose: function() { |
||
799 | // clean name and url for next input |
||
800 | jQ('#testlog_name').val(''); |
||
801 | jQ('#testlog_url').val(''); |
||
802 | |||
803 | return true; |
||
804 | }, |
||
805 | /* ATTENTION: target_id can be determined when open this dialog, and |
||
806 | * this must be set |
||
807 | */ |
||
808 | target_id: null |
||
809 | }); |
||
810 | } |
||
811 | |||
812 | |||
813 | /* |
||
814 | * Toggle TestExecution panel to edit a case run in run page. |
||
815 | * |
||
816 | * Arguments: |
||
817 | * options.casrunContainer: |
||
818 | * options.expandPaneContainer: |
||
819 | * options.caseId: |
||
820 | * options.caserunId: |
||
821 | * options.caseTextVersion: |
||
822 | * options.callback: |
||
823 | */ |
||
824 | function toggleTestExecutionPane(options) { |
||
825 | var container = options.caserunRowContainer; |
||
826 | var content_container = options.expandPaneContainer; |
||
827 | var callback = options.callback; |
||
828 | |||
829 | content_container.toggle(); |
||
830 | |||
831 | if (content_container.find('.ajax_loading').length) { |
||
832 | var url = '/case/' + options.caseId + '/execution-detail-pane/'; |
||
833 | var data = { case_run_id: options.caserunId, case_text_version: options.caseTextVersion }; |
||
834 | |||
835 | jQ.get(url, data, function(data, textStatus) { |
||
836 | content_container.html(data); |
||
837 | callback(); |
||
838 | }, 'html'); |
||
839 | } |
||
840 | |||
841 | toggleExpandArrow({ caseRowContainer: container, expandPaneContainer: content_container }); |
||
842 | } |
||
843 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.