Удаление списков.
[mpd-web.git] / ajax / mpd.js
index 5d64a923c719731bcd24427078dd2135760ce94b..37176039def197a4fce50871e54939d3b518628a 100644 (file)
@@ -6,7 +6,6 @@ var req = new XMLHttpRequest();
 req.onreadystatechange = function () {
   if (this.readyState != 4 || this.status != 200) return;
   document.getElementById('nowplaying_content').innerHTML=this.responseText;
-  document.title='MPD Player: '+this.responseText;
 };
 
 req.open("GET", "ajax/trackinfo.php", true);
@@ -14,6 +13,19 @@ req.send();
 
 }
 
+function RefreshTitle() {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  document.title='MPD Player: '+this.responseText;
+};
+
+req.open("GET", "ajax/trackname.php", true);
+req.send();
+}
+
 function RefreshPlayerState() {
 
 var req = new XMLHttpRequest();
@@ -66,6 +78,7 @@ req.send();
 
 function RefreshPageStatus() {
 
+  RefreshTitle();
   RefreshNowPlaying();
   RefreshPlayerState();
   RefreshRepeatState();
@@ -103,6 +116,55 @@ req.send();
 
 }
 
+function LoadPlayList() {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  document.getElementById('playlist').innerHTML=this.responseText;
+};
+
+req.open("GET", "ajax/playlists.php", true);
+req.send();
+
+}
+
+function SavePlayList() {
+
+var name=window.prompt('Имя списка','');
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  if (this.responseText != 'OK') {
+    window.alert(this.responseText);
+  }
+};
+
+req.open("GET", "ajax/save.php?item="+name, true);
+req.send();
+
+}
+
+function DelPlayList(item) {
+
+var req = new XMLHttpRequest();
+
+//if (! window.alert("Удалить список "+item+"?")) return;
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageStatus();
+  LoadPlayList();
+};
+
+req.open("GET", "ajax/playlist-command.php?task=dellist&item="+item, true);
+req.send();
+
+}
+
 function RefreshPageContent() {
 
   RefreshPageStatus();
@@ -138,10 +200,43 @@ req.send();
 
 }
 
+function PlaylistCommandRefStatus(cmd,item) {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageStatus();
+};
+
+req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
+req.send();
+
+}
+
 function PlaylistEditCommand(cmd,item) {
 
 var req = new XMLHttpRequest();
 
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageStatus();
+};
+
+req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
+req.send();
+
+}
+
+function PlaylistEditCommandRefFull(cmd,item) {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageContent();
+};
+
 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
 req.send();
 
@@ -189,10 +284,15 @@ params=selected.map(function(el) {
         return 'itemlist[]=' + encodeURIComponent(el);
     }).join('&');
 
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageStatus();
+};
+
 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 req.send(params);
 
 }
 
-// setInterval(RefreshPageStatus, 5000);
+setInterval(RefreshPageStatus, 10000);