Added a spinner closes #34

Started work on #60 you can select songs by clicking and ctrl-clicking
(can't do anything with the selected songs though)
This commit is contained in:
Anders Betnér 2006-04-20 21:30:47 +00:00
parent 1af9e8c08e
commit aa5c3adb9a
2 changed files with 66 additions and 30 deletions

View File

@ -1965,7 +1965,8 @@ Rico.LiveGridBuffer.prototype = {
getBlankRow: function() { getBlankRow: function() {
if (!this.blankRow ) { if (!this.blankRow ) {
this.blankRow = new Array(); this.blankRow = new Array();
for ( var i=0; i < this.metaData.columnCount ; i++ ) this.blankRow[0] = {name: '&nbsp;',id: ''};
for ( var i=1; i < this.metaData.columnCount ; i++ )
this.blankRow[i] = "&nbsp;"; this.blankRow[i] = "&nbsp;";
} }
return this.blankRow; return this.blankRow;
@ -1975,7 +1976,6 @@ Rico.LiveGridBuffer.prototype = {
var newRows = []; var newRows = [];
$A(ajaxResponse.responseXML.getElementsByTagName('dmap.listingitem')).each(function (el) { $A(ajaxResponse.responseXML.getElementsByTagName('dmap.listingitem')).each(function (el) {
var row = []; var row = [];
//,dmap.itemid,,dmap.itemname']
row.push({id:Element.textContent(el.getElementsByTagName('dmap.itemid')[0]), row.push({id:Element.textContent(el.getElementsByTagName('dmap.itemid')[0]),
name: Element.textContent(el.getElementsByTagName('dmap.itemname')[0])}); name: Element.textContent(el.getElementsByTagName('dmap.itemname')[0])});
['daap.songtime','daap.songartist','daap.songalbum'].each(function (name) { ['daap.songtime','daap.songartist','daap.songalbum'].each(function (name) {
@ -2162,21 +2162,7 @@ Rico.GridViewPort.prototype = {
}, },
populateRow: function(htmlRow, row) { populateRow: function(htmlRow, row) {
var songId = '';
if (typeof(row[0]) == 'object') {
htmlRow.cells[0].innerHTML = row[0].name; htmlRow.cells[0].innerHTML = row[0].name;
htmlRow.setAttribute('songid',row[0].id);
songId = row[0].id;
} else {
// empty row
htmlRow.cells[0].innerHTML = '';
htmlRow.removeAttribute('songid');
}
if (SelectedRows.isSelected(songId)) {
htmlRow.style.backgroundColor = '#8CACBB';
} else {
htmlRow.style.backgroundColor = '';
}
for (var j=1; j < row.length; j++) { for (var j=1; j < row.length; j++) {
htmlRow.cells[j].innerHTML = row[j] htmlRow.cells[j].innerHTML = row[j]
} }
@ -2225,9 +2211,11 @@ Rico.GridViewPort.prototype = {
var contentOffset = viewPrecedesBuffer ? blankSize: 0; var contentOffset = viewPrecedesBuffer ? blankSize: 0;
for (var i=0; i < rows.length; i++) {//initialize what we have for (var i=0; i < rows.length; i++) {//initialize what we have
SelectedRows.updateState(this.table.rows[i + contentOffset],rows[i][0].id,startPos+i);
this.populateRow(this.table.rows[i + contentOffset], rows[i]); this.populateRow(this.table.rows[i + contentOffset], rows[i]);
} }
for (var i=0; i < blankSize; i++) {// blank out the rest for (var i=0; i < blankSize; i++) {// blank out the rest
SelectedRows.updateState(this.table.rows[i + contentOffset]);
this.populateRow(this.table.rows[i + blankOffset], this.buffer.getBlankRow()); this.populateRow(this.table.rows[i + blankOffset], this.buffer.getBlankRow());
} }
this.isPartialBlank = blankSize > 0; this.isPartialBlank = blankSize > 0;

View File

@ -31,18 +31,18 @@ Ajax.Responders.register({ onCreate: Spinner.incRequestCount,
} }
var Spinner = { var Spinner = {
count: 0, count: 0,
incRequestCount: function () { incRequestCount: function (ca) {
Spinner.count++; Spinner.count++;
$('spinner').style.visibility = 'visible'; $('spinner').style.visibility = 'visible';
}, },
decRequestCount: function () { decRequestCount: function (caller) {
Spinner.count--; Spinner.count--;
if (Spinner.count <= 0) { if (/index/.test(caller.url)) {
Spinner.count = 0; Spinner.count = 0;
$('spinner').style.visibility = 'hidden'; $('spinner').style.visibility = 'hidden';
} }
} }
} };
var GlobalEvents = { var GlobalEvents = {
_clickListeners: [], _clickListeners: [],
click: function (e) { click: function (e) {
@ -58,7 +58,7 @@ var GlobalEvents = {
return (element != el); return (element != el);
}); });
} }
} };
var Source = { var Source = {
playlistId: '', playlistId: '',
@ -157,7 +157,8 @@ var Source = {
} }
Source.savePlaylistName(); Source.savePlaylistName();
} }
} };
var EventHandler = { var EventHandler = {
searchTimeOut: '', searchTimeOut: '',
sourceClickCount: [], sourceClickCount: [],
@ -168,7 +169,7 @@ var EventHandler = {
return; return;
} }
if (EventHandler.sourceClickCount[playlistId]) { if (EventHandler.sourceClickCount[playlistId]) {
EventHandler.sourceClickCount[playlistId]++ EventHandler.sourceClickCount[playlistId]++;
} else { } else {
EventHandler.sourceClickCount[playlistId] = 1; EventHandler.sourceClickCount[playlistId] = 1;
} }
@ -235,6 +236,7 @@ var EventHandler = {
}, },
albumsChange: function (e) { albumsChange: function (e) {
EventHandler._setSelected('albums'); EventHandler._setSelected('albums');
SelectedRows.clearAll();
g_myLiveGrid.resetContents(); g_myLiveGrid.resetContents();
g_myLiveGrid.requestContentRefresh(0); g_myLiveGrid.requestContentRefresh(0);
// Query.send('songs'); // Query.send('songs');
@ -402,6 +404,7 @@ var ResponseHandler = {
Query.send('albums'); Query.send('albums');
break; break;
case 'albums': case 'albums':
SelectedRows.clearAll();
g_myLiveGrid.resetContents(); g_myLiveGrid.resetContents();
g_myLiveGrid.requestContentRefresh(0); g_myLiveGrid.requestContentRefresh(0);
// Query.send('songs'); // Query.send('songs');
@ -487,15 +490,60 @@ SelectedRows = {
click: function(e) { click: function(e) {
var tr = Event.findElement(e,'tr'); var tr = Event.findElement(e,'tr');
if (tr.hasAttribute('songid')) { if (tr.hasAttribute('songid')) {
SelectedRows.songId[tr.getAttribute('songid')] = 1; var id = tr.getAttribute('songid');
tr.style.backgroundColor = '#8CACBB'; } else {
return;
}
if (e.ctrlKey) {
if (SelectedRows.isSelected(tr)) {
SelectedRows.unsetSelected(tr);
} else {
SelectedRows.setSelected(tr);
}
return;
}
if (e.shiftKey) {
return;
}
if (SelectedRows.isSelected(tr)) {
SelectedRows.clearAll();
} else {
SelectedRows.clearAll();
SelectedRows.setSelected(tr);
} }
Event.stop(e);
}, },
isSelected: function (songId) { isSelected: function (tr) {
return SelectedRows.songId[songId]; return SelectedRows.songId[tr.getAttribute('songid')];
},
setSelected: function (tr) {
SelectedRows.songId[tr.getAttribute('songid')] = tr.getAttribute('index');
tr.style.backgroundColor = '#8CACBB';
},
unsetSelected: function (tr) {
SelectedRows.songId[tr.getAttribute('songid')] = '';
tr.style.backgroundColor = '';
},
clearAll: function () {
SelectedRows.songId = [];
$A($('songs_data').getElementsByTagName('tr')).each(SelectedRows.unsetSelected);
},
updateState: function (tr,songId,index) {
if (songId && index) {
tr.setAttribute('songid',songId);
tr.setAttribute('index',index);
if (SelectedRows.isSelected(tr)) {
SelectedRows.setSelected(tr);
} else {
SelectedRows.unsetSelected(tr);
} }
} } else {
tr.removeAttribute('songid');
tr.removeAttribute('index');
SelectedRows.unsetSelected(tr);
}
}
};
Object.extend(Element, { Object.extend(Element, {
removeChildren: function(element) { removeChildren: function(element) {
while(element.hasChildNodes()) { while(element.hasChildNodes()) {