2008-07-03 14:59:31 +00:00
|
|
|
/*
|
|
|
|
* MIT License
|
2008-09-28 11:57:09 +00:00
|
|
|
* Copyright (c) 2008 Ishan Arora <ishan@qbittorrent.org> & Christophe Dumez <chris@qbittorrent.org>
|
2008-07-03 14:59:31 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2008-07-04 07:48:15 +00:00
|
|
|
*/
|
2008-05-17 12:44:42 +00:00
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
|
|
|
|
Script : Dynamic Table
|
2008-09-28 11:57:09 +00:00
|
|
|
Version : 0.5
|
|
|
|
Authors : Ishan Arora & Christophe Dumez
|
2008-05-17 12:44:42 +00:00
|
|
|
Desc : Programable sortable table
|
|
|
|
Licence : Open Source MIT Licence
|
|
|
|
|
|
|
|
**************************************************************/
|
|
|
|
|
|
|
|
var dynamicTable = new Class ({
|
2008-12-24 11:28:02 +00:00
|
|
|
|
|
|
|
initialize: function(){
|
|
|
|
},
|
2008-05-17 12:44:42 +00:00
|
|
|
|
2008-12-30 11:23:18 +00:00
|
|
|
setup: function(table, progressIndex){
|
2008-05-17 12:44:42 +00:00
|
|
|
this.table = $(table);
|
|
|
|
this.rows = new Object();
|
2008-09-27 10:08:07 +00:00
|
|
|
this.cur = new Array();
|
2008-12-29 23:04:45 +00:00
|
|
|
this.priority_hidden = false;
|
2008-12-30 11:23:18 +00:00
|
|
|
this.progressIndex = progressIndex;
|
2008-05-17 12:44:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
altRow: function()
|
|
|
|
{
|
|
|
|
var trs = this.table.getElements('tr');
|
|
|
|
trs.each(function(el,i){
|
|
|
|
if(i % 2){
|
2008-12-24 11:28:02 +00:00
|
|
|
el.addClass('alt');
|
2008-05-17 12:44:42 +00:00
|
|
|
}else{
|
2008-12-24 11:28:02 +00:00
|
|
|
el.removeClass('alt');
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2008-12-29 23:04:45 +00:00
|
|
|
hidePriority: function(){
|
|
|
|
if(this.priority_hidden) return;
|
|
|
|
$('prioHeader').addClass('invisible');
|
|
|
|
var trs = this.table.getElements('tr');
|
|
|
|
trs.each(function(tr,i){
|
|
|
|
var tds = tr.getElements('td');
|
|
|
|
tds.getLast().addClass('invisible');
|
|
|
|
}.bind(this));
|
|
|
|
this.priority_hidden = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
showPriority: function(){
|
|
|
|
if(!this.priority_hidden) return;
|
|
|
|
$('prioHeader').removeClass('invisible');
|
|
|
|
var trs = this.table.getElements('tr');
|
|
|
|
trs.each(function(tr,i){
|
|
|
|
var tds = tr.getElements('td');
|
|
|
|
tds.getLast().removeClass('invisible');
|
|
|
|
}.bind(this));
|
|
|
|
this.priority_hidden = false;
|
|
|
|
},
|
|
|
|
|
2008-05-17 12:44:42 +00:00
|
|
|
insertRow: function(id, row){
|
2008-09-27 19:55:56 +00:00
|
|
|
var tr = this.rows[id];
|
|
|
|
if($defined(tr))
|
|
|
|
return;
|
|
|
|
//this.removeRow(id);
|
2008-05-17 12:44:42 +00:00
|
|
|
var tr = new Element('tr');
|
|
|
|
this.rows[id] = tr;
|
|
|
|
for(var i=0; i<row.length; i++)
|
|
|
|
{
|
|
|
|
var td = new Element('td');
|
2008-12-30 11:23:18 +00:00
|
|
|
if(i==this.progressIndex) {
|
|
|
|
td.adopt(new ProgressBar(row[i].toFloat(), {width:80}));
|
|
|
|
} else {
|
|
|
|
td.set('html', row[i]);
|
|
|
|
}
|
2008-05-17 12:44:42 +00:00
|
|
|
td.injectInside(tr);
|
|
|
|
};
|
|
|
|
|
2008-09-15 05:27:56 +00:00
|
|
|
tr.addEvent('mouseover', function(e){
|
2008-12-24 11:28:02 +00:00
|
|
|
tr.addClass('over');
|
2008-05-17 12:44:42 +00:00
|
|
|
}.bind(this));
|
2008-09-15 05:27:56 +00:00
|
|
|
tr.addEvent('mouseout', function(e){
|
2008-12-24 11:28:02 +00:00
|
|
|
tr.removeClass('over');
|
2008-05-17 12:44:42 +00:00
|
|
|
}.bind(this));
|
2008-09-15 05:27:56 +00:00
|
|
|
tr.addEvent('click', function(e){
|
2008-09-28 16:39:39 +00:00
|
|
|
e.stop();
|
2008-09-27 10:08:07 +00:00
|
|
|
if(e.control) {
|
2008-09-27 10:18:27 +00:00
|
|
|
// CTRL key was pressed
|
2008-09-27 10:08:07 +00:00
|
|
|
if(this.cur.contains(id)) {
|
|
|
|
// remove it
|
|
|
|
this.cur.erase(id);
|
|
|
|
// Remove selected style
|
|
|
|
temptr = this.rows[id];
|
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
temptr.removeClass('selected');
|
2008-09-27 10:08:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.cur[this.cur.length] = id;
|
|
|
|
// Add selected style
|
|
|
|
temptr = this.rows[id];
|
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
temptr.addClass('selected');
|
2008-09-27 10:08:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-09-27 10:18:27 +00:00
|
|
|
if(e.shift && this.cur.length == 1) {
|
|
|
|
// Shift key was pressed
|
|
|
|
ids = this.getRowIds();
|
|
|
|
beginIndex = ids.indexOf(this.cur[0]);
|
|
|
|
endIndex = ids.indexOf(id);
|
2008-09-28 16:23:08 +00:00
|
|
|
if(beginIndex > endIndex) {
|
|
|
|
// Backward shift
|
|
|
|
tmp = beginIndex;
|
|
|
|
beginIndex = endIndex-1;
|
|
|
|
endIndex = tmp-1;
|
|
|
|
}
|
2008-09-27 10:18:27 +00:00
|
|
|
for(i=beginIndex+1; i<(endIndex+1); i++) {
|
|
|
|
curID = ids[i];
|
|
|
|
this.cur[this.cur.length] = curID;
|
|
|
|
// Add selected style
|
|
|
|
temptr = this.rows[curID];
|
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
temptr.addClass('selected');
|
2008-09-27 10:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Simple selection
|
|
|
|
// Remove selected style from previous ones
|
|
|
|
for(i=0; i<this.cur.length; i++) {
|
|
|
|
var temptr = this.rows[this.cur[i]];
|
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
temptr.removeClass('selected');
|
2008-09-27 10:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-28 16:23:08 +00:00
|
|
|
this.cur.empty();
|
2008-09-27 10:18:27 +00:00
|
|
|
// Add selected style to new one
|
|
|
|
temptr = this.rows[id];
|
2008-09-27 10:08:07 +00:00
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
temptr.addClass('selected');
|
2008-09-27 10:08:07 +00:00
|
|
|
}
|
2008-09-27 10:18:27 +00:00
|
|
|
this.cur[0] = id;
|
2008-09-27 10:08:07 +00:00
|
|
|
}
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
2008-09-28 16:39:39 +00:00
|
|
|
return false;
|
2008-05-17 12:44:42 +00:00
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
tr.injectInside(this.table);
|
|
|
|
this.altRow();
|
|
|
|
},
|
2008-09-28 16:23:08 +00:00
|
|
|
|
|
|
|
selectAll: function() {
|
|
|
|
this.cur.empty();
|
|
|
|
for (var id in this.rows) {
|
|
|
|
this.cur[this.cur.length] = id;
|
|
|
|
temptr = this.rows[id];
|
|
|
|
if(temptr){
|
2008-12-24 11:28:02 +00:00
|
|
|
if(!temptr.hasClass('selected')) {
|
|
|
|
temptr.addClass('selected');
|
2008-09-28 16:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2008-05-17 12:44:42 +00:00
|
|
|
|
|
|
|
updateRow: function(id, row){
|
|
|
|
var tr = this.rows[id];
|
|
|
|
if($defined(tr))
|
|
|
|
{
|
|
|
|
var tds = tr.getElements('td');
|
2008-12-30 11:23:18 +00:00
|
|
|
for(var i=0; i<row.length; i++) {
|
|
|
|
if(i==this.progressIndex) {
|
|
|
|
tds[i].set('html', '');
|
|
|
|
tds[i].adopt(new ProgressBar(row[i].toFloat(), {width:80}));
|
|
|
|
} else {
|
|
|
|
tds[i].set('html', row[i]);
|
|
|
|
}
|
|
|
|
};
|
2008-05-17 12:44:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRow: function(id){
|
2008-09-27 10:08:07 +00:00
|
|
|
if(this.cur.contains(id))
|
2008-05-17 12:44:42 +00:00
|
|
|
{
|
2008-09-27 10:08:07 +00:00
|
|
|
this.cur.erase(id);
|
2008-05-17 12:44:42 +00:00
|
|
|
}
|
|
|
|
var tr = this.rows[id];
|
|
|
|
if($defined(tr))
|
|
|
|
{
|
2008-09-14 10:14:54 +00:00
|
|
|
tr.dispose();
|
2008-05-17 12:44:42 +00:00
|
|
|
this.altRow();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2008-09-27 10:08:07 +00:00
|
|
|
selectedIds: function(){
|
2008-05-17 12:44:42 +00:00
|
|
|
return this.cur;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRowIds: function(){
|
|
|
|
var ids = new Array();
|
|
|
|
var i = 0;
|
|
|
|
for (var id in this.rows) {
|
|
|
|
ids[i] = id;
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
});
|
2008-12-24 11:28:02 +00:00
|
|
|
//dynamicTable.implement(new Options);
|
|
|
|
//dynamicTable.implement(new Events);
|
2008-05-17 12:44:42 +00:00
|
|
|
|
|
|
|
/*************************************************************/
|