Passed
Push — master ( a8de6e...8a642a )
by Alexander
04:10
created

testrun_actions.js ➔ toggleDiv   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 13
rs 9.85
c 0
b 0
f 0
cc 2
1
Nitrate.TestRuns = {};
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

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.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

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.

Loading history...
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 {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
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]);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
52
      } else {
53
        this.title = "Expand all cases";
54
        blindupAllCases(element[0]);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
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';
0 ignored issues
show
Unused Code introduced by
The variable type seems to be never used. Consider removing it.
Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

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.

Loading history...
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)) {
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
81
          return false;
82
        }
83
        removeComment(this, refresh_case);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
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-caserun-bug').bind('click', function(){
101
        var params = jQ(this).data('params');
102
        addCaseRunBug(params[0], c[0], c_container[0], params[1], params[2]);
103
      });
104
      c_container.find('.js-remove-caserun-bug').bind('click', function(){
105
        var params = jQ(this).data('params');
106
        removeCaseBug(params[1], params[2], params[3]);
107
      });
108
      c_container.find('.js-add-testlog').bind('click', function(){
109
        var params = jQ(this).data('params');
110
        addLinkToCaseRun(this, params[0], params[1]);
111
      });
112
      c_container.find('.js-remove-testlog').bind('click', function(){
113
        removeLink(this, window.parseInt(jQ(this).data('param')));
114
      });
115
    };
116
117
    toggleTestExecutionPane({
118
      'callback': callback,
119
      'caseId': case_id,
120
      'caserunId': case_run_id,
121
      'caseTextVersion': case_text_version,
122
      'caserunRowContainer': c,
123
      'expandPaneContainer': c_container
124
    });
125
  };
126
  jQ('.expandable').bind('click', toggle_case_run);
127
128
  // Auto show the case run contents.
129
  if (window.location.hash != '') {
130
    fireEvent(jQ('a[href=\"' + window.location.hash + '\"]')[0], 'click');
131
  };
132
133
  // Filter Case-Run
134
  if (jQ('#filter_case_run').length) {
135
    jQ('#filter_case_run').bind('click',function(e){
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

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.

Loading history...
136
      if (jQ('#id_filter').is(':hidden')){
137
        jQ('#id_filter').show();
138
        jQ(this).html(default_messages.link.hide_filter);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
139
      } else {
140
        jQ('#id_filter').hide();
141
        jQ(this).html(default_messages.link.show_filter);
142
      }
143
    });
144
  }
145
  //bind click to status btn
146
  jQ('.btn_status').live('click', function() {
147
    var from = jQ(this).siblings('.btn_status:disabled')[0].title;
148
    var to = this.title;
149
    if (jQ('span#' + to + ' a').text() === '0') {
150
      var htmlstr = "[<a href='javascript:void(0)' onclick=\"showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], '"
151
        + jQ(this).attr('crs_id')+"')\">0</a>]";
152
      jQ('span#' + to).html(htmlstr);
153
    }
154
    if (jQ('span#' + from + ' a').text() === '1') {
155
      jQ('span#' + from).html("[<a>1</a>]");
156
    }
157
    jQ('span#' + to + ' a').text(window.parseInt(jQ('span#' + to + ' a').text()) + 1);
158
    jQ('span#' + from + ' a').text(window.parseInt(jQ('span#' + from + ' a').text()) - 1);
159
160
    var caseRunCount = window.parseInt(jQ('span#TOTAL').next().text()) || 0;
161
    var passedCaseRunCount = window.parseInt(jQ('span#PASSED a').text()) || 0;
162
    var errorCaseRunCount = window.parseInt(jQ('span#ERROR a').text()) || 0;
163
    var failedCaseRunCount = window.parseInt(jQ('span#FAILED a').text()) || 0;
164
    var waivedCaseRunCount = window.parseInt(jQ('span#WAIVED a').text()) || 0;
165
    var completePercent = 100 * ((passedCaseRunCount + errorCaseRunCount + failedCaseRunCount
166
      + waivedCaseRunCount) / caseRunCount).toFixed(2);
167
    var failedPercent = 100 * ((errorCaseRunCount + failedCaseRunCount) / (passedCaseRunCount
168
      + errorCaseRunCount + failedCaseRunCount + waivedCaseRunCount)).toFixed(2);
169
170
    jQ('span#complete_percent').text(completePercent);
171
    jQ('div.progress-inner').attr('style', 'width:' + completePercent + '%');
172
    jQ('div.progress-failed').attr('style', 'width:' + failedPercent + '%');
173
  });
