commit | author | age
|
05e9c4
|
1 |
function AppVorlage() { |
U |
2 |
var self = this; |
41ab37
|
3 |
this.appMenu; |
U |
4 |
this.vorlagen; |
|
5 |
this.api; |
|
6 |
this.userid; |
|
7 |
this.pfad = ''; |
|
8 |
this.loc; |
|
9 |
this.modus = 'kacheln'; |
|
10 |
this.PERS_DIR = "Persoenlich"; |
|
11 |
this.PUB_DIR = "Oeffentlich"; |
|
12 |
this.DAV_DIR = "Austausch"; |
|
13 |
this.BASE_DIR = "$basis"; |
|
14 |
this.DATA_DIR = "$daten"; |
|
15 |
this.WWW_DIR = "www"; |
|
16 |
this.cache = {}; // mustache template cache |
05e9c4
|
17 |
|
94b871
|
18 |
this.datei_neuer_text = function () { |
58bcbd
|
19 |
self.meldung_mit_timeout("Neuer Text", 1500); |
05e9c4
|
20 |
}; |
U |
21 |
|
|
22 |
/* Funktionen aus App-Vorlage */ |
94b871
|
23 |
|
U |
24 |
this.init = function () { |
41ab37
|
25 |
//self.vorlagen = new Vorlagen(); |
05e9c4
|
26 |
self.appMenu = new AppMenu(); |
U |
27 |
self.appMenu.init( |
94b871
|
28 |
"data/menu/", |
U |
29 |
"hauptmenue.json", |
|
30 |
"data/tpl/app-menu.tpl", |
|
31 |
".west", |
|
32 |
"8em"); |
|
33 |
document.querySelector('.hamburger').addEventListener('click', function (e) { |
05e9c4
|
34 |
self.menue_umschalten(); |
U |
35 |
}); |
58bcbd
|
36 |
self.fm_get_login(); |
41ab37
|
37 |
|
U |
38 |
var parsedUrl = new URL(window.location.href); |
|
39 |
var wunschPfad = parsedUrl.searchParams.get("pfad"); |
|
40 |
|
|
41 |
if(wunschPfad !== null && wunschPfad.length > 0) { |
|
42 |
self.pfad = wunschPfad; |
|
43 |
self.fm_get_list(wunschPfad); |
|
44 |
} else { |
|
45 |
self.fm_get_list(''); |
|
46 |
} |
|
47 |
//fm_init_uploader(); |
58bcbd
|
48 |
self.loc = window.location.protocol + '//' + window.location.host; |
41ab37
|
49 |
|
U |
50 |
//self.fm_get_list(''); |
|
51 |
//self.loc = window.location.protocol + '//' + window.location.host; |
05e9c4
|
52 |
}; |
U |
53 |
|
58bcbd
|
54 |
this.login_zeigen = function() { |
U |
55 |
self.meldung_mit_timeout("Benutzer: " + self.userid, 1500); |
|
56 |
}; |
|
57 |
|
94b871
|
58 |
this.menue_umschalten = function () { |
05e9c4
|
59 |
var ham = document.querySelector(".hamburger"); |
U |
60 |
ham.classList.toggle("is-active"); // hamburger-icon umschalten |
|
61 |
self.appMenu.toggle(); // menue oeffnen/schliessen |
|
62 |
}; |
|
63 |
|
94b871
|
64 |
this.info_dialog_zeigen = function () { |
05e9c4
|
65 |
self.dialog_laden_und_zeigen('data/tpl/dlg-info.tpl', ''); |
U |
66 |
self.menue_umschalten(); |
|
67 |
}; |
|
68 |
|
94b871
|
69 |
this.seitenleiste_umschalten = function () { |
05e9c4
|
70 |
var ostDiv = document.querySelector('.ost'); |
94b871
|
71 |
if (ostDiv.classList.contains('ost-open')) { |
05e9c4
|
72 |
ostDiv.classList.remove('ost-open'); |
94b871
|
73 |
ostDiv.style.flexBasis = '0em'; |
05e9c4
|
74 |
} else { |
94b871
|
75 |
ostDiv.classList.add('ost-open'); |
U |
76 |
ostDiv.style.flexBasis = '6em'; |
05e9c4
|
77 |
} |
U |
78 |
self.menue_umschalten(); |
|
79 |
}; |
|
80 |
|
94b871
|
81 |
this.fusszeile_umschalten = function () { |
05e9c4
|
82 |
var suedDiv = document.querySelector('.sued'); |
94b871
|
83 |
if (suedDiv.classList.contains('sued-open')) { |
05e9c4
|
84 |
suedDiv.classList.remove('sued-open'); |
94b871
|
85 |
suedDiv.style.height = '0'; |
05e9c4
|
86 |
} else { |
U |
87 |
suedDiv.classList.add('sued-open'); |
94b871
|
88 |
suedDiv.style.height = '1.5em'; |
05e9c4
|
89 |
} |
U |
90 |
self.menue_umschalten(); |
|
91 |
}; |
|
92 |
|
94b871
|
93 |
this.meldung_mit_timeout = function (meldung, timeout) { |
05e9c4
|
94 |
var s = document.querySelector('.sued'); |
U |
95 |
s.textContent = meldung; |
94b871
|
96 |
setTimeout(function () { |
05e9c4
|
97 |
s.textContent = 'Bereit.'; |
94b871
|
98 |
setTimeout(function () { |
05e9c4
|
99 |
var suedDiv = document.querySelector('.sued'); |
94b871
|
100 |
if (suedDiv.classList.contains('sued-open')) { |
U |
101 |
suedDiv.classList.remove('sued-open'); |
|
102 |
suedDiv.style.height = '0'; |
05e9c4
|
103 |
} |
U |
104 |
}, 500); |
|
105 |
}, timeout); |
|
106 |
}; |
|
107 |
|
|
108 |
/* Dialog-Funktionen */ |
|
109 |
|
|
110 |
/* |
94b871
|
111 |
Einen Dialog aus Vorlagen erzeugen |
U |
112 |
|
|
113 |
vurl - URL zur Dialogvorlage |
|
114 |
msgTpl - URL mit einer Vorlage eines Mitteilungstextes (optional) |
|
115 |
*/ |
|
116 |
this.dialog_laden_und_zeigen = function (vurl, msgTpl) { |
|
117 |
if (msgTpl !== '') { |
05e9c4
|
118 |
fetch(msgTpl) |
94b871
|
119 |
.then(data => { |
U |
120 |
// Handle data |
|
121 |
self.dialog_zeigen(vurl, data); |
|
122 |
}).catch(error => { |
|
123 |
// Handle error |
|
124 |
}); |
05e9c4
|
125 |
} else { |
U |
126 |
self.dialog_zeigen(vurl, ''); |
|
127 |
} |
|
128 |
}; |
|
129 |
|
94b871
|
130 |
this.dialog_zeigen = function (vurl, inhalt) { |
05e9c4
|
131 |
var dlg = document.querySelector(".dialog"); |
U |
132 |
self.vorlagen.html_erzeugen( |
94b871
|
133 |
vurl, |
U |
134 |
inhalt, |
|
135 |
function (html) { |
|
136 |
//dlg.html(html); |
|
137 |
dlg.style.height = '5em'; |
|
138 |
dlg.innerHTML = html; |
|
139 |
document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen); |
|
140 |
//dlg.slideDown(300); |
|
141 |
}); |
05e9c4
|
142 |
}; |
U |
143 |
|
58bcbd
|
144 |
this.dialog_schliessen = function () { |
05e9c4
|
145 |
document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen); |
U |
146 |
//$('.dialog').slideUp(300); |
|
147 |
var dlg = document.querySelector('.dialog'); |
|
148 |
//dlg.style.display = "none"; |
|
149 |
dlg.style.height = '0'; |
|
150 |
dlg.innerHTML = ''; |
|
151 |
}; |
58bcbd
|
152 |
|
41ab37
|
153 |
this.html_zeigen = function(html) { |
U |
154 |
// was mit dem html getan werden soll.. |
|
155 |
var elem = document.querySelector('#dateien'); |
|
156 |
elem.innerHTML = html; |
|
157 |
}; |
|
158 |
|
58bcbd
|
159 |
this.fm_render_list = function (fl) { |
U |
160 |
if (self.modus == 'kacheln') { |
|
161 |
// Kachelansicht |
|
162 |
|
|
163 |
// neu bauen |
41ab37
|
164 |
|
U |
165 |
//html_erzeugen = function(vurl, inhalt, cb) |
|
166 |
|
|
167 |
self.html_erzeugen("data/tpl/kacheln.tpl", fl, self.html_zeigen); |
58bcbd
|
168 |
|
U |
169 |
/* |
|
170 |
var template = $('#tpl-kacheln').html(); |
|
171 |
Mustache.parse(template); // optional, speeds up future uses |
|
172 |
$('.datei-zeile').attr('onclick', '').unbind('click'); |
|
173 |
$('#dateien').empty(); |
|
174 |
$('#dateien').html(Mustache.render(template, fl)); |
|
175 |
$('.figure').click(fm_dateiwahl); |
|
176 |
*/ |
|
177 |
} else { |
|
178 |
// Listenansicht |
|
179 |
|
|
180 |
// neu bauen |
|
181 |
|
|
182 |
/* |
|
183 |
var template = $('#tpl-liste').html(); |
|
184 |
Mustache.parse(template); // optional, speeds up future uses |
|
185 |
$('.figure').attr('onclick', '').unbind('click'); |
|
186 |
$('#dateien').empty(); |
|
187 |
$('#dateien').html(Mustache.render(template, fl)); |
|
188 |
$('.datei-zeile').click(fm_dateiwahl); |
|
189 |
*/ |
|
190 |
} |
|
191 |
}; |
|
192 |
|
|
193 |
this.fm_get_path = function (uid) { |
|
194 |
//console.log('pfad: ' + pfad); |
|
195 |
var restdir; |
|
196 |
if (self.pfad.indexOf(self.PUB_DIR) > -1) { |
|
197 |
restdir = self.pfad.substr(self.PUB_DIR.length); |
|
198 |
} else if (self.pfad.indexOf(self.PERS_DIR) > -1) { |
|
199 |
restdir = self.pfad.substr(self.PERS_DIR.length); |
|
200 |
} else if (self.pfad.indexOf(self.BASE_DIR) > -1) { |
|
201 |
restdir = self.pfad.substr(self.BASE_DIR.length); |
|
202 |
} else if (self.pfad.indexOf(self.DATA_DIR) > -1) { |
|
203 |
restdir = self.pfad.substr(self.DATA_DIR.length); |
|
204 |
} else if (self.pfad.indexOf(self.DAV_DIR) > -1) { |
|
205 |
restdir = self.pfad.substr(self.DAV_DIR.length); |
|
206 |
} |
|
207 |
if (restdir !== undefined && restdir.startsWith('/')) { |
|
208 |
restdir = restdir.substr(1); |
|
209 |
if (restdir.indexOf(self.WWW_DIR) > -1) { |
|
210 |
restdir = restdir.replace(self.WWW_DIR, 'data'); |
|
211 |
} |
|
212 |
} |
41ab37
|
213 |
var pdir = self.fm_get_base(uid); |
58bcbd
|
214 |
// console.log('fm_get_path path: ' + pdir + "/" + restdir); |
U |
215 |
if (restdir.length > 1) { |
|
216 |
return pdir + "/" + restdir; |
|
217 |
} else { |
|
218 |
return pdir; |
|
219 |
} |
|
220 |
}; |
|
221 |
|
|
222 |
this.fm_get_base = function (uid) { |
|
223 |
//console.log('pfad: ' + pfad); |
|
224 |
var pdir; |
|
225 |
if (self.pfad.indexOf(self.PUB_DIR) > -1) { |
|
226 |
pdir = '/data/' + uid; |
|
227 |
} else if (self.pfad.indexOf(self.PERS_DIR) > -1) { |
|
228 |
pdir = '/home/' + uid; |
|
229 |
} else if (self.pfad.indexOf(self.BASE_DIR) > -1) { |
|
230 |
pdir = ''; |
|
231 |
} else if (self.pfad.indexOf(self.DATA_DIR) > -1) { |
|
232 |
pdir = ''; |
|
233 |
} |
|
234 |
//console.log('fm_get_base base: ' + pdir + uid); |
|
235 |
return pdir; |
|
236 |
}; |
|
237 |
|
05e9c4
|
238 |
|
94b871
|
239 |
/* API functions */ |
05e9c4
|
240 |
|
94b871
|
241 |
// http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p= |
U |
242 |
this.fm_get_list = function (relPfad) { |
58bcbd
|
243 |
//$('#ansicht').attr('onclick', '').unbind('click'); |
94b871
|
244 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPfad; |
U |
245 |
var u = '../svc' + m; |
58bcbd
|
246 |
self.fm_get(u, "json", function (respText) { |
U |
247 |
var resp = JSON.parse(respText); |
94b871
|
248 |
if (resp.List[0].FileRef !== undefined) { |
U |
249 |
var files = new Array(); |
|
250 |
if (resp.List[0].FileRef instanceof Array) { |
|
251 |
for (var i = 0; i < resp.List[0].FileRef.length; i++) { |
|
252 |
files.push(new FileRef(resp.List[0].FileRef[i])); |
05e9c4
|
253 |
} |
U |
254 |
} else { |
94b871
|
255 |
files.push(new FileRef(resp.List[0].FileRef)); |
05e9c4
|
256 |
} |
94b871
|
257 |
var fl = new FileList(files); |
58bcbd
|
258 |
self.fm_render_list(fl); |
41ab37
|
259 |
//self.fm_render_list(resp); |
94b871
|
260 |
} else { |
58bcbd
|
261 |
// #dateien leeren |
U |
262 |
var elems = document.querySelector("#dateien"); |
|
263 |
var count = elems[0].childElementCount; |
|
264 |
for(var i = count-1; i > -1; i--) { |
|
265 |
elems[0].removeChild(i); |
|
266 |
} |
94b871
|
267 |
} |
U |
268 |
}); |
|
269 |
}; |
05e9c4
|
270 |
|
94b871
|
271 |
/* -------- An- und Abmelden ------------- */ |
05e9c4
|
272 |
|
94b871
|
273 |
this.fm_get_login = function() { |
U |
274 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=getSessionUser'; |
|
275 |
var u = '../pub' + m; |
|
276 |
self.fm_get(u, "text", function (resp) { |
|
277 |
self.userid = resp; |
58bcbd
|
278 |
self.login_zeigen(); |
U |
279 |
//document.querySelector("#userMenu").textContent = resp; |
94b871
|
280 |
}); |
U |
281 |
}; |
05e9c4
|
282 |
|
94b871
|
283 |
this.fm_logout = function() { |
U |
284 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession'; |
|
285 |
var u = '../pub' + m; |
|
286 |
self.fm_get(u, "text", function (resp) { |
|
287 |
//$('#userMenu').text('nicht angemeldet'); |
|
288 |
window.location.href = '../logout.html'; |
|
289 |
}); |
|
290 |
}; |
41ab37
|
291 |
|
U |
292 |
/* ---- Vorlagen ---- */ |
|
293 |
|
|
294 |
this.html_erzeugen = function(vurl, inhalt, cb) { |
|
295 |
var vorlage = self.cache[vurl]; |
|
296 |
if(vorlage === undefined) { |
|
297 |
self.vorlage_laden_und_fuellen(vurl, inhalt, cb); |
|
298 |
} else { |
|
299 |
self.vorlage_fuellen(vurl, inhalt, cb); |
|
300 |
} |
|
301 |
}; |
|
302 |
|
|
303 |
this.vorlage_fuellen = function(vurl, inhalt, cb) { |
|
304 |
cb(Mustache.render(self.cache[vurl], inhalt)); |
|
305 |
}; |
|
306 |
|
|
307 |
this.vorlage_laden_und_fuellen = function(vurl, inhalt, cb) { |
|
308 |
self.fm_get(vurl, "text", function(antwort) { |
|
309 |
self.cache[vurl] = antwort; |
|
310 |
self.vorlage_fuellen(vurl, inhalt, cb); |
|
311 |
}); |
|
312 |
}; |
|
313 |
|
|
314 |
|
94b871
|
315 |
|
U |
316 |
/* -------- ajax helper functions ----------- */ |
|
317 |
|
58bcbd
|
318 |
this.fm_get = function (u, dtype, scallback) { |
U |
319 |
var xmlhttp = new XMLHttpRequest(); |
|
320 |
var url = u; |
|
321 |
xmlhttp.onreadystatechange = function() { |
|
322 |
if (this.readyState == 4 && this.status == 200) { |
|
323 |
scallback(this.responseText); |
94b871
|
324 |
} |
58bcbd
|
325 |
}; |
U |
326 |
xmlhttp.open("GET", url, true); |
|
327 |
xmlhttp.send(); |
94b871
|
328 |
}; |
U |
329 |
|
05e9c4
|
330 |
} |