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 RefreshPageContent() {
158 function Command(cmd) {
160 var req = new XMLHttpRequest();
162 req.onreadystatechange = function () {
163 if (this.readyState != 4 || this.status != 200) return;
167 req.open("GET", "ajax/command.php?task="+cmd, true);
172 function PlaylistCommand(cmd,item) {
174 var req = new XMLHttpRequest();
176 req.onreadystatechange = function () {
177 if (this.readyState != 4 || this.status != 200) return;
178 RefreshPageContent();
181 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
186 function PlaylistCommandRefStatus(cmd,item) {
188 var req = new XMLHttpRequest();
190 req.onreadystatechange = function () {
191 if (this.readyState != 4 || this.status != 200) return;
195 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
200 function PlaylistEditCommand(cmd,item) {
202 var req = new XMLHttpRequest();
204 req.onreadystatechange = function () {
205 if (this.readyState != 4 || this.status != 200) return;
209 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
214 function PlaylistEditCommandRefFull(cmd,item) {
216 var req = new XMLHttpRequest();
218 req.onreadystatechange = function () {
219 if (this.readyState != 4 || this.status != 200) return;
220 RefreshPageContent();
223 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
229 function PlaylistItemsCommand(cmd) {
231 var req = new XMLHttpRequest();
233 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
239 req.onreadystatechange = function () {
240 if (this.readyState != 4 || this.status != 200) return;
241 RefreshPageContent();
244 params=selected.map(function(el) {
245 //Map each field into a name=value string, make sure to properly escape!
246 return 'itemlist[]=' + encodeURIComponent(el);
249 req.open("POST", "ajax/playlist-command.php?task="+cmd, true);
250 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
255 function PlaylistEditItemsCommand(cmd,dir) {
257 var req = new XMLHttpRequest();
259 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
265 params=selected.map(function(el) {
266 //Map each field into a name=value string, make sure to properly escape!
267 return 'itemlist[]=' + encodeURIComponent(el);
270 req.onreadystatechange = function () {
271 if (this.readyState != 4 || this.status != 200) return;
275 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
276 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
281 setInterval(RefreshPageStatus, 10000);