Удаление списков.
[mpd-web.git] / ajax / mpd.js
1
2 function RefreshNowPlaying() {
3
4 var req = new XMLHttpRequest();
5
6 req.onreadystatechange = function () {
7   if (this.readyState != 4 || this.status != 200) return;
8   document.getElementById('nowplaying_content').innerHTML=this.responseText;
9 };
10
11 req.open("GET", "ajax/trackinfo.php", true);
12 req.send();
13
14 }
15
16 function RefreshTitle() {
17
18 var req = new XMLHttpRequest();
19
20 req.onreadystatechange = function () {
21   if (this.readyState != 4 || this.status != 200) return;
22   document.title='MPD Player: '+this.responseText;
23 };
24
25 req.open("GET", "ajax/trackname.php", true);
26 req.send();
27 }
28
29 function RefreshPlayerState() {
30
31 var req = new XMLHttpRequest();
32
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>";
37   } else {
38     document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('play')\"><img class=\"button\" src=\"images/play.png\"></span>";
39   }
40 };
41
42 req.open("GET", "ajax/playerstate.php", true);
43 req.send();
44
45 }
46
47 function RefreshRepeatState() {
48
49 var req = new XMLHttpRequest();
50
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>";
55   } else {
56     document.getElementById('repeatstate').innerHTML="<img src=\"images/repeatoff.png\"></a>";
57   }
58 };
59
60 req.open("GET", "ajax/repeatstate.php", true);
61 req.send();
62
63 }
64
65 function RefreshVolume() {
66
67 var req = new XMLHttpRequest();
68
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+"%\">";
72 };
73
74 req.open("GET", "ajax/volume.php", true);
75 req.send();
76
77 }
78
79 function RefreshPageStatus() {
80
81   RefreshTitle();
82   RefreshNowPlaying();
83   RefreshPlayerState();
84   RefreshRepeatState();
85   RefreshVolume();
86
87 }
88
89 function RefreshPlaylist() {
90
91 var req = new XMLHttpRequest();
92
93 req.onreadystatechange = function () {
94   if (this.readyState != 4 || this.status != 200) return;
95   document.getElementById('playlist').innerHTML=this.responseText;
96 };
97
98 req.open("GET", "ajax/playlist.php", true);
99 req.send();
100
101 }
102
103 function EditPlayList(dir) {
104
105 var req = new XMLHttpRequest();
106
107 req.onreadystatechange = function () {
108   if (this.readyState != 4 || this.status != 200) return;
109   document.getElementById('playlist').innerHTML=this.responseText;
110 };
111
112 if (!dir) { dir = ''; };
113
114 req.open("GET", "ajax/editplaylist.php?dir="+dir, true);
115 req.send();
116
117 }
118
119 function LoadPlayList() {
120
121 var req = new XMLHttpRequest();
122
123 req.onreadystatechange = function () {
124   if (this.readyState != 4 || this.status != 200) return;
125   document.getElementById('playlist').innerHTML=this.responseText;
126 };
127
128 req.open("GET", "ajax/playlists.php", true);
129 req.send();
130
131 }
132
133 function SavePlayList() {
134
135 var name=window.prompt('Имя списка','');
136
137 var req = new XMLHttpRequest();
138
139 req.onreadystatechange = function () {
140   if (this.readyState != 4 || this.status != 200) return;
141   if (this.responseText != 'OK') {
142     window.alert(this.responseText);
143   }
144 };
145
146 req.open("GET", "ajax/save.php?item="+name, true);
147 req.send();
148
149 }
150
151 function DelPlayList(item) {
152
153 var req = new XMLHttpRequest();
154
155 //if (! window.alert("Удалить список "+item+"?")) return;
156
157 req.onreadystatechange = function () {
158   if (this.readyState != 4 || this.status != 200) return;
159   RefreshPageStatus();
160   LoadPlayList();
161 };
162
163 req.open("GET", "ajax/playlist-command.php?task=dellist&item="+item, true);
164 req.send();
165
166 }
167
168 function RefreshPageContent() {
169
170   RefreshPageStatus();
171   RefreshPlaylist();
172
173 }
174
175 function Command(cmd) {
176
177 var req = new XMLHttpRequest();
178
179 req.onreadystatechange = function () {
180   if (this.readyState != 4 || this.status != 200) return;
181   RefreshPageStatus();
182 };
183
184 req.open("GET", "ajax/command.php?task="+cmd, true);
185 req.send();
186
187 }
188
189 function PlaylistCommand(cmd,item) {
190
191 var req = new XMLHttpRequest();
192
193 req.onreadystatechange = function () {
194   if (this.readyState != 4 || this.status != 200) return;
195   RefreshPageContent();
196 };
197
198 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
199 req.send();
200
201 }
202
203 function PlaylistCommandRefStatus(cmd,item) {
204
205 var req = new XMLHttpRequest();
206
207 req.onreadystatechange = function () {
208   if (this.readyState != 4 || this.status != 200) return;
209   RefreshPageStatus();
210 };
211
212 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
213 req.send();
214
215 }
216
217 function PlaylistEditCommand(cmd,item) {
218
219 var req = new XMLHttpRequest();
220
221 req.onreadystatechange = function () {
222   if (this.readyState != 4 || this.status != 200) return;
223   RefreshPageStatus();
224 };
225
226 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
227 req.send();
228
229 }
230
231 function PlaylistEditCommandRefFull(cmd,item) {
232
233 var req = new XMLHttpRequest();
234
235 req.onreadystatechange = function () {
236   if (this.readyState != 4 || this.status != 200) return;
237   RefreshPageContent();
238 };
239
240 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
241 req.send();
242
243 }
244
245
246 function PlaylistItemsCommand(cmd) {
247
248 var req = new XMLHttpRequest();
249
250 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
251   return c.checked;
252 }).map(function(c) {
253   return c.value;
254 });
255   
256 req.onreadystatechange = function () {
257   if (this.readyState != 4 || this.status != 200) return;
258   RefreshPageContent();
259 };
260
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);
264     }).join('&');
265
266 req.open("POST", "ajax/playlist-command.php?task="+cmd, true);
267 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
268 req.send(params);
269
270 }
271
272 function PlaylistEditItemsCommand(cmd,dir) {
273
274 var req = new XMLHttpRequest();
275
276 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
277   return c.checked;
278 }).map(function(c) {
279   return c.value;
280 });
281   
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);
285     }).join('&');
286
287 req.onreadystatechange = function () {
288   if (this.readyState != 4 || this.status != 200) return;
289   RefreshPageStatus();
290 };
291
292 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
293 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
294 req.send(params);
295
296 }
297
298 setInterval(RefreshPageStatus, 10000);