Dateiverwaltung für die WebBox
ulrich
2017-02-18 9159275f8efe97da69e138ef3378931181447370
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');
11   })
e5ff42 12   fm_get_login();
a4d3b5 13 }
U 14
15 function fm_menu_neue_textdatei() {
16   $('#dateiansicht').hide();
17   $('.codeeditor-space').show();
18   $('.code-editor-container').show();
19   fm_code_edit('Test');
20 }
21
22 function fm_menu_datei_schliessen() {
23   $('.codeeditor-space').hide();
24   $('.code-editor-container').hide();
25   cm.toTextArea();
26   $('#dateiansicht').show();  
e5ff42 27 }
U 28
29 function fm_get_login() {
30   var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser';
31   var u = '../../um/pub' + m;
32   fm_get(u, function(resp) {
33     $('#userMenu').text(resp.UserData.firstName);
34   });  
35 }
36
37 function fm_menu_datei_speichern() {
38   
915927 39   $('#modal_ok').click(function() {
U 40     // hier speichern
41     alert("Speichern");
42     var m = '?c=de.uhilger.filecms.api.FileMgr&m=saveTextFile';
43     var u = '../svc' + m;
44     fm_post(u, {p1: '', p2: $('#dateiname').val(), p3: cm.getValue()}, function(resp) {
45
46     });
47   });
48   $('#saveModal').modal({
49     keyboard: false,
50     show: true
51   });
52   
53   
54   // FileRef saveTextFile(String relPath, String fileName, String contents)
e5ff42 55   
U 56   
57   /*
58   var t = new Template(-2, $('#filename').val(), self.cm.getValue(), 3);
59   var u = '../api/tr/?c=de.uhilger.webbox.api.ContentApi&m=newTemplate';
60   self.post(u, {p: self.serialise(t)}, function (resp) {
61     self.isnew = false;
62     self.editid = resp.Template.id;
63     $('#contlist').append(self.buildContListItem(3, resp.Template.name, resp.Template.id));
64     $('#templateeditor').addClass('hidden');
65   });
66   */
a4d3b5 67 }
U 68
69 /* ---- codemirror editor handling -------- */
70
71 function fm_code_edit(content) {
915927 72   //var windowHeight = $(window).height();
a4d3b5 73   //$("editspace").empty();
U 74   //self.cm.toTextArea();
75
76   cm = CodeMirror.fromTextArea(document.getElementById("editspace"), {
77     lineNumbers: true,
78     mode: "xml",
79     viewportMargin : Infinity,
80     extraKeys: {
915927 81         "F9": function(cm) {
U 82         cm.setOption("fullScreen", !cm.getOption("fullScreen"));
83       },
84         "Esc": function(cm) {
85         if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
86       }
a4d3b5 87     }
U 88   });
89   cm.setValue(content);
915927 90 }
a4d3b5 91
U 92
93
94 /* -------- helper functions ----------- */
95
96 function fm_get(u, scallback) {
97   $.ajax({
98     url: u,
99     type: "GET",
100     dataType: "json",
101     success: scallback,
102     error: function (xhr, status, errorThrown) {
103       alert("Error: " + errorThrown + " Status: " + status + " URL: " + u);
104     },
105     complete: function (xhr, status) {
106       //console.log( "The request is complete!" );
107     }
108
109   });
915927 110 }
a4d3b5 111
U 112 function fm_post(u, d, scallback) {
113   $.ajax({
114     url: u,
115     data: d,
116     type: "POST",
117     dataType: "json",
118     success: scallback,
119     error: function (xhr, status, errorThrown) {
120       $('#fehler').html("Error: " + errorThrown + " Status: " + status);
121     },
122     complete: function (xhr, status) {
123       //alert( "The request is complete!" );
124     }
125   });
915927 126 }
a4d3b5 127
e5ff42 128 function fm_serialise(obj) {
U 129   return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
915927 130 }
e5ff42 131