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'; |
df379b
|
9 |
var templateCache = {}; // mustache templates |
623a61
|
10 |
var prefsRendered = false; |
56852d
|
11 |
var senderKlickModus = "0"; // 1=abspielen, 2=bearbeiten, 3=loeschen |
623a61
|
12 |
|
U |
13 |
function app_init() { |
9f0d54
|
14 |
$('.dialog').hide(); |
623a61
|
15 |
$('.ost').hide(); |
136220
|
16 |
app_menu_init( |
U |
17 |
"data/menu/", |
|
18 |
"hauptmenue.json", |
|
19 |
"../jslib/app-menu/app-menu.tpl", |
|
20 |
".west", |
|
21 |
"8em"); |
8881ca
|
22 |
app_get_template('data/tpl/dlg-msg.tpl', TPL_DLG_MSG); |
U |
23 |
app_get_template('data/tpl/dlg-info.tpl', TPL_DLG_INFO); |
|
24 |
app_get_template('data/tpl/sender.tpl', TPL_SENDER); |
ffc872
|
25 |
app_get_template('data/tpl/dlg-sender-neu.tpl', TPL_DLG_SENDER_NEU); |
U |
26 |
app_get_template('data/tpl/dlg-sender-edit.tpl', TPL_DLG_SENDER_EDIT); |
56852d
|
27 |
app_get_template('data/tpl/dlg-sender-edit-form.tpl', TPL_SENDER_EDIT_FORM); |
623a61
|
28 |
//app_get_template('tpl/prefs.tpl', 'prefs'); |
U |
29 |
$('.sued').text('Bereit.'); |
|
30 |
setTimeout(function() { |
a480d0
|
31 |
app_get_sender(); |
623a61
|
32 |
}, 200); |
47a970
|
33 |
} |
U |
34 |
|
8881ca
|
35 |
/* --- Menüfunktionen --- */ |
U |
36 |
|
9f0d54
|
37 |
function app_nachricht_test() { |
b520d1
|
38 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_MSG], 'data/msg-test.json'); |
df379b
|
39 |
app_menu_toggle(); |
36646e
|
40 |
} |
U |
41 |
|
|
42 |
function app_info_dialog_zeigen() { |
b520d1
|
43 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_INFO], ''); |
df379b
|
44 |
app_menu_toggle(); |
8881ca
|
45 |
} |
U |
46 |
|
5226a2
|
47 |
function app_neuer_sender() { |
ffc872
|
48 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_NEU], ''); |
b520d1
|
49 |
$('#sender-speichern').on('click', function() { |
136220
|
50 |
$('#sender-speichern').off('click'); |
b520d1
|
51 |
app_dialog_schliessen(); |
742e75
|
52 |
app_meldung_mit_timeout('Speichern gewaehlt', 1500); |
b520d1
|
53 |
}); |
U |
54 |
app_menu_toggle(); |
5226a2
|
55 |
} |
U |
56 |
|
742e75
|
57 |
function app_sender_bearbeiten() { |
56852d
|
58 |
senderKlickModus = "2"; // bearbeiten |
ffc872
|
59 |
app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_EDIT], ''); |
c0ad5e
|
60 |
app_menu_toggle(); |
742e75
|
61 |
} |
5226a2
|
62 |
|
742e75
|
63 |
function app_sender_loeschen() { |
U |
64 |
app_meldung_mit_timeout('Nicht implementiert: Sender loeschen.', 1500); |
c0ad5e
|
65 |
app_menu_toggle(); |
742e75
|
66 |
} |
U |
67 |
|
|
68 |
/* --- Dialogfunktionen --- */ |
8881ca
|
69 |
|
U |
70 |
function app_dialog_zeigen(vorlage, inhalt) { |
|
71 |
$(".dialog").html(Mustache.render(vorlage, inhalt)); |
|
72 |
$(".close-btn").on('click', function() { |
b520d1
|
73 |
app_dialog_schliessen(); |
8881ca
|
74 |
}); |
U |
75 |
$('.dialog').slideDown(300); |
b520d1
|
76 |
} |
U |
77 |
|
|
78 |
function app_dialog_schliessen() { |
56852d
|
79 |
senderKlickModus = "0"; |
136220
|
80 |
$('.close-btn').off('click'); |
b520d1
|
81 |
$('.dialog').slideUp(300); |
9f0d54
|
82 |
} |
U |
83 |
|
742e75
|
84 |
/* --- Meldungen in der Fusszeile --- */ |
U |
85 |
|
|
86 |
/* |
|
87 |
Eine Meldung eine Zeitlang in der Fusszeile anzeigen |
|
88 |
|
|
89 |
meldung - Text der Meldung |
|
90 |
timeout - die Anzahl Millisekunden, die eine Meldung zu sehen sein soll |
|
91 |
*/ |
|
92 |
function app_meldung_mit_timeout(meldung, timeout) { |
|
93 |
$('.sued').text(meldung); |
|
94 |
setTimeout(function() { |
|
95 |
$('.sued').text('Bereit.'); |
|
96 |
}, timeout); |
|
97 |
} |
|
98 |
|
47a970
|
99 |
/* --- Ajax-Aufrufe --- */ |
U |
100 |
|
a480d0
|
101 |
function app_get_sender() { |
U |
102 |
$.ajax({ |
0c85a2
|
103 |
url: "data/sender.json", |
a480d0
|
104 |
type: "GET", |
U |
105 |
dataType : "json" |
|
106 |
}).done(function( senderliste ) { |
56852d
|
107 |
$(".sender-kachel").off("click"); |
U |
108 |
$(".sender-behaelter").html( |
|
109 |
Mustache.render(templateCache[TPL_SENDER], senderliste)); |
136220
|
110 |
$('.sender-kachel').on('click', function() { |
U |
111 |
var kachel = $( this ); |
|
112 |
var senderId = kachel.attr("sid"); |
|
113 |
var senderName = $(kachel).find(".sender-name").text(); |
56852d
|
114 |
switch (senderKlickModus) { |
U |
115 |
case "1": |
|
116 |
break; |
|
117 |
case "2": |
|
118 |
$(".dlg-behaelter").html( |
|
119 |
Mustache.render(templateCache[TPL_SENDER_EDIT_FORM], '') |
|
120 |
); |
|
121 |
$('#sender-speichern').on('click', function() { |
|
122 |
$('#sender-speichern').off('click'); |
|
123 |
app_dialog_schliessen(); |
|
124 |
app_meldung_mit_timeout('Speichern gewaehlt', 1500); |
|
125 |
}); |
|
126 |
break; |
|
127 |
case "3": |
|
128 |
break; |
|
129 |
default: |
|
130 |
app_meldung_mit_timeout( |
|
131 |
'Sender ' + senderName + ', ID ' + senderId, |
|
132 |
1500 |
|
133 |
); |
|
134 |
break; |
|
135 |
} |
136220
|
136 |
}); |
a480d0
|
137 |
}); |
U |
138 |
} |
|
139 |
|
b520d1
|
140 |
function app_dialog_laden_und_zeigen(vorlage, adresse) { |
36646e
|
141 |
if(adresse !== '') { |
U |
142 |
$.ajax({ |
|
143 |
url: adresse, |
|
144 |
type: "GET", |
|
145 |
dataType : "json" |
|
146 |
}).done(function( msg ) { |
8881ca
|
147 |
app_dialog_zeigen(vorlage, msg); |
36646e
|
148 |
}); |
U |
149 |
} else { |
8881ca
|
150 |
app_dialog_zeigen(vorlage, ''); |
36646e
|
151 |
} |
9e336a
|
152 |
} |
U |
153 |
|
47a970
|
154 |
/* |
U |
155 |
Ein Template vom Server in den Cache laden |
|
156 |
template_url - home.tpl, prefs.tpl, sender.tpl |
|
157 |
tname - 'home', 'prefs', 'sender' |
|
158 |
*/ |
|
159 |
function app_get_template(template_url, tname) { |
|
160 |
$.ajax({ |
|
161 |
url: template_url, |
|
162 |
type: "GET", |
|
163 |
dataType : "text" |
|
164 |
}).done(function( template ) { |
|
165 |
templateCache[tname] = template; |
|
166 |
}); |
623a61
|
167 |
} |