2 function RefreshNowPlaying() {
4 var req = new XMLHttpRequest();
6 req.onreadystatechange = function () {
7 if (this.readyState != 4 || this.status != 200) return;
8 document.getElementById('nowplaying_content').innerHTML=this.responseText;
11 req.open("GET", "ajax/trackinfo.php", true);
16 function RefreshTitle() {
18 var req = new XMLHttpRequest();
20 req.onreadystatechange = function () {
21 if (this.readyState != 4 || this.status != 200) return;
22 document.title='MPD Player: '+this.responseText;
25 req.open("GET", "ajax/trackname.php", true);
29 function RefreshPlayerState() {
31 var req = new XMLHttpRequest();
33 req.onreadystatechange = function () {
34 if (this.readyState != 4 || this.status != 200) return;
35 if (this.responseText=="play") {
36 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('pause')\"><img class=\"button\" src=\"images/pause.png\"></span>";
38 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('play')\"><img class=\"button\" src=\"images/play.png\"></span>";
42 req.open("GET", "ajax/playerstate.php", true);
47 function RefreshRepeatState() {
49 var req = new XMLHttpRequest();
51 req.onreadystatechange = function () {
52 if (this.readyState != 4 || this.status != 200) return;
53 if (this.responseText=="1") {
54 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeaton.png\"></a>";
56 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeatoff.png\"></a>";
60 req.open("GET", "ajax/repeatstate.php", true);
65 function RefreshVolume() {
67 var req = new XMLHttpRequest();
69 req.onreadystatechange = function () {
70 if (this.readyState != 4 || this.status != 200) return;
71 document.getElementById('volume_total').innerHTML="<div id=\"volume_actual\" style=\"width:"+this.responseText+"%\">";
74 req.open("GET", "ajax/volume.php", true);
79 function RefreshPageStatus() {
89 function RefreshPlaylist() {
91 var req = new XMLHttpRequest();
93 req.onreadystatechange = function () {
94 if (this.readyState != 4 || this.status != 200) return;
95 document.getElementById('playlist').innerHTML=this.responseText;
98 req.open("GET", "ajax/playlist.php", true);
103 function EditPlayList(dir) {
105 var req = new XMLHttpRequest();
107 req.onreadystatechange = function () {
108 if (this.readyState != 4 || this.status != 200) return;
109 document.getElementById('playlist').innerHTML=this.responseText;
112 if (!dir) { dir = ''; };
114 req.open("GET", "ajax/editplaylist.php?dir="+dir, true);
119 function LoadPlayList() {
121 var req = new XMLHttpRequest();
123 req.onreadystatechange = function () {
124 if (this.readyState != 4 || this.status != 200) return;
125 document.getElementById('playlist').innerHTML=this.responseText;
128 req.open("GET", "ajax/playlists.php", true);
133 function SavePlayList() {
135 var name=window.prompt('Имя списка','');
137 var req = new XMLHttpRequest();
139 req.onreadystatechange = function () {
140 if (this.readyState != 4 || this.status != 200) return;
141 if (this.responseText != 'OK') {
142 window.alert(this.responseText);
146 req.open("GET", "ajax/save.php?item="+name, true);
151 function DelPlayList(item) {
153 var req = new XMLHttpRequest();
155 //if (! window.alert("Удалить список "+item+"?")) return;
157 req.onreadystatechange = function () {
158 if (this.readyState != 4 || this.status != 200) return;
163 req.open("GET", "ajax/playlist-command.php?task=dellist&item="+item, true);
168 function RefreshPageContent() {
175 function Command(cmd) {
177 var req = new XMLHttpRequest();
179 req.onreadystatechange = function () {
180 if (this.readyState != 4 || this.status != 200) return;
184 req.open("GET", "ajax/command.php?task="+cmd, true);
189 function PlaylistCommand(cmd,item) {
191 var req = new XMLHttpRequest();
193 req.onreadystatechange = function () {
194 if (this.readyState != 4 || this.status != 200) return;
195 RefreshPageContent();
198 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
203 function PlaylistCommandRefStatus(cmd,item) {
205 var req = new XMLHttpRequest();
207 req.onreadystatechange = function () {
208 if (this.readyState != 4 || this.status != 200) return;
212 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
217 function PlaylistEditCommand(cmd,item) {
219 var req = new XMLHttpRequest();
221 req.onreadystatechange = function () {
222 if (this.readyState != 4 || this.status != 200) return;
226 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
231 function PlaylistEditCommandRefFull(cmd,item) {
233 var req = new XMLHttpRequest();
235 req.onreadystatechange = function () {
236 if (this.readyState != 4 || this.status != 200) return;
237 RefreshPageContent();
240 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
246 function PlaylistItemsCommand(cmd) {
248 var req = new XMLHttpRequest();
250 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
256 req.onreadystatechange = function () {
257 if (this.readyState != 4 || this.status != 200) return;
258 RefreshPageContent();
261 params=selected.map(function(el) {
262 //Map each field into a name=value string, make sure to properly escape!
263 return 'itemlist[]=' + encodeURIComponent(el);
266 req.open("POST", "ajax/playlist-command.php?task="+cmd, true);
267 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
272 function PlaylistEditItemsCommand(cmd,dir) {
274 var req = new XMLHttpRequest();
276 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
282 params=selected.map(function(el) {
283 //Map each field into a name=value string, make sure to properly escape!
284 return 'itemlist[]=' + encodeURIComponent(el);
287 req.onreadystatechange = function () {
288 if (this.readyState != 4 || this.status != 200) return;
292 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
293 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
298 setInterval(RefreshPageStatus, 10000);