ulrich@undisclosed
2020-05-08 002c445416c96ec3af57df02e86ac8d5aaecf38b
commit | author | age
002c44 1 function AppVorlage() {
U 2   var self = this;
3   var appMenu;
4   var vorlagen;
5   var api;
6   var userid;
7   var pfad = '';
8   var loc;
9   var modus = 'kacheln';
10   var PERS_DIR = "Persoenlich";
11   var PUB_DIR = "Oeffentlich";
12   var DAV_DIR = "Austausch";
13   var BASE_DIR = "$basis";
14   var DATA_DIR = "$daten";
15   var WWW_DIR = "www";
16
17   this.datei_neuer_text = function () {
18     self.meldung_mit_timeout("Neuer Text", 1500);
19   };
20
21   /* Funktionen aus App-Vorlage */
22
23   this.init = function () {
24     self.vorlagen = new Vorlagen();
25     self.appMenu = new AppMenu();
26     self.appMenu.init(
27             "data/menu/",
28             "hauptmenue.json",
29             "data/tpl/app-menu.tpl",
30             ".west",
31             "8em");
32     document.querySelector('.hamburger').addEventListener('click', function (e) {
33       self.menue_umschalten();
34     });
35     self.um_get_login();
36     self.um_get_user_list();
37     self.loc = window.location.protocol + '//' + window.location.host;
38   };
39
40   this.login_zeigen = function() {
41     self.meldung_mit_timeout("Benutzer: " + self.userid, 1500);
42   };
43   
44   this.menue_umschalten = function () {
45     var ham = document.querySelector(".hamburger");
46     ham.classList.toggle("is-active"); // hamburger-icon umschalten
47     self.appMenu.toggle(); // menue oeffnen/schliessen
48   };
49
50   this.info_dialog_zeigen = function () {
51     self.dialog_laden_und_zeigen('data/tpl/dlg-info.tpl', '');
52     self.menue_umschalten();
53   };
54
55   this.seitenleiste_umschalten = function () {
56     var ostDiv = document.querySelector('.ost');
57     if (ostDiv.classList.contains('ost-open')) {
58       ostDiv.classList.remove('ost-open');
59       ostDiv.style.flexBasis = '0em';
60     } else {
61       ostDiv.classList.add('ost-open');
62       ostDiv.style.flexBasis = '6em';
63     }
64     self.menue_umschalten();
65   };
66
67   this.fusszeile_umschalten = function () {
68     var suedDiv = document.querySelector('.sued');
69     if (suedDiv.classList.contains('sued-open')) {
70       suedDiv.classList.remove('sued-open');
71       suedDiv.style.height = '0';
72     } else {
73       suedDiv.classList.add('sued-open');
74       suedDiv.style.height = '1.5em';
75     }
76     self.menue_umschalten();
77   };
78
79   this.meldung_mit_timeout = function (meldung, timeout) {
80     var s = document.querySelector('.sued');
81     s.textContent = meldung;
82     setTimeout(function () {
83       s.textContent = 'Bereit.';
84       setTimeout(function () {
85         var suedDiv = document.querySelector('.sued');
86         if (suedDiv.classList.contains('sued-open')) {
87           suedDiv.classList.remove('sued-open');
88           suedDiv.style.height = '0';
89         }
90       }, 500);
91     }, timeout);
92   };
93
94   /* Dialog-Funktionen */
95
96   /*
97    Einen Dialog aus Vorlagen erzeugen
98    
99    vurl - URL zur Dialogvorlage
100    msgTpl - URL mit einer Vorlage eines Mitteilungstextes (optional)
101    */
102   this.dialog_laden_und_zeigen = function (vurl, msgTpl) {
103     if (msgTpl !== '') {
104       fetch(msgTpl)
105               .then(data => {
106                 // Handle data
107                 self.dialog_zeigen(vurl, data);
108               }).catch(error => {
109         // Handle error
110       });
111     } else {
112       self.dialog_zeigen(vurl, '');
113     }
114   };
115
116   this.dialog_zeigen = function (vurl, inhalt) {
117     var dlg = document.querySelector(".dialog");
118     self.vorlagen.html_erzeugen(
119             vurl,
120             inhalt,
121             function (html) {
122               //dlg.html(html);
123               dlg.style.height = '5em';
124               dlg.innerHTML = html;
125               document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen);
126               //dlg.slideDown(300);
127             });
128   };
129
130   this.dialog_schliessen = function () {
131     document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen);
132     //$('.dialog').slideUp(300);
133     var dlg = document.querySelector('.dialog');
134     //dlg.style.display = "none";
135     dlg.style.height = '0';
136     dlg.innerHTML = '';
137   };
138
139   /* API functions */
140   
141   this.um_get_user_list = function() {
142     var m = 'getUserNameList';
143     var u = '../svc/' + m;
144     self.fm_get(u, "json", function (antwort) {
145       var elem = document.getElementById('nutzer');
146       elem.textContent = antwort;
147     });
148   }
149   
150
151   /* -------- An- und Abmelden ------------- */
152
153   this.um_get_login = function() {
154     var m = '?c=de.uhilger.um.pub.SessionManager&m=getSessionUser';
155     var u = '../pub' + m;
156     self.fm_get(u, "text", function (resp) {
157       self.userid = resp;
158       self.login_zeigen();
159       //document.querySelector("#userMenu").textContent = resp;
160     });
161   };
162
163   this.um_logout = function() {
164     var m = '?c=de.uhilger.um.pub.SessionManager&m=expireSession';
165     var u = '../pub' + m;
166     self.fm_get(u, "text", function (resp) {
167       //$('#userMenu').text('nicht angemeldet');
168       window.location.href = '../logout.html';
169     });
170   };
171
172   /* -------- ajax helper functions ----------- */
173
174   this.fm_get = function (u, dtype, scallback) {    
175     var xmlhttp = new XMLHttpRequest();
176     var url = u;
177     xmlhttp.onreadystatechange = function() {
178       if (this.readyState == 4 && this.status == 200) {
179         scallback(this.responseText);
180       }
181     };
182     xmlhttp.open("GET", url, true);
183     xmlhttp.send();
184   };
185
186 }