Dateiverwaltung für die WebBox
ulrich
2017-02-20 7342b1f3850299264b571d1d63778173c9a30703
commit | author | age
a4d3b5 1 var cm;
c7c502 2
U 3 function fm_init() {
a4d3b5 4   $('.codeeditor-space').hide();
U 5   $('.code-editor-container').hide();
6   $('#newTextFile').on('click', fm_menu_neue_textdatei);
e5ff42 7   $('#saveFile').on('click', fm_menu_datei_speichern);
a4d3b5 8   $('#closeFile').on('click', fm_menu_datei_schliessen);
915927 9   $('#myModal').on('hidden.bs.modal', function (e) {
U 10     $('#modal_ok').attr('onclick','').unbind('click');
b7475d 11   });
U 12   $('#logout').click(fm_logout);  
e5ff42 13   fm_get_login();
7342b1 14   fm_get_list('');
a4d3b5 15 }
U 16
17 function fm_menu_neue_textdatei() {
18   $('#dateiansicht').hide();
19   $('.codeeditor-space').show();
20   $('.code-editor-container').show();
21   fm_code_edit('Test');
22 }
23
24 function fm_menu_datei_schliessen() {
25   $('.codeeditor-space').hide();
26   $('.code-editor-container').hide();
27   cm.toTextArea();
28   $('#dateiansicht').show();  
e5ff42 29 }
U 30
b7475d 31 /* ----- API Calls ------------- */
U 32
e5ff42 33 function fm_get_login() {
U 34   var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser';
35   var u = '../../um/pub' + m;
b7475d 36   fm_get(u, "json", function(resp) {
e5ff42 37     $('#userMenu').text(resp.UserData.firstName);
7342b1 38   });  
U 39 }
40
41 // http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p=
42 function fm_get_list(relPath) {
43   var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPath;
44   var u = '../svc' + m;
45   fm_get(u, "json", function(resp) {
46     var files = new Array();
47     for(var i = 0; i < resp.List[0].FileRef.length; i++) {
48       files.push(new FileRef(resp.List[0].FileRef[i]));
49     }
50     var fl = new FileList(files);
51     var template = $('#tpl-kacheln').html();
52     Mustache.parse(template);   // optional, speeds up future uses
53     $('#dateien').empty();
54     $('#dateien').html(Mustache.render(template, fl));
e5ff42 55   });  
U 56 }
57
58 function fm_menu_datei_speichern() {
59   
915927 60   $('#modal_ok').click(function() {
U 61     // hier speichern
62     var m = '?c=de.uhilger.filecms.api.FileMgr&m=saveTextFile';
63     var u = '../svc' + m;
64     fm_post(u, {p1: '', p2: $('#dateiname').val(), p3: cm.getValue()}, function(resp) {
65
66     });
67   });
68   $('#saveModal').modal({
69     keyboard: false,
70     show: true
71   });
72   
73   
74   // FileRef saveTextFile(String relPath, String fileName, String contents)
e5ff42 75   
U 76   
77   /*
78   var t = new Template(-2, $('#filename').val(), self.cm.getValue(), 3);
79   var u = '../api/tr/?c=de.uhilger.webbox.api.ContentApi&m=newTemplate';
80   self.post(u, {p: self.serialise(t)}, function (resp) {
81     self.isnew = false;
82     self.editid = resp.Template.id;
83     $('#contlist').append(self.buildContListItem(3, resp.Template.name, resp.Template.id));
84     $('#templateeditor').addClass('hidden');
85   });
86   */
a4d3b5 87 }
U 88
b7475d 89 function fm_logout() {
U 90   var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession';
91   var u = '../pub' + m;
92   
93   fm_get(u, "text", function(resp) {
94     $('#userMenu').text('nicht angemeldet');
95     window.location.href = '../logout.html';
96   });
97 }
98
99
a4d3b5 100 /* ---- codemirror editor handling -------- */
U 101
102 function fm_code_edit(content) {
915927 103   //var windowHeight = $(window).height();
a4d3b5 104   //$("editspace").empty();
U 105   //self.cm.toTextArea();
106
107   cm = CodeMirror.fromTextArea(document.getElementById("editspace"), {
108     lineNumbers: true,
109     mode: "xml",
110     viewportMargin : Infinity,
111     extraKeys: {
915927 112         "F9": function(cm) {
U 113         cm.setOption("fullScreen", !cm.getOption("fullScreen"));
114       },
115         "Esc": function(cm) {
116         if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
117       }
a4d3b5 118     }
U 119   });
120   cm.setValue(content);
915927 121 }
a4d3b5 122
U 123
124
125 /* -------- helper functions ----------- */
126
b7475d 127 function fm_get(u, dtype, scallback) {
a4d3b5 128   $.ajax({
U 129     url: u,
130     type: "GET",
b7475d 131     dataType: dtype,
a4d3b5 132     success: scallback,
U 133     error: function (xhr, status, errorThrown) {
134       alert("Error: " + errorThrown + " Status: " + status + " URL: " + u);
135     },
136     complete: function (xhr, status) {
137       //console.log( "The request is complete!" );
138     }
139
140   });
915927 141 }
a4d3b5 142
U 143 function fm_post(u, d, scallback) {
144   $.ajax({
145     url: u,
146     data: d,
147     type: "POST",
148     dataType: "json",
149     success: scallback,
150     error: function (xhr, status, errorThrown) {
151       $('#fehler').html("Error: " + errorThrown + " Status: " + status);
152     },
153     complete: function (xhr, status) {
154       //alert( "The request is complete!" );
155     }
156   });
915927 157 }
a4d3b5 158
e5ff42 159 function fm_serialise(obj) {
U 160   return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
915927 161 }
e5ff42 162
7342b1 163 /* ----- Objekte ----- */
U 164
165 function FileList(fl) {
166   this.files = fl;
167 }
168
169 function FileRef(obj) {
170   var self = this;
171   this.fr = obj;
172   
173   this.typeClass = function() {
174     if(self.fr.isDirectory) {
175       return 'fa-folder';
176     } else {
177       return 'fa-file';
178     }
179   }
180 }