1
|
|
|
Nitrate.TestCases = {}; |
|
|
|
|
2
|
|
|
Nitrate.TestCases.Details = {}; |
3
|
|
|
Nitrate.TestCases.Edit = {}; |
4
|
|
|
Nitrate.TestCases.Clone = {}; |
5
|
|
|
|
6
|
|
|
(function() { |
7
|
|
|
var TestCases = window.Nitrate.TestCases || {}; |
8
|
|
|
|
9
|
|
|
TestCases.CasesSelection = function(options) { |
10
|
|
|
this.selectedCasesIds = options.selectedCasesIds || []; |
11
|
|
|
this.selectAll = options.selectAll; |
12
|
|
|
|
13
|
|
|
if (Object.prototype.toString.call(this.selectedCasesIds) !== '[object Array]') { |
14
|
|
|
throw new TypeError('selectedCasesIds must an object of Array.'); |
15
|
|
|
} |
16
|
|
|
if (typeof this.selectAll !== 'boolean') { |
17
|
|
|
throw new TypeError('selectAll must be a boolean value.'); |
18
|
|
|
} |
19
|
|
|
}; |
20
|
|
|
|
21
|
|
|
TestCases.CasesSelection.prototype.empty = function() { |
22
|
|
|
return this.selectedCasesIds.length === 0 && !this.selectAll; |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
window.Nitrate.TestCases = TestCases; |
26
|
|
|
}()); |
27
|
|
|
|
28
|
|
|
function addComponent(component_name) { |
29
|
|
|
jsonRPC('Component.filter', |
30
|
|
|
{ |
31
|
|
|
'name': component_name, |
32
|
|
|
'product_id': Nitrate.TestCases.Instance.product_id |
|
|
|
|
33
|
|
|
}, function(data){ |
34
|
|
|
jsonRPC('TestCase.add_component', |
35
|
|
|
[Nitrate.TestCases.Instance.pk, data[0].id], |
|
|
|
|
36
|
|
|
function(data) { |
|
|
|
|
37
|
|
|
window.location.reload(); |
38
|
|
|
} |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function removeComponent(case_id, component_id) { |
45
|
|
|
if (! window.confirm(default_messages.confirm.remove_case_component)) { |
|
|
|
|
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
jsonRPC('TestCase.remove_component', [case_id, component_id], function(data){ |
|
|
|
|
50
|
|
|
$('#row-' + component_id).hide(); |
51
|
|
|
}); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
Nitrate.TestCases.Details.on_load = function() { |
55
|
|
|
var case_id = Nitrate.TestCases.Instance.pk; |
|
|
|
|
56
|
|
|
constructTagZone(jQ('#tag')[0], { 'case': case_id }); |
57
|
|
|
constructPlanCaseZone(jQ('#plan')[0], case_id); |
58
|
|
|
jQ('li.tab a').bind('click', function(i) { |
|
|
|
|
59
|
|
|
jQ('div.tab_list').hide(); |
60
|
|
|
jQ('li.tab').removeClass('tab_focus'); |
61
|
|
|
jQ(this).parent().addClass('tab_focus'); |
62
|
|
|
jQ('#' + this.title).show(); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
if (window.location.hash) { |
66
|
|
|
fireEvent(jQ('a[href=\"' + window.location.hash + '\"]')[0], 'click'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// configure autocomplete for components |
70
|
|
|
jQ('#id_components').autocomplete({ |
71
|
|
|
'source': function(request, response) { |
72
|
|
|
jsonRPC('Component.filter', |
73
|
|
|
{ |
74
|
|
|
'name__startswith': request.term, |
75
|
|
|
'product_id': Nitrate.TestCases.Instance.product_id, |
|
|
|
|
76
|
|
|
}, function(data) { |
77
|
|
|
var processedData = []; |
78
|
|
|
data.forEach(function(element) { |
79
|
|
|
processedData.push(element.name); |
80
|
|
|
}); |
81
|
|
|
response(processedData); |
82
|
|
|
} |
83
|
|
|
); |
84
|
|
|
}, |
85
|
|
|
'appendTo': '#id_components_autocomplete' |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
$('#js-add-component').bind('click', function() { |
89
|
|
|
addComponent($('#id_components').val()); |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
jQ('.link_remove_component').bind('click', function(e) { |
|
|
|
|
93
|
|
|
removeComponent(Nitrate.TestCases.Instance.pk, |
|
|
|
|
94
|
|
|
jQ('input[name="component"]')[jQ('.link_remove_component').index(this)].value); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
var toggle_case_run = function(e) { |
|
|
|
|
98
|
|
|
var c = jQ(this).parent(); // Container |
99
|
|
|
var c_container = c.next(); // Content Containers |
100
|
|
|
var case_id = c.find('input[name="case"]')[0].value; |
101
|
|
|
var case_run_id = c.find('input[name="case_run"]')[0].value; |
102
|
|
|
// FIXME: case_text_version is not used in the backend to show caserun |
103
|
|
|
// information, notes, logs, and comments. |
104
|
|
|
var case_text_version = c.find('input[name="case_text_version"]')[0].value; |
|
|
|
|
105
|
|
|
var type = 'case_case_run'; |
|
|
|
|
106
|
|
|
toggleSimpleCaseRunPane({ |
107
|
|
|
caserunRowContainer: c, |
108
|
|
|
expandPaneContainer: c_container, |
109
|
|
|
caseId: case_id, |
110
|
|
|
caserunId: case_run_id |
111
|
|
|
}); |
112
|
|
|
}; |
113
|
|
|
|
114
|
|
|
var toggle_case_runs_by_plan = function(e) { |
115
|
|
|
var c = jQ(this).parent(); |
116
|
|
|
var case_id = c.find('input').first().val(); |
117
|
|
|
var params = { |
118
|
|
|
'type' : 'case_run_list', |
119
|
|
|
'container': c[0], |
120
|
|
|
'c_container': c.next()[0], |
121
|
|
|
'case_id': case_id, |
122
|
|
|
'case_run_plan_id': c[0].id |
123
|
|
|
}; |
124
|
|
|
var callback = function(e) { |
|
|
|
|
125
|
|
|
jQ('#table_case_runs_by_plan .expandable').bind('click', toggle_case_run); |
126
|
|
|
}; |
127
|
|
|
toggleCaseRunsByPlan(params, callback); |
128
|
|
|
}; |
129
|
|
|
|
130
|
|
|
jQ('.plan_expandable').bind('click', toggle_case_runs_by_plan); |
131
|
|
|
|
132
|
|
|
jQ('.js-remove-button').bind('click', function(event) { |
133
|
|
|
var params = jQ(event.target).data('params'); |
134
|
|
|
removeCaseBug(params.id, params.caseId, params.caseRunId); |
135
|
|
|
}); |
136
|
|
|
|
137
|
|
|
jQ('.js-add-bug').bind('click', function(event) { |
|
|
|
|
138
|
|
|
addCaseBug(jQ('#id_case_bug_form')[0]); |
139
|
|
|
}); |
140
|
|
|
|
141
|
|
|
jQ('#id_bugs').bind('keydown', function(event) { |
142
|
|
|
addCaseBugViaEnterKey(jQ('#id_case_bug_form')[0], event); |
143
|
|
|
}); |
144
|
|
|
}; |
145
|
|
|
|
146
|
|
|
function configure_product_on_load() { |
147
|
|
|
$('#id_product').change(function() { |
148
|
|
|
$('#id_category').find('option').remove(); |
149
|
|
|
update_category_select_from_product(); |
150
|
|
|
}); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
Nitrate.TestCases.Edit.on_load = function() { |
154
|
|
|
configure_product_on_load(); |
155
|
|
|
if ($('#id_category').val() === null || !$('#id_category').val().length) { |
156
|
|
|
update_category_select_from_product(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
jQ('.js-back-button').bind('click', function() { |
160
|
|
|
window.history.go(-1); |
161
|
|
|
}); |
162
|
|
|
}; |
163
|
|
|
|
164
|
|
|
Nitrate.TestCases.Clone.on_load = function() { |
165
|
|
|
$('#id_product').change(update_version_select_from_product); |
|
|
|
|
166
|
|
|
if (!$('#id_version').val().length) { |
167
|
|
|
update_version_select_from_product(); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
jQ('#id_form_search_plan').bind('submit', function(e) { |
171
|
|
|
e.stopPropagation(); |
172
|
|
|
e.preventDefault(); |
173
|
|
|
|
174
|
|
|
var url = '/plans/'; |
175
|
|
|
var container = jQ('#id_plan_container'); |
176
|
|
|
container.show(); |
177
|
|
|
|
178
|
|
|
jQ.ajax({ |
|
|
|
|
179
|
|
|
'url': url, |
180
|
|
|
'type': 'GET', |
181
|
|
|
'data': jQ(this).serialize(), |
182
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
183
|
|
|
container.html(data); |
184
|
|
|
} |
185
|
|
|
}); |
186
|
|
|
}); |
187
|
|
|
|
188
|
|
|
jQ('#id_use_filterplan').bind('click', function(e) { |
|
|
|
|
189
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', false); |
190
|
|
|
jQ('#id_plan_id').val(''); |
191
|
|
|
jQ('#id_plan_id').attr('name', ''); |
192
|
|
|
jQ('#id_copy_case').attr('checked', true); |
193
|
|
|
}); |
194
|
|
|
|
195
|
|
|
if (jQ('#id_use_sameplan').length) { |
196
|
|
|
jQ('#id_use_sameplan').bind('click', function(e) { |
|
|
|
|
197
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', true); |
198
|
|
|
jQ('#id_plan_id').val(jQ('#value_plan_id').val()); |
199
|
|
|
jQ('#id_plan_id').attr('name', 'plan'); |
200
|
|
|
jQ('#id_plan_container').html('<div class="ajax_loading"></div>').hide(); |
201
|
|
|
jQ('#id_copy_case').attr('checked', false); |
202
|
|
|
}); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
jQ('.js-cancel-button').bind('click', function() { |
206
|
|
|
window.history.go('-1'); |
207
|
|
|
}); |
208
|
|
|
|
209
|
|
|
}; |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/* |
213
|
|
|
* Used for expanding test case in test plan page specifically |
214
|
|
|
* |
215
|
|
|
* Arguments: |
216
|
|
|
* options.caseRowContainer: a jQuery object referring to the container of the |
217
|
|
|
* test case that is being expanded to show more |
218
|
|
|
* information. |
219
|
|
|
* options.expandPaneContainer: a jQuery object referring to the container of |
220
|
|
|
* the expanded pane showing test case detail |
221
|
|
|
* information. |
222
|
|
|
*/ |
223
|
|
|
function toggleExpandArrow(options) { |
224
|
|
|
var container = options.caseRowContainer; |
225
|
|
|
var content_container = options.expandPaneContainer; |
226
|
|
|
var blind_icon = container.find('img.blind_icon'); |
227
|
|
|
if (content_container.css('display') === 'none') { |
228
|
|
|
blind_icon.removeClass('collapse').addClass('expand').attr('src', '/static/images/t1.gif'); |
229
|
|
|
} else { |
230
|
|
|
blind_icon.removeClass('expand').addClass('collapse').attr('src', '/static/images/t2.gif'); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/* |
236
|
|
|
* Toggle simple caserun pane in Case Runs tab in case page. |
237
|
|
|
*/ |
238
|
|
|
function toggleSimpleCaseRunPane(options) { |
239
|
|
|
var container = options.caserunRowContainer; |
240
|
|
|
var content_container = options.expandPaneContainer; |
241
|
|
|
var caseId = options.caseId; |
242
|
|
|
var caserunId = options.caserunId; |
243
|
|
|
|
244
|
|
|
content_container.toggle(); |
245
|
|
|
|
246
|
|
|
if (container.next().find('.ajax_loading').length) { |
247
|
|
|
var url = '/case/' + caseId + '/caserun-simple-pane/'; |
248
|
|
|
var data = {case_run_id: caserunId}; |
249
|
|
|
|
250
|
|
|
jQ.get(url, data, function(data, textStatus) { |
|
|
|
|
251
|
|
|
content_container.html(data); |
252
|
|
|
},'html'); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
toggleExpandArrow({ caseRowContainer: container, expandPaneContainer: content_container }); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
function toggleTestCaseContents(template_type, container, content_container, object_pk, case_text_version, case_run_id, callback) { |
259
|
|
|
if (typeof container === 'string') { |
260
|
|
|
var container = jQ('#' + container)[0]; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
if(typeof content_container === 'string') { |
264
|
|
|
var content_container = jQ('#' + content_container)[0]; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
jQ(content_container).toggle(); |
268
|
|
|
|
269
|
|
|
if (jQ('#id_loading_' + object_pk).length) { |
270
|
|
|
var url = Nitrate.http.URLConf.reverse({ name: 'case_details', arguments: {id: object_pk} }); |
|
|
|
|
271
|
|
|
var parameters = { |
272
|
|
|
template_type: template_type, |
273
|
|
|
case_text_version: case_text_version, |
274
|
|
|
case_run_id: case_run_id |
275
|
|
|
}; |
276
|
|
|
|
277
|
|
|
jQ.ajax({ |
|
|
|
|
278
|
|
|
'url': url, |
279
|
|
|
'data': parameters, |
280
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
281
|
|
|
jQ(content_container).html(data); |
282
|
|
|
}, |
283
|
|
|
'error': function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
284
|
|
|
html_failure(); |
285
|
|
|
}, |
286
|
|
|
'complete': function (jqXHR, textStatus) { |
|
|
|
|
287
|
|
|
callback(jqXHR); |
288
|
|
|
} |
289
|
|
|
}); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
toggleExpandArrow({ caseRowContainer: jQ(container), expandPaneContainer: jQ(content_container) }); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
function changeTestCaseStatus(plan_id, case_ids, new_value, container) { |
296
|
|
|
case_ids.forEach(function(element) { |
297
|
|
|
jsonRPC('TestCase.update', [element, {case_status: new_value}], function(data) {}); |
|
|
|
|
298
|
|
|
}); |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
var template_type = 'case'; |
302
|
|
|
if (container.attr('id') === 'reviewcases') { |
303
|
|
|
template_type = 'review_case'; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
var parameters = { |
307
|
|
|
'a': 'initial', |
308
|
|
|
'from_plan': plan_id, |
309
|
|
|
'template_type': template_type, |
310
|
|
|
}; |
311
|
|
|
|
312
|
|
|
// todo: #run_case_count, #case_count, #review_case_count |
313
|
|
|
// are no longer updated |
314
|
|
|
constructPlanDetailsCasesZone(container, plan_id, parameters); |
315
|
|
|
|
316
|
|
|
Nitrate.TestPlans.Details.reopenTabHelper(jQ(container)); |
|
|
|
|
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
function toggleAllCheckBoxes(element, container, name) { |
320
|
|
|
if (element.checked) { |
321
|
|
|
jQ('#' + container).parent().find('input[name="' + name + '"]').not(':disabled').attr('checked', true); |
322
|
|
|
} else { |
323
|
|
|
jQ('#' + container).parent().find('input[name="'+ name + '"]').not(':disabled').attr('checked', false); |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
function toggleAllCases(element) { |
328
|
|
|
//If and only if both case length is 0, remove the lock. |
329
|
|
|
if (jQ('div[id^="id_loading_"].normal_cases').length === 0 && jQ('div[id^="id_loading_"].review_cases').length === 0){ |
330
|
|
|
jQ(element).removeClass('locked'); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
if (jQ(element).is('.locked')) { |
334
|
|
|
return false; |
335
|
|
|
} else { |
|
|
|
|
336
|
|
|
jQ(element).addClass('locked'); |
337
|
|
|
if (jQ(element).is('.collapse-all')) { |
338
|
|
|
element.title = "Collapse all cases"; |
339
|
|
|
blinddownAllCases(element); |
|
|
|
|
340
|
|
|
} else { |
341
|
|
|
element.title = "Expand all cases"; |
342
|
|
|
blindupAllCases(element); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
function blinddownAllCases(element) { |
348
|
|
|
jQ('img.expand').each(function(e) { |
|
|
|
|
349
|
|
|
fireEvent(this, 'click'); |
350
|
|
|
}); |
351
|
|
|
if (element) { |
352
|
|
|
jQ(element) |
353
|
|
|
.removeClass('collapse-all').addClass('expand-all') |
354
|
|
|
.attr('src', '/static/images/t2.gif'); |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
function blindupAllCases(element) { |
359
|
|
|
jQ('.collapse').each(function(e) { |
|
|
|
|
360
|
|
|
fireEvent(this, 'click'); |
361
|
|
|
}); |
362
|
|
|
|
363
|
|
|
if (element) { |
364
|
|
|
jQ(element) |
365
|
|
|
.removeClass('expand-all').addClass('collapse-all') |
366
|
|
|
.attr('src', '/static/images/t1.gif'); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
function addCaseBug(form, callback) { |
371
|
|
|
var addBugInfo = Nitrate.Utils.formSerialize(form); |
|
|
|
|
372
|
|
|
addBugInfo.bug_validation_regexp = jQ('select[name="bug_system"] option:selected').data('validation-regexp'); |
373
|
|
|
addBugInfo.bug_id = addBugInfo.bug_id.trim(); |
374
|
|
|
|
375
|
|
|
if (!addBugInfo.bug_id.length) { |
376
|
|
|
// No bug ID input, no any response is required |
377
|
|
|
return false; |
378
|
|
|
} else if (!validateIssueID(addBugInfo.bug_validation_regexp, addBugInfo.bug_id)) { |
379
|
|
|
return false; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
var complete = function(t) { |
|
|
|
|
383
|
|
|
jQ('.js-add-bug').bind('click', function(event) { |
|
|
|
|
384
|
|
|
addCaseBug(jQ('#id_case_bug_form')[0]); |
385
|
|
|
}); |
386
|
|
|
jQ('#id_bugs').bind('keydown', function(event) { |
387
|
|
|
addCaseBugViaEnterKey(jQ('#id_case_bug_form')[0], event); |
388
|
|
|
}); |
389
|
|
|
jQ('.js-remove-button').bind('click', function(event) { |
390
|
|
|
var params = jQ(event.target).data('params'); |
391
|
|
|
removeCaseBug(params.id, params.caseId, params.caseRunId); |
392
|
|
|
}); |
393
|
|
|
if (jQ('#response').length) { |
394
|
|
|
window.alert(jQ('#response').html()); |
395
|
|
|
return false; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
if (callback) { |
399
|
|
|
callback(); |
400
|
|
|
} |
401
|
|
|
jQ('#case_bug_count').text(jQ('table#bugs').attr('count')); |
|
|
|
|
402
|
|
|
}; |
403
|
|
|
|
404
|
|
|
jQ.ajax({ |
|
|
|
|
405
|
|
|
'url': form.action, |
406
|
|
|
'type': form.method, |
407
|
|
|
'data': addBugInfo, |
408
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
409
|
|
|
jQ('#bug_list').html(data); |
410
|
|
|
}, |
411
|
|
|
'complete': function () { |
412
|
|
|
complete(); |
413
|
|
|
} |
414
|
|
|
}); |
|
|
|
|
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
function constructPlanCaseZone(container, case_id, parameters) { |
418
|
|
|
var complete = function(t) { |
|
|
|
|
419
|
|
|
jQ('#id_plan_form').bind('submit', function(e) { |
420
|
|
|
e.stopPropagation(); |
421
|
|
|
e.preventDefault(); |
422
|
|
|
|
423
|
|
|
var callback = function(e) { |
424
|
|
|
e.stopPropagation(); |
425
|
|
|
e.preventDefault(); |
426
|
|
|
var plan_ids = Nitrate.Utils.formSerialize(this)['plan_id']; |
|
|
|
|
427
|
|
|
if (!plan_ids) { |
428
|
|
|
window.alert(default_messages.alert.no_plan_specified); |
|
|
|
|
429
|
|
|
return false; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
var p = { a: 'add', plan_id: plan_ids }; |
433
|
|
|
constructPlanCaseZone(container, case_id, p); |
434
|
|
|
clearDialog(); |
435
|
|
|
jQ('#plan_count').text(jQ('table#testplans_table').attr('count')); |
|
|
|
|
436
|
|
|
}; |
437
|
|
|
|
438
|
|
|
var p = Nitrate.Utils.formSerialize(this); |
|
|
|
|
439
|
|
|
if (!p.pk__in) { |
440
|
|
|
window.alert(default_messages.alert.no_plan_specified); |
|
|
|
|
441
|
|
|
return false; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
var action_url = Nitrate.http.URLConf.reverse({ name: 'case_plan', arguments: {id: case_id} }); |
445
|
|
|
previewPlan(p, action_url, callback); |
|
|
|
|
446
|
|
|
}); |
447
|
|
|
if (jQ('#testplans_table td a').length) { |
448
|
|
|
jQ('#testplans_table').DataTable({ |
449
|
|
|
"bFilter": false, |
450
|
|
|
"bLengthChange": false, |
451
|
|
|
"bPaginate": false, |
452
|
|
|
"bInfo": false, |
453
|
|
|
"bAutoWidth": false, |
454
|
|
|
"aaSorting": [[ 0, "desc" ]], |
455
|
|
|
"aoColumns": [ |
456
|
|
|
null, |
457
|
|
|
{"sType": "html"}, |
458
|
|
|
{"sType": "html"}, |
459
|
|
|
{"sType": "html"}, |
460
|
|
|
null, |
461
|
|
|
{"bSortable": false} |
462
|
|
|
] |
463
|
|
|
}); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
jQ('.js-remove-plan').bind('click', function() { |
467
|
|
|
var params = jQ(this).data('params'); |
468
|
|
|
removePlanFromCase(jQ('#testplans_table_wrapper')[0], params[0], params[1]); |
469
|
|
|
}); |
470
|
|
|
|
471
|
|
|
}; |
472
|
|
|
|
473
|
|
|
var url = Nitrate.http.URLConf.reverse({ name: 'case_plan', arguments: {id: case_id} }); |
|
|
|
|
474
|
|
|
|
475
|
|
|
jQ.ajax({ |
|
|
|
|
476
|
|
|
'url': url, |
477
|
|
|
'type': 'GET', |
478
|
|
|
'data': parameters, |
479
|
|
|
'traditional': true, |
480
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
481
|
|
|
jQ(container).html(data); |
482
|
|
|
}, |
483
|
|
|
'complete': function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
484
|
|
|
complete(); |
485
|
|
|
} |
486
|
|
|
}); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
function removePlanFromCase(container, plan_id, case_id) { |
490
|
|
|
var c = window.confirm('Are you sure to remove the case from this plan?'); |
491
|
|
|
if (!c) { |
492
|
|
|
return false; |
493
|
|
|
} |
494
|
|
|
var parameters = { a: 'remove', plan_id: plan_id }; |
495
|
|
|
constructPlanCaseZone(container, case_id, parameters); |
496
|
|
|
jQ('#plan_count').text(jQ('table#testplans_table').attr('count')); |
|
|
|
|
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
|
500
|
|
|
/* |
501
|
|
|
* Serialize selected cases' Ids. |
502
|
|
|
* |
503
|
|
|
* This function inherits the ability from original definition named |
504
|
|
|
* serializeCaseFromInputList, except that it also collects whehter all cases |
505
|
|
|
* are also selected even through not all of cases are displayed. |
506
|
|
|
* |
507
|
|
|
* Return value is an object of dictionary holding two properties. `selectAll' |
508
|
|
|
* is a boolean value indicating whether user select all cases. |
509
|
|
|
* `selectedCasesIds' is an array containing all selected cases' Ids the |
510
|
|
|
* current loaded set of cases. |
511
|
|
|
* |
512
|
|
|
* Whatever user selects all cases, above two properties appears always with |
513
|
|
|
* proper value. |
514
|
|
|
*/ |
515
|
|
|
function serializeCaseFromInputList2(table) { |
516
|
|
|
var selectAll = jQ(table).parent().find('.js-cases-select-all input[type="checkbox"]')[0].checked; |
517
|
|
|
var case_ids = []; |
518
|
|
|
var checkedCases = jQ(table).find('input[name="case"]:checked'); |
519
|
|
|
checkedCases.each(function(i, checkedCase) { |
520
|
|
|
if (typeof checkedCase.value === 'string') { |
521
|
|
|
case_ids.push(checkedCase.value); |
522
|
|
|
} |
523
|
|
|
}); |
524
|
|
|
var selectedCasesIds = case_ids; |
525
|
|
|
|
526
|
|
|
return new Nitrate.TestCases.CasesSelection({ |
|
|
|
|
527
|
|
|
selectedCasesIds: selectedCasesIds, |
528
|
|
|
selectAll: selectAll |
529
|
|
|
}); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
function serializeCaseFromInputList(table) { |
533
|
|
|
var case_ids = []; |
534
|
|
|
jQ(table).parent().find('input[name="case"]:checked').each(function(i) { |
|
|
|
|
535
|
|
|
if (typeof this.value === 'string') { |
536
|
|
|
case_ids.push(this.value); |
537
|
|
|
} |
538
|
|
|
}); |
539
|
|
|
return case_ids; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/* |
543
|
|
|
* Serialize criterias for searching cases. |
544
|
|
|
* |
545
|
|
|
* Arguments: |
546
|
|
|
* - form: the form from which criterias are searched |
547
|
|
|
* - table: the table containing all loaded cases |
548
|
|
|
* - serialized: whether to serialize the form data. true is default, if not |
549
|
|
|
* passed. |
550
|
|
|
* - exclude_cases: whether to exclude all cases while serializing. For |
551
|
|
|
* instance, when filter cases, it's unnecessary to collect all selected |
552
|
|
|
* cases' IDs, due to all filtered cases in the response should be selected |
553
|
|
|
* by default. Default to true if not passed. |
554
|
|
|
*/ |
555
|
|
|
function serialzeCaseForm(form, table, serialized, exclude_cases) { |
|
|
|
|
556
|
|
|
if (typeof serialized != 'boolean') { |
557
|
|
|
var serialized = true; |
558
|
|
|
} |
559
|
|
|
if (exclude_cases === undefined) { |
560
|
|
|
var exclude_cases = false; |
561
|
|
|
} |
562
|
|
|
var data; |
563
|
|
|
if (serialized) { |
564
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
565
|
|
|
} else { |
566
|
|
|
data = jQ(form).serialize(); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
if (!exclude_cases) { |
570
|
|
|
data['case'] = serializeCaseFromInputList(table); |
571
|
|
|
} |
572
|
|
|
return data; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/* |
576
|
|
|
* New implementation of serialzeCaseForm to allow to choose whether the |
577
|
|
|
* TestCases' Ids are necessary to be serialized. |
578
|
|
|
* |
579
|
|
|
* Be default if no value is passed to exclude_cases, not exclude them. |
580
|
|
|
*/ |
581
|
|
|
function serializeCaseForm2(form, table, serialized, exclude_cases) { |
|
|
|
|
582
|
|
|
if (typeof serialized != 'boolean') { |
583
|
|
|
var serialized = true; |
584
|
|
|
} |
585
|
|
|
var data; |
586
|
|
|
if (serialized) { |
587
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
588
|
|
|
} else { |
589
|
|
|
data = jQ(form).serialize(); |
590
|
|
|
} |
591
|
|
|
var _exclude = exclude_cases === undefined ? false : exclude_cases; |
592
|
|
|
if (!_exclude) { |
593
|
|
|
data['case'] = serializeCaseFromInputList(table); |
594
|
|
|
} |
595
|
|
|
return data; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
function toggleDiv(link, divId) { |
599
|
|
|
var link = jQ(link); |
600
|
|
|
var div = jQ('#' + divId); |
601
|
|
|
var show = 'Show All'; |
602
|
|
|
var hide = 'Hide All'; |
603
|
|
|
div.toggle(); |
604
|
|
|
var text = link.html(); |
605
|
|
|
if (text !== show) { |
606
|
|
|
link.html(show); |
607
|
|
|
} else { |
608
|
|
|
link.html(hide); |
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
function addCaseBugViaEnterKey(element, e) { |
613
|
|
|
if (e.keyCode == 13) { |
614
|
|
|
addCaseBug(element); |
615
|
|
|
} |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
function toggleCaseRunsByPlan(params, callback) { |
619
|
|
|
var container = params.container; |
620
|
|
|
var content_container = params.c_container; |
621
|
|
|
var case_run_plan_id = params.case_run_plan_id; |
622
|
|
|
var case_id = params.case_id; |
623
|
|
|
if (typeof container === 'string') { |
624
|
|
|
container = jQ('#' + container); |
625
|
|
|
} else { |
626
|
|
|
container = jQ(container); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
if(typeof content_container === 'string') { |
630
|
|
|
content_container = jQ('#' + content_container); |
631
|
|
|
} else { |
632
|
|
|
content_container = jQ(content_container); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
content_container.toggle(); |
636
|
|
|
|
637
|
|
|
if (jQ('#id_loading_' + case_run_plan_id).length) { |
638
|
|
|
var url = '/case/' + case_id + '/caserun-list-pane/'; |
639
|
|
|
var parameters = { plan_id: case_run_plan_id }; |
640
|
|
|
|
641
|
|
|
jQ.ajax({ |
|
|
|
|
642
|
|
|
'url': url, |
643
|
|
|
'type': 'GET', |
644
|
|
|
'data': parameters, |
645
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
646
|
|
|
content_container.html(data); |
647
|
|
|
}, |
648
|
|
|
'error': function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
649
|
|
|
html_failure(); |
650
|
|
|
}, |
651
|
|
|
'complete': function() { |
652
|
|
|
callback(); |
653
|
|
|
} |
654
|
|
|
}); |
655
|
|
|
|
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
var blind_icon = container.find('img').first(); |
659
|
|
|
if (content_container.is(':hidden')) { |
660
|
|
|
blind_icon.removeClass('collapse').addClass('expand').attr('src', '/static/images/t1.gif'); |
661
|
|
|
} else { |
662
|
|
|
blind_icon.removeClass('expand').addClass('collapse').attr('src', '/static/images/t2.gif'); |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.