174
175
  jQ('#btn_clone').bind('click', function() {
176
    postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases','case_run'));
177
  });
178
  jQ('#btn_delete').bind('click', function() {
179
    window.location.href = jQ(this).data('param');
180
  });
181
182
  bindJSRemoveTagButton();
183
  jQ('.js-add-tag').bind('click', function() {
184
    addRunTag(jQ('.js-tag-ul')[0], jQ(this).data('param'));
185
  });
186
  jQ('.js-set-running').bind('click', function() {
187
    window.location.href = jQ(this).data('param') + '?finished=0';
188
  });
189
  jQ('.js-set-finished').bind('click', function() {
190
    window.location.href = jQ(this).data('param') + '?finished=1';
191
  });
192
  jQ('.js-del-case').bind('click', function() {
193
    delCaseRun(jQ(this).data('param'));
194
  });
195
  jQ('.js-update-case').bind('click', function() {
196
    postToURL(jQ(this).data('param'), serializeCaseRunFromInputList('id_table_cases', 'case_run'));
197
  });
198
  jQ('.js-change-assignee').bind('click', function() {
199
    changeCaseRunAssignee();
200
  });
201
  jQ('.js-add-bugs').bind('click', function() {
202
    updateBugs('add');
203
  });
204
  jQ('.js-remove-bugs').bind('click', function() {
205
    updateBugs('remove');
206
  });
207
  jQ('.js-show-commentdialog').bind('click', function() {
208
    showCommentForm();
209
  });
210
  jQ('.js-add-cc').bind('click', function() {
211
    addRunCC(jQ(this).data('param'), jQ('.js-cc-ul')[0]);
212
  });
213
  jQ('.js-remove-cc').bind('click', function() {
214
    var params = jQ(this).data('params');
215
    removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]);
216
  });
217
  jQ('.js-caserun-total').bind('click', function() {
218
    showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], '');
219
  });
220
  jQ('.js-status-subtotal').bind('click', function() {
221
    showCaseRunsWithSelectedStatus(jQ('#id_filter')[0], jQ(this).data('param'));
222
  });
223
};
224
225
Nitrate.TestRuns.AssignCase.on_load = function() {
226
  if (jQ('#id_check_all_button').length) {
227
    jQ('#id_check_all_button').bind('click', function(m) {
0 ignored issues
show
Unused Code introduced by
The parameter m is not used and could be removed.

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.

Loading history...
228
      toggleAllCheckBoxes(this, 'id_table_cases', 'case');
229
    });
230
  }
231
232
  jQ('input[name="case"]').bind('click', function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

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.

Loading history...
233
    if (this.checked) {
234
      jQ(this).closest('tr').addClass('selection_row');
235
      jQ(this).parent().siblings().eq(7).html('<div class="apply_icon"></div>');
236
    } else {
237
      jQ(this).closest('tr').removeClass('selection_row');
238
      jQ(this).parent().siblings().eq(7).html('');
239
    }
240
  });
241
242
  jQ('.js-how-assign-case').bind('click', function() {
243
    jQ('#help_assign').show();
244
  });
245
  jQ('.js-close-how-assign').bind('click', function() {
246
    jQ('#help_assign').hide();
247
  });
248
  jQ('.js-toggle-button, .js-case-summary').bind('click', function() {
249
    toggleTestCaseContents(jQ(this).data('param'));
250
  });
251
};
252
253
254
function updateRunStatus(object_pk, value, callback) {
255
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
256
    'url': '/runs/case-run-update-status/',
257
    'type': 'POST',
258
    'data': {'object_pk': object_pk, 'status_id': value },
259
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter data is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

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.

Loading history...
260
      callback();
261
    },
262
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

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.

Loading history...
263
      json_failure(jqXHR);
264
    }
265
  });
