Passed
Push — master ( 62d7d9...8230b1 )
by Alexander
03:29
created

testrun_actions.js ➔ AddIssueDialog   A

Complexity

Conditions 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 9.2833
c 0
b 0
f 0
cc 5
1
Nitrate.TestRuns = {};
0 ignored issues
show
Bug introduced by jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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 jianchen
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-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) {
0 ignored issues
show
Unused Code introduced by Mr. Senko
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...
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){
0 ignored issues
show
Unused Code introduced by jianchen
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...
131
      if (jQ('#id_filter').is(':hidden')){
132
        jQ('#id_filter').show();
133
        jQ(this).html(default_messages.link.hide_filter);
0 ignored issues
show
Bug introduced by jianchen
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...
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) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
222
      toggleAllCheckBoxes(this, 'id_table_cases', 'case');
223
    });
224
  }
225
226
  jQ('input[name="case"]').bind('click', function(t) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
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({
0 ignored issues
show
Bug introduced by Mr. Senko
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...
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) {
0 ignored issues
show
Unused Code introduced by Mr. Senko
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 Mr. Senko
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 Mr. Senko
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...
254
      callback();
255
    },
256
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by Mr. Senko
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 Mr. Senko
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
270
  var object_pk = parameters['object_pk'];
271
  var value = parameters['value'];
272
273
  // Callback when
274
  var callback = function(t) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
275
    // Update the contents
276
    if (parameters['value'] != '') {
277
      // Update the case run status icon
278
      var crs = Nitrate.TestRuns.CaseRunStatus;
0 ignored issues
show
Bug introduced by jianchen
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...
279
      title.find('.icon_status').each(function(index) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
280
        for (i in crs) {
0 ignored issues
show
Bug introduced by jianchen
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...
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]);
0 ignored issues
show
Bug introduced by jianchen
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...
286
      });
287
288
      // Update related people
289
      var usr = Nitrate.User;
290
      title.find('.link_tested_by').each(function(i) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
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')) {
0 ignored issues
show
Complexity Best Practice introduced by jianchen
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...
308
        fireEvent(next_title.find('.expandable')[0], 'click');
0 ignored issues
show
Best Practice introduced by jianchen
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...
309
      }
310
    } else {
311
      fireEvent(link, 'click');
0 ignored issues
show
Best Practice introduced by jianchen
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...
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();
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by jianchen
The variable ajax_loading already seems to be declared on line 318. 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...
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) {
0 ignored issues
show
Best Practice introduced by jianchen
Comparing dialog to null using the == operator is not safe. Consider using === instead.
Loading history...
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) {
0 ignored issues
show
Complexity introduced by jianchen
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...
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());
0 ignored issues
show
Bug introduced by jianchen
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
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
                        '&nbsp;<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);
0 ignored issues
show
Best Practice introduced by Mr. Senko
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...
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) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
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) {
0 ignored issues
show
Complexity Best Practice introduced by jianchen
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...
535
      window.alert(jQ('#message').html());
536
      return false;
537
    }
538
  };
539
  var url = '/runs/' + run_id + '/cc/';
540
  jQ.ajax({
0 ignored issues
show
Bug introduced by jianchen
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...
541
    'url': url,
542
    'type': 'GET',
543
    'data': parameters,
544
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by jianchen
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 jianchen
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...
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);
0 ignored issues
show
Best Practice introduced by jianchen
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...
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);
0 ignored issues
show
Best Practice introduced by jianchen
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
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({
0 ignored issues
show
Bug introduced by Mr. Senko
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...
586
    'url': '/runs/update-assignee/',
587
    'type': 'POST',
588
    'data': { ids: runs, assignee: p },
589
    'success': function (data, textStatus, jqXHR) {
0 ignored issues
show
Unused Code introduced by Mr. Senko
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 Mr. Senko
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 Mr. Senko
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...
590
      window.location.reload();
591
    },
592
    'error': function (jqXHR, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by Mr. Senko
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 Mr. Senko
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...
593
      json_failure(jqXHR);
594
    }
595
  });
0 ignored issues
show
Best Practice introduced by Mr. Senko
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...
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) {
0 ignored issues
show
Unused Code introduced by jianchen
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
646
  }
647
  var template = Handlebars.compile(jQ("#batch_add_comment_to_caseruns_template").html());
0 ignored issues
show
Bug introduced by jianchen
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...
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());
0 ignored issues
show
Bug introduced by jianchen
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...
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) {
0 ignored issues
show
Best Practice introduced by jianchen
Comparing res.rc to 0 using the == operator is not safe. Consider using === instead.
Loading history...
669
          reloadWindow();
0 ignored issues
show
Best Practice introduced by jianchen
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...
670
        } else {
671
          commentsErr.html(res.response);
672
          return false;
673
        }
674
      }
675
    });
0 ignored issues
show
Best Practice introduced by jianchen
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...
676
  });
677
  jQ('#btnCancelComment').live('click', function(){
678
    jQ(dialog).hide();
679
    commentText.val('');
680
  });
681
  jQ(dialog).show();
0 ignored issues
show
Best Practice introduced by jianchen
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...
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);
0 ignored issues
show
Bug introduced by jianchen
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...
698
      return false;
699
    }
700
    if (!window.confirm(default_messages.confirm.change_case_status)) {
701
      return false;
702
    }
703
    updateRunStatus(object_pks, option, reloadWindow);
0 ignored issues
show
Bug introduced by Mr. Senko
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 Mr. Senko
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...
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);
0 ignored issues
show
Bug introduced by Mr. Senko
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...
712
    }
713
714
    addLinkToTestExecution(null, null, execution_ids);