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