commit | author | age
|
a4d3b5
|
1 |
var cm; |
5dfab6
|
2 |
var pfad = ''; |
10d3d3
|
3 |
var modus = 'kacheln'; |
c7c502
|
4 |
|
U |
5 |
function fm_init() { |
a4d3b5
|
6 |
$('.codeeditor-space').hide(); |
U |
7 |
$('.code-editor-container').hide(); |
|
8 |
$('#newTextFile').on('click', fm_menu_neue_textdatei); |
adf812
|
9 |
$('#newFolder').on('click', fm_get_new_folder); |
3ad4db
|
10 |
$('#editTextFile').on('click', fm_get_file_content); |
e5ff42
|
11 |
$('#saveFile').on('click', fm_menu_datei_speichern); |
a4d3b5
|
12 |
$('#closeFile').on('click', fm_menu_datei_schliessen); |
c509a0
|
13 |
$('#saveModal').on('hidden.bs.modal', function (e) { |
915927
|
14 |
$('#modal_ok').attr('onclick','').unbind('click'); |
b7475d
|
15 |
}); |
U |
16 |
$('#logout').click(fm_logout); |
e5ff42
|
17 |
fm_get_login(); |
7342b1
|
18 |
fm_get_list(''); |
10d3d3
|
19 |
} |
U |
20 |
|
|
21 |
function fm_ansicht_umschalten() { |
|
22 |
if($('#ansicht').children(0).hasClass('fa-th-list')) { |
|
23 |
$('#ansicht').children(0).addClass('fa-th-large'); |
|
24 |
$('#ansicht').children(0).removeClass('fa-th-list'); |
|
25 |
modus = 'liste'; |
|
26 |
} else { |
|
27 |
$('#ansicht').children(0).addClass('fa-th-list'); |
|
28 |
$('#ansicht').children(0).removeClass('fa-th-large'); |
|
29 |
modus = 'kacheln'; |
|
30 |
} |
|
31 |
fm_get_list(pfad); |
|
32 |
} |
|
33 |
|
|
34 |
function fm_set_modus() { |
|
35 |
if(modus == 'kacheln') { |
|
36 |
$('#ansicht').children(0).addClass('fa-th-list'); |
|
37 |
$('#ansicht').children(0).removeClass('fa-th-large'); |
|
38 |
} else { |
|
39 |
$('#ansicht').children(0).addClass('fa-th-large'); |
|
40 |
$('#ansicht').children(0).removeClass('fa-th-list'); |
|
41 |
} |
a4d3b5
|
42 |
} |
U |
43 |
|
|
44 |
function fm_menu_neue_textdatei() { |
adf812
|
45 |
fm_text_edit('Neue Datei'); |
a4d3b5
|
46 |
} |
U |
47 |
|
|
48 |
function fm_menu_datei_schliessen() { |
|
49 |
$('.codeeditor-space').hide(); |
|
50 |
$('.code-editor-container').hide(); |
|
51 |
cm.toTextArea(); |
f5505f
|
52 |
$('#bcnav').show(); |
U |
53 |
$('#dateien').show(); |
adf812
|
54 |
fm_get_list(pfad); |
e5ff42
|
55 |
} |
U |
56 |
|
5dfab6
|
57 |
function fm_dateiwahl() { |
U |
58 |
var elem = this; |
10d3d3
|
59 |
if(modus == 'kacheln') { |
U |
60 |
if($(elem).children(0).hasClass('fa-folder')) { |
|
61 |
var ordner = $(elem).text().trim(); |
|
62 |
if(pfad.length > 0) { |
|
63 |
pfad = pfad + '/' + ordner; |
|
64 |
} else { |
|
65 |
pfad = ordner; |
|
66 |
} |
|
67 |
fm_get_list(pfad); |
|
68 |
} else if($(elem).children(0).hasClass('fa-file')) { |
|
69 |
$('.datei-gewaehlt').removeClass('datei-gewaehlt'); |
|
70 |
$(elem).children(0).addClass('datei-gewaehlt'); |
5dfab6
|
71 |
} else { |
10d3d3
|
72 |
//console.log('kein folder oder file...'); |
5dfab6
|
73 |
} |
U |
74 |
} else { |
10d3d3
|
75 |
if($(elem).find('.datei-elem').children(0).hasClass('fa-file-o')) { |
U |
76 |
$('.table-info').removeClass('table-info'); |
|
77 |
$(elem).addClass('table-info'); |
|
78 |
$('.datei-gewaehlt').removeClass('datei-gewaehlt'); |
|
79 |
$(elem).find('.dateiname').addClass('datei-gewaehlt'); |
|
80 |
} else { |
|
81 |
var ordner = $(elem).find('.dateiname').text(); |
|
82 |
if(pfad.length > 0) { |
|
83 |
pfad = pfad + '/' + ordner; |
|
84 |
} else { |
|
85 |
pfad = ordner; |
|
86 |
} |
|
87 |
fm_get_list(pfad); |
|
88 |
} |
5dfab6
|
89 |
} |
c509a0
|
90 |
} |
U |
91 |
|
a94216
|
92 |
function fm_bc_click() { |
U |
93 |
var elem = this; |
|
94 |
var bcPfad = $(elem).attr('rpath'); |
|
95 |
if(bcPfad !== undefined) { |
c509a0
|
96 |
pfad = bcPfad; |
a94216
|
97 |
fm_get_list(bcPfad); |
U |
98 |
} else { |
|
99 |
pfad = ''; |
|
100 |
fm_get_list(''); |
|
101 |
} |
|
102 |
} |
|
103 |
|
3ad4db
|
104 |
function fm_text_edit(content) { |
f5505f
|
105 |
$('#bcnav').hide(); |
U |
106 |
$('#dateien').hide(); |
3ad4db
|
107 |
$('.codeeditor-space').show(); |
U |
108 |
$('.code-editor-container').show(); |
|
109 |
fm_code_edit(content); |
|
110 |
} |
|
111 |
|
b7475d
|
112 |
/* ----- API Calls ------------- */ |
U |
113 |
|
e5ff42
|
114 |
function fm_get_login() { |
3ad4db
|
115 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=getSessionUser'; |
U |
116 |
var u = '../pub' + m; |
|
117 |
fm_get(u, "text", function(resp) { |
|
118 |
$('#userMenu').text(resp); |
7342b1
|
119 |
}); |
c509a0
|
120 |
} |
U |
121 |
|
|
122 |
function fm_get_new_folder() { |
|
123 |
$('#modal_ok').click(function() { |
|
124 |
// hier speichern |
|
125 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=newFolder&p=' + pfad + '&p=' + $('#dateiname').val(); |
|
126 |
var u = '../svc' + m; |
|
127 |
fm_get(u, "json", function(resp) { |
adf812
|
128 |
fm_get_list(pfad); |
c509a0
|
129 |
}); |
U |
130 |
}); |
|
131 |
$('.modal-title').text('Neuer Ordner'); |
|
132 |
$('#dialogfrage').text("Name?"); |
|
133 |
$('#dateiname').val(''); |
|
134 |
$('#dateiname').attr('placeholder', 'Ordnername'); |
|
135 |
$('#saveModal').modal({ |
|
136 |
keyboard: false, |
|
137 |
show: true |
|
138 |
}); |
7342b1
|
139 |
} |
U |
140 |
|
2121cc
|
141 |
function fm_get_file_content() { |
U |
142 |
var fname = $('.datei-gewaehlt').text(); |
3ad4db
|
143 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=getCode&p=' + pfad + '&p=' + fname; |
2121cc
|
144 |
var u = '../svc' + m; |
3ad4db
|
145 |
fm_get(u, "text", function(resp) { |
U |
146 |
fm_text_edit(resp); |
2121cc
|
147 |
}); |
3ad4db
|
148 |
|
2121cc
|
149 |
} |
U |
150 |
|
10d3d3
|
151 |
function fm_render_list(fl) { |
U |
152 |
if(modus == 'kacheln') { |
|
153 |
// Kachelansicht |
|
154 |
var template = $('#tpl-kacheln').html(); |
|
155 |
Mustache.parse(template); // optional, speeds up future uses |
|
156 |
$('.datei-zeile').attr('onclick','').unbind('click'); |
|
157 |
$('#dateien').empty(); |
|
158 |
$('#dateien').html(Mustache.render(template, fl)); |
|
159 |
$('.figure').click(fm_dateiwahl); |
|
160 |
} else { |
|
161 |
// Listenansicht |
|
162 |
var template = $('#tpl-liste').html(); |
|
163 |
Mustache.parse(template); // optional, speeds up future uses |
|
164 |
$('.figure').attr('onclick','').unbind('click'); |
|
165 |
$('#dateien').empty(); |
|
166 |
$('#dateien').html(Mustache.render(template, fl)); |
|
167 |
$('.datei-zeile').click(fm_dateiwahl); |
|
168 |
} |
|
169 |
} |
|
170 |
|
7342b1
|
171 |
// http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p= |
a94216
|
172 |
function fm_get_list(relPfad) { |
10d3d3
|
173 |
$('#ansicht').attr('onclick','').unbind('click'); |
a94216
|
174 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPfad; |
7342b1
|
175 |
var u = '../svc' + m; |
U |
176 |
fm_get(u, "json", function(resp) { |
10d3d3
|
177 |
|
2121cc
|
178 |
if(resp.List[0].FileRef !== undefined) { |
U |
179 |
var files = new Array(); |
c509a0
|
180 |
if(resp.List[0].FileRef instanceof Array) { |
U |
181 |
for(var i = 0; i < resp.List[0].FileRef.length; i++) { |
|
182 |
files.push(new FileRef(resp.List[0].FileRef[i])); |
|
183 |
} |
|
184 |
} else { |
|
185 |
files.push(new FileRef(resp.List[0].FileRef)); |
2121cc
|
186 |
} |
U |
187 |
var fl = new FileList(files); |
10d3d3
|
188 |
fm_render_list(fl); |
2121cc
|
189 |
} else { |
U |
190 |
$('#dateien').empty(); |
7342b1
|
191 |
} |
5dfab6
|
192 |
|
10d3d3
|
193 |
// Breadcrumb-Ansicht |
2315a0
|
194 |
var template; |
a94216
|
195 |
$('.breadcrumb-item').attr('onclick','').unbind('click'); |
2315a0
|
196 |
$('#bcnav').empty(); |
5dfab6
|
197 |
var dirList = new Array(); |
U |
198 |
var rp = ''; |
a94216
|
199 |
//console.log("'" + relPfad + "'"); |
U |
200 |
var dirs = relPfad.split('/'); |
|
201 |
//console.log(dirs.length); |
2121cc
|
202 |
dirList.push(new BcrFile(rp, 'Home')); |
a94216
|
203 |
if(relPfad.length > 0) { |
2315a0
|
204 |
for(var i = 0; i < dirs.length - 1; i++) { |
5dfab6
|
205 |
if(rp.length > 0 ) { |
U |
206 |
dirList.push(new BcrFile(rp + '/' + dirs[i], dirs[i])); |
2315a0
|
207 |
rp = rp + '/' + dirs[i]; |
5dfab6
|
208 |
} else { |
U |
209 |
dirList.push(new BcrFile(dirs[i], dirs[i])); |
2315a0
|
210 |
rp = dirs[i]; |
5dfab6
|
211 |
} |
U |
212 |
} |
|
213 |
var bl = new BcrFiles(dirList); |
2315a0
|
214 |
|
U |
215 |
if(dirList.length > 0) { |
|
216 |
template = $('#tpl-bcr').html(); |
|
217 |
Mustache.parse(template); // optional, speeds up future uses |
|
218 |
$('#bcnav').html(Mustache.render(template, bl)); |
|
219 |
} |
|
220 |
|
|
221 |
if(dirs.length > 0) { |
|
222 |
dirList.push(new BcrFile(rp + '/' + dirs[dirs.length-1], dirs[dirs.length-1])); |
|
223 |
template = $('#tpl-bcr2').html(); |
|
224 |
Mustache.parse(template); // optional, speeds up future uses |
|
225 |
$('#bcnav').append(Mustache.render(template, dirList[dirList.length-1])); |
|
226 |
} else { |
|
227 |
template = $('#tpl-bcr2').html(); |
|
228 |
Mustache.parse(template); // optional, speeds up future uses |
|
229 |
$('#bcnav').append(Mustache.render(template, dirList[0])); |
|
230 |
} |
|
231 |
|
5dfab6
|
232 |
$('#bcnav').append($('#tpl-bcr3').html()); |
2315a0
|
233 |
} else { |
a94216
|
234 |
pfad = ''; |
2315a0
|
235 |
template = $('#tpl-bcr2').html(); |
U |
236 |
Mustache.parse(template); // optional, speeds up future uses |
10d3d3
|
237 |
$('#bcnav').append(Mustache.render(template, dirList[0])); |
U |
238 |
$('#bcnav').append($('#tpl-bcr3').html()); |
5dfab6
|
239 |
} |
a94216
|
240 |
$('.breadcrumb-item').click(fm_bc_click); |
10d3d3
|
241 |
$('#ansicht').click(fm_ansicht_umschalten); |
U |
242 |
fm_set_modus(); |
e5ff42
|
243 |
}); |
U |
244 |
} |
|
245 |
|
|
246 |
function fm_menu_datei_speichern() { |
|
247 |
|
915927
|
248 |
$('#modal_ok').click(function() { |
U |
249 |
// hier speichern |
|
250 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=saveTextFile'; |
|
251 |
var u = '../svc' + m; |
2121cc
|
252 |
fm_post(u, {p1: pfad, p2: $('#dateiname').val(), p3: cm.getValue()}, function(resp) { |
915927
|
253 |
|
U |
254 |
}); |
|
255 |
}); |
c509a0
|
256 |
$('.modal-title').text('Datei speichern'); |
U |
257 |
$('#dialogfrage').text("Dateiname?"); |
3ad4db
|
258 |
|
U |
259 |
var fname = $('.datei-gewaehlt').text(); |
|
260 |
if(fname !== undefined) { |
|
261 |
$('#dateiname').val(fname); |
|
262 |
} else { |
|
263 |
$('#dateiname').val(''); |
|
264 |
} |
c509a0
|
265 |
$('#dateiname').attr('placeholder', 'Dateiname'); |
915927
|
266 |
$('#saveModal').modal({ |
U |
267 |
keyboard: false, |
|
268 |
show: true |
|
269 |
}); |
a4d3b5
|
270 |
} |
U |
271 |
|
b7475d
|
272 |
function fm_logout() { |
U |
273 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession'; |
|
274 |
var u = '../pub' + m; |
|
275 |
|
|
276 |
fm_get(u, "text", function(resp) { |
|
277 |
$('#userMenu').text('nicht angemeldet'); |
|
278 |
window.location.href = '../logout.html'; |
|
279 |
}); |
|
280 |
} |
|
281 |
|
|
282 |
|
a4d3b5
|
283 |
/* ---- codemirror editor handling -------- */ |
U |
284 |
|
|
285 |
function fm_code_edit(content) { |
|
286 |
cm = CodeMirror.fromTextArea(document.getElementById("editspace"), { |
|
287 |
lineNumbers: true, |
|
288 |
mode: "xml", |
|
289 |
viewportMargin : Infinity, |
|
290 |
extraKeys: { |
915927
|
291 |
"F9": function(cm) { |
U |
292 |
cm.setOption("fullScreen", !cm.getOption("fullScreen")); |
|
293 |
}, |
|
294 |
"Esc": function(cm) { |
|
295 |
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); |
|
296 |
} |
a4d3b5
|
297 |
} |
U |
298 |
}); |
|
299 |
cm.setValue(content); |
915927
|
300 |
} |
a4d3b5
|
301 |
|
U |
302 |
|
|
303 |
|
|
304 |
/* -------- helper functions ----------- */ |
|
305 |
|
b7475d
|
306 |
function fm_get(u, dtype, scallback) { |
a4d3b5
|
307 |
$.ajax({ |
U |
308 |
url: u, |
|
309 |
type: "GET", |
b7475d
|
310 |
dataType: dtype, |
a4d3b5
|
311 |
success: scallback, |
U |
312 |
error: function (xhr, status, errorThrown) { |
|
313 |
alert("Error: " + errorThrown + " Status: " + status + " URL: " + u); |
|
314 |
}, |
|
315 |
complete: function (xhr, status) { |
|
316 |
//console.log( "The request is complete!" ); |
|
317 |
} |
|
318 |
|
|
319 |
}); |
915927
|
320 |
} |
a4d3b5
|
321 |
|
U |
322 |
function fm_post(u, d, scallback) { |
|
323 |
$.ajax({ |
|
324 |
url: u, |
|
325 |
data: d, |
|
326 |
type: "POST", |
|
327 |
dataType: "json", |
|
328 |
success: scallback, |
|
329 |
error: function (xhr, status, errorThrown) { |
|
330 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
331 |
}, |
|
332 |
complete: function (xhr, status) { |
|
333 |
//alert( "The request is complete!" ); |
|
334 |
} |
|
335 |
}); |
915927
|
336 |
} |
a4d3b5
|
337 |
|
e5ff42
|
338 |
function fm_serialise(obj) { |
U |
339 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
915927
|
340 |
} |
e5ff42
|
341 |
|
7342b1
|
342 |
/* ----- Objekte ----- */ |
U |
343 |
|
|
344 |
function FileList(fl) { |
|
345 |
this.files = fl; |
|
346 |
} |
|
347 |
|
|
348 |
function FileRef(obj) { |
|
349 |
var self = this; |
|
350 |
this.fr = obj; |
|
351 |
|
|
352 |
this.typeClass = function() { |
10d3d3
|
353 |
if(modus == 'kacheln') { |
U |
354 |
if(self.fr.isDirectory) { |
|
355 |
return 'fa-folder'; |
|
356 |
} else { |
|
357 |
return 'fa-file'; |
|
358 |
} |
7342b1
|
359 |
} else { |
10d3d3
|
360 |
if(self.fr.isDirectory) { |
U |
361 |
return 'fa-folder'; |
|
362 |
} else { |
|
363 |
return 'fa-file-o'; |
|
364 |
} |
7342b1
|
365 |
} |
2121cc
|
366 |
}; |
U |
367 |
|
|
368 |
this.fileName = function() { |
|
369 |
var namen = self.fr.absolutePath.split('/'); |
|
370 |
if(namen.length > 0) { |
|
371 |
return namen[namen.length - 1]; |
|
372 |
} else { |
|
373 |
return self.fr.absolutePath; |
|
374 |
} |
|
375 |
}; |
7342b1
|
376 |
} |
5dfab6
|
377 |
|
U |
378 |
function BcrFiles(fl) { |
|
379 |
this.files = fl; |
|
380 |
} |
|
381 |
|
|
382 |
function BcrFile(rp, n) { |
|
383 |
this.relPath = rp; |
|
384 |
this.fName = n; |
f5505f
|
385 |
} |