commit | author | age
|
05e9c4
|
1 |
function AppVorlage() { |
U |
2 |
var self = this; |
41ab37
|
3 |
this.appMenu; |
4e450e
|
4 |
//this.vorlagen; |
41ab37
|
5 |
this.api; |
U |
6 |
this.userid; |
|
7 |
this.pfad = ''; |
|
8 |
this.loc; |
|
9 |
this.modus = 'kacheln'; |
ebc1f3
|
10 |
this.cm; |
4e450e
|
11 |
//this.tinymce; |
U |
12 |
this.ed; |
|
13 |
this.tmo; |
|
14 |
this.tmo2; |
41ab37
|
15 |
this.PERS_DIR = "Persoenlich"; |
U |
16 |
this.PUB_DIR = "Oeffentlich"; |
|
17 |
this.DAV_DIR = "Austausch"; |
|
18 |
this.BASE_DIR = "$basis"; |
|
19 |
this.DATA_DIR = "$daten"; |
|
20 |
this.WWW_DIR = "www"; |
f002d9
|
21 |
this.openEditor; |
U |
22 |
this.openFileName; |
beb124
|
23 |
this.cutCopyOperation; |
U |
24 |
this.cutCopySrcDir; |
|
25 |
this.cutCopyFiles; |
41ab37
|
26 |
this.cache = {}; // mustache template cache |
05e9c4
|
27 |
|
94b871
|
28 |
this.datei_neuer_text = function () { |
ebc1f3
|
29 |
//self.meldung_mit_timeout("Neuer Text", 1500); |
U |
30 |
self.fm_text_edit('Neue Datei'); |
|
31 |
}; |
|
32 |
|
05e9c4
|
33 |
/* Funktionen aus App-Vorlage */ |
94b871
|
34 |
|
4e450e
|
35 |
this.init = function () { |
f002d9
|
36 |
document.querySelector(".codeeditor-space").style.display = "none"; |
U |
37 |
document.querySelector("#mce-editor").style.display = "none"; |
05e9c4
|
38 |
self.appMenu = new AppMenu(); |
U |
39 |
self.appMenu.init( |
94b871
|
40 |
"data/menu/", |
U |
41 |
"hauptmenue.json", |
|
42 |
"data/tpl/app-menu.tpl", |
|
43 |
".west", |
|
44 |
"8em"); |
|
45 |
document.querySelector('.hamburger').addEventListener('click', function (e) { |
05e9c4
|
46 |
self.menue_umschalten(); |
U |
47 |
}); |
f32042
|
48 |
document.querySelector('#top-neuer-text-btn').addEventListener('click', self.datei_neuer_text); |
U |
49 |
document.querySelector('#top-neuer-ordner-btn').addEventListener('click', self.datei_neuer_ordner); |
|
50 |
document.querySelector('#top-close-btn').addEventListener('click', self.fm_menu_datei_schliessen); |
58bcbd
|
51 |
self.fm_get_login(); |
41ab37
|
52 |
|
U |
53 |
var parsedUrl = new URL(window.location.href); |
|
54 |
var wunschPfad = parsedUrl.searchParams.get("pfad"); |
|
55 |
|
|
56 |
if(wunschPfad !== null && wunschPfad.length > 0) { |
|
57 |
self.pfad = wunschPfad; |
|
58 |
self.fm_get_list(wunschPfad); |
|
59 |
} else { |
|
60 |
self.fm_get_list(''); |
|
61 |
} |
ebc1f3
|
62 |
|
U |
63 |
self.seitenleiste_umschalten(); |
41ab37
|
64 |
//fm_init_uploader(); |
58bcbd
|
65 |
self.loc = window.location.protocol + '//' + window.location.host; |
05e9c4
|
66 |
}; |
U |
67 |
|
58bcbd
|
68 |
this.login_zeigen = function() { |
U |
69 |
self.meldung_mit_timeout("Benutzer: " + self.userid, 1500); |
|
70 |
}; |
|
71 |
|
b20b74
|
72 |
this.fm_neuer_reiter = function() { |
U |
73 |
window.open('/file-cms/ui2/?pfad=' + self.pfad, '_blank'); |
|
74 |
}; |
|
75 |
|
94b871
|
76 |
this.menue_umschalten = function () { |
05e9c4
|
77 |
var ham = document.querySelector(".hamburger"); |
U |
78 |
ham.classList.toggle("is-active"); // hamburger-icon umschalten |
|
79 |
self.appMenu.toggle(); // menue oeffnen/schliessen |
|
80 |
}; |
|
81 |
|
94b871
|
82 |
this.info_dialog_zeigen = function () { |
05e9c4
|
83 |
self.dialog_laden_und_zeigen('data/tpl/dlg-info.tpl', ''); |
U |
84 |
self.menue_umschalten(); |
|
85 |
}; |
|
86 |
|
94b871
|
87 |
this.seitenleiste_umschalten = function () { |
05e9c4
|
88 |
var ostDiv = document.querySelector('.ost'); |
94b871
|
89 |
if (ostDiv.classList.contains('ost-open')) { |
05e9c4
|
90 |
ostDiv.classList.remove('ost-open'); |
94b871
|
91 |
ostDiv.style.flexBasis = '0em'; |
05e9c4
|
92 |
} else { |
94b871
|
93 |
ostDiv.classList.add('ost-open'); |
U |
94 |
ostDiv.style.flexBasis = '6em'; |
05e9c4
|
95 |
} |
ebc1f3
|
96 |
//self.menue_umschalten(); |
05e9c4
|
97 |
}; |
U |
98 |
|
94b871
|
99 |
this.fusszeile_umschalten = function () { |
05e9c4
|
100 |
var suedDiv = document.querySelector('.sued'); |
94b871
|
101 |
if (suedDiv.classList.contains('sued-open')) { |
05e9c4
|
102 |
suedDiv.classList.remove('sued-open'); |
94b871
|
103 |
suedDiv.style.height = '0'; |
05e9c4
|
104 |
} else { |
U |
105 |
suedDiv.classList.add('sued-open'); |
94b871
|
106 |
suedDiv.style.height = '1.5em'; |
05e9c4
|
107 |
} |
U |
108 |
self.menue_umschalten(); |
|
109 |
}; |
|
110 |
|
94b871
|
111 |
this.meldung_mit_timeout = function (meldung, timeout) { |
05e9c4
|
112 |
var s = document.querySelector('.sued'); |
U |
113 |
s.textContent = meldung; |
85ba85
|
114 |
s.classList.add('sued-open'); |
U |
115 |
s.style.height = '1.5em'; |
94b871
|
116 |
setTimeout(function () { |
05e9c4
|
117 |
s.textContent = 'Bereit.'; |
94b871
|
118 |
setTimeout(function () { |
05e9c4
|
119 |
var suedDiv = document.querySelector('.sued'); |
94b871
|
120 |
if (suedDiv.classList.contains('sued-open')) { |
U |
121 |
suedDiv.classList.remove('sued-open'); |
|
122 |
suedDiv.style.height = '0'; |
05e9c4
|
123 |
} |
U |
124 |
}, 500); |
|
125 |
}, timeout); |
|
126 |
}; |
ebc1f3
|
127 |
|
U |
128 |
this.fm_menu_datei_schliessen = function() { |
|
129 |
if(self.openEditor === 'text') { |
|
130 |
if(!self.cm.getDoc().isClean()) { |
|
131 |
self.fm_ask_for_save(); |
|
132 |
} else { |
|
133 |
self.fm_do_close(); |
|
134 |
} |
|
135 |
} else { |
4e450e
|
136 |
if(tinymce.activeEditor.undoManager.hasUndo()) { |
ebc1f3
|
137 |
self.fm_ask_for_save(); |
U |
138 |
} else { |
|
139 |
self.fm_do_close(); |
|
140 |
} |
|
141 |
} |
|
142 |
}; |
|
143 |
|
|
144 |
this.fm_ask_for_save = function() { |
|
145 |
self.dialog_laden_und_zeigen('data/tpl/dlg-ask-save.tpl', '', function() { |
|
146 |
// wenn dialog da ist, hier events verknuepfen |
|
147 |
document.querySelector('#cancel-btn').addEventListener('click', function() { |
|
148 |
self.fm_do_close(); |
|
149 |
self.dialog_schliessen(); |
|
150 |
}); |
|
151 |
document.querySelector('#speichern-btn').addEventListener('click', function() { |
|
152 |
self.fm_menu_datei_speichern(function() { |
|
153 |
self.fm_do_close(); |
|
154 |
self.dialog_schliessen(); |
|
155 |
}); |
|
156 |
}); |
|
157 |
}); |
|
158 |
}; |
|
159 |
|
|
160 |
this.fm_menu_datei_speichern = function(callback) { |
|
161 |
//var fname = $('.datei-gewaehlt').text(); |
|
162 |
var fname = self.openFileName; |
|
163 |
if(fname !== undefined && fname !== '') { |
|
164 |
self.fm_save_file(fname, 'saveTextFile', callback); |
03be8f
|
165 |
self.meldung_mit_timeout(fname + ' gespeichert.', 1500); |
ebc1f3
|
166 |
} else { |
U |
167 |
self.fm_menu_datei_speichern_unter(callback); |
|
168 |
} |
|
169 |
}; |
|
170 |
|
|
171 |
this.fm_menu_datei_speichern_unter = function(callback) { |
|
172 |
self.dialog_laden_und_zeigen('data/tpl/dlg-save-as.tpl', '', function() { |
5b4d03
|
173 |
document.querySelector('#cancel-btn').addEventListener('click', function() { |
U |
174 |
//self.fm_do_close(); |
|
175 |
self.dialog_schliessen(); |
|
176 |
}); |
|
177 |
document.querySelector('#speichern-btn').addEventListener('click', function() { |
1a9589
|
178 |
//self.fm_menu_datei_speichern(function() { |
U |
179 |
//console.log(document.querySelector('#datei-name-in').value); |
03be8f
|
180 |
var fname = document.querySelector('#datei-name-in').value; |
U |
181 |
self.fm_save_file(fname, 'saveTextFileAs', callback); |
|
182 |
self.meldung_mit_timeout(fname + ' gespeichert.', 1500); |
4e450e
|
183 |
if(typeof(callback) !== 'function') { |
03be8f
|
184 |
//self.fm_do_close(); |
4e450e
|
185 |
self.dialog_schliessen(); |
U |
186 |
} |
1a9589
|
187 |
//}); |
5b4d03
|
188 |
}); |
ebc1f3
|
189 |
}); |
4e450e
|
190 |
}; |
U |
191 |
|
|
192 |
this.fm_menu_neues_dokument = function() { |
|
193 |
self.fm_dok_edit(''); |
ebc1f3
|
194 |
}; |
05e9c4
|
195 |
|
U |
196 |
/* Dialog-Funktionen */ |
|
197 |
|
|
198 |
/* |
94b871
|
199 |
Einen Dialog aus Vorlagen erzeugen |
U |
200 |
|
|
201 |
vurl - URL zur Dialogvorlage |
|
202 |
msgTpl - URL mit einer Vorlage eines Mitteilungstextes (optional) |
|
203 |
*/ |
ebc1f3
|
204 |
this.dialog_laden_und_zeigen = function (vurl, msgTpl, cb) { |
U |
205 |
var vorlage = self.cache[vurl]; |
|
206 |
if(vorlage === undefined) { |
|
207 |
self.fm_get(vurl, "text", function(antwort) { |
|
208 |
self.cache[vurl] = antwort; |
|
209 |
self.dialog_zeigen(vurl, antwort, cb); |
|
210 |
//self.vorlage_fuellen(vurl, inhalt, cb); |
94b871
|
211 |
}); |
05e9c4
|
212 |
} else { |
ebc1f3
|
213 |
self.dialog_zeigen(vurl, vorlage, cb); |
05e9c4
|
214 |
} |
U |
215 |
}; |
|
216 |
|
ebc1f3
|
217 |
this.dialog_zeigen = function (vurl, inhalt, cb) { |
05e9c4
|
218 |
var dlg = document.querySelector(".dialog"); |
ebc1f3
|
219 |
self.html_erzeugen( |
94b871
|
220 |
vurl, |
U |
221 |
inhalt, |
|
222 |
function (html) { |
|
223 |
//dlg.html(html); |
1a9589
|
224 |
dlg.style.height = '7em'; |
94b871
|
225 |
dlg.innerHTML = html; |
U |
226 |
document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen); |
|
227 |
//dlg.slideDown(300); |
ebc1f3
|
228 |
if(typeof(cb) !== 'function') { |
U |
229 |
// .. |
|
230 |
} else { |
|
231 |
cb(); |
|
232 |
} |
94b871
|
233 |
}); |
05e9c4
|
234 |
}; |
U |
235 |
|
58bcbd
|
236 |
this.dialog_schliessen = function () { |
05e9c4
|
237 |
document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen); |
U |
238 |
//$('.dialog').slideUp(300); |
|
239 |
var dlg = document.querySelector('.dialog'); |
|
240 |
//dlg.style.display = "none"; |
|
241 |
dlg.style.height = '0'; |
|
242 |
dlg.innerHTML = ''; |
5b4d03
|
243 |
self.removeAllListeners('#cancel-btn'); |
U |
244 |
self.removeAllListeners('#speichern-btn'); |
05e9c4
|
245 |
}; |
39e714
|
246 |
|
U |
247 |
this.fm_auswahl_marke_entfernen = function() { |
|
248 |
var gew = document.querySelector('.datei-gewaehlt'); |
|
249 |
if(gew !== null) { |
|
250 |
gew.classList.remove('datei-gewaehlt'); |
|
251 |
} |
|
252 |
}; |
0783c5
|
253 |
|
U |
254 |
this.fm_view_file = function() { |
|
255 |
var fname = document.querySelector('.datei-gewaehlt').textContent; |
|
256 |
var path = self.fm_get_path(self.userid); |
|
257 |
window.open(path + '/' + fname, '_blank'); |
|
258 |
}; |
39e714
|
259 |
|
0783c5
|
260 |
this.datei_ansehen_oder_bearbeiten = function(dateiname) { |
U |
261 |
if(dateiname.endsWith('htmi')) { |
|
262 |
self.fm_get_file_content('doc', dateiname); |
|
263 |
} else if(dateiname.endsWith('jpg') || dateiname.endsWith('png') || |
98f80c
|
264 |
dateiname.endsWith('gif') || dateiname.endsWith('pdf') ) { |
U |
265 |
self.fm_view_file(); |
0783c5
|
266 |
} else { |
U |
267 |
self.fm_get_file_content('text', dateiname); |
|
268 |
} |
39e714
|
269 |
}; |
U |
270 |
|
|
271 |
/** |
85ba85
|
272 |
* Hier werden die folgenden Faelle einer Datei- |
U |
273 |
* bzw. Ordnerauswahl ausgefuehrt: |
|
274 |
* |
|
275 |
* geklickt, nicht gewaehlt: |
|
276 |
* auswaehlen, evtl. bestehende andere Auswahl entfernen |
|
277 |
* |
|
278 |
* geklickt, ausgewaehlt: |
|
279 |
* Datei ansehen oder oeffnen bzw. Ordner oeffnen |
|
280 |
* |
|
281 |
* geklickt mit [Strg], nicht gewahlt: |
|
282 |
* auswaehlen, bestehende Auswahl beibehalten (Mehrfachauswahl) |
|
283 |
* |
|
284 |
* geklickt mit [Strg], gewaehlt: |
|
285 |
* Auswahl bei diesem Element entfernen |
39e714
|
286 |
* |
U |
287 |
* Diese Fälle sind unterteilt in |
85ba85
|
288 |
* 1. Kachel-Modus |
U |
289 |
* 2. Listenmodus |
39e714
|
290 |
* |
85ba85
|
291 |
* @param {type} ev Klick-Event |
U |
292 |
* @returns {undefined} nichts |
39e714
|
293 |
*/ |
6648a8
|
294 |
this.fm_dateiwahl = function(ev) { |
U |
295 |
var elem = ev.target; |
|
296 |
if(self.modus == 'kacheln') { |
|
297 |
// Kacheln |
0783c5
|
298 |
var par = elem.parentElement; |
U |
299 |
var dElem = par.querySelector('.dateiname'); |
6648a8
|
300 |
if(elem.classList.contains("icon-folder")) { |
39e714
|
301 |
// Ordner |
0783c5
|
302 |
//var par = elem.parentElement; |
U |
303 |
var istGewaehlt = dElem.classList.contains('datei-gewaehlt'); |
39e714
|
304 |
if(istGewaehlt) { |
U |
305 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
306 |
// mehrere Ordner sind gewaehlt, diese eine wieder entfernen |
0783c5
|
307 |
dElem.classList.remove('datei-gewaehlt'); |
6648a8
|
308 |
} else { |
39e714
|
309 |
// Ordner oeffnen |
0783c5
|
310 |
var ordner = dElem.textContent.trim(); |
39e714
|
311 |
if(self.pfad.length > 0) { |
U |
312 |
self.pfad = self.pfad + '/' + ordner; |
|
313 |
} else { |
|
314 |
self.pfad = ordner; |
|
315 |
} |
|
316 |
self.fm_get_list(self.pfad); |
6648a8
|
317 |
} |
39e714
|
318 |
} else { |
U |
319 |
// Ordner auswaehlen |
|
320 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
321 |
// Mehrfachauswahl |
|
322 |
} else { |
|
323 |
self.fm_auswahl_marke_entfernen(); |
|
324 |
} |
0783c5
|
325 |
dElem.classList.add('datei-gewaehlt'); |
6648a8
|
326 |
} |
U |
327 |
} else if(elem.classList.contains('datei')) { |
39e714
|
328 |
// Datei |
0783c5
|
329 |
//var par = elem.parentElement; |
U |
330 |
//var dElem = par.querySelector('.dateiname'); |
|
331 |
var istGewaehlt = dElem.classList.contains('datei-gewaehlt'); |
39e714
|
332 |
if(istGewaehlt) { |
U |
333 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
334 |
// mehrere Dateien sind gewaehlt, diese eine wieder entfernen |
0783c5
|
335 |
dElem.classList.remove('datei-gewaehlt'); |
39e714
|
336 |
} else { |
U |
337 |
// Datei zum Bearbeiten oeffnen |
0783c5
|
338 |
self.datei_ansehen_oder_bearbeiten(dElem.textContent); |
39e714
|
339 |
} |
U |
340 |
} else { |
|
341 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
342 |
// mehrere Dateien sollen gewaehlt werden |
|
343 |
} else { |
|
344 |
self.fm_auswahl_marke_entfernen(); |
|
345 |
} |
0783c5
|
346 |
dElem.classList.add('datei-gewaehlt'); |
39e714
|
347 |
} |
6648a8
|
348 |
} else { |
U |
349 |
//console.log('kein folder oder file...'); |
|
350 |
} |
|
351 |
} else { |
4f01b8
|
352 |
// Liste |
U |
353 |
var pElem = elem.closest('.datei-zeile'); |
|
354 |
var dElem = pElem.querySelector('.datei-elem'); |
0783c5
|
355 |
var dnElem = pElem.querySelector('.dateiname'); |
U |
356 |
var istGewaehlt = dnElem.classList.contains('datei-gewaehlt'); |
4f01b8
|
357 |
if(dElem.getElementsByTagName("i")[0].classList.contains('icon-doc-text-inv')) { |
6648a8
|
358 |
// Datei |
39e714
|
359 |
if(istGewaehlt) { |
U |
360 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
361 |
// mehrere Dateien sind gewaehlt, diese eine wieder entfernen |
0783c5
|
362 |
dnElem.classList.remove('datei-gewaehlt'); |
39e714
|
363 |
} else { |
U |
364 |
// gewaehlte Datei ohne [Strg] geklickt: ansehen oder oeffnen |
0783c5
|
365 |
self.datei_ansehen_oder_bearbeiten(dnElem.textContent); |
39e714
|
366 |
} |
6648a8
|
367 |
} else { |
39e714
|
368 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
U |
369 |
// mehrere Dateien sollen gewaehlt werden, Auswahl ist weiter unten |
|
370 |
} else { |
|
371 |
var ti = document.querySelector('.table-info'); |
|
372 |
if(ti !== null) { |
|
373 |
ti.classList.remove('table-info'); |
|
374 |
} |
|
375 |
self.fm_auswahl_marke_entfernen(); |
4f01b8
|
376 |
} |
39e714
|
377 |
pElem.classList.add('table-info'); |
0783c5
|
378 |
dnElem.classList.add('datei-gewaehlt'); |
6648a8
|
379 |
} |
U |
380 |
} else { |
|
381 |
// Ordner |
39e714
|
382 |
if(istGewaehlt) { |
U |
383 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
384 |
// ein gewaehlter Ordner ist mit [Strg] geklickt, Auswahl entfernen |
0783c5
|
385 |
dnElem.classList.remove('datei-gewaehlt'); |
6648a8
|
386 |
} else { |
39e714
|
387 |
// Ordner oeffnen |
0783c5
|
388 |
var ordner = dnElem.textContent; |
39e714
|
389 |
if(self.pfad.length > 0) { |
U |
390 |
self.pfad = self.pfad + '/' + ordner; |
|
391 |
} else { |
|
392 |
self.pfad = ordner; |
|
393 |
} |
|
394 |
self.fm_get_list(self.pfad); |
6648a8
|
395 |
} |
39e714
|
396 |
} else { |
U |
397 |
if(/*ev.shiftKey || */ ev.ctrlKey) { |
|
398 |
// nicht gewaehlter Ordner und [Strg]: zu Mehrfachauswahl hinzufuegen |
|
399 |
} else { |
|
400 |
// nicht gewaehlter Ordner ohne [Strg]: andere Auswhalen entfernen und weiter unten Ordner auswaehlen |
|
401 |
self.fm_auswahl_marke_entfernen(); |
|
402 |
} |
0783c5
|
403 |
dnElem.classList.add('datei-gewaehlt'); |
6648a8
|
404 |
} |
U |
405 |
} |
|
406 |
} |
|
407 |
}; |
|
408 |
|
41ab37
|
409 |
|
58bcbd
|
410 |
this.fm_render_list = function (fl) { |
4f01b8
|
411 |
if (self.modus === 'kacheln') { |
58bcbd
|
412 |
// Kachelansicht |
6648a8
|
413 |
self.html_erzeugen("data/tpl/kacheln.tpl", fl, function(html) { |
U |
414 |
var elem = document.querySelector('#dateien'); |
|
415 |
elem.innerHTML = html; |
|
416 |
self.addEvtListener('.figure', 'click', self.fm_dateiwahl); |
|
417 |
}); |
58bcbd
|
418 |
} else { |
U |
419 |
// Listenansicht |
4f01b8
|
420 |
self.html_erzeugen("data/tpl/liste.tpl", fl, function(html) { |
U |
421 |
var elem = document.querySelector('#dateien'); |
|
422 |
elem.innerHTML = html; |
|
423 |
self.addEvtListener('.datei-zeile', 'click', self.fm_dateiwahl); |
|
424 |
}); |
58bcbd
|
425 |
} |
U |
426 |
}; |
|
427 |
|
|
428 |
this.fm_get_path = function (uid) { |
|
429 |
var restdir; |
|
430 |
if (self.pfad.indexOf(self.PUB_DIR) > -1) { |
|
431 |
restdir = self.pfad.substr(self.PUB_DIR.length); |
|
432 |
} else if (self.pfad.indexOf(self.PERS_DIR) > -1) { |
|
433 |
restdir = self.pfad.substr(self.PERS_DIR.length); |
|
434 |
} else if (self.pfad.indexOf(self.BASE_DIR) > -1) { |
|
435 |
restdir = self.pfad.substr(self.BASE_DIR.length); |
|
436 |
} else if (self.pfad.indexOf(self.DATA_DIR) > -1) { |
|
437 |
restdir = self.pfad.substr(self.DATA_DIR.length); |
|
438 |
} else if (self.pfad.indexOf(self.DAV_DIR) > -1) { |
|
439 |
restdir = self.pfad.substr(self.DAV_DIR.length); |
|
440 |
} |
|
441 |
if (restdir !== undefined && restdir.startsWith('/')) { |
|
442 |
restdir = restdir.substr(1); |
|
443 |
if (restdir.indexOf(self.WWW_DIR) > -1) { |
|
444 |
restdir = restdir.replace(self.WWW_DIR, 'data'); |
|
445 |
} |
|
446 |
} |
41ab37
|
447 |
var pdir = self.fm_get_base(uid); |
58bcbd
|
448 |
if (restdir.length > 1) { |
U |
449 |
return pdir + "/" + restdir; |
|
450 |
} else { |
|
451 |
return pdir; |
|
452 |
} |
|
453 |
}; |
|
454 |
|
|
455 |
this.fm_get_base = function (uid) { |
|
456 |
var pdir; |
|
457 |
if (self.pfad.indexOf(self.PUB_DIR) > -1) { |
|
458 |
pdir = '/data/' + uid; |
|
459 |
} else if (self.pfad.indexOf(self.PERS_DIR) > -1) { |
|
460 |
pdir = '/home/' + uid; |
|
461 |
} else if (self.pfad.indexOf(self.BASE_DIR) > -1) { |
|
462 |
pdir = ''; |
|
463 |
} else if (self.pfad.indexOf(self.DATA_DIR) > -1) { |
|
464 |
pdir = ''; |
|
465 |
} |
|
466 |
return pdir; |
|
467 |
}; |
2864b2
|
468 |
|
U |
469 |
/** |
|
470 |
* Aus einem relativen Pfad ein Array aus BcrFile Objekten |
|
471 |
* machen |
|
472 |
* |
|
473 |
* @param {String} relPfad der relative Pfad |
|
474 |
* @returns {Array} die BcrFile-Objekte zum Pfad als Array |
|
475 |
*/ |
|
476 |
this.fm_buildBreadcrumb = function(relPfad) { |
|
477 |
var rp = ''; |
|
478 |
var dirList = new Array(); |
|
479 |
dirList.push(new BcrFile(rp, 'Home')); |
|
480 |
if(relPfad.length > 1) { |
|
481 |
var dirs = relPfad.split('/'); |
|
482 |
for(var i = 0; i < dirs.length; i++) { |
|
483 |
if(rp.length > 0 ) { |
|
484 |
// weitere Einträge |
|
485 |
dirList.push(new BcrFile(rp + '/' + dirs[i], dirs[i])); |
|
486 |
rp = rp + '/' + dirs[i]; |
|
487 |
} else { |
|
488 |
// erster Eintrag |
|
489 |
dirList.push(new BcrFile(dirs[i], dirs[i])); |
|
490 |
rp = dirs[i]; |
|
491 |
} |
|
492 |
} |
|
493 |
} |
|
494 |
return dirList; |
|
495 |
}; |
|
496 |
|
4f01b8
|
497 |
/* |
U |
498 |
* icon-th-large |
|
499 |
* icon-th-list |
|
500 |
* @returns {undefined} |
|
501 |
*/ |
|
502 |
this.fm_ansicht_umschalten = function() { |
|
503 |
var elem = document.querySelector('#ansicht'); |
|
504 |
var iElem = elem.getElementsByTagName("i")[0]; |
|
505 |
if(iElem.classList.contains('icon-th-list')) { |
|
506 |
iElem.classList.add('icon-th-large'); |
|
507 |
iElem.classList.remove('icon-th-list'); |
|
508 |
self.modus = 'liste'; |
|
509 |
} else { |
|
510 |
iElem.classList.add('icon-th-list'); |
|
511 |
iElem.classList.remove('icon-th-large'); |
|
512 |
self.modus = 'kacheln'; |
|
513 |
} |
|
514 |
self.fm_get_list(self.pfad); |
|
515 |
}; |
|
516 |
|
|
517 |
this.fm_set_modus = function() { |
|
518 |
var elem = document.querySelector('#ansicht'); |
|
519 |
var iElem = elem.getElementsByTagName("i")[0]; |
|
520 |
if(self.modus === 'kacheln') { |
|
521 |
iElem.classList.add('icon-th-list'); |
|
522 |
iElem.classList.remove('icon-th-large'); |
|
523 |
} else { |
|
524 |
iElem.classList.add('icon-th-large'); |
|
525 |
iElem.classList.remove('icon-th-list'); |
|
526 |
} |
|
527 |
}; |
|
528 |
|
|
529 |
|
2864b2
|
530 |
/** |
U |
531 |
* Der letzte Eintrag in dirs ist der aktuelle Ordner und |
|
532 |
* deshalb ausgegraut. |
|
533 |
* |
|
534 |
* Wenn nur ein Ordner in dirs enthalten ist, dann sind wir |
|
535 |
* an der obersten Ebene (Home). |
|
536 |
* |
|
537 |
* @param {Array} dirList ein Array aus BcrFile-Objekten |
|
538 |
* @returns nichts |
|
539 |
*/ |
|
540 |
this.fm_renderBreadcrumb = function(dirList) { |
|
541 |
var elem = document.querySelector('.breadcrumb'); |
|
542 |
if(dirList.length > 1) { |
|
543 |
var last = dirList.pop(); |
|
544 |
var bcList = new BcrFiles(dirList); |
4f01b8
|
545 |
|
2864b2
|
546 |
self.html_erzeugen("data/tpl/bcr.tpl", bcList, function(html) { |
4f01b8
|
547 |
var htmlGesamt = html; |
2864b2
|
548 |
self.html_erzeugen("data/tpl/bcr2.tpl", last, function(html) { |
4f01b8
|
549 |
htmlGesamt += html; |
U |
550 |
self.html_erzeugen("data/tpl/bcr3.tpl", dirList[0], function(html) { |
|
551 |
htmlGesamt += html; |
|
552 |
elem.innerHTML = htmlGesamt; |
|
553 |
self.addEvtListener('.bc-link', 'click', self.fm_bc_click); |
|
554 |
self.addEvtListener('#ansicht', 'click', self.fm_ansicht_umschalten); |
|
555 |
self.fm_set_modus(); |
|
556 |
}); |
|
557 |
|
2864b2
|
558 |
}); |
U |
559 |
}); |
|
560 |
} else { |
|
561 |
// oberste Ebene |
4f01b8
|
562 |
var htmla; |
U |
563 |
var htmlb; |
2864b2
|
564 |
self.html_erzeugen("data/tpl/bcr2.tpl", dirList[0], function(html) { |
4f01b8
|
565 |
htmla = html; |
U |
566 |
self.html_erzeugen("data/tpl/bcr3.tpl", dirList[0], function(html) { |
|
567 |
htmlb = html; |
|
568 |
elem.innerHTML = htmla + htmlb; |
|
569 |
self.addEvtListener('.bc-link', 'click', self.fm_bc_click); |
|
570 |
self.addEvtListener('#ansicht', 'click', self.fm_ansicht_umschalten); |
|
571 |
self.fm_set_modus(); |
|
572 |
}); |
2864b2
|
573 |
}); |
U |
574 |
} |
|
575 |
}; |
|
576 |
|
|
577 |
/** |
|
578 |
* Auf den Klick auf ein Breadcrumb-Element reagieren: |
|
579 |
* Den Ordner-Inhalt des geklickten Elements anzeigen |
|
580 |
* @returns nichts |
|
581 |
*/ |
|
582 |
this.fm_bc_click = function() { |
|
583 |
var elem = this; |
|
584 |
var bcPfad = elem.getAttribute("rpath"); |
|
585 |
if(bcPfad !== undefined) { |
|
586 |
self.pfad = bcPfad; |
|
587 |
self.fm_get_list(bcPfad); |
|
588 |
} else { |
|
589 |
pfad = ''; |
|
590 |
self.fm_get_list(''); |
|
591 |
} |
|
592 |
}; |
|
593 |
|
beb124
|
594 |
/* ------- Dateifunktionen Start ----------- */ |
U |
595 |
|
|
596 |
this.fm_menu_cut = function() { |
|
597 |
console.log('fm_menu_cut'); |
|
598 |
self.fm_cut_files(); |
|
599 |
}; |
39e714
|
600 |
this.fm_menu_copy = function() { |
03be8f
|
601 |
//console.log('fm_menu_kopie'); |
beb124
|
602 |
self.fm_copy_files(); |
U |
603 |
}; |
|
604 |
this.fm_menu_paste = function() { |
|
605 |
console.log('fm_menu_paste'); |
|
606 |
self.fm_paste_files(); |
|
607 |
}; |
|
608 |
this.fm_menu_delete = function() { |
|
609 |
self.dialog_laden_und_zeigen('data/tpl/dlg-ask-del.tpl', '', function() { |
|
610 |
// wenn dialog da ist, hier events verknuepfen |
|
611 |
document.querySelector('#cancel-btn').addEventListener('click', function() { |
|
612 |
//self.fm_do_close(); |
|
613 |
self.dialog_schliessen(); |
|
614 |
}); |
|
615 |
document.querySelector('#speichern-btn').addEventListener('click', function() { |
39e714
|
616 |
//self.fm_menu_datei_speichern(function() { |
beb124
|
617 |
self.fm_del_files(); |
U |
618 |
self.dialog_schliessen(); |
39e714
|
619 |
//}); |
beb124
|
620 |
}); |
U |
621 |
}); |
|
622 |
}; |
|
623 |
|
|
624 |
/* |
|
625 |
* Hier merkt sich die Dateiverwalting die markierten Dateien fuer |
|
626 |
* eine Dateioperation. Bei cut wird in der 'paste' Operation auf dem Server |
|
627 |
* fuer die 'gemerkten' Dateien ein Move gemacht. Die Dateien werden |
|
628 |
* vom gewaehlten Ort zum Zielort verschoben. |
|
629 |
* |
|
630 |
* @returns {undefined} |
|
631 |
*/ |
|
632 |
this.fm_cut_files = function() { |
|
633 |
console.log('fm_cut_files'); |
|
634 |
self.cutCopySrcDir = self.pfad; |
|
635 |
self.cutCopyFiles = self.fm_gewaehlte_dateien(); |
|
636 |
self.cutCopyOperation = 'cut'; |
03be8f
|
637 |
self.meldung_mit_timeout('zum Ausschneiden in Zwischenablage', 1500); |
beb124
|
638 |
}; |
U |
639 |
|
|
640 |
/* |
|
641 |
* Hier merkt sich die Dateiverwalting die markierten Dateien fuer |
|
642 |
* eine Dateioperation. Bei copy wird in der 'paste' Operation auf dem Server |
|
643 |
* fuer die 'gemerkten' Dateien eine Kopie gemacht. Die Dateien werden |
|
644 |
* am gewaehlten Ort behalten und am Zielort wird eine Kopier der |
|
645 |
* gewaehlten DAteien erstellt |
|
646 |
* |
|
647 |
* @returns {undefined} |
|
648 |
*/ |
|
649 |
this.fm_copy_files = function() { |
03be8f
|
650 |
//console.log('fm_copy_files'); |
beb124
|
651 |
self.cutCopySrcDir = self.pfad; |
U |
652 |
self.cutCopyFiles = self.fm_gewaehlte_dateien(); |
|
653 |
self.cutCopyOperation = 'copy'; |
03be8f
|
654 |
self.meldung_mit_timeout('in Zwischenablage kopiert', 1500); |
beb124
|
655 |
}; |
U |
656 |
|
|
657 |
|
|
658 |
|
|
659 |
/* |
|
660 |
* Gewaehlte Dateien feststellen |
|
661 |
* |
|
662 |
* @returns {String} eine per JSON.stringify schon vorbereitete List zum |
|
663 |
* Absenden als Parameter an den Server |
|
664 |
*/ |
|
665 |
this.fm_gewaehlte_dateien = function() { |
|
666 |
var gewaehlte = document.querySelectorAll('.datei-gewaehlt'); |
|
667 |
return self.fm_dateiliste_bilden(gewaehlte); |
|
668 |
}; |
|
669 |
|
|
670 |
this.fm_dateiliste_bilden = function(gewaehlte) { |
|
671 |
var fnames = new Array(); |
|
672 |
var i = 0; |
|
673 |
while(i < gewaehlte.length) { |
|
674 |
var str = { "java.lang.String": gewaehlte[i].innerText}; |
|
675 |
fnames.push(str); |
|
676 |
//console.log('loeschen ' + pfad + ' ' + $(gewaehlte[i]).text()); |
|
677 |
//i += 2; |
|
678 |
i++; |
|
679 |
} |
|
680 |
var liste = '{"List":' + JSON.stringify(fnames) + '}'; |
|
681 |
// 'liste' enthaelt: |
|
682 |
// {"List":[{"java.lang.String":"test3.txt"},{"java.lang.String":"Test1.txt"},{"java.lang.String":"Test2.txt"}]} |
|
683 |
// und wird auf dem Server zu einer List[ArrayList<String>] bei der jede ArrayList<String> nur ein Element hat |
|
684 |
console.log(liste); |
|
685 |
return liste; |
|
686 |
}; |
|
687 |
|
98f80c
|
688 |
this.fm_menu_datei_umbenennen = function() { |
U |
689 |
//var gewaehlte = $('.datei-gewaehlt'); |
|
690 |
var gewaehlte = document.querySelector('.datei-gewaehlt'); |
|
691 |
var fname = gewaehlte.textContent; |
|
692 |
|
|
693 |
self.dialog_laden_und_zeigen('data/tpl/dlg-rename.tpl', '', function() { |
|
694 |
document.querySelector('#cancel-btn').addEventListener('click', function() { |
|
695 |
self.dialog_schliessen(); |
|
696 |
}); |
|
697 |
document.querySelector('#speichern-btn').addEventListener('click', function() { |
|
698 |
self.fm_rename_file(fname, self.pfad, document.querySelector('#datei-name-in').value); |
|
699 |
self.dialog_schliessen(); |
|
700 |
}); |
|
701 |
}); |
|
702 |
|
|
703 |
/* |
|
704 |
$('#modal_ok').click(function() { |
|
705 |
// hier umbenennen |
|
706 |
fm_rename_file(fname, pfad, $('#dateiname').val()); |
|
707 |
}); |
|
708 |
$('#saveModalTitle').text('Datei umbenennen'); |
|
709 |
$('#dialogfrage').text("Neuer Dateiname?"); |
|
710 |
|
|
711 |
if(fname !== undefined) { |
|
712 |
$('#dateiname').val(fname); |
|
713 |
$('#dateiname').attr('placeholder', 'Dateiname'); |
|
714 |
$('#saveModal').modal({ |
|
715 |
keyboard: false, |
|
716 |
show: true |
|
717 |
}); |
|
718 |
} |
|
719 |
*/ |
|
720 |
}; |
|
721 |
|
beb124
|
722 |
this.fm_menu_html_export = function() { |
U |
723 |
self.fm_export_html(); |
|
724 |
}; |
|
725 |
|
|
726 |
/* --------- Dateifunktionen Ende ---------- */ |
|
727 |
|
94b871
|
728 |
/* API functions */ |
05e9c4
|
729 |
|
94b871
|
730 |
// http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p= |
U |
731 |
this.fm_get_list = function (relPfad) { |
|
732 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPfad; |
|
733 |
var u = '../svc' + m; |
58bcbd
|
734 |
self.fm_get(u, "json", function (respText) { |
U |
735 |
var resp = JSON.parse(respText); |
94b871
|
736 |
if (resp.List[0].FileRef !== undefined) { |
U |
737 |
var files = new Array(); |
|
738 |
if (resp.List[0].FileRef instanceof Array) { |
|
739 |
for (var i = 0; i < resp.List[0].FileRef.length; i++) { |
|
740 |
files.push(new FileRef(resp.List[0].FileRef[i])); |
05e9c4
|
741 |
} |
U |
742 |
} else { |
94b871
|
743 |
files.push(new FileRef(resp.List[0].FileRef)); |
05e9c4
|
744 |
} |
94b871
|
745 |
var fl = new FileList(files); |
58bcbd
|
746 |
self.fm_render_list(fl); |
94b871
|
747 |
} else { |
58bcbd
|
748 |
// #dateien leeren |
8ba358
|
749 |
var elem = document.querySelector("#dateien"); |
U |
750 |
elem.innerHTML = ''; |
94b871
|
751 |
} |
8ba358
|
752 |
|
U |
753 |
// Breadcrumb |
|
754 |
|
2864b2
|
755 |
var dirList = self.fm_buildBreadcrumb(relPfad); |
4f01b8
|
756 |
self.fm_renderBreadcrumb(dirList); |
94b871
|
757 |
}); |
U |
758 |
}; |
f002d9
|
759 |
|
1a9589
|
760 |
this.datei_neuer_ordner = function() { |
U |
761 |
self.dialog_laden_und_zeigen('data/tpl/dlg-ask-folder.tpl', '', function() { |
|
762 |
document.querySelector('#cancel-btn').addEventListener('click', function() { |
|
763 |
self.dialog_schliessen(); |
|
764 |
}); |
|
765 |
document.querySelector('#speichern-btn').addEventListener('click', function() { |
|
766 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=newFolder&p=' + |
|
767 |
self.pfad + |
|
768 |
'&p=' + document.querySelector('#folder-name-in').value; |
|
769 |
var u = '../svc' + m; |
|
770 |
self.fm_get(u, "json", function(resp) { |
|
771 |
self.dialog_schliessen(); |
|
772 |
self.fm_get_list(self.pfad); |
|
773 |
}); |
|
774 |
}); |
|
775 |
}); |
|
776 |
}; |
03be8f
|
777 |
|
U |
778 |
this.fm_open_file = function() { |
|
779 |
var gewaehlte = document.querySelector('.datei-gewaehlt'); |
|
780 |
var fname = gewaehlte.textContent; |
|
781 |
if(fname.endsWith('htmi')) { |
|
782 |
//self.fm_edit_as_doc(); |
|
783 |
self.fm_get_file_content('doc', fname); |
|
784 |
} else { |
|
785 |
//self.fm_edit_as_text(); |
|
786 |
self.fm_get_file_content('text', fname); |
|
787 |
} |
|
788 |
}; |
1a9589
|
789 |
|
03be8f
|
790 |
/* |
ebc1f3
|
791 |
this.fm_edit_as_text = function() { |
0783c5
|
792 |
self.fm_get_sel_for_file_content('text'); |
4e450e
|
793 |
}; |
U |
794 |
|
|
795 |
this.fm_edit_as_doc = function() { |
0783c5
|
796 |
self.fm_get_sel_for_file_content('doc'); |
ebc1f3
|
797 |
}; |
U |
798 |
|
98f80c
|
799 |
this.fm_get_sel_for_file_content = function(typ) { |
f002d9
|
800 |
var gewaehlte = document.querySelector('.datei-gewaehlt'); |
U |
801 |
//var fname = $(gewaehlte).find('.dateiname').text(); |
|
802 |
|
|
803 |
var fname = gewaehlte.textContent; |
0783c5
|
804 |
self.fm_get_file_content(typ, fname); |
U |
805 |
}; |
03be8f
|
806 |
*/ |
0783c5
|
807 |
|
U |
808 |
this.fm_get_file_content = function(typ, fname) { |
|
809 |
//var gewaehlte = document.querySelector('.datei-gewaehlt'); |
|
810 |
//var fname = $(gewaehlte).find('.dateiname').text(); |
|
811 |
|
|
812 |
//var fname = gewaehlte.textContent; |
ebc1f3
|
813 |
//console.log('fname: ' + fname); |
f002d9
|
814 |
self.openFileName = fname; |
U |
815 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=getCode&p=' + self.pfad + '&p=' + fname; |
|
816 |
var u = '../svc' + m; |
|
817 |
self.fm_get(u, "text", function(resp) { |
|
818 |
if(typ === 'text') { |
|
819 |
var mode = "text/x-java"; |
|
820 |
if(fname.endsWith('js')) { |
|
821 |
mode = 'javascript'; |
|
822 |
} else if(fname.endsWith('xml')) { |
|
823 |
mode = 'xml'; |
|
824 |
} else if(fname.endsWith('properties')) { |
|
825 |
mode = 'xml'; |
|
826 |
} else if(fname.endsWith('adoc')) { |
|
827 |
mode = 'text/x-markdown'; |
|
828 |
} |
|
829 |
self.fm_text_edit(resp, mode); |
|
830 |
} else { |
|
831 |
self.fm_dok_edit(resp); |
|
832 |
} |
|
833 |
}); |
|
834 |
}; |
|
835 |
|
ebc1f3
|
836 |
this.fm_save_file = function(saveFileName, method, callback) { |
U |
837 |
var content; |
|
838 |
if(self.openEditor === 'text') { |
|
839 |
content = self.cm.getValue(); |
|
840 |
self.cm.getDoc().markClean(); |
|
841 |
} else { |
4e450e
|
842 |
content = self.ed.getContent(); |
ebc1f3
|
843 |
tinymce.activeEditor.undoManager.clear(); |
U |
844 |
} |
|
845 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=' + method; |
5b4d03
|
846 |
var u = '../svc' + m; |
c79727
|
847 |
//var data = '&p=' + self.pfad + '&p=' + saveFileName + '&p=' + |
U |
848 |
// encodeURIComponent(content); |
|
849 |
var data = '&p=' + self.pfad + '&p=' + saveFileName + '&p=' + |
|
850 |
encodeURIComponent(content); |
|
851 |
// '{"foo": "bar"}' |
|
852 |
|
|
853 |
//var data = '{"p1": "' + self.pfad + '", "p2": "' + saveFileName + |
|
854 |
// '", "p3": "' + encodeURIComponent(self.escapeHtml(content)) + '"}'; |
5b4d03
|
855 |
self.fm_post(u, data, "text", function(resp) { |
U |
856 |
// ... |
ebc1f3
|
857 |
}); |
U |
858 |
self.openFileName = saveFileName; |
|
859 |
if(typeof (callback) !== 'function') { |
|
860 |
|
|
861 |
} else { |
|
862 |
callback(); |
|
863 |
} |
|
864 |
}; |
|
865 |
|
beb124
|
866 |
/* |
U |
867 |
* Hier wird fuer eine zuvor markierte Liste von Dateien, fuer die |
|
868 |
* Cut oder Copy gewaehlt wurde, die Operations ausgefuehrt (move oder copy) |
|
869 |
* @returns {undefined} |
|
870 |
*/ |
|
871 |
this.fm_paste_files = function() { |
|
872 |
var m; |
|
873 |
if(self.cutCopyOperation === 'cut') { |
|
874 |
//m = '?c=de.uhilger.filecms.api.FileMgr&m=moveFiles'; //&p=' + cutCopySrcDir + '&p=' + pfad + '&p=' + encodeURIComponent(liste); |
|
875 |
m = '?c=de.uhilger.filecms.api.FileMgr&m=moveFiles&p=' + self.cutCopySrcDir + '&p=' + self.pfad + '&p=' + encodeURIComponent(self.cutCopyFiles); |
|
876 |
} else { |
|
877 |
//m = '?c=de.uhilger.filecms.api.FileMgr&m=copyFiles'; //&p=' + cutCopySrcDir + '&p=' + pfad + '&p=' + encodeURIComponent(liste); |
|
878 |
m = '?c=de.uhilger.filecms.api.FileMgr&m=copyFiles&p=' + self.cutCopySrcDir + '&p=' + self.pfad + '&p=' + encodeURIComponent(self.cutCopyFiles); |
|
879 |
} |
|
880 |
var u = '../svc' + m; |
|
881 |
self.fm_get(u, "text", function(resp) { |
|
882 |
// console.log('deleteFiles gab folgendes zurueck: ' + resp); |
|
883 |
self.fm_get_list(self.pfad); |
|
884 |
}); |
|
885 |
}; |
ebc1f3
|
886 |
|
beb124
|
887 |
this.fm_del_files = function() { |
U |
888 |
var liste = self.fm_gewaehlte_dateien(); |
|
889 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=deleteFiles&p=' + self.pfad + '&p=' + encodeURIComponent(liste); |
|
890 |
var u = '../svc' + m; |
|
891 |
self.fm_get(u, "text", function(resp) { |
|
892 |
// console.log('deleteFiles gab folgendes zurueck: ' + resp); |
|
893 |
self.fm_get_list(self.pfad); |
|
894 |
}); |
|
895 |
}; |
f002d9
|
896 |
|
98f80c
|
897 |
this.fm_rename_file = function(fn, p, neuerName) { |
U |
898 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=renameFile'; |
|
899 |
m = m + '&p=' + p; |
|
900 |
m = m + '&p=' + fn; |
|
901 |
m = m + '&p=' + neuerName; |
|
902 |
var u = '../svc' + m; |
|
903 |
self.fm_get(u, "text", function(resp) { |
|
904 |
self.fm_get_list(self.pfad); |
|
905 |
}); |
|
906 |
}; |
|
907 |
|
f002d9
|
908 |
/* ---- codemirror editor handling -------- */ |
U |
909 |
|
|
910 |
/* |
|
911 |
function htmlDecode(value){ |
|
912 |
return $('<div/>').html(value).text(); |
|
913 |
} |
|
914 |
*/ |
|
915 |
|
|
916 |
this.fm_code_edit = function(content, m) { |
ebc1f3
|
917 |
//console.log('fm_code_edit content: ' + content.substring(0,30)); |
U |
918 |
self.cm = CodeMirror.fromTextArea(document.getElementById("editspace"), { |
f002d9
|
919 |
lineNumbers: true, |
U |
920 |
lineWrapping: true, |
|
921 |
gutters: ["CodeMirror-linenumbers", "breakpoints"], |
|
922 |
mode: m, |
|
923 |
viewportMargin : Infinity, |
|
924 |
tabSize: 2, |
|
925 |
extraKeys: { |
|
926 |
"F9": function(cm) { |
|
927 |
cm.setOption("fullScreen", !cm.getOption("fullScreen")); |
|
928 |
}, |
|
929 |
"Esc": function(cm) { |
|
930 |
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); |
|
931 |
}, |
|
932 |
".": function(cm) { |
|
933 |
console.log('dot pressed: perhaps look up class or method name'); |
|
934 |
/* |
|
935 |
* Hier kann man eine Funktion ausloesen, die fuer das |
|
936 |
* Wort vor dem Punkt (Name der Klasse) eine Liste mit |
|
937 |
* Vorschlaegen fuer Methodennamen einblendet. |
|
938 |
*/ |
|
939 |
|
|
940 |
/* |
|
941 |
* CodeMirror.Pass laesst das Zeichen zum Editorinhalt durch, |
|
942 |
* verhindert aber das Ausloesen von 'keyHandled' |
|
943 |
*/ |
|
944 |
return CodeMirror.Pass; |
|
945 |
} |
|
946 |
} |
|
947 |
}); |
|
948 |
//cm.setValue(htmlDecode(content)); |
c79727
|
949 |
//self.cm.setValue(content); |
ebc1f3
|
950 |
self.cm.setValue(self.unescapeHtml(content)); |
U |
951 |
self.cm.getDoc().markClean(); |
|
952 |
self.cm.on("gutterClick", function(theEditor, lineNumber) { |
f002d9
|
953 |
var info = theEditor.lineInfo(lineNumber); |
U |
954 |
//--lineNumber; |
|
955 |
//console.log(info.gutterMarkers.breakpoints.message); |
|
956 |
//var marker = info.gutterMarkers.breakpoints; |
|
957 |
//$(marker).tooltip('toggle'); |
|
958 |
}); |
|
959 |
/* |
|
960 |
cm.on("keyHandled", function(theEditor, keyName, event){ |
|
961 |
console.log('cm.keyHandled keyName: ' + keyName + ', event.type: ' + event.type); |
|
962 |
}); |
|
963 |
*/ |
|
964 |
}; |
|
965 |
|
|
966 |
this.makeMarker = function(msg) { |
|
967 |
var marker = document.createElement("div"); |
|
968 |
marker.style.color = "#822"; |
|
969 |
marker.innerHTML = "●"; |
|
970 |
//marker.message = msg; |
|
971 |
$(marker).tooltip({ |
|
972 |
placement: 'right', |
|
973 |
title: msg, |
|
974 |
offset: '0 -30' |
|
975 |
}); |
|
976 |
return marker; |
|
977 |
}; |
|
978 |
|
4e450e
|
979 |
/* ---- TinyMCE editor handling -------- */ |
U |
980 |
|
|
981 |
this.fm_dok_editor_init = function(uid) { |
|
982 |
var base = self.fm_get_path(uid); |
|
983 |
//var edCount = 0; |
|
984 |
//console.log("fm_dok_editor_init calling tinymce.init with base: " + base + "/"); |
|
985 |
|
|
986 |
/* |
|
987 |
* vgl. |
|
988 |
* http://stackoverflow.com/questions/4651676/how-do-i-remove-tinymce-and-then-re-add-it |
|
989 |
*/ |
|
990 |
//tinymce.EditorManager.execCommand('mceRemoveControl',true, 'textarea.text-editor'); |
|
991 |
//tinymce.EditorManager.execCommand('mceAddControl',true, editor_id); |
|
992 |
if(self.ed !== undefined) { |
|
993 |
self.ed.destroy(); |
|
994 |
} |
|
995 |
if(tinymce !== undefined) { |
|
996 |
tinymce.remove('textarea.text-editor'); |
|
997 |
tinymce.EditorManager.editors = []; |
|
998 |
} |
|
999 |
|
|
1000 |
/* |
|
1001 |
* Konfiguration TinyMCE |
|
1002 |
*/ |
|
1003 |
tinymce.init({ |
|
1004 |
content_css : "/file-cms/ui/mce.css", |
|
1005 |
//content_css: "/jslib/bootstrap/css/bootstrap.min.css", |
|
1006 |
selector: "textarea.text-editor", |
|
1007 |
statusbar: false, |
|
1008 |
menubar: false, |
|
1009 |
plugins: 'advlist charmap code image link lists media table print preview save table textcolor importcss', |
|
1010 |
toolbar: 'undo redo | styleselect | image table | link unlink | bullist numlist | outdent indent | code', |
|
1011 |
/* |
|
1012 |
menu: { |
|
1013 |
file: {title: 'File', items: 'savevers | exit'}, |
|
1014 |
edit: {title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall'}, |
|
1015 |
view: {title: 'View', items: 'visualaid | code | link image media | template hr'}, |
|
1016 |
}, |
|
1017 |
*/ |
|
1018 |
resize: 'both', |
|
1019 |
importcss_append: true, |
|
1020 |
width: "100%", |
|
1021 |
height: '100%', |
|
1022 |
relative_urls : true, |
|
1023 |
convert_urls : false, |
|
1024 |
document_base_url : base + "/", |
|
1025 |
setup: function (editor) { |
|
1026 |
self.ed = editor; |
|
1027 |
} |
|
1028 |
}); |
|
1029 |
|
|
1030 |
window.addEventListener('resize', self.fm_resize_editor); |
|
1031 |
//$(window).on('resize', self.fm_resize_editor); |
|
1032 |
self.fm_resize_editor(); |
|
1033 |
}; |
|
1034 |
|
|
1035 |
this.fm_resize_editor = function() { |
|
1036 |
window.clearTimeout(self.tmo); |
|
1037 |
self.tmo = window.setTimeout(function () { |
|
1038 |
try { |
|
1039 |
var myHeight = document.querySelector('.inhalt').offsetHeight - |
|
1040 |
document.querySelector('.nord').offsetHeight + 2; // - 4; |
|
1041 |
//console.log('myHeight: ' + myHeight); |
|
1042 |
self.ed.theme.resizeTo('100%', myHeight); // sets the dimensions of the editable area |
|
1043 |
} catch (err) { |
|
1044 |
} |
|
1045 |
}, 200); |
|
1046 |
}; |
|
1047 |
|
|
1048 |
|
f002d9
|
1049 |
|
U |
1050 |
/* -------- Editoren --------- */ |
|
1051 |
|
|
1052 |
this.fm_text_edit = function(content, mode) { |
|
1053 |
document.querySelector(".codeeditor-space").style.display = "block"; |
5b4d03
|
1054 |
//document.querySelector(".code-editor-container").style.display = "block"; |
U |
1055 |
//document.querySelector(".zentrum-behaelter").style.display = "none"; |
|
1056 |
document.querySelector(".breadcrumb").style.display = "none"; |
|
1057 |
document.querySelector(".zentrum").style.display = "none"; |
f002d9
|
1058 |
self.fm_code_edit(content, mode); |
U |
1059 |
self.openEditor = 'text'; |
|
1060 |
}; |
|
1061 |
|
|
1062 |
this.fm_dok_edit = function(content) { |
|
1063 |
//fm_filectls_hide(); |
4e450e
|
1064 |
self.fm_dok_editor_init(self.userid); |
U |
1065 |
document.querySelector("#mce-editor").style.display = "block"; |
|
1066 |
//$("#mce-editor").show(); |
|
1067 |
document.querySelector(".breadcrumb").style.display = "none"; |
|
1068 |
document.querySelector(".zentrum").style.display = "none"; |
f002d9
|
1069 |
|
4e450e
|
1070 |
window.clearTimeout(self.tmo2); |
U |
1071 |
self.tmo2 = window.setTimeout(function () { |
f002d9
|
1072 |
try { |
4e450e
|
1073 |
self.ed.setContent(content); |
U |
1074 |
self.openEditor = 'dok'; |
f002d9
|
1075 |
} catch (err) { |
U |
1076 |
} |
|
1077 |
}, 200); |
|
1078 |
}; |
ebc1f3
|
1079 |
|
U |
1080 |
this.fm_do_close = function() { |
|
1081 |
document.querySelector(".codeeditor-space").style.display = "none"; |
4e450e
|
1082 |
document.querySelector("#mce-editor").style.display = "none"; |
U |
1083 |
// $("#mce-editor").hide(); |
5b4d03
|
1084 |
//document.querySelector(".code-editor-container").style.display = "none"; |
U |
1085 |
//document.querySelector(".zentrum-behaelter").style.display = "block"; |
|
1086 |
document.querySelector(".breadcrumb").style.display = "block"; |
|
1087 |
document.querySelector(".zentrum").style.display = "block"; |
ebc1f3
|
1088 |
if(self.cm !== undefined) { |
U |
1089 |
self.cm.toTextArea(); |
|
1090 |
} |
|
1091 |
self.openFileName = ''; |
|
1092 |
self.openEditor = ''; |
|
1093 |
self.fm_get_list(self.pfad); |
|
1094 |
}; |
05e9c4
|
1095 |
|
94b871
|
1096 |
/* -------- An- und Abmelden ------------- */ |
05e9c4
|
1097 |
|
94b871
|
1098 |
this.fm_get_login = function() { |
U |
1099 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=getSessionUser'; |
|
1100 |
var u = '../pub' + m; |
|
1101 |
self.fm_get(u, "text", function (resp) { |
|
1102 |
self.userid = resp; |
58bcbd
|
1103 |
self.login_zeigen(); |
U |
1104 |
//document.querySelector("#userMenu").textContent = resp; |
94b871
|
1105 |
}); |
U |
1106 |
}; |
05e9c4
|
1107 |
|
94b871
|
1108 |
this.fm_logout = function() { |
U |
1109 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession'; |
|
1110 |
var u = '../pub' + m; |
|
1111 |
self.fm_get(u, "text", function (resp) { |
|
1112 |
//$('#userMenu').text('nicht angemeldet'); |
|
1113 |
window.location.href = '../logout.html'; |
|
1114 |
}); |
|
1115 |
}; |
41ab37
|
1116 |
|
6648a8
|
1117 |
/* ----- Hilfsfunktionen ----- */ |
U |
1118 |
|
|
1119 |
this.serialisieren = function(obj) { |
|
1120 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
|
1121 |
}; |
|
1122 |
|
|
1123 |
this.addEvtListener = function(selector, eventName, func) { |
|
1124 |
document.querySelectorAll(selector).forEach(elem => { elem.addEventListener(eventName, func); }); |
|
1125 |
}; |
|
1126 |
|
|
1127 |
this.removeAllListeners = function(id) { |
|
1128 |
var el = document.getElementById(id); |
5b4d03
|
1129 |
if(el !== null) { |
U |
1130 |
elClone = el.cloneNode(true); |
|
1131 |
el.parentNode.replaceChild(elClone, el); |
|
1132 |
} |
6648a8
|
1133 |
}; // https://stackoverflow.com/questions/19469881/remove-all-event-listeners-of-specific-type |
U |
1134 |
|
ebc1f3
|
1135 |
this.escapeHtml = function(text) { |
U |
1136 |
text = text.replace(/\u228/g,'ä'); |
|
1137 |
text = text.replace(/\u246/g,'ö'); |
|
1138 |
text = text.replace(/\u252/g,'ü'); |
|
1139 |
text = text.replace(/\u196/g,'Ä'); |
|
1140 |
text = text.replace(/\u214/g,'Ö'); |
|
1141 |
text = text.replace(/\u220/g,'Ü'); |
|
1142 |
text = text.replace(/\u223/g,'ß'); |
|
1143 |
text = text.replace(/\u26/g,'&'); |
|
1144 |
return text; |
|
1145 |
}; |
|
1146 |
|
|
1147 |
this.unescapeHtml = function(text) { |
|
1148 |
text = text.replace(/ä/g, String.fromCharCode(228)); |
|
1149 |
text = text.replace(/ö/g, String.fromCharCode(246)); |
|
1150 |
text = text.replace(/ü/g, String.fromCharCode(252)); |
|
1151 |
text = text.replace(/Ä/g, String.fromCharCode(196)); |
|
1152 |
text = text.replace(/Ö/g, String.fromCharCode(214)); |
|
1153 |
text = text.replace(/Ü/g, String.fromCharCode(220)); |
|
1154 |
text = text.replace(/ß/g, String.fromCharCode(223)); |
|
1155 |
text = text.replace(/&/g, String.fromCharCode(26)); |
|
1156 |
return text; |
|
1157 |
}; |
|
1158 |
|
41ab37
|
1159 |
/* ---- Vorlagen ---- */ |
U |
1160 |
|
|
1161 |
this.html_erzeugen = function(vurl, inhalt, cb) { |
|
1162 |
var vorlage = self.cache[vurl]; |
|
1163 |
if(vorlage === undefined) { |
|
1164 |
self.vorlage_laden_und_fuellen(vurl, inhalt, cb); |
|
1165 |
} else { |
|
1166 |
self.vorlage_fuellen(vurl, inhalt, cb); |
|
1167 |
} |
|
1168 |
}; |
|
1169 |
|
|
1170 |
this.vorlage_fuellen = function(vurl, inhalt, cb) { |
|
1171 |
cb(Mustache.render(self.cache[vurl], inhalt)); |
|
1172 |
}; |
|
1173 |
|
|
1174 |
this.vorlage_laden_und_fuellen = function(vurl, inhalt, cb) { |
|
1175 |
self.fm_get(vurl, "text", function(antwort) { |
|
1176 |
self.cache[vurl] = antwort; |
|
1177 |
self.vorlage_fuellen(vurl, inhalt, cb); |
|
1178 |
}); |
|
1179 |
}; |
94b871
|
1180 |
|
U |
1181 |
/* -------- ajax helper functions ----------- */ |
|
1182 |
|
58bcbd
|
1183 |
this.fm_get = function (u, dtype, scallback) { |
U |
1184 |
var xmlhttp = new XMLHttpRequest(); |
|
1185 |
var url = u; |
|
1186 |
xmlhttp.onreadystatechange = function() { |
5b4d03
|
1187 |
if (this.readyState === 4 && this.status === 200) { |
58bcbd
|
1188 |
scallback(this.responseText); |
94b871
|
1189 |
} |
58bcbd
|
1190 |
}; |
U |
1191 |
xmlhttp.open("GET", url, true); |
|
1192 |
xmlhttp.send(); |
94b871
|
1193 |
}; |
ebc1f3
|
1194 |
|
U |
1195 |
self.fm_post = function(u, d, dtype, scallback) { |
|
1196 |
var xmlhttp = new XMLHttpRequest(); |
|
1197 |
var url = u; |
|
1198 |
xmlhttp.onreadystatechange = function() { |
5b4d03
|
1199 |
if (this.readyState === 4 && this.status === 200) { |
ebc1f3
|
1200 |
scallback(this.responseText); |
U |
1201 |
} |
|
1202 |
}; |
|
1203 |
xmlhttp.open("POST", url, true); |
c79727
|
1204 |
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8'); |
5b4d03
|
1205 |
xmlhttp.send(d); |
ebc1f3
|
1206 |
}; |
U |
1207 |
|
5b4d03
|
1208 |
/* |
ebc1f3
|
1209 |
this.http_get = function(u, cb) { |
U |
1210 |
self.http_call('GET', u, null, cb); |
|
1211 |
}; |
|
1212 |
|
|
1213 |
this.http_post = function(u, data, cb) { |
|
1214 |
self.http_call('POST', u, data, cb); |
|
1215 |
}; |
|
1216 |
|
|
1217 |
this.http_call = function (method, u, data, scallback) { |
|
1218 |
var xhr = new XMLHttpRequest(); |
|
1219 |
var url = u; |
|
1220 |
xhr.onreadystatechange = function() { |
|
1221 |
if (this.readyState === 4 && this.status === 200) { |
|
1222 |
scallback(this.responseText); |
|
1223 |
} |
|
1224 |
}; |
5b4d03
|
1225 |
xhr.open(method, url, false); |
ebc1f3
|
1226 |
if(method === 'GET') { |
U |
1227 |
xhr.send(); |
|
1228 |
} else if(method === 'POST' || method === 'PUT') { |
|
1229 |
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
|
1230 |
xhr.send(data); |
|
1231 |
} |
|
1232 |
}; |
5b4d03
|
1233 |
*/ |
ebc1f3
|
1234 |
|
94b871
|
1235 |
|
05e9c4
|
1236 |
} |