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