2005-06-19 23:18:16 -04:00
|
|
|
var req;
|
|
|
|
var playlist_info={};
|
|
|
|
|
2005-10-26 02:00:54 -04:00
|
|
|
|
|
|
|
function pl_editor_state(state) {
|
|
|
|
var pleditor = document.getElementById("pl_editor");
|
|
|
|
if(!pleditor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(state) {
|
|
|
|
pleditor.style.display="block";
|
|
|
|
} else {
|
|
|
|
pleditor.style.display="none";
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
function pl_errormsg(msg) {
|
|
|
|
var msgdiv = document.getElementById("pl_warning");
|
|
|
|
|
|
|
|
if(!msgdiv)
|
|
|
|
return;
|
2005-10-26 02:00:54 -04:00
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
msgdiv.innerHTML = msg + "\n";
|
2005-10-26 02:00:54 -04:00
|
|
|
|
|
|
|
if(msg == "") {
|
|
|
|
msgdiv.style.display="none";
|
|
|
|
} else {
|
|
|
|
msgdiv.style.display="block";
|
|
|
|
}
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
|
|
|
|
2006-01-16 17:28:44 -05:00
|
|
|
function pl_displayresults(xmldoc,query) {
|
|
|
|
var status_string;
|
|
|
|
var status;
|
|
|
|
|
|
|
|
if(!xmldoc) {
|
|
|
|
pl_errormsg("No xmldoc!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!xmldoc.getElementsByTagName("dmap.status")) {
|
|
|
|
pl_errormsg("No dmap.status??");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = xmldoc.getElementsByTagName("dmap.status")[0].firstChild.nodeValue;
|
|
|
|
|
|
|
|
if(!status)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = status * 1;
|
|
|
|
|
|
|
|
if(status != 200) {
|
|
|
|
status_string = "Error " + status + ": ";
|
|
|
|
|
|
|
|
if(xmldoc.getElementsByTagName("dmap.statusstring")) {
|
|
|
|
status_string = status_string + xmldoc.getElementsByTagName("dmap.statusstring")[0].firstChild.nodeValue;
|
|
|
|
} else {
|
|
|
|
status_string = status_string + "Unspecified error";
|
|
|
|
}
|
|
|
|
|
|
|
|
pl_errormsg(status_string);
|
|
|
|
} else {
|
|
|
|
pl_errormsg("Success");
|
|
|
|
}
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function pl_update() {
|
|
|
|
/* this is either update or create, depending... */
|
|
|
|
var id, name, spec;
|
|
|
|
|
|
|
|
id = document.forms['pl_form']['playlist_id'].value;
|
|
|
|
name = encodeURIComponent(document.forms['pl_form']['playlist_name'].value);
|
|
|
|
spec = encodeURIComponent(document.forms['pl_form']['playlist_spec'].value);
|
2005-06-19 23:18:16 -04:00
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
if(id == '0') {
|
|
|
|
/* new playlist... post it! */
|
|
|
|
var url = '/databases/1/containers/add?output=xml&org.mt-daapd.playlist-type=1&dmap.itemname=' + name + '&org.mt-daapd.smart-playlist-spec=' + spec;
|
|
|
|
result = pl_exec(url,false);
|
|
|
|
} else {
|
2005-11-03 00:02:17 -05:00
|
|
|
var url='/databases/1/containers/edit?output=xml&dmap.itemid=' + id + '&dmap.itemname=' + name + '&org.mt-daapd.smart-playlist-spec=' + spec;
|
|
|
|
result = pl_exec(url,false);
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
2006-01-16 17:28:44 -05:00
|
|
|
|
|
|
|
pl_displayresults(req.responseXML);
|
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
init();
|
2005-10-26 02:00:54 -04:00
|
|
|
pl_editor_state(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pl_cancel() {
|
|
|
|
pl_errormsg("Cancelled");
|
|
|
|
pl_editor_state(false);
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function pl_new() {
|
|
|
|
var msgdiv = document.getElementById("pl_warning");
|
|
|
|
var pleditor=document.getElementById("pl_editor");
|
2005-06-19 23:18:16 -04:00
|
|
|
|
2005-10-26 02:00:54 -04:00
|
|
|
pl_errormsg("");
|
2005-10-23 19:55:35 -04:00
|
|
|
|
|
|
|
document.forms['pl_form']['playlist_id'].value='0';
|
|
|
|
document.forms['pl_form']['playlist_name'].value = 'New Playlist';
|
|
|
|
document.forms['pl_form']['playlist_spec'].value = '';
|
|
|
|
document.forms['pl_form']['submit_button'].value = 'Create';
|
|
|
|
|
2005-10-26 02:00:54 -04:00
|
|
|
pl_editor_state(true);
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
2005-06-19 23:18:16 -04:00
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
function pl_delete(pl_id) {
|
|
|
|
if(confirm('Are you sure you want to delete playlist "' + playlist_info[pl_id]['name'] + '"?')) {
|
|
|
|
result=pl_exec("/databases/1/containers/del?output=xml&dmap.itemid=" + pl_id,false);
|
|
|
|
init();
|
|
|
|
}
|
2005-06-19 23:18:16 -04:00
|
|
|
}
|
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
|
|
|
|
function pl_edit(pl_id) {
|
|
|
|
var msgdiv = document.getElementById("pl_warning");
|
|
|
|
var pleditor=document.getElementById("pl_editor");
|
|
|
|
|
|
|
|
if((!msgdiv)||(!pleditor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
msgdiv.style.display="none";
|
|
|
|
pleditor.style.display="none";
|
|
|
|
|
|
|
|
if(pl_id == 1) {
|
|
|
|
msgdiv.innerHTML="Cannot edit library playlist";
|
|
|
|
msgdiv.style.display="block";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(playlist_info[pl_id]['type'] != 1) {
|
|
|
|
msgdiv.innerHTML="Can only edit smart playlists";
|
|
|
|
msgdiv.style.display="block";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.forms['pl_form']['playlist_id'].value = pl_id;
|
|
|
|
document.forms['pl_form']['playlist_name'].value = playlist_info[pl_id]['name'];
|
|
|
|
document.forms['pl_form']['playlist_spec'].value = playlist_info[pl_id]['spec'];
|
|
|
|
document.forms['pl_form']['submit_button'].value = 'Update';
|
|
|
|
|
|
|
|
pleditor.style.display="block";
|
|
|
|
|
|
|
|
//alert(playlist_info[pl_id]['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pl_process() {
|
2005-06-19 23:18:16 -04:00
|
|
|
var xmldoc = req.responseXML;
|
|
|
|
var playlists = xmldoc.getElementsByTagName("dmap.listingitem");
|
|
|
|
var pl_table = document.getElementById("playlists");
|
|
|
|
playlist_info = {};
|
|
|
|
|
|
|
|
while(pl_table.childNodes.length > 0) {
|
|
|
|
pl_table.removeChild(pl_table.lastChild);
|
|
|
|
}
|
|
|
|
for(var x=0; x < playlists.length; x++) {
|
2005-10-26 02:00:54 -04:00
|
|
|
var pl_id;
|
|
|
|
var pl_name;
|
|
|
|
var pl_type;
|
|
|
|
|
|
|
|
pl_id=playlists[x].getElementsByTagName("dmap.itemid")[0].firstChild.nodeValue;
|
|
|
|
if(playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild) {
|
|
|
|
pl_name=playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild.nodeValue;
|
|
|
|
} else {
|
|
|
|
pl_name = "";
|
|
|
|
}
|
|
|
|
pl_type=playlists[x].getElementsByTagName("org.mt-daapd.playlist-type")[0].firstChild.nodeValue;
|
2005-06-19 23:18:16 -04:00
|
|
|
|
2005-10-26 02:00:54 -04:00
|
|
|
|
2005-06-19 23:18:16 -04:00
|
|
|
playlist_info[String(pl_id)] = { 'name': pl_name, 'type': pl_type };
|
|
|
|
if(pl_type == 1) {
|
|
|
|
var pl_spec=playlists[x].getElementsByTagName("org.mt-daapd.smart-playlist-spec")[0].firstChild.nodeValue;
|
|
|
|
playlist_info[String(pl_id)]['spec'] = pl_spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(pl_type) {
|
|
|
|
case "0":
|
|
|
|
pl_type = "Static (Web Edited)";
|
|
|
|
break;
|
|
|
|
case "1":
|
|
|
|
pl_type = "Smart";
|
|
|
|
break;
|
|
|
|
case "2":
|
2005-10-31 19:09:39 -05:00
|
|
|
pl_type = "Static (m3u/pls file)";
|
2005-06-19 23:18:16 -04:00
|
|
|
break;
|
|
|
|
case "3":
|
2005-10-31 19:09:39 -05:00
|
|
|
pl_type = "Static (iTunes xml)";
|
2005-06-19 23:18:16 -04:00
|
|
|
break;
|
|
|
|
}
|
2005-10-23 19:55:35 -04:00
|
|
|
|
2005-10-26 02:00:54 -04:00
|
|
|
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
var td1 = document.createElement("td");
|
|
|
|
var td2 = document.createElement("td");
|
|
|
|
var td3 = document.createElement("td");
|
|
|
|
var td4 = document.createElement("td");
|
|
|
|
td1.innerHTML=pl_id + '\n';
|
|
|
|
td2.innerHTML=pl_name + '\n';
|
|
|
|
td3.innerHTML=pl_type + '\n';
|
|
|
|
if((pl_id != 1) && (playlist_info[pl_id]['type'] == 1)) {
|
2005-10-23 19:55:35 -04:00
|
|
|
td4.innerHTML='<a href="javascript:pl_edit(' + pl_id + ')">Edit</a>';
|
2005-10-26 02:00:54 -04:00
|
|
|
td4.innerHTML = td4.innerHTML + ' <a href="javascript:pl_delete(' + pl_id + ')">Delete</a>';
|
|
|
|
} else {
|
|
|
|
td4.innerHTML=" ";
|
2005-10-23 19:55:35 -04:00
|
|
|
}
|
2005-10-26 02:00:54 -04:00
|
|
|
|
|
|
|
row.appendChild(td1);
|
|
|
|
row.appendChild(td2);
|
|
|
|
row.appendChild(td3);
|
|
|
|
row.appendChild(td4);
|
|
|
|
pl_table.appendChild(row);
|
2005-06-19 23:18:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
function pl_state_change() {
|
2005-06-19 23:18:16 -04:00
|
|
|
if(req.readyState == 4) {
|
|
|
|
if(req.status == 200) {
|
2005-10-23 19:55:35 -04:00
|
|
|
pl_process();
|
2005-06-19 23:18:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
2005-10-23 19:55:35 -04:00
|
|
|
pl_exec("/databases/1/containers?output=xml&meta=dmap.itemid,dmap.itemname,org.mt-daapd.playlist-type,org.mt-daapd.smart-playlist-spec",true);
|
2005-06-19 23:18:16 -04:00
|
|
|
}
|
|
|
|
|
2005-10-23 19:55:35 -04:00
|
|
|
function pl_exec(url, async) {
|
2005-06-19 23:18:16 -04:00
|
|
|
// branch for native XMLHttpRequest object
|
|
|
|
if (window.XMLHttpRequest) {
|
|
|
|
req = new XMLHttpRequest();
|
2005-10-23 19:55:35 -04:00
|
|
|
req.onreadystatechange = pl_state_change;
|
|
|
|
req.open("GET", url, async);
|
|
|
|
return req.send(null);
|
2005-06-19 23:18:16 -04:00
|
|
|
// branch for IE/Windows ActiveX version
|
|
|
|
} else if (window.ActiveXObject) {
|
|
|
|
req = new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
|
if (req) {
|
2005-10-23 19:55:35 -04:00
|
|
|
req.onreadystatechange = pl_state_change;
|
|
|
|
req.open("GET", url, async);
|
|
|
|
return req.send();
|
2005-06-19 23:18:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|