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