owntone-server/admin-root/smart.js

214 lines
6.2 KiB
JavaScript
Raw Normal View History

2005-06-19 23:18:16 -04:00
var req;
var playlist_info={};
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-23 19:55:35 -04:00
msgdiv.innerHTML = msg + "\n";
if(msg == "") {
msgdiv.style.display="none";
} else {
msgdiv.style.display="block";
}
2005-10-23 19:55:35 -04:00
}
function pl_displayresults(xmldoc) {
}
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 {
pl_errormsg("Can't yet update existing playlists.. sorry.");
}
2005-06-19 23:18:16 -04:00
2005-10-23 19:55:35 -04:00
init();
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
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';
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++) {
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-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&nbsp;(Web&nbsp;Edited)";
break;
case "1":
pl_type = "Smart";
break;
case "2":
2005-10-31 19:09:39 -05:00
pl_type = "Static&nbsp;(m3u/pls&nbsp;file)";
2005-06-19 23:18:16 -04:00
break;
case "3":
2005-10-31 19:09:39 -05:00
pl_type = "Static&nbsp;(iTunes&nbsp;xml)";
2005-06-19 23:18:16 -04:00
break;
}
2005-10-23 19:55:35 -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>';
td4.innerHTML = td4.innerHTML + '&nbsp;<a href="javascript:pl_delete(' + pl_id + ')">Delete</a>';
} else {
td4.innerHTML="&nbsp;";
2005-10-23 19:55:35 -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
}
}
}