266
}
267
268
var updateCaseRunStatus = function(e) {
269
  e.stopPropagation();
270
  e.preventDefault();
271
  var container = jQ(this).parents().eq(3);
272
  var parent = container.parent();
273
  var title = parent.prev();
274
  var link = title.find('.expandable')[0];
275
  var parameters = Nitrate.Utils.formSerialize(this);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
276
  var object_pk = parameters['object_pk'];
277
  var value = parameters['value'];
278
279
  // Callback when
280
  var callback = function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

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.

Loading history...
281
    // Update the contents
282
    if (parameters['value'] != '') {
283
      // Update the case run status icon
284
      var crs = Nitrate.TestRuns.CaseRunStatus;
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
285
      title.find('.icon_status').each(function(index) {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

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.

Loading history...
286
        for (i in crs) {
0 ignored issues
show
Bug introduced by
The variable i seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.i.
Loading history...
287
          if (typeof crs[i] === 'string' && jQ(this).is('.btn_' + crs[i])) {
288
            jQ(this).removeClass('btn_' + crs[i]);
289
          }
290
        }
291
        jQ(this).addClass('btn_' + Nitrate.TestRuns.CaseRunStatus[value - 1]);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
292
      });
293
294
      // Update related people
295
      var usr = Nitrate.User;
296
      title.find('.link_tested_by').each(function(i) {
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

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.

Loading history...
297
        jQ(this).html(usr.username);
298
      });
299
    }
300
301
    // Mark the case run to mine
302
    if (!title.is('.mine')) {
303
      title.addClass('mine');
304
    }
305
306
    // Blind down next case
307
    fireEvent(link, 'click');
308
    if (jQ('#id_check_box_auto_blinddown').attr('checked') && parameters['value'] != '') {
309
      var next_title = parent.next();
310
      if (!next_title.length) {
311
        return false;
312
      }
313
      if (next_title.next().is(':hidden')) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if next_title.next().is(":hidden") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
314
        fireEvent(next_title.find('.expandable')[0], 'click');
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
315
      }
316
    } else {
317
      fireEvent(link, 'click');
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
318
    }
319
  };
320
321
  // Add comment
322
  if (parameters['comment'] != '') {
323
    // Reset the content to loading
324
    var ajax_loading = getAjaxLoading();
325
    ajax_loading.id = 'id_loading_' + parameters['case_id'];
326
    container.html(ajax_loading);
327
    var c = jQ('<div>');
328
    if (parameters['value'] != '') {
329
      submitComment(c[0], parameters);
330
    } else {
331
      submitComment(c[0], parameters, callback);
332
    }
333
  }
334
335
  // Update the object when changing the status
336
  if (parameters['value'] != '') {
337
    // Reset the content to loading
338
    var ajax_loading = getAjaxLoading();
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable ajax_loading already seems to be declared on line 324. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
339
    ajax_loading.id = 'id_loading_' + parameters['case_id'];
340
    container.html(ajax_loading);
341
    updateRunStatus([object_pk], value, callback);
342
  }
343
};
344
345
346
function constructCaseRunZone(container, title_container, case_id) {
347
  var link = jQ(title_container).find('.expandable')[0];
348
  if (container) {
349
    var td = jQ('<td>', {'id': 'id_loading_' + case_id, 'colspan': 12 });
350
    td.html(getAjaxLoading());
351
    jQ(container).html(td);
352
  }
353
354
  if (title_container) {
355
    fireEvent(link, 'click');
356
    fireEvent(link, 'click');
357
  }
358
}
359
360
361
//////////////////////////////////////////////////////////////////////////////////////////////
362
////////   AddIssueDialog Definition //////////////
363
364
365
/*
366
 * Dialog to allow user to add sort of issue keys to case run(s).
367
 *
368
 * Here, issue key is a general to whatever the issue tracker system is.
369
 *
370
 * options:
371
 * @param extraFormHiddenData: used for providing extra data for specific AJAX request.
372
 * @param onSubmit: callback function when user click Add button
373
 * @param action: string - Add or Remove. Default is Add
374
 */
375
/*
376
 * FIXME: which namespace is proper to hold this dialog class?
377
 */
