commit | author | age
|
623a61
|
1 |
var TPL_HOME = 'home'; |
U |
2 |
var TPL_PREFS = 'prefs'; |
47a970
|
3 |
var TPL_SENDER = 'sender'; |
9e336a
|
4 |
var TPL_DLG_MSG = 'dlg-msg'; |
36646e
|
5 |
var TPL_DLG_INFO = 'dlg-info'; |
ffc872
|
6 |
var TPL_DLG_SENDER_NEU = 'dlg-sender-neu'; |
U |
7 |
var TPL_DLG_SENDER_EDIT = 'dlg-sender-edit'; |
56852d
|
8 |
var TPL_SENDER_EDIT_FORM = 'sender-edit-form'; |
f9c6e2
|
9 |
var TPL_SENDER_KACHEL = 'sender-kachel'; |
576085
|
10 |
var TPL_ABSPIELER = 'abspieler'; |
df379b
|
11 |
var templateCache = {}; // mustache templates |
623a61
|
12 |
var prefsRendered = false; |
56852d
|
13 |
var senderKlickModus = "0"; // 1=abspielen, 2=bearbeiten, 3=loeschen |
f9c6e2
|
14 |
var ID_UNDEFINED = -1; |
599f2f
|
15 |
var suchTimeout; |
623a61
|
16 |
|
U |
17 |
function app_init() { |
9f0d54
|
18 |
$('.dialog').hide(); |
623a61
|
19 |
$('.ost').hide(); |
136220
|
20 |
app_menu_init( |
U |
21 |
"data/menu/", |
|
22 |
"hauptmenue.json", |
|
23 |
"../jslib/app-menu/app-menu.tpl", |
|
24 |
".west", |
|
25 |
"8em"); |
8881ca
|
26 |
app_get_template('data/tpl/dlg-msg.tpl', TPL_DLG_MSG); |
U |
27 |
app_get_template('data/tpl/dlg-info.tpl', TPL_DLG_INFO); |
|
28 |
app_get_template('data/tpl/sender.tpl', TPL_SENDER); |
ffc872
|
29 |
app_get_template('data/tpl/dlg-sender-neu.tpl', TPL_DLG_SENDER_NEU); |
U |
30 |
app_get_template('data/tpl/dlg-sender-edit.tpl', TPL_DLG_SENDER_EDIT); |
56852d
|
31 |
app_get_template('data/tpl/dlg-sender-edit-form.tpl', TPL_SENDER_EDIT_FORM); |
f9c6e2
|
32 |
app_get_template('data/tpl/kachel.tpl', TPL_SENDER_KACHEL); |
576085
|
33 |
app_get_template('data/tpl/abspieler.tpl', TPL_ABSPIELER); |
599f2f
|
34 |
$(".sendersuche-eingabe").on('keyup', function() { |
U |
35 |
clearTimeout(suchTimeout); |
|
36 |
suchTimeout = setTimeout('app_sendersuche()', 500); |
|
37 |
}); |
623a61
|
38 |
$('.sued').text('Bereit.'); |
U |
39 |
setTimeout(function() { |
576085
|
40 |
app_get_abspieler(); |
a480d0
|
41 |
app_get_sender(); |
623a61
|
42 |
}, 200); |
47a970
|
43 |
} |
U |
44 |
|
599f2f
|
45 |
function app_sendersuche() { |
U |
46 |
var suchbegriff = $(".sendersuche-eingabe").val(); |
|
47 |
/* |
|
48 |
Anstelle der folgenden Meldung wuerde hier |
|
49 |
die Suchfunktion ausgefuehrt |
|
50 |
*/ |
|
51 |
app_meldung_mit_timeout( |
|
52 |
'Suchbegriff: ' + suchbegriff, |
|
53 |
1500 |
|
54 |
); |
|
55 |
} |
|
56 |
|
3cecdc
|
57 |
/* Senderliste */ |
U |
58 |
|
|
59 |
function app_kachel_anpassen(sender) { |
|
60 |
var kachel = $( "div[sid='" + sender.id + "']" ); |
|
61 |
$(kachel).find(".sender-name").text(sender.name); |
|
62 |
$(kachel).attr("data-verweis", sender.url); |
|
63 |
$(kachel).find("img").attr("src", sender.logo); |
f9c6e2
|
64 |
} |
U |
65 |
|
|
66 |
function app_kachel_neu(sender) { |
|
67 |
var html = Mustache.render(templateCache[TPL_SENDER_KACHEL], sender); |
|
68 |
$("#sender").append(html); |
|
69 |
var kachel = $( "div[sid='" + sender.id + "']" ); |
|
70 |
$(kachel).on('click', app_kachel_klick); |
|
71 |
} |
|
72 |
|
|
73 |
function app_kachel_klick() { |
|
74 |
var kachel = $( this ); |
|
75 |
var senderId = $(kachel).attr("sid"); |
|
76 |
var senderName = $(kachel).find(".sender-name").text(); |
|
77 |
var senderUrl = $(kachel).attr("data-verweis"); |
|
78 |
var senderLogo = $(kachel).find("img").attr("src"); |
|
79 |
var s = new Sender(senderId, senderName, senderUrl, senderLogo); |
|
80 |
switch (senderKlickModus) { |
|
81 |
case "1": |
|
82 |
break; |
|
83 |
case "2": |
|
84 |
$(".dlg-behaelter").html( |
|
85 |
Mustache.render(templateCache[TPL_SENDER_EDIT_FORM], s) |
|
86 |
); |
|
87 |
$('#sender-speichern').on('click', function() { |
|
88 |
$('#sender-speichern').off('click'); |
|
89 |
app_kachel_anpassen(app_sender_dialog_lesen(senderId)); |
|
90 |
app_dialog_schliessen(); |
|
91 |
app_meldung_mit_timeout('Speichern gewaehlt', 1500); |
|
92 |
}); |
|
93 |
break; |
|
94 |
case "3": |
|
95 |
break; |
|
96 |
default: |
|
97 |
app_meldung_mit_timeout( |
|
98 |
'Sender ' + s.name + ', ID ' + s.id, |
|
99 |
1500 |
|
100 |
); |
|
101 |
break; |
|
102 |
} |
|
103 |
|
3cecdc
|
104 |
} |
U |
105 |
|
8881ca
|
106 |
/* --- Menüfunktionen --- */ |
U |
107 |
|
9f0d54
|
108 |
function app_nachricht_test() { |
e6c850
|
109 |
app_dialog_laden_und_zeigen( |
U |
110 |
templateCache[TPL_DLG_MSG], 'data/msg-test.json'); |
df379b
|
111 |
app_menu_toggle(); |
36646e
|
112 |
} |
U |
113 |
|
|
114 |
function app_info_dialog_zeigen() { |
b520d1
|
115 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_INFO], ''); |
df379b
|
116 |
app_menu_toggle(); |
8881ca
|
117 |
} |
U |
118 |
|
5226a2
|
119 |
function app_neuer_sender() { |
ffc872
|
120 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_NEU], ''); |
b520d1
|
121 |
$('#sender-speichern').on('click', function() { |
136220
|
122 |
$('#sender-speichern').off('click'); |
f9c6e2
|
123 |
app_kachel_neu(app_sender_dialog_lesen(--ID_UNDEFINED)); |
b520d1
|
124 |
app_dialog_schliessen(); |
742e75
|
125 |
app_meldung_mit_timeout('Speichern gewaehlt', 1500); |
b520d1
|
126 |
}); |
U |
127 |
app_menu_toggle(); |
5226a2
|
128 |
} |
U |
129 |
|
742e75
|
130 |
function app_sender_bearbeiten() { |
56852d
|
131 |
senderKlickModus = "2"; // bearbeiten |
ffc872
|
132 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_EDIT], ''); |
c0ad5e
|
133 |
app_menu_toggle(); |
742e75
|
134 |
} |
5226a2
|
135 |
|
742e75
|
136 |
function app_sender_loeschen() { |
U |
137 |
app_meldung_mit_timeout('Nicht implementiert: Sender loeschen.', 1500); |
c0ad5e
|
138 |
app_menu_toggle(); |
742e75
|
139 |
} |
U |
140 |
|
69ffa5
|
141 |
function app_abspieler_loeschen() { |
U |
142 |
app_meldung_mit_timeout('Nicht implementiert: Abspieler loeschen.', 1500); |
|
143 |
app_menu_toggle(); |
|
144 |
} |
|
145 |
function app_neuer_abspieler() { |
|
146 |
app_meldung_mit_timeout('Nicht implementiert: Neuer Abspieler.', 1500); |
|
147 |
app_menu_toggle(); |
|
148 |
} |
|
149 |
function app_abspieler_bearbeiten() { |
|
150 |
app_meldung_mit_timeout('Nicht implementiert: Abspieler bearbeiten.', 1500); |
|
151 |
app_menu_toggle(); |
|
152 |
} |
|
153 |
|
742e75
|
154 |
/* --- Dialogfunktionen --- */ |
8881ca
|
155 |
|
U |
156 |
function app_dialog_zeigen(vorlage, inhalt) { |
|
157 |
$(".dialog").html(Mustache.render(vorlage, inhalt)); |
|
158 |
$(".close-btn").on('click', function() { |
b520d1
|
159 |
app_dialog_schliessen(); |
8881ca
|
160 |
}); |
U |
161 |
$('.dialog').slideDown(300); |
f9c6e2
|
162 |
} |
U |
163 |
|
|
164 |
function app_sender_dialog_lesen(senderId) { |
|
165 |
var nameNeu = $("#sender-name").val(); |
|
166 |
var logoNeu = $("#sender-logo").val(); |
|
167 |
var urlNeu = $("#sender-url").val(); |
|
168 |
return new Sender(senderId, nameNeu, urlNeu, logoNeu); |
b520d1
|
169 |
} |
U |
170 |
|
|
171 |
function app_dialog_schliessen() { |
56852d
|
172 |
senderKlickModus = "0"; |
136220
|
173 |
$('.close-btn').off('click'); |
b520d1
|
174 |
$('.dialog').slideUp(300); |
9f0d54
|
175 |
} |
U |
176 |
|
742e75
|
177 |
/* --- Meldungen in der Fusszeile --- */ |
U |
178 |
|
|
179 |
/* |
|
180 |
Eine Meldung eine Zeitlang in der Fusszeile anzeigen |
|
181 |
|
|
182 |
meldung - Text der Meldung |
|
183 |
timeout - die Anzahl Millisekunden, die eine Meldung zu sehen sein soll |
|
184 |
*/ |
|
185 |
function app_meldung_mit_timeout(meldung, timeout) { |
|
186 |
$('.sued').text(meldung); |
|
187 |
setTimeout(function() { |
|
188 |
$('.sued').text('Bereit.'); |
|
189 |
}, timeout); |
|
190 |
} |
|
191 |
|
47a970
|
192 |
/* --- Ajax-Aufrufe --- */ |
U |
193 |
|
a480d0
|
194 |
function app_get_sender() { |
U |
195 |
$.ajax({ |
0c85a2
|
196 |
url: "data/sender.json", |
a480d0
|
197 |
type: "GET", |
U |
198 |
dataType : "json" |
|
199 |
}).done(function( senderliste ) { |
56852d
|
200 |
$(".sender-kachel").off("click"); |
U |
201 |
$(".sender-behaelter").html( |
|
202 |
Mustache.render(templateCache[TPL_SENDER], senderliste)); |
f9c6e2
|
203 |
$('.sender-kachel').on('click', app_kachel_klick); |
a480d0
|
204 |
}); |
U |
205 |
} |
|
206 |
|
576085
|
207 |
function app_get_abspieler() { |
U |
208 |
$.ajax({ |
|
209 |
url: "data/abspieler.json", |
|
210 |
type: "GET", |
|
211 |
dataType : "json" |
|
212 |
}).done(function( abspielerliste ) { |
|
213 |
$(".abspieler-behaelter").html( |
|
214 |
Mustache.render(templateCache[TPL_ABSPIELER], abspielerliste)); |
|
215 |
}); |
|
216 |
} |
|
217 |
|
b520d1
|
218 |
function app_dialog_laden_und_zeigen(vorlage, adresse) { |
36646e
|
219 |
if(adresse !== '') { |
U |
220 |
$.ajax({ |
|
221 |
url: adresse, |
|
222 |
type: "GET", |
|
223 |
dataType : "json" |
|
224 |
}).done(function( msg ) { |
8881ca
|
225 |
app_dialog_zeigen(vorlage, msg); |
36646e
|
226 |
}); |
U |
227 |
} else { |
8881ca
|
228 |
app_dialog_zeigen(vorlage, ''); |
36646e
|
229 |
} |
9e336a
|
230 |
} |
U |
231 |
|
47a970
|
232 |
/* |
U |
233 |
Ein Template vom Server in den Cache laden |
|
234 |
template_url - home.tpl, prefs.tpl, sender.tpl |
|
235 |
tname - 'home', 'prefs', 'sender' |
|
236 |
*/ |
|
237 |
function app_get_template(template_url, tname) { |
|
238 |
$.ajax({ |
|
239 |
url: template_url, |
|
240 |
type: "GET", |
|
241 |
dataType : "text" |
|
242 |
}).done(function( template ) { |
|
243 |
templateCache[tname] = template; |
|
244 |
}); |
623a61
|
245 |
} |
e6c850
|
246 |
|
U |
247 |
/* Objekte */ |
|
248 |
|
|
249 |
function Sender(i, n, u, l) { |
|
250 |
this.id = i; |
|
251 |
this.name = n; |
|
252 |
this.url = u; |
|
253 |
this.logo = l; |
|
254 |
} |