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); |
e5ff42
|
8 |
$('#saveFile').on('click', fm_menu_datei_speichern); |
a4d3b5
|
9 |
$('#closeFile').on('click', fm_menu_datei_schliessen); |
915927
|
10 |
$('#myModal').on('hidden.bs.modal', function (e) { |
U |
11 |
$('#modal_ok').attr('onclick','').unbind('click'); |
b7475d
|
12 |
}); |
U |
13 |
$('#logout').click(fm_logout); |
e5ff42
|
14 |
fm_get_login(); |
7342b1
|
15 |
fm_get_list(''); |
a4d3b5
|
16 |
} |
U |
17 |
|
|
18 |
function fm_menu_neue_textdatei() { |
|
19 |
$('#dateiansicht').hide(); |
|
20 |
$('.codeeditor-space').show(); |
|
21 |
$('.code-editor-container').show(); |
|
22 |
fm_code_edit('Test'); |
|
23 |
} |
|
24 |
|
|
25 |
function fm_menu_datei_schliessen() { |
|
26 |
$('.codeeditor-space').hide(); |
|
27 |
$('.code-editor-container').hide(); |
|
28 |
cm.toTextArea(); |
|
29 |
$('#dateiansicht').show(); |
e5ff42
|
30 |
} |
U |
31 |
|
5dfab6
|
32 |
function fm_dateiwahl() { |
U |
33 |
var elem = this; |
|
34 |
//console.log('datei gewaehlt ' + $(elem).text().trim()); |
|
35 |
if($(elem).children(0).hasClass('fa-folder')) { |
|
36 |
var ordner = $(elem).text().trim(); |
|
37 |
if(pfad.length > 0) { |
|
38 |
pfad = pfad + '/' + ordner; |
|
39 |
} else { |
|
40 |
pfad = ordner; |
|
41 |
} |
|
42 |
fm_get_list(pfad); |
|
43 |
} else if($(elem).children(0).hasClass('fa-file')) { |
|
44 |
$('.datei-gewaehlt').removeClass('datei-gewaehlt'); |
|
45 |
$(elem).children(0).addClass('datei-gewaehlt'); |
|
46 |
} else { |
|
47 |
//console.log('kein folder oder file...'); |
|
48 |
} |
|
49 |
} |
|
50 |
|
b7475d
|
51 |
/* ----- API Calls ------------- */ |
U |
52 |
|
e5ff42
|
53 |
function fm_get_login() { |
U |
54 |
var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser'; |
|
55 |
var u = '../../um/pub' + m; |
b7475d
|
56 |
fm_get(u, "json", function(resp) { |
e5ff42
|
57 |
$('#userMenu').text(resp.UserData.firstName); |
7342b1
|
58 |
}); |
U |
59 |
} |
|
60 |
|
|
61 |
// http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p= |
|
62 |
function fm_get_list(relPath) { |
|
63 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPath; |
|
64 |
var u = '../svc' + m; |
|
65 |
fm_get(u, "json", function(resp) { |
5dfab6
|
66 |
//if(resp) |
7342b1
|
67 |
var files = new Array(); |
U |
68 |
for(var i = 0; i < resp.List[0].FileRef.length; i++) { |
|
69 |
files.push(new FileRef(resp.List[0].FileRef[i])); |
|
70 |
} |
|
71 |
var fl = new FileList(files); |
|
72 |
var template = $('#tpl-kacheln').html(); |
|
73 |
Mustache.parse(template); // optional, speeds up future uses |
5dfab6
|
74 |
$('.figure').attr('onclick','').unbind('click'); |
7342b1
|
75 |
$('#dateien').empty(); |
U |
76 |
$('#dateien').html(Mustache.render(template, fl)); |
5dfab6
|
77 |
$('.figure').click(fm_dateiwahl); |
U |
78 |
|
|
79 |
var dirList = new Array(); |
|
80 |
var rp = ''; |
|
81 |
var dirs = relPath.split('/'); |
|
82 |
dirList.push(new BcrFile(rp, 'Home')) |
|
83 |
if(dirs.length > 0) { |
|
84 |
for(var i = 0; i < dirs.length; i++) { |
|
85 |
if(rp.length > 0 ) { |
|
86 |
dirList.push(new BcrFile(rp + '/' + dirs[i], dirs[i])); |
|
87 |
} else { |
|
88 |
dirList.push(new BcrFile(dirs[i], dirs[i])); |
|
89 |
} |
|
90 |
} |
|
91 |
var bl = new BcrFiles(dirList); |
|
92 |
var template = $('#tpl-bcr').html(); |
|
93 |
Mustache.parse(template); // optional, speeds up future uses |
|
94 |
$('#bcnav').empty(); |
|
95 |
$('#bcnav').html(Mustache.render(template, bl)); |
|
96 |
$('#bcnav').append($('#tpl-bcr2').html()); |
|
97 |
$('#bcnav').append($('#tpl-bcr3').html()); |
|
98 |
} |
e5ff42
|
99 |
}); |
U |
100 |
} |
|
101 |
|
|
102 |
function fm_menu_datei_speichern() { |
|
103 |
|
915927
|
104 |
$('#modal_ok').click(function() { |
U |
105 |
// hier speichern |
|
106 |
var m = '?c=de.uhilger.filecms.api.FileMgr&m=saveTextFile'; |
|
107 |
var u = '../svc' + m; |
|
108 |
fm_post(u, {p1: '', p2: $('#dateiname').val(), p3: cm.getValue()}, function(resp) { |
|
109 |
|
|
110 |
}); |
|
111 |
}); |
|
112 |
$('#saveModal').modal({ |
|
113 |
keyboard: false, |
|
114 |
show: true |
|
115 |
}); |
|
116 |
|
|
117 |
|
|
118 |
// FileRef saveTextFile(String relPath, String fileName, String contents) |
e5ff42
|
119 |
|
U |
120 |
|
|
121 |
/* |
|
122 |
var t = new Template(-2, $('#filename').val(), self.cm.getValue(), 3); |
|
123 |
var u = '../api/tr/?c=de.uhilger.webbox.api.ContentApi&m=newTemplate'; |
|
124 |
self.post(u, {p: self.serialise(t)}, function (resp) { |
|
125 |
self.isnew = false; |
|
126 |
self.editid = resp.Template.id; |
|
127 |
$('#contlist').append(self.buildContListItem(3, resp.Template.name, resp.Template.id)); |
|
128 |
$('#templateeditor').addClass('hidden'); |
|
129 |
}); |
|
130 |
*/ |
a4d3b5
|
131 |
} |
U |
132 |
|
b7475d
|
133 |
function fm_logout() { |
U |
134 |
var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession'; |
|
135 |
var u = '../pub' + m; |
|
136 |
|
|
137 |
fm_get(u, "text", function(resp) { |
|
138 |
$('#userMenu').text('nicht angemeldet'); |
|
139 |
window.location.href = '../logout.html'; |
|
140 |
}); |
|
141 |
} |
|
142 |
|
|
143 |
|
a4d3b5
|
144 |
/* ---- codemirror editor handling -------- */ |
U |
145 |
|
|
146 |
function fm_code_edit(content) { |
915927
|
147 |
//var windowHeight = $(window).height(); |
a4d3b5
|
148 |
//$("editspace").empty(); |
U |
149 |
//self.cm.toTextArea(); |
|
150 |
|
|
151 |
cm = CodeMirror.fromTextArea(document.getElementById("editspace"), { |
|
152 |
lineNumbers: true, |
|
153 |
mode: "xml", |
|
154 |
viewportMargin : Infinity, |
|
155 |
extraKeys: { |
915927
|
156 |
"F9": function(cm) { |
U |
157 |
cm.setOption("fullScreen", !cm.getOption("fullScreen")); |
|
158 |
}, |
|
159 |
"Esc": function(cm) { |
|
160 |
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); |
|
161 |
} |
a4d3b5
|
162 |
} |
U |
163 |
}); |
|
164 |
cm.setValue(content); |
915927
|
165 |
} |
a4d3b5
|
166 |
|
U |
167 |
|
|
168 |
|
|
169 |
/* -------- helper functions ----------- */ |
|
170 |
|
b7475d
|
171 |
function fm_get(u, dtype, scallback) { |
a4d3b5
|
172 |
$.ajax({ |
U |
173 |
url: u, |
|
174 |
type: "GET", |
b7475d
|
175 |
dataType: dtype, |
a4d3b5
|
176 |
success: scallback, |
U |
177 |
error: function (xhr, status, errorThrown) { |
|
178 |
alert("Error: " + errorThrown + " Status: " + status + " URL: " + u); |
|
179 |
}, |
|
180 |
complete: function (xhr, status) { |
|
181 |
//console.log( "The request is complete!" ); |
|
182 |
} |
|
183 |
|
|
184 |
}); |
915927
|
185 |
} |
a4d3b5
|
186 |
|
U |
187 |
function fm_post(u, d, scallback) { |
|
188 |
$.ajax({ |
|
189 |
url: u, |
|
190 |
data: d, |
|
191 |
type: "POST", |
|
192 |
dataType: "json", |
|
193 |
success: scallback, |
|
194 |
error: function (xhr, status, errorThrown) { |
|
195 |
$('#fehler').html("Error: " + errorThrown + " Status: " + status); |
|
196 |
}, |
|
197 |
complete: function (xhr, status) { |
|
198 |
//alert( "The request is complete!" ); |
|
199 |
} |
|
200 |
}); |
915927
|
201 |
} |
a4d3b5
|
202 |
|
e5ff42
|
203 |
function fm_serialise(obj) { |
U |
204 |
return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; |
915927
|
205 |
} |
e5ff42
|
206 |
|
7342b1
|
207 |
/* ----- Objekte ----- */ |
U |
208 |
|
|
209 |
function FileList(fl) { |
|
210 |
this.files = fl; |
|
211 |
} |
|
212 |
|
|
213 |
function FileRef(obj) { |
|
214 |
var self = this; |
|
215 |
this.fr = obj; |
|
216 |
|
|
217 |
this.typeClass = function() { |
|
218 |
if(self.fr.isDirectory) { |
|
219 |
return 'fa-folder'; |
|
220 |
} else { |
|
221 |
return 'fa-file'; |
|
222 |
} |
|
223 |
} |
|
224 |
} |
5dfab6
|
225 |
|
U |
226 |
function BcrFiles(fl) { |
|
227 |
this.files = fl; |
|
228 |
} |
|
229 |
|
|
230 |
function BcrFile(rp, n) { |
|
231 |
this.relPath = rp; |
|
232 |
this.fName = n; |
|
233 |
} |