378
function AddIssueDialog(options) {
379
  this.onSubmit = options.onSubmit;
380
  if (this.onSubmit !== undefined && typeof this.onSubmit !== "function") {
381
    throw new Error("onSubmit should be a function object.");
382
  }
383
  this.extraFormHiddenData = options.extraFormHiddenData;
384
  if (this.extraFormHiddenData !== undefined && typeof this.extraFormHiddenData !== "object") {
385
    throw new Error("extraFormHiddenData sould be an object if present.");
386
  }
387
388
  this.action = options.action;
389
  if (this.action === undefined) {
390
    this.action = "Add";
391
  }
392
393
  this.a = options.a;
394
  if (this.a === undefined) {
395
    this.a = this.action.toLowerCase();
396
  }
397
398
  if (options.hasOwnProperty("show_bug_id_field")) {
399
    this.show_bug_id_field = options.show_bug_id_field;
400
  } else {
401
    this.show_bug_id_field = false;
402
  }
403
}
404
405
406
AddIssueDialog.prototype.show = function () {
407
  var dialog = jQ("#dialog")[0];
408
  if (dialog == null) {
0 ignored issues
show
Best Practice introduced by
Comparing dialog to null using the == operator is not safe. Consider using === instead.
Loading history...
409
    throw new Error("No HTML element with ID dialog. This should not happen in the runtime.");
410
  }
411
412
  var hiddenPart = [];
413
  if (this.extraFormHiddenData !== undefined) {
414
    for (var name_attr in this.extraFormHiddenData) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
415
      hiddenPart.push({'name': name_attr, 'value': this.extraFormHiddenData[name_attr]});
416
    }
417
  }
418
419
  var template = Handlebars.compile(jQ("#add_issue_form_template").html());
0 ignored issues
show
Bug introduced by
The variable Handlebars seems to be never declared. If this is a global, consider adding a /** global: Handlebars */ comment.

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.

Loading history...
420
  var context = {
421
    'hiddenFields': hiddenPart,
422
    'action_button_text': this.action,
423
    'show_bug_id_field': this.show_bug_id_field || this.action === 'Add',
424
    'show_add_to_bugzilla_checkbox': this.action === 'Add',
425
    'a': this.a,
426
  };
427
428
  jQ('#dialog').html(template(context))
429
    .find('.js-cancel-button').bind('click', function() {
430
      jQ('#dialog').hide();
431
    })
432
    .end().show();
433
434
  this.form = jQ("#add_issue_form")[0];
435
436
  // Used for following event callbacks to ref this dialog's instance
437
  var that = this;
438
439
  // Set custom callback functions
440
  if (this.onSubmit !== undefined) {
441
    jQ(this.form).bind('submit', function (form_event) {
442
      that.onSubmit(form_event, that);
443
    });
444
  }
