Browse Source

Implement key functions in Class and refactor

adaptive-webui-19844
Thomas Piccirello 7 years ago
parent
commit
091ad6103e
  1. 98
      src/webui/www/private/scripts/dynamicTable.js

98
src/webui/www/private/scripts/dynamicTable.js

@ -465,6 +465,10 @@ var DynamicTable = new Class({
return ''; return '';
}, },
isRowSelected: function(rowId) {
return this.selectedRows.contains(rowId);
},
altRow: function() { altRow: function() {
if (!MUI.ieLegacySupport) if (!MUI.ieLegacySupport)
return; return;
@ -481,7 +485,7 @@ var DynamicTable = new Class({
}, },
selectAll: function() { selectAll: function() {
this.selectedRows.empty(); this.deselectAll();
var trs = this.tableBody.getElements('tr'); var trs = this.tableBody.getElements('tr');
for (var i = 0; i < trs.length; ++i) { for (var i = 0; i < trs.length; ++i) {
@ -497,14 +501,36 @@ var DynamicTable = new Class({
}, },
selectRow: function(rowId) { selectRow: function(rowId) {
this.deselectAll();
this.selectedRows.push(rowId); this.selectedRows.push(rowId);
this.setRowClass();
this.onSelectedRowChanged();
},
deselectRow: function(rowId) {
this.selectedRows.erase(rowId);
this.setRowClass();
this.onSelectedRowChanged();
},
selectRows: function(rowId1, rowId2) {
this.deselectAll();
if (rowId1 === rowId2) {
this.selectRow(rowId1);
return;
}
var select = false;
var that = this;
this.tableBody.getElements('tr').each(function(tr) { this.tableBody.getElements('tr').each(function(tr) {
if (tr.rowId == rowId) if ((tr.rowId == rowId1) || (tr.rowId == rowId2)) {
tr.addClass('selected'); select = !select;
else that.selectedRows.push(tr.rowId);
tr.removeClass('selected'); }
else if (select) {
that.selectedRows.push(tr.rowId);
}
}); });
this.setRowClass();
this.onSelectedRowChanged(); this.onSelectedRowChanged();
}, },
@ -517,6 +543,16 @@ var DynamicTable = new Class({
}); });
}, },
setRowClass: function() {
var that = this;
this.tableBody.getElements('tr').each(function(tr) {
if (that.isRowSelected(tr.rowId))
tr.addClass('selected');
else
tr.removeClass('selected');
});
},
onSelectedRowChanged: function() {}, onSelectedRowChanged: function() {},
updateRowData: function(data) { updateRowData: function(data) {
@ -604,57 +640,30 @@ var DynamicTable = new Class({
tr._this = this; tr._this = this;
tr.addEvent('contextmenu', function(e) { tr.addEvent('contextmenu', function(e) {
if (!this._this.selectedRows.contains(this.rowId)) if (!this._this.isRowSelected(this.rowId)) {
this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
}
return true; return true;
}); });
tr.addEvent('click', function(e) { tr.addEvent('click', function(e) {
e.stop(); e.stop();
if (e.control) { if (e.control) {
// CTRL key was pressed // CTRL key was pressed
if (this._this.selectedRows.contains(this.rowId)) { if (this._this.isRowSelected(this.rowId))
// remove it this._this.deselectRow(this.rowId);
this._this.selectedRows.erase(this.rowId);
// Remove selected style
this.removeClass('selected');
}
else {
this._this.selectedRows.push(this.rowId);
// Add selected style
this.addClass('selected');
}
}
else {
if (e.shift && this._this.selectedRows.length == 1) {
// Shift key was pressed
var first_row_id = this._this.selectedRows[0];
var last_row_id = this.rowId;
this._this.selectedRows.empty();
var trs = this._this.tableBody.getElements('tr');
var select = false;
for (var i = 0; i < trs.length; ++i) {
var tr = trs[i];
if ((tr.rowId == first_row_id) || (tr.rowId == last_row_id)) {
this._this.selectedRows.push(tr.rowId);
tr.addClass('selected');
select = !select;
}
else {
if (select) {
this._this.selectedRows.push(tr.rowId);
tr.addClass('selected');
}
else else
tr.removeClass('selected'); this._this.selectRow(this.rowId);
}
} }
else if (e.shift && (this._this.selectedRows.length == 1)) {
// Shift key was pressed
this._this.selectRows(this._this.getSelectedRowId(), this.rowId);
} }
else { else {
// Simple selection // Simple selection
this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
} }
}
return false; return false;
}); });
@ -719,7 +728,7 @@ var DynamicTable = new Class({
}, },
clear: function() { clear: function() {
this.selectedRows.empty(); this.deselectAll();
this.rows.empty(); this.rows.empty();
var trs = this.tableBody.getElements('tr'); var trs = this.tableBody.getElements('tr');
while (trs.length > 0) { while (trs.length > 0) {
@ -1199,6 +1208,7 @@ var TorrentsTable = new Class({
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent('dblclick', function(e) { tr.addEvent('dblclick', function(e) {
e.stop(); e.stop();
this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
var row = this._this.rows.get(this.rowId); var row = this._this.rows.get(this.rowId);
var state = row['full_data'].state; var state = row['full_data'].state;

Loading…
Cancel
Save