Skip to content

Commit

Permalink
Remove more unused functions from testcase_actions.js
Browse files Browse the repository at this point in the history
- Nitrate.TestCases.CasesSelection()
- toggleAllCases()
- serializeCaseFromInputList2()
- serializeCaseFromInputList()
- serialzeCaseForm()
  • Loading branch information
atodorov committed Oct 23, 2020
1 parent b1f424e commit dd4d118
Showing 1 changed file with 0 additions and 122 deletions.
122 changes: 0 additions & 122 deletions tcms/static/js/testcase_actions.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
Nitrate.TestCases = {};
Nitrate.TestCases.Clone = {};

(function() {
var TestCases = window.Nitrate.TestCases || {};

TestCases.CasesSelection = function(options) {
this.selectedCasesIds = options.selectedCasesIds || [];
this.selectAll = options.selectAll;

if (Object.prototype.toString.call(this.selectedCasesIds) !== '[object Array]') {
throw new TypeError('selectedCasesIds must an object of Array.');
}
if (typeof this.selectAll !== 'boolean') {
throw new TypeError('selectAll must be a boolean value.');
}
};

TestCases.CasesSelection.prototype.empty = function() {
return this.selectedCasesIds.length === 0 && !this.selectAll;
};

window.Nitrate.TestCases = TestCases;
}());



/*
* Used for expanding test case in test plan page specifically
*
Expand Down Expand Up @@ -56,26 +29,6 @@ function toggleAllCheckBoxes(element, container, name) {
}
}

function toggleAllCases(element) {
//If and only if both case length is 0, remove the lock.
if (jQ('div[id^="id_loading_"].normal_cases').length === 0 && jQ('div[id^="id_loading_"].review_cases').length === 0){
jQ(element).removeClass('locked');
}

if (jQ(element).is('.locked')) {
return false;
} else {
jQ(element).addClass('locked');
if (jQ(element).is('.collapse-all')) {
element.title = "Collapse all cases";
blinddownAllCases(element);
} else {
element.title = "Expand all cases";
blindupAllCases(element);
}
}
}

function blinddownAllCases(element) {
jQ('img.expand').each(function(e) {
fireEvent(this, 'click');
Expand All @@ -98,78 +51,3 @@ function blindupAllCases(element) {
.attr('src', '/static/images/t1.gif');
}
}

/*
* Serialize selected cases' Ids.
*
* This function inherits the ability from original definition named
* serializeCaseFromInputList, except that it also collects whehter all cases
* are also selected even through not all of cases are displayed.
*
* Return value is an object of dictionary holding two properties. `selectAll'
* is a boolean value indicating whether user select all cases.
* `selectedCasesIds' is an array containing all selected cases' Ids the
* current loaded set of cases.
*
* Whatever user selects all cases, above two properties appears always with
* proper value.
*/
function serializeCaseFromInputList2(table) {
var selectAll = jQ(table).parent().find('.js-cases-select-all input[type="checkbox"]')[0].checked;
var case_ids = [];
var checkedCases = jQ(table).find('input[name="case"]:checked');
checkedCases.each(function(i, checkedCase) {
if (typeof checkedCase.value === 'string') {
case_ids.push(checkedCase.value);
}
});
var selectedCasesIds = case_ids;

return new Nitrate.TestCases.CasesSelection({
selectedCasesIds: selectedCasesIds,
selectAll: selectAll
});
}

function serializeCaseFromInputList(table) {
var case_ids = [];
jQ(table).parent().find('input[name="case"]:checked').each(function(i) {
if (typeof this.value === 'string') {
case_ids.push(this.value);
}
});
return case_ids;
}

/*
* Serialize criterias for searching cases.
*
* Arguments:
* - form: the form from which criterias are searched
* - table: the table containing all loaded cases
* - serialized: whether to serialize the form data. true is default, if not
* passed.
* - exclude_cases: whether to exclude all cases while serializing. For
* instance, when filter cases, it's unnecessary to collect all selected
* cases' IDs, due to all filtered cases in the response should be selected
* by default. Default to true if not passed.
*/
function serialzeCaseForm(form, table, serialized, exclude_cases) {
if (typeof serialized != 'boolean') {
var serialized = true;
}
if (exclude_cases === undefined) {
var exclude_cases = false;
}
var data;
if (serialized) {
data = Nitrate.Utils.formSerialize(form);
} else {
data = jQ(form).serialize();
}

if (!exclude_cases) {
data['case'] = serializeCaseFromInputList(table);
}
return data;
}

0 comments on commit dd4d118

Please sign in to comment.