445
};
446
447
AddIssueDialog.prototype.get_data = function () {
448
  var form_data = Nitrate.Utils.formSerialize(this.form);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
449
  form_data.bug_validation_regexp = $('#bug_system_id option:selected').data('validation-regexp');
450
  form_data.bz_external_track = $('input[name=bz_external_track]').is(':checked');
451
  return form_data;
452
};
453
454
//// end of AddIssueDialog definition /////////
455
/////////////////////////////////////////////////////////////////////////////////////////////
456
457
function fileCaseRunBug(run_id, title_container, container, case_id, case_run_id) {
458
  var dialog = new AddIssueDialog({
459
    'action': 'Report',
460
    'onSubmit': function (e, dialog) {
461
      e.stopPropagation();
462
      e.preventDefault();
463
464
        var tracker_id = dialog.get_data()['bug_system_id'];
465
        jsonRPC('Bug.report', [case_run_id, tracker_id], function(result) {
466
            $('#dialog').hide();
467
468
            if (result.rc === 0) {
469
                window.open(result.response, '_blank');
470
            } else {
471
                window.alert(result.response);
472
            }
473
      });
474
    }
475
  });
476
477
  dialog.show();
478
}
479
480
function addCaseRunBug(run_id, title_container, container, case_id, case_run_id) {
481
  var dialog = new AddIssueDialog({
482
    'onSubmit': function (e, dialog) {
483
      e.stopPropagation();
484
      e.preventDefault();
485
486
      form_data = dialog.get_data();
0 ignored issues
show
Bug introduced by
The variable form_data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.form_data.
Loading history...
487
488
      form_data.bug_id = form_data.bug_id.trim();
489
      if (!form_data.bug_id.length) {
490
        return;
491
      }
492
493
        jsonRPC('Bug.create', [{
494
                case_id: case_id,
495
                case_run_id: case_run_id,
496
                bug_id: form_data.bug_id,
497
                bug_system_id: form_data.bug_system_id
498
            }, form_data.bz_external_track],
499
            function(result) {
0 ignored issues
show
Unused Code introduced by
The parameter result is not used and could be removed.

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.

Loading history...
500
                // todo: missing error handling when bz_external_track is true
501
                $('#dialog').hide();
502
503
                // Update bugs count associated with just updated case run
504
                var jqCaserunBugCount = $('span#' + case_run_id + '_case_bug_count');
505
                jqCaserunBugCount.addClass('have_bug');
506
507
                // refresh the links of bugs
508
                constructCaseRunZone(container, title_container, case_id);
509
        });
510
    }
511
  });
512
513
  dialog.show();
514
}
515
516
517
function delCaseRun(run_id) {
0 ignored issues
show
Unused Code introduced by
The parameter run_id is not used and could be removed.

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.

Loading history...
518
  var caseruns = serializeCaseRunFromInputList('id_table_cases', 'case_run');
519
  var numCaseRuns = caseruns.case_run.length;
520
  if (window.confirm('You are about to delete ' + numCaseRuns + ' case run(s). Are you sure?')) {
521
    postToURL('remove_execution/', caseruns);
522
  }
523
}
524
525
526
// binds the remove buttons for all tags
527
function bindJSRemoveTagButton() {
528
  $('.js-remove-tag').bind('click', function() {
529
    var params = $(this).data('params');
530
    removeRunTag($('.js-tag-ul')[0], params[0], params[1]);
531
  });
532
}
533
534
535
// data is an array of id/name for tags
536
function updateTagContainer(container, data, run_id) {
537
    var html = '';
538
539
    data.forEach(function(element) {
540
        var li = '<li>' + element['name'] +
541
                    '<a href="#" class="js-remove-tag" data-params=\'["'+ run_id + '", "' + element['name'] + '"]\'>' +
542
                        '&nbsp;<i class="fa fa-trash-o"></i>' +
543
                    '</a>' +
544
                 '</li>';
545
        html += li;
546
    });
547
548
    $(container).html(html);
549
    bindJSRemoveTagButton();
550
}
551
552
553
function addRunTag(container, run_id) {
554
    var tag_container = $('#id_tags');
555
    var tag = tag_container.val();
556
557
    if (!tag) {
558
        return false;
559
    }
560
561
    var inner_callback = function(data) {
562
        updateTagContainer(container, data, run_id);
563
        tag_container.val('');
564
    }
565
    jsonRPC('TestRun.add_tag', [run_id, tag], inner_callback);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
566
}
567
568
function removeRunTag(container, run_id, tag) {
569
    var inner_callback = function(data) {
570
        updateTagContainer(container, data, run_id);
571
    }
572
    jsonRPC('TestRun.remove_tag', [run_id, tag], inner_callback);
573
}
574
575
function constructRunCC(container, run_id, parameters) {
576
  var complete = function(t) {
0 ignored issues
show
Unused Code introduced by
The parameter t is not used and could be removed.

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.

Loading history...
577
    jQ('.js-remove-cc').bind('click', function() {
578
      var params = jQ(this).data('params');
579
      removeRunCC(params[0], params[1], jQ('.js-cc-ul')[0]);
580
    });
581
    if (jQ('#message').length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if jQ("#message").length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
582
      window.alert(jQ('#message').html());
583
      return false;
584
    }
585
  };
586
  var url = '/runs/' + run_id + '/cc/';
587
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
588
    'url': url,
589
    'type': 'GET',
590
    'data': parameters,
591
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

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.

Loading history...
592
      jQ(container).html(data);
593
    },
594
    'complete': function() {
595
      complete();
596
    }
597
  });
