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