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