598
}
599
600
function addRunCC(run_id, container) {
601
  var user = window.prompt('Please type new email or username for CC.');
602
  if (!user) {
603
    return false;
604
  }
605
  var parameters = {'do': 'add', 'user': user};
606
  constructRunCC(container, run_id, parameters);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
607
}
608
609
function removeRunCC(run_id, user, container) {
610
  var c = window.confirm('Are you sure to delete this user from CC?');
611
612
  if (!c) {
613
    return false;
614
  }
615
616
  var parameters = { 'do': 'remove', 'user': user };
617
  constructRunCC(container, run_id, parameters);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
618
}
619
620
function changeCaseRunAssignee() {
621
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
622
  if (!runs.length) {
623
    window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
624
    return false;
625
  }
626
627
  var p = window.prompt('Please type new email or username for assignee');
628
  if (!p) {
629
    return false;
630
  }
631
632
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
633
    'url': '/runs/update-assignee/',
634
    'type': 'POST',
635
    'data': { ids: runs, assignee: p },
636
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
637
      window.location.reload();
638
    },
639
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

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.

Loading history...
640
      json_failure(jqXHR);
641
    }
642
  });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
643
}
644
645
function serializeCaseRunFromInputList(table, name) {
646
  var elements;
647
  if (typeof table === 'string') {
648
    elements = jQ('#' + table).parent().find('input[name="case_run"]:checked');
649
  } else {
650
    elements = jQ(table).parent().find('input[name="case_run"]:checked');
651
  }
652
653
  var returnobj_list = [];
654
  elements.each(function(i) {
0 ignored issues
show
Unused Code introduced by
The parameter i is not used and could be removed.

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.

Loading history...
655
    if (typeof this.value === 'string') {
656
      returnobj_list.push(this.value);
657
    }
658
  });
659
  if (name) {
660
    var returnobj = {};
661
    returnobj[name] = returnobj_list;
662
    return returnobj;
663
  }
664
665
  return returnobj_list;
666
}
667
668
function serialzeCaseForm(form, table, serialized) {
669
  if (typeof serialized !== 'boolean') {
670
    var serialized = true;
671
  }
672
  var data;
673
  if (serialized) {
674
    data = Nitrate.Utils.formSerialize(form);
0 ignored issues
show
Bug introduced by
The variable Nitrate seems to be never declared. If this is a global, consider adding a /** global: Nitrate */ comment.

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.

Loading history...
675
  } else {
676
    data = jQ(form).serialize();
677
  }
678
679
  data['case_run'] = serializeCaseFromInputList(table);
680
  return data;
681
}
682
683
function showCaseRunsWithSelectedStatus(form, status_id) {
684
  form.status__pk.value = status_id;
685
  fireEvent(jQ(form).find('input[type="submit"]')[0], 'click');
686
}
687
688
function updateBugsActionAdd(case_runs) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
689
  var dialog = new AddIssueDialog({
690
    'extraFormHiddenData': { 'case_runs': case_runs.join() },
691
    'onSubmit': function(e, dialog) {
692
      e.stopPropagation();
693
      e.preventDefault();
694
      var form_data = dialog.get_data();
695
      form_data.bug_id = form_data.bug_id.trim();
696
697
      if (!form_data.bug_id.length) {
698
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
699
      }
700
701
      if (!validateIssueID(form_data.bug_validation_regexp, form_data.bug_id)) {
702
        return false;
703
      }
704
705
      jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
706
        url: '/caserun/update-bugs-for-many/',
707
        dataType: 'json',
708
        data: form_data,
709
        success: function(res){
710
          if (res.rc === 0) {
711
            reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
712
          } else {
713
            window.alert(res.response);
714
            return false;
715
          }
716
        }
717
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
718
    }
719
  });
720
  dialog.show();
721
}
722
723
function updateBugsActionRemove(case_runs) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
724
  var dialog = new AddIssueDialog({
725
    'action': 'Remove',
726
    'show_bug_id_field': true,
727
    'extraFormHiddenData': { 'case_runs': case_runs.join() },
728
    'onSubmit': function(e, dialog) {
729
      e.stopPropagation();
730
      e.preventDefault();
731
      var form_data = dialog.get_data();
732
      form_data.bug_id = form_data.bug_id.trim();
733
734
      if (!form_data.bug_id.length) {
735
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
736
      }
737
738
      if (!validateIssueID(form_data.bug_validation_regexp, form_data.bug_id)) {
739
        return false;
740
      }
741
742
      jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
743
        url: '/caserun/update-bugs-for-many/',
744
        dataType: 'json',
745
        success: function(res) {
746
          if (res.rc == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing res.rc to 0 using the == operator is not safe. Consider using === instead.
Loading history...
747
            reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
748
          } else {
749
            window.alert(res.response);
750
            return false;
751
          }
752
        },
753
        data: form_data,
754
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
755
    }
756
  });
