Dateiverwaltung für die WebBox
ulrich
2020-01-24 94b87168466ef2904087039ac111d569d241b809
commit | author | age
05e9c4 1 function AppVorlage() {
U 2   var self = this;
3   var appMenu;
4   var vorlagen;
5   var api;
94b871 6   var userid;
05e9c4 7
94b871 8   this.datei_neuer_text = function () {
U 9     self.menu_message("Neuer Text");
05e9c4 10   };
U 11
12   /* Funktionen aus App-Vorlage */
94b871 13
U 14   this.init = function () {
05e9c4 15     self.vorlagen = new Vorlagen();
U 16     self.appMenu = new AppMenu();
17     self.appMenu.init(
94b871 18             "data/menu/",
U 19             "hauptmenue.json",
20             "data/tpl/app-menu.tpl",
21             ".west",
22             "8em");
05e9c4 23
94b871 24     document.querySelector('.hamburger').addEventListener('click', function (e) {
05e9c4 25       self.menue_umschalten();
U 26     });
27
28   };
29
94b871 30   this.menue_umschalten = function () {
05e9c4 31     var ham = document.querySelector(".hamburger");
U 32     ham.classList.toggle("is-active"); // hamburger-icon umschalten
33     self.appMenu.toggle(); // menue oeffnen/schliessen
34   };
35
94b871 36   this.info_dialog_zeigen = function () {
05e9c4 37     self.dialog_laden_und_zeigen('data/tpl/dlg-info.tpl', '');
U 38     self.menue_umschalten();
39   };
40
94b871 41   this.seitenleiste_umschalten = function () {
05e9c4 42     var ostDiv = document.querySelector('.ost');
94b871 43     if (ostDiv.classList.contains('ost-open')) {
05e9c4 44       ostDiv.classList.remove('ost-open');
94b871 45       ostDiv.style.flexBasis = '0em';
05e9c4 46     } else {
94b871 47       ostDiv.classList.add('ost-open');
U 48       ostDiv.style.flexBasis = '6em';
05e9c4 49     }
U 50     self.menue_umschalten();
51   };
52
94b871 53   this.fusszeile_umschalten = function () {
05e9c4 54     var suedDiv = document.querySelector('.sued');
94b871 55     if (suedDiv.classList.contains('sued-open')) {
05e9c4 56       suedDiv.classList.remove('sued-open');
94b871 57       suedDiv.style.height = '0';
05e9c4 58     } else {
U 59       suedDiv.classList.add('sued-open');
94b871 60       suedDiv.style.height = '1.5em';
05e9c4 61     }
U 62     self.menue_umschalten();
63   };
64
94b871 65   this.menu_message = function (msg) {
05e9c4 66     self.meldung_mit_timeout(msg, 1500);
U 67     var suedDiv = document.querySelector('.sued');
94b871 68     if (suedDiv.classList.contains('sued-open')) {
05e9c4 69     } else {
U 70       suedDiv.classList.add('sued-open');
94b871 71       suedDiv.style.height = '1.5em';
05e9c4 72     }
U 73     self.menue_umschalten();
74   };
75
94b871 76   this.message_1 = function () {
05e9c4 77     self.menu_message('Eine Mitteilung.');
U 78   };
79
94b871 80   this.message_2 = function () {
05e9c4 81     self.menu_message('Was wir schon immer sagen wollten.');
U 82   };
83
94b871 84   this.message_3 = function (text) {
05e9c4 85     self.menu_message(text);
U 86   };
87
94b871 88   this.meldung_mit_timeout = function (meldung, timeout) {
05e9c4 89     var s = document.querySelector('.sued');
U 90     s.textContent = meldung;
94b871 91     setTimeout(function () {
05e9c4 92       s.textContent = 'Bereit.';
94b871 93       setTimeout(function () {
05e9c4 94         var suedDiv = document.querySelector('.sued');
94b871 95         if (suedDiv.classList.contains('sued-open')) {
U 96           suedDiv.classList.remove('sued-open');
97           suedDiv.style.height = '0';
05e9c4 98         }
U 99       }, 500);
100     }, timeout);
101   };
102
103   /* Dialog-Funktionen */
104
105   /*
94b871 106    Einen Dialog aus Vorlagen erzeugen
U 107    
108    vurl - URL zur Dialogvorlage
109    msgTpl - URL mit einer Vorlage eines Mitteilungstextes (optional)
110    */
111   this.dialog_laden_und_zeigen = function (vurl, msgTpl) {
112     if (msgTpl !== '') {
05e9c4 113       fetch(msgTpl)
94b871 114               .then(data => {
U 115                 // Handle data
116                 self.dialog_zeigen(vurl, data);
117               }).catch(error => {
118         // Handle error
119       });
05e9c4 120     } else {
U 121       self.dialog_zeigen(vurl, '');
122     }
123   };
124
94b871 125   this.dialog_zeigen = function (vurl, inhalt) {
05e9c4 126     var dlg = document.querySelector(".dialog");
U 127     self.vorlagen.html_erzeugen(
94b871 128             vurl,
U 129             inhalt,
130             function (html) {
131               //dlg.html(html);
132               dlg.style.height = '5em';
133               dlg.innerHTML = html;
134               document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen);
135               //dlg.slideDown(300);
136             });
05e9c4 137   };
U 138
94b871 139   self.dialog_schliessen = function () {
05e9c4 140     document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen);
U 141     //$('.dialog').slideUp(300);
142     var dlg = document.querySelector('.dialog');
143     //dlg.style.display = "none";
144     dlg.style.height = '0';
145     dlg.innerHTML = '';
146   };
147
94b871 148   /* API functions */
05e9c4 149
94b871 150   // http://localhost:8079/file-cms/svc?c=de.uhilger.filecms.api.FileMgr&f=JSONNICE&m=list&p=
U 151   this.fm_get_list = function (relPfad) {
152     $('#ansicht').attr('onclick', '').unbind('click');
153     var m = '?c=de.uhilger.filecms.api.FileMgr&m=list&p=' + relPfad;
154     var u = '../svc' + m;
155     self.fm_get(u, "json", function (resp) {
05e9c4 156
94b871 157       if (resp.List[0].FileRef !== undefined) {
U 158         var files = new Array();
159         if (resp.List[0].FileRef instanceof Array) {
160           for (var i = 0; i < resp.List[0].FileRef.length; i++) {
161             files.push(new FileRef(resp.List[0].FileRef[i]));
05e9c4 162           }
U 163         } else {
94b871 164           files.push(new FileRef(resp.List[0].FileRef));
05e9c4 165         }
94b871 166         var fl = new FileList(files);
U 167         fm_render_list(fl);
168       } else {
169         $('#dateien').empty();
170       }
05e9c4 171
94b871 172     });
U 173   };
05e9c4 174
94b871 175   /* -------- An- und Abmelden ------------- */
05e9c4 176
94b871 177   this.fm_get_login = function() {
U 178     var m = '?c=de.uhilger.filecms.pub.SessionManager&m=getSessionUser';
179     var u = '../pub' + m;
180     self.fm_get(u, "text", function (resp) {
181       self.userid = resp;
182       document.querySelector("#userMenu").textContent = resp;
183     });
184   };
05e9c4 185
94b871 186   this.fm_logout = function() {
U 187     var m = '?c=de.uhilger.filecms.pub.SessionManager&m=expireSession';
188     var u = '../pub' + m;
05e9c4 189
94b871 190     self.fm_get(u, "text", function (resp) {
U 191       //$('#userMenu').text('nicht angemeldet');
192       window.location.href = '../logout.html';
193     });
194   };
195
196   /* -------- ajax helper functions ----------- */
197
198   this.fm_get = function (u, dtype, scallback) {
199     $.ajax({
200       url: u,
201       type: "GET",
202       dataType: dtype,
203       success: scallback,
204       error: function (xhr, status, errorThrown) {
205         alert("Error: " + errorThrown + " Status: " + status + " URL: " + u);
206       },
207       complete: function (xhr, status) {
208         //console.log( "The request is complete!" );
209       }
210
211     });
212   };
213
214   this.fm_post = function (u, d, dtype, scallback) {
215     $.ajax({
216       url: u,
217       data: d,
218       type: "POST",
219       dataType: dtype,
220       success: scallback,
221       error: function (xhr, status, errorThrown) {
222         $('#fehler').html("Error: " + errorThrown + " Status: " + status);
223       },
224       complete: function (xhr, status) {
225         //alert( "The request is complete!" );
226       }
227     });
228   };
229
05e9c4 230 }