Skip to content

Commit

Permalink
JS: reuse datatable common settings (#755)
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiong Qi <qcxhome@gmail.com>
  • Loading branch information
tkdchen committed Sep 2, 2020
1 parent 3a5920f commit c4fc316
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/static/js/tcms_actions.js
Expand Up @@ -1010,14 +1010,14 @@ function confirmDialog(options) {

Nitrate.DataTable = {
commonSettings: {
aLengthMenu: [[10, 20, 50, -1], [10, 20, 50, 'All']],
bFilter: false,
bInfo: true,
bLengthChange: false,
bProcessing: true,
bServerSide: true,
iDisplayLength: 20,
sPaginationType: 'full_numbers',
aLengthMenu: [[10, 20, 50, -1], [10, 20, 50, 'All']],
bProcessing: true,

fnInitComplete: function (oSettings, json) {
if (oSettings.aoData.length > 1) {
Expand Down
97 changes: 50 additions & 47 deletions src/static/js/testplan_actions.js
Expand Up @@ -922,26 +922,28 @@ Nitrate.TestPlans.SearchCase.on_load = function () {
});

if (jQ('#id_table_cases').length) {
jQ('#id_table_cases').dataTable({
'aoColumnDefs':[{'bSortable':false, 'aTargets':[ 'nosort' ]}],
'aaSorting': [[ 1, 'desc' ]],
'sPaginationType': 'full_numbers',
'bFilter': false,
'aLengthMenu': [[10, 20, 50, -1], [10, 20, 50, 'All']],
'iDisplayLength': 20,
'bProcessing': true,
'fnDrawCallback': function () {
jQ('#id_table_cases tbody tr td:nth-child(1)').shiftcheckbox({
checkboxSelector: ':checkbox',
selectAll: '#id_table_cases .js-select-all'
});
jQ('#id_table_cases').dataTable(
Object.assign({}, Nitrate.DataTable.commonSettings, {
bServerSide: false,

aaSorting: [[1, 'desc']],
aoColumnDefs: [
{'bSortable': false, 'aTargets': ['nosort']}
],

fnDrawCallback: function () {
jQ('#id_table_cases tbody tr td:nth-child(1)').shiftcheckbox({
checkboxSelector: ':checkbox',
selectAll: '#id_table_cases .js-select-all'
});

jQ('#id_table_cases :checkbox').on('change', function () {
let disable = jQ('#id_table_cases tbody :checkbox:checked').length === 0;
jQ('#add-selected-cases').prop('disabled', disable);
});
}
});
jQ('#id_table_cases :checkbox').on('change', function () {
let disable = jQ('#id_table_cases tbody :checkbox:checked').length === 0;
jQ('#add-selected-cases').prop('disabled', disable);
});
}
})
);
}
};

Expand Down Expand Up @@ -2170,34 +2172,35 @@ Nitrate.TestPlans.Runs = {
if (jQ('#tab_testruns').hasClass('tab_focus')) {
if (!jQ.fn.DataTable.fnIsDataTable(jQ('#testruns_table')[0])) {
let url = that.makeUrlFromPlanId(jQ('#testruns_table').data('param'));
jQ('#testruns_table').dataTable({
'aoColumnDefs':[
{'bSortable': false, 'aTargets':[0, 8, 9, 10]},
{'sType': 'numeric', 'aTargets': [1, 6, 8, 9, 10 ]},
{'sType': 'date', 'aTargets': [5]}
],
'bSort': true,
'bProcessing': true,
'bFilter': false,
'bLengthChange': false,
'oLanguage': {'sEmptyTable': 'No test run was found in this plan.'},
'bServerSide': true,
'sAjaxSource': url,
'iDisplayLength': 20,
'sPaginationType': 'full_numbers',
'fnServerParams': function (aoData) {
let params = jQ('#run_filter').serializeArray();
params.forEach(function (param) {
aoData.push(param);
});
},
'fnDrawCallback': function () {
jQ('#testruns_table tbody tr').shiftcheckbox({
checkboxSelector: ':checkbox',
selectAll: '#testruns_table .js-select-all'
});
}
});
jQ('#testruns_table').dataTable(
Object.assign({}, Nitrate.DataTable.commonSettings, {
sAjaxSource: url,

'aoColumnDefs':[
{'bSortable': false, 'aTargets':[0, 8, 9, 10]},
{'sType': 'numeric', 'aTargets': [1, 6, 8, 9, 10 ]},
{'sType': 'date', 'aTargets': [5]}
],

oLanguage: {
sEmptyTable: 'No test run was found in this plan.'
},

fnServerParams: function (aoData) {
let params = jQ('#run_filter').serializeArray();
params.forEach(function (param) {
aoData.push(param);
});
},

fnDrawCallback: function () {
jQ('#testruns_table tbody tr').shiftcheckbox({
checkboxSelector: ':checkbox',
selectAll: '#testruns_table .js-select-all'
});
}
})
);
}
}
},
Expand Down

0 comments on commit c4fc316

Please sign in to comment.