757
  dialog.show();
758
}
759
760
function updateBugs(action) {
761
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
762
  if (!runs.length) {
763
    window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
764
    return false;
765
  }
766
767
  if (action === "add") {
768
    updateBugsActionAdd(runs);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
769
  } else if (action === "remove") {
770
    updateBugsActionRemove(runs);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
771
  } else {
772
    throw new Error("Unknown operation when update case runs' bugs. This should not happen.");
773
  }
774
}
775
776
function showCommentForm() {
777
  var dialog = getDialog();
778
  var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
779
  if (!runs.length) {
780
    return window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
781
  }
782
  var template = Handlebars.compile(jQ("#batch_add_comment_to_caseruns_template").html());
0 ignored issues
show
Bug introduced by
The variable Handlebars seems to be never declared. If this is a global, consider adding a /** global: Handlebars */ comment.

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.

Loading history...
783
  jQ(dialog).html(template());
784
785
  var commentText = jQ('#commentText');
786
  var commentsErr = jQ('#commentsErr');
787
  jQ('#btnComment').live('click', function() {
788
    var error;
789
    var comments = jQ.trim(commentText.val());
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
790
    if (!comments) {
791
      error = 'No comments given.';
792
    }
793
    if (error) {
794
      commentsErr.html(error);
795
      return false;
796
    }
797
    jQ.ajax({
798
      url: '/caserun/comment-many/',
799
      data: {'comment': comments, 'run': runs.join()},
800
      dataType: 'json',
801
      type: 'post',
802
      success: function(res) {
803
        if (res.rc == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing res.rc to 0 using the == operator is not safe. Consider using === instead.
Loading history...
804
          reloadWindow();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
805
        } else {
806
          commentsErr.html(res.response);
807
          return false;
808
        }
809
      }
810
    });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
811
  });
812
  jQ('#btnCancelComment').live('click', function(){
813
    jQ(dialog).hide();
814
    commentText.val('');
815
  });
816
  jQ(dialog).show();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
817
}
818
819
jQ(document).ready(function(){
820
  jQ('.btnBlueCaserun').mouseover(function() {
821
    jQ(this).find('ul').show();
822
  }).mouseout(function() {
823
    jQ(this).find('ul').hide();
824
  });
825
  jQ('ul.statusOptions a').click(function() {
826
    var option = jQ(this).attr('value');
827
    var object_pks = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
828
    if (option == '') {
829
      return false;
830
    }
831
    if (!object_pks.length) {
832
      window.alert(default_messages.alert.no_case_selected);
0 ignored issues
show
Bug introduced by
The variable default_messages seems to be never declared. If this is a global, consider adding a /** global: default_messages */ comment.

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.

Loading history...
833
      return false;
834
    }
835
    if (!window.confirm(default_messages.confirm.change_case_status)) {
836
      return false;
837
    }
838
    updateRunStatus(object_pks, option, reloadWindow);
0 ignored issues
show
Bug introduced by
The variable reloadWindow seems to be never declared. If this is a global, consider adding a /** global: reloadWindow */ comment.

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.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
839
  });
840
});
841
842
function get_addlink_dialog() {
843
  return jQ('#addlink_dialog');
844
}
845
846
/*
847
 * Do AJAX request to backend to remove a link
848
 *
849
 * - sender:
850
 * - link_id: the ID of an arbitrary link.
851
 */
852
function removeLink(sender, link_id) {
853
  jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
854
    url: '/linkref/remove/' + link_id + '/',
855
    type: 'GET',
856
    dataType: 'json',
857
    success: function(data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

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.

Loading history...
858
      if (data.rc !== 0) {
859
        window.alert(data.response);
860
        return false;
861
      }
862
      var li_node = sender.parentNode;
863
      li_node.parentNode.removeChild(li_node);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
864
    },
865
    error: function(jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
866
      var data = JSON.parse(jqXHR.responseText);
867
      window.alert(data.message);
868
    }
869
  });
870
}
871
872
/*
873
 * Add link to case run
874
 *
875
 * - sender: the Add link button, which is pressed to fire this event.
876
 * - target_id: to which TestExecution the new link will be linked.
877
 */
