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