878
function addLinkToCaseRun(sender, case_id, case_run_id) {
879
  var dialog_p = get_addlink_dialog();
880
881
  dialog_p.dialog('option', 'target_id', case_run_id);
882
  // These two options are used for reloading TestExecution when successfully.
883
  var container = jQ(sender).parents('.case_content.hide')[0];
884
  dialog_p.dialog('option', 'container', container);
885
  var title_container = jQ(container).prev()[0];
886
  dialog_p.dialog('option', 'title_container', title_container);
887
  dialog_p.dialog('option', 'case_id', case_id);
888
  dialog_p.dialog('open');
889
}
890
891
/*
892
 * Initialize dialog for getting information about new link, which is attached
893
 * to an arbitrary instance of TestExecution
894
 */
895
function initialize_addlink_dialog() {
896
  var dialog_p = get_addlink_dialog();
897
898
  dialog_p.dialog({
899
    autoOpen: false,
900
    modal: true,
901
    resizable: false,
902
    height: 300,
903
    width: 400,
904
    open: function() {
905
      jQ(this).unbind('submit').bind('submit', function (e) {
906
        e.stopPropagation();
907
        e.preventDefault();
908
        jQ(this).dialog('widget').find('span:contains("OK")').click();
909
      });
910
    },
911
    buttons: {
912
      "OK": function() {
913
        // TODO: validate name and url
914
        var name = jQ('#testlog_name').attr('value');
915
        var url = jQ('#testlog_url').attr('value');
916
        var target_id = jQ(this).dialog('option', 'target_id');
917
918
        jQ.ajax({
0 ignored issues
show
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
919
          url: '/linkref/add/',
920
          type: 'POST',
921
          data: { name: name, url: url, target_id: target_id },
922
          dataType: 'json',
923
          success: function(data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by
The parameter jqXHR is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
924
            if (data.rc !== 0) {
925
              window.alert(data.response);
926
              return false;
927
            }
928
            dialog_p.dialog('close');
929
930
            // Begin to construct case run area
931
            var container = dialog_p.dialog('option', 'container');
932
            var title_container = dialog_p.dialog('option', 'title_container');
933
            var case_id = dialog_p.dialog('option', 'case_id');
934
            constructCaseRunZone(container, title_container, case_id);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
935
          },
936
          error: function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

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.

Loading history...
937
            var data = JSON.parse(jqXHR.responseText);
938
            window.alert(data.response);
939
          }
940
        });
941
      },
942
      "Cancel": function() {
943
        jQ(this).dialog('close');
944
      }
945
    },
946
    beforeClose: function() {
947
      // clean name and url for next input
948
      jQ('#testlog_name').val('');
949
      jQ('#testlog_url').val('');
950
951
      return true;
952
    },
953
    /* ATTENTION: target_id can be determined when open this dialog, and
954
     * this must be set
955
     */
956
    target_id: null
957
  });
958
}
959
960
961
/*
962
 * Toggle TestExecution panel to edit a case run in run page.
963
 *
964
 * Arguments:
965
 * options.casrunContainer:
966
 * options.expandPaneContainer:
967
 * options.caseId:
968
 * options.caserunId:
969
 * options.caseTextVersion:
970
 * options.callback:
971
 */
972
function toggleTestExecutionPane(options) {
973
  var container = options.caserunRowContainer;
974
  var content_container = options.expandPaneContainer;
975
  var callback = options.callback;
976
977
  content_container.toggle();
978
979
  if (content_container.find('.ajax_loading').length) {
980
    var url = '/case/' + options.caseId + '/execution-detail-pane/';
981
    var data = { case_run_id: options.caserunId, case_text_version: options.caseTextVersion };
982
983
    jQ.get(url, data, function(data, textStatus) {
0 ignored issues
show
Unused Code introduced by
The parameter textStatus is not used and could be removed.

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.

Loading history...
Bug introduced by
The variable jQ seems to be never declared. If this is a global, consider adding a /** global: jQ */ comment.

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.

Loading history...
984
      content_container.html(data);
985
      callback();
986
    }, 'html');
987
  }
988
989
  toggleExpandArrow({ caseRowContainer: container, expandPaneContainer: content_container });
990
}
991