This repository has been archived by the owner on Sep 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evab.js
11014 lines (10288 loc) · 387 KB
/
evab.js
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Diese Funktionen werden in evab auf mehreren Seiten benutzt
*/
window.em = window.em || {};
window.em.erstelleNeuesDatum = function() {
'use strict';
var jetzt = new Date(),
Jahr = jetzt.getFullYear(),
Mnt = jetzt.getMonth()+1,
MntAusgabe = ((Mnt < 10) ? "0" + Mnt : Mnt),
Tag = jetzt.getDate(),
TagAusgabe = ((Tag < 10) ? "0" + Tag : Tag);
return Jahr + "-" + MntAusgabe + "-" + TagAusgabe;
};
window.em.erstelleNeueUhrzeit = function() {
'use strict';
var jetzt = new Date(),
Std = jetzt.getHours(),
StdAusgabe = ((Std < 10) ? "0" + Std : Std),
Min = jetzt.getMinutes(),
MinAusgabe = ((Min < 10) ? "0" + Min : Min),
Sek = jetzt.getSeconds(),
SekAusgabe = ((Sek < 10) ? "0" + Sek : Sek);
return StdAusgabe + ":" + MinAusgabe + ":" + SekAusgabe;
};
// wandelt decimal degrees (vom GPS) in WGS84 um
/**
* @return {number}
*/
window.em.DdInWgs84BreiteGrad = function(Breite) {
'use strict';
return Math.floor(Breite);
};
/**
* @return {number}
*/
window.em.DdInWgs84BreiteMin = function(Breite) {
'use strict';
var BreiteGrad = Math.floor(Breite);
return Math.floor((Breite-BreiteGrad)*60);
};
/**
* @return {number}
*/
window.em.DdInWgs84BreiteSec = function(Breite) {
'use strict';
var BreiteGrad = Math.floor(Breite),
BreiteMin = Math.floor((Breite-BreiteGrad)*60);
return Math.round((((Breite - BreiteGrad) - (BreiteMin/60)) * 60 * 60) * 100) / 100;
};
/**
* @return {number}
*/
window.em.DdInWgs84LaengeGrad = function(Laenge) {
'use strict';
return Math.floor(Laenge);
};
/**
* @return {number}
*/
window.em.DdInWgs84LaengeMin = function(Laenge) {
'use strict';
var LaengeGrad = Math.floor(Laenge);
return Math.floor((Laenge-LaengeGrad)*60);
};
/**
* @return {number}
*/
window.em.DdInWgs84LaengeSec = function(Laenge) {
'use strict';
var LaengeGrad = Math.floor(Laenge),
LaengeMin = Math.floor((Laenge-LaengeGrad)*60);
return Math.round((((Laenge - LaengeGrad) - (LaengeMin/60)) * 60 * 60) * 100 ) / 100;
};
// Wandelt WGS84 lat/long (° dec) in CH-Landeskoordinaten um
/**
* @return {number}
*/
window.em.Wgs84InChX = function(BreiteGrad, BreiteMin, BreiteSec, LaengeGrad, LaengeMin, LaengeSec) {
'use strict';
var lat,
lng,
lat_aux,
lng_aux,
x;
// Converts degrees dec to sex
lat = BreiteSec + BreiteMin*60 + BreiteGrad*3600;
lng = LaengeSec + LaengeMin*60 + LaengeGrad*3600;
// Axiliary values (% Bern)
lat_aux = (lat - 169028.66)/10000;
lng_aux = (lng - 26782.5)/10000;
x = 200147.07
+ 308807.95 * lat_aux
+ 3745.25 * Math.pow(lng_aux,2)
+ 76.63 * Math.pow(lat_aux,2)
- 194.56 * Math.pow(lng_aux,2) * lat_aux
+ 119.79 * Math.pow(lat_aux,3);
return x;
};
// Wandelt WGS84 in CH-Landeskoordinaten um
/**
* @return {number}
*/
window.em.Wgs84InChY = function(BreiteGrad, BreiteMin, BreiteSec, LaengeGrad, LaengeMin, LaengeSec) {
'use strict';
var lat,
lng,
lat_aux,
lng_aux,
y;
// Converts degrees dec to sex
lat = BreiteSec + BreiteMin*60 + BreiteGrad*3600;
lng = LaengeSec + LaengeMin*60 + LaengeGrad*3600;
// Axiliary values (% Bern)
lat_aux = (lat - 169028.66)/10000;
lng_aux = (lng - 26782.5)/10000;
// Process Y
y = 600072.37
+ 211455.93 * lng_aux
- 10938.51 * lng_aux * lat_aux
- 0.36 * lng_aux * Math.pow(lat_aux,2)
- 44.54 * Math.pow(lng_aux,3);
return y;
};
// wandelt decimal degrees (vom GPS) in CH-Landeskoordinaten um
/**
* @return {number}
*/
window.em.DdInChX = function(Breite, Laenge) {
'use strict';
var BreiteGrad = window.em.DdInWgs84BreiteGrad(Breite),
BreiteMin = window.em.DdInWgs84BreiteMin(Breite),
BreiteSec = window.em.DdInWgs84BreiteSec(Breite),
LaengeGrad = window.em.DdInWgs84LaengeGrad(Laenge),
LaengeMin = window.em.DdInWgs84LaengeMin(Laenge),
LaengeSec = window.em.DdInWgs84LaengeSec(Laenge);
return Math.floor(window.em.Wgs84InChX(BreiteGrad, BreiteMin, BreiteSec, LaengeGrad, LaengeMin, LaengeSec));
};
/**
* @return {number}
*/
window.em.DdInChY = function(Breite, Laenge) {
'use strict';
var BreiteGrad = window.em.DdInWgs84BreiteGrad(Breite),
BreiteMin = window.em.DdInWgs84BreiteMin(Breite),
BreiteSec = window.em.DdInWgs84BreiteSec(Breite),
LaengeGrad = window.em.DdInWgs84LaengeGrad(Laenge),
LaengeMin = window.em.DdInWgs84LaengeMin(Laenge),
LaengeSec = window.em.DdInWgs84LaengeSec(Laenge);
return Math.floor(window.em.Wgs84InChY(BreiteGrad, BreiteMin, BreiteSec, LaengeGrad, LaengeMin, LaengeSec));
};
// von CH-Landeskoord zu DecDeg
// Convert CH y/x to WGS lat
/**
* @return {number}
*/
window.em.CHtoWGSlat = function(y, x) {
'use strict';
// Converts militar to civil and to unit = 1000km
var lat,
y_aux,
x_aux;
// Axiliary values (% Bern)
y_aux = (y - 600000)/1000000;
x_aux = (x - 200000)/1000000;
// Process lat
lat = 16.9023892
+ 3.238272 * x_aux
- 0.270978 * Math.pow(y_aux,2)
- 0.002528 * Math.pow(x_aux,2)
- 0.0447 * Math.pow(y_aux,2) * x_aux
- 0.0140 * Math.pow(x_aux,3);
// Unit 10000" to 1 " and converts seconds to degrees (dec)
lat = lat * 100/36;
return lat;
};
// Convert CH y/x to WGS long
/**
* @return {number}
*/
window.em.CHtoWGSlng = function(y, x) {
'use strict';
// Converts militar to civil and to unit = 1000km
var lng,
y_aux,
x_aux;
// Axiliary values (% Bern)
y_aux = (y - 600000)/1000000;
x_aux = (x - 200000)/1000000;
// Process long
lng = 2.6779094
+ 4.728982 * y_aux
+ 0.791484 * y_aux * x_aux
+ 0.1306 * y_aux * Math.pow(x_aux,2)
- 0.0436 * Math.pow(y_aux,3);
// Unit 10000" to 1 " and converts seconds to degrees (dec)
lng = lng * 100/36;
return lng;
};
window.em.melde = function(Meldung) {
'use strict';
$("<div id='meldung' data-role='popup' class='ui-content' data-overlay-theme='a'><a href='#' data-rel='back' class='ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right'>Close</a>"+Meldung+"</div>")
.css({"line-height": "95%", "font-weight": "bold"})
.appendTo($.mobile.pageContainer);
$("#meldung").popup({
afterclose: function() {
// Meldung wieder aus pageContainer entfernen
$("#meldung").remove();
}
}).popup("open");
};
// wird in FeldEdit.html verwendet
window.em.geheZurueckFE = function() {
'use strict';
window.em.leereStorageFeldEdit();
if (localStorage.zurueck && localStorage.zurueck !== "FelderWaehlen.html") {
// via die Feldliste zurück
window.em.leereStorageFeldEdit();
$.mobile.navigate("FeldListe.html");
} else if (localStorage.zurueck && localStorage.zurueck === "FelderWaehlen.html") {
// direkt zurück, Feldliste auslassen
window.em.leereStorageFeldEdit();
window.em.leereStorageFeldListe();
// TODO: Geht zwar richtig zurück. Springt dann aber direkt zur BeobListe.html!
$.mobile.navigate("FelderWaehlen.html");
delete localStorage.zurueck;
} else {
// uups, kein zurück vorhanden
window.em.leereAlleVariabeln();
$.mobile.navigate("BeobListe.html");
}
};
// Neue Beobachtungen werden gespeichert
// ausgelöst durch BeobListe.html, BeobEdit.html, hArtListe.html oder hArtEdit.html
// aufgerufen bloss von Artenliste.html
window.em.speichereNeueBeob = function(aArtBezeichnung) {
'use strict';
var doc = {};
doc.User = localStorage.Email;
doc.aAutor = localStorage.Autor;
doc.aArtGruppe = localStorage.aArtGruppe;
//delete localStorage.aArtGruppe;
doc.aArtName = aArtBezeichnung;
doc.aArtId = localStorage.aArtId;
if (localStorage.Von === "hArtListe" || localStorage.Von === "hArtEdit") {
doc.Typ = "hArt";
doc.hProjektId = localStorage.ProjektId;
doc.hRaumId = localStorage.RaumId;
doc.hOrtId = localStorage.OrtId;
doc.hZeitId = localStorage.ZeitId;
doc.aArtId = localStorage.aArtId;
window.em.speichereNeueBeob_02(doc);
} else {
//localStorage.Von == "BeobListe" || localStorage.Von == "BeobEdit"
doc.Typ = "Beobachtung";
doc.zDatum = window.em.erstelleNeuesDatum();
doc.zUhrzeit = window.em.erstelleNeueUhrzeit();
window.em.speichereNeueBeob_02(doc);
}
};
// Neue Beobachtungen werden gespeichert
// ausgelöst durch BeobListe.html, BeobEdit.html, hArtListe.html oder hArtEdit.html
// dies ist der letzte Schritt:
// Autor anfügen und weiter zum Edit-Formular
window.em.speichereNeueBeob_02 = function(doc) {
'use strict';
var $db = $.couch.db("evab");
$db.saveDoc(doc, {
success: function(data) {
var row_objekt = {};
// doc um id und rev ergänzen
doc._id = data.id;
doc._rev = data.rev;
if (doc.Typ === 'hArt') {
// Variabeln verfügbar machen
localStorage.hArtId = data.id;
// damit hArtEdit.html die hArt nicht aus der DB holen muss
window.em.hArt = doc;
localStorage.aArtId = window.em.hArt.aArtId;
localStorage.aArtName = window.em.hArt.aArtName;
localStorage.aArtGruppe = window.em.hArt.aArtGruppe;
// window.em.hArtListe ergänzen, damit bei der nächsten Art kontrolliert werden kann, ob sie schon erfasst wurde
row_objekt.id = data.id;
row_objekt.doc = doc;
// Vorsicht: window.em.hArtListe existiert nicht, wenn in hArtEdit F5 gedrückt wurde!
if (window.em.hArtListe && window.em.hArtListe.rows) {
window.em.hArtListe.rows.push(row_objekt);
// jetzt die Liste neu sortieren
window.em.hArtListe.rows = _.sortBy(window.em.hArtListe.rows, function(row) {
return row.doc.aArtName;
});
}
if (localStorage.hArtSicht === "liste") {
$.mobile.navigate("hArtEditListe.html");
} else {
$.mobile.navigate("hArtEdit.html");
}
} else {
// Variabeln verfügbar machen
localStorage.BeobId = data.id;
// damit BeobEdit.html die Beob nicht aus der DB holen muss
window.em.Beobachtung = doc;
// Globale Variablen für BeobListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
window.em.leereStorageBeobListe();
$.mobile.navigate("BeobEdit.html");
}
},
error: function() {
window.em.melde("Beobachtung nicht gespeichert.");
}
});
};
// Speichert, wenn in BeobEdit oder hArtEdit eine neue Art und ev. auch eine neue Artgruppe gewählt wurde
// erwartet localStorage.Von = von welchem Formular aufgerufen wurde
window.em.speichereBeobNeueArtgruppeArt = function(aArtName) {
'use strict';
var docId;
if (localStorage.Von === "BeobListe" || localStorage.Von === "BeobEdit") {
docId = localStorage.BeobId;
} else {
docId = localStorage.hArtId;
}
var $db = $.couch.db("evab");
$db.openDoc(docId, {
success: function(beob) {
if (localStorage.aArtGruppe) {
beob.aArtGruppe = localStorage.aArtGruppe;
}
beob.aArtName = aArtName;
beob.aArtId = localStorage.aArtId;
$db.saveDoc(beob, {
success: function(data) {
if (localStorage.Von === "BeobListe" || localStorage.Von === "BeobEdit") {
// Variabeln verfügbar machen
localStorage.BeobId = docId;
// Globale Variablen für BeobListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
window.em.leereStorageBeobListe();
$.mobile.navigate("BeobEdit.html");
} else {
// Variabeln verfügbar machen
localStorage.hArtId = docId;
// damit hArtEdit.html die hArt nicht aus der DB holen muss
window.em.hArt = data;
localStorage.aArtId = window.em.hArt.aArtId;
localStorage.aArtName = window.em.hArt.aArtName;
localStorage.aArtGruppe = window.em.hArt.aArtGruppe;
// window.em.hArtListe anpassen
// Vorsicht: window.em.hArtListe existiert nicht, wenn in hArtEdit F5 gedrückt wurde!
if (window.em.hArtListe && window.em.hArtListe.rows) {
_.each(window.em.hArtListe.rows, function(row) {
var hArt = row.doc;
if (hArt._id == docId) {
hArt.aArtGruppe = localStorage.aArtGruppe;
hArt.aArtName = aArtName;
hArt.aArtId = localStorage.aArtId;
}
});
// window.em.hArtListe neu sortieren
window.em.hArtListe.rows = _.sortBy(window.em.hArtListe.rows, function(row) {
return row.doc.aArtName;
});
}
delete localStorage.aArtGruppe;
if (localStorage.hArtSicht === "liste") {
$.mobile.navigate("hArtEditListe.html");
} else {
$.mobile.navigate("hArtEdit.html");
}
}
},
error: function() {
window.em.melde("Fehler: Beobachtung nicht gespeichert");
}
});
}
});
};
window.em.erstelleNeueZeit = function() {
'use strict';
// Neue Zeiten werden erstellt
// ausgelöst durch hZeitListe.html oder hZeitEdit.html
// dies ist der erste Schritt: doc bilden
var doc = {},
$hZeitEdit = $("#hZeitEdit");
doc.Typ = "hZeit";
doc.User = localStorage.Email;
doc.hProjektId = localStorage.ProjektId;
doc.hRaumId = localStorage.RaumId;
doc.hOrtId = localStorage.OrtId;
doc.zDatum = window.em.erstelleNeuesDatum();
doc.zUhrzeit = window.em.erstelleNeueUhrzeit();
// an hZeitEdit.html übergeben
window.em.hZeit = doc;
// Variabeln verfügbar machen
delete localStorage.ZeitId;
localStorage.Status = "neu";
// Globale Variablen für ZeitListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
delete window.em.ZeitListe;
// Vorsicht: Von hZeitEdit.html aus samepage transition!
if ($hZeitEdit.length > 0 && $hZeitEdit.attr("data-url") !== "hZeitEdit") {
// Wenn die data-url ein Pfad ist, verursacht changePage einen Fehler: b.data("page") is undefined
// das Objekt muss über die localStorage übermittelt werden
localStorage.hZeit = JSON.stringify(window.em.hZeit);
window.open("hZeitEdit.html", "_self");
} else if ($hZeitEdit.length > 0 && $hZeitEdit.attr("data-url") === "hZeitEdit") {
//$(":mobile-pagecontainer").pagecontainer("change", "#hZeitEdit.html", { allowSamePageTransition : true }); FUNKTIONIERT NICHT
localStorage.hZeit = JSON.stringify(window.em.hZeit);
window.open("hZeitEdit.html", "_self");
} else {
$.mobile.navigate("hZeitEdit.html");
}
};
// erstellt einen neuen Ort
// wird aufgerufen von: hOrtEdit.html, hOrtListe.html
// erwartet Username, hProjektId, hRaumId
window.em.erstelleNeuenOrt = function() {
'use strict';
var doc = {},
$hOrtEdit = $("#hOrtEdit");
doc.Typ = "hOrt";
doc.User = localStorage.Email;
doc.hProjektId = localStorage.ProjektId;
doc.hRaumId = localStorage.RaumId;
// an hOrtEdit.html übergeben
window.em.hOrt = doc;
// Variabeln verfügbar machen
delete localStorage.OrtId;
// Globale Variablen für OrtListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
window.em.leereStorageOrtListe("mitLatLngListe");
localStorage.Status = "neu"; // das löst bei initiiereOrtEdit die Verortung aus
// Vorsicht: Von hOrtEdit.html aus samepage transition!
if ($hOrtEdit.length > 0 && $hOrtEdit.attr("data-url") !== "hOrtEdit") {
// Wenn die data-url ein Pfad ist, verursacht changePage einen Fehler: b.data("page") is undefined
// das Objekt muss über die localStorage übermittelt werden
localStorage.hOrt = JSON.stringify(window.em.hOrt);
window.open("hOrtEdit.html", "_self");
} else if ($hOrtEdit.length > 0 && $hOrtEdit.attr("data-url") === "hOrtEdit") {
//$(":mobile-pagecontainer").pagecontainer("change", "#hOrtEdit.html", {allowSamePageTransition : true}); FUNKTIONIERT NICHT
localStorage.hOrt = JSON.stringify(window.em.hOrt);
window.open("hOrtEdit.html", "_self");
} else {
$.mobile.navigate("hOrtEdit.html");
}
};
window.em.erstelleNeuenRaum = function() {
'use strict';
var doc = {},
$hRaumEdit = $("#hRaumEdit");
doc.Typ = "hRaum";
doc.User = localStorage.Email;
doc.hProjektId = localStorage.ProjektId;
// in Objekt speichern, das an hRaumEdit.html übergeben wird
window.em.hRaum = doc;
// Variabeln verfügbar machen
delete localStorage.RaumId;
localStorage.Status = "neu";
// Globale Variablen für RaumListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
window.em.leereStorageRaumListe("mitLatLngListe");
// Vorsicht: Von hRaumEdit.html aus same page transition!
if ($hRaumEdit.length > 0 && $hRaumEdit.attr("data-url") !== "hRaumEdit") {
// Wenn die data-url ein Pfad ist, verursacht changePage einen Fehler: b.data("page") is undefined
// das Objekt muss über die localStorage übermittelt werden
localStorage.hRaum = JSON.stringify(window.em.hRaum);
window.open("hRaumEdit.html", "_self");
} else if ($hRaumEdit.length > 0 && $hRaumEdit.attr("data-url") === "hRaumEdit") {
//$(":mobile-pagecontainer").pagecontainer("change", "#hRaumEdit.html", {allowSamePageTransition : "true"}); FUNKTIONIERT NICHT
localStorage.hRaum = JSON.stringify(window.em.hRaum);
window.open("hRaumEdit.html", "_self");
} else {
$.mobile.navigate("hRaumEdit.html");
}
};
// erstellt ein Objekt für ein neues Projekt und öffnet danach hProjektEdit.html
// das Objekt wird erst von initiiereProjektEdit gespeichert (einen DB-Zugriff sparen)
window.em.erstelleNeuesProjekt = function() {
'use strict';
var doc = {},
$hProjektEdit = $("#hProjektEdit");
doc.Typ = "hProjekt";
doc.User = localStorage.Email;
// damit hProjektEdit.html die hArt nicht aus der DB holen muss
window.em.hProjekt = doc;
// ProjektId faken, sonst leitet die edit-Seite an die oberste Liste weiter
delete localStorage.ProjektId;
localStorage.Status = "neu";
// Globale Variablen für hProjektListe zurücksetzen, damit die Liste beim nächsten Aufruf neu aufgebaut wird
window.em.leereStorageProjektListe("mitLatLngListe");
// Vorsicht: Von hProjektEdit.html aus same page transition!
if ($hProjektEdit.length > 0 && $hProjektEdit.attr("data-url") !== "hProjektEdit") {
// Wenn die data-url ein Pfad ist, verursacht changePage einen Fehler: b.data("page") is undefined
// das Objekt muss über die localStorage übermittelt werden
localStorage.hProjekt = JSON.stringify(window.em.hProjekt);
window.open("hProjektEdit.html", "_self");
} else if ($hProjektEdit.length > 0 && $hProjektEdit.attr("data-url") === "hProjektEdit") {
//$.mobile.navigate($hProjektEdit, {allowSamePageTransition: true}); FUNKTIONIERT NICHT
localStorage.hProjekt = JSON.stringify(window.em.hProjekt);
window.open("hProjektEdit.html", "_self");
} else {
$.mobile.navigate("hProjektEdit.html");
}
};
window.em.öffneMeineEinstellungen = function() {
'use strict';
$.mobile.navigate("UserEdit.html");
};
window.em.löscheDokument = function(DocId) {
'use strict';
var $db = $.couch.db("evab");
return $db.openDoc(DocId, {
success: function(document) {
$db.removeDoc(document, {
success: function() {
return true;
},
error: function() {
return false;
}
});
},
error: function() {
return false;
}
});
};
// initiiert Variabeln, fixe Felder und dynamische Felder in BeobEdit.html
// wird aufgerufen von BeobEdit.html und Felder_Beob.html
window.em.initiiereBeobEdit = function() {
'use strict';
// Anhänge ausblenden, weil sie sonst beim Wechsel stören
//$('#AnhängeBE').hide();
// prüfen, ob die Feldliste schon geholt wurde
// wenn ja: deren globale Variable verwenden
if (window.em.FeldlisteBeobEdit) {
window.em.initiiereBeobEdit_2();
} else {
// das dauert länger - hinweisen
$("#BeobEditFormHtml").html('<p class="HinweisDynamischerFeldaufbau">Die Felder werden aufgebaut...</p>');
// holt die Feldliste aus der DB
var $db = $.couch.db("evab");
$db.view('evab/FeldListeBeob?include_docs=true', {
success: function(data) {
// Globale Variable erstellen, damit ab dem zweiten mal die vorige Abfrage gespaart werden kann
window.em.FeldlisteBeobEdit = data;
window.em.initiiereBeobEdit_2();
}
});
}
};
// allfällige Beob übernehmen von speichereNeueBeob
// um die DB-Abfrage zu sparen
window.em.initiiereBeobEdit_2 = function() {
'use strict';
// achtung: wenn soeben die Art geändert wurde, müssen ArtId und ArtName neu geholt werden
if (window.em.Beobachtung && (!localStorage.Von || localStorage.Von !== "BeobEdit")) {
window.em.initiiereBeobEdit_3();
} else {
var $db = $.couch.db("evab");
$db.openDoc(localStorage.BeobId, {
success: function(data) {
window.em.Beobachtung = data;
window.em.initiiereBeobEdit_3();
}
});
}
};
window.em.initiiereBeobEdit_3 = function() {
'use strict';
// diese (globalen) Variabeln werden in BeobEdit.html gebraucht
// bei neuen Beob hat das Objekt noch keine ID
if (window.em.Beobachtung._id) {
localStorage.BeobId = window.em.Beobachtung._id;
} else {
localStorage.BeobId = "neu";
}
localStorage.aArtGruppe = window.em.Beobachtung.aArtGruppe;
localStorage.aArtName = window.em.Beobachtung.aArtName;
localStorage.aArtId = window.em.Beobachtung.aArtId;
localStorage.oLongitudeDecDeg = window.em.Beobachtung.oLongitudeDecDeg || "";
localStorage.oLatitudeDecDeg = window.em.Beobachtung.oLatitudeDecDeg || "";
localStorage.oLagegenauigkeit = window.em.Beobachtung.oLagegenauigkeit || "";
localStorage.oXKoord = window.em.Beobachtung.oXKoord;
localStorage.oYKoord = window.em.Beobachtung.oYKoord;
window.em.setzeFixeFelderInBeobEdit(window.em.Beobachtung);
window.em.erstelleDynamischeFelderBeobEdit();
window.em.blendeMenus();
// letzte url speichern - hier und nicht im pageshow, damit es bei jedem Datensatzwechsel passiert
window.em.speichereLetzteUrl();
};
// generiert in BeobEdit.html dynamisch die von den Sichtbarkeits-Einstellungen abhängigen Felder
// und aktualisiert die Links für pagination
// Mitgeben: id der Beobachtung, Username
window.em.erstelleDynamischeFelderBeobEdit = function() {
'use strict';
var htmlContainer = window.em.generiereHtmlFürBeobEditForm();
// Linie nur anfügen, wenn Felder erstellt wurden
if (htmlContainer) {
htmlContainer = "<hr />" + htmlContainer;
} else {
htmlContainer = "";
}
// nötig, weil sonst die dynamisch eingefügten Elemente nicht erscheinen (Felder) bzw. nicht funktionieren (links)
$("#BeobEditFormHtml").html(htmlContainer).trigger("create").trigger("refresh");
// jetzt alle Flipswitsches, die "nein" sind, aktiv setzen
window.em.aktiviereFlipswitches("#BeobEditFormHtml", window.em.Beobachtung);
$("#BeobEdit").trigger("create").trigger("refresh");
};
// setzt die Values in die hart codierten Felder im Formular BeobEdit.html
// erwartet das Objekt Beob, welches die Werte enthält
window.em.setzeFixeFelderInBeobEdit = function() {
'use strict';
var $aArtGruppeBE = $("#aArtGruppeBE"),
$aArtNameBE = $("#aArtNameBE");
$aArtGruppeBE.selectmenu();
$aArtGruppeBE.html("<option value='" + window.em.Beobachtung.aArtGruppe + "'>" + window.em.Beobachtung.aArtGruppe + "</option>");
$aArtGruppeBE.val(window.em.Beobachtung.aArtGruppe);
// JQUERY MOBILE BRACHT MANCHMAL LANGE UM ZU INITIALIIEREN
// OHNE TIMEOUT REKLAMIERT ES BEIM REFRESH, DAS WIDGET SEI NOCH NICHT INITIALISIERT!!!!
// NACH EIN MAL VERZÖGERN HAT ES ABER WIEDER FUNKTIONIERT????!!!!
setTimeout(function() {
$aArtGruppeBE.selectmenu("refresh");
}, 0);
$aArtNameBE.selectmenu();
$aArtNameBE.html("<option value='" + window.em.Beobachtung.aArtName + "'>" + window.em.Beobachtung.aArtName + "</option>");
$aArtNameBE.val(window.em.Beobachtung.aArtName);
$aArtNameBE.selectmenu("refresh");
$("[name='aAutor']").val(window.em.Beobachtung.aAutor);
$("[name='oXKoord']").val(window.em.Beobachtung.oXKoord);
$("[name='oYKoord']").val(window.em.Beobachtung.oYKoord);
$("[name='oLagegenauigkeit']").val(window.em.Beobachtung.oLagegenauigkeit);
$("[name='zDatum']").val(window.em.Beobachtung.zDatum);
$("[name='zUhrzeit']").val(window.em.Beobachtung.zUhrzeit);
};
// generiert das Html für das Formular in BeobEdit.html
// erwartet Feldliste als Objekt; Beob als Objekt, Artgruppe
// der htmlContainer wird zurück gegeben
window.em.generiereHtmlFürBeobEditForm = function() {
'use strict';
var htmlContainer = "",
ArtGruppe = window.em.Beobachtung.aArtGruppe,
FeldWert;
_.each(window.em.FeldlisteBeobEdit.rows, function(row) {
var Feld = row.doc,
FeldName = Feld.FeldName;
// nur sichtbare eigene Felder. Bereits im Formular integrierte Felder nicht anzeigen
if ((Feld.User === localStorage.Email || Feld.User === "ZentrenBdKt") && Feld.SichtbarImModusEinfach.indexOf(localStorage.Email) !== -1 && ['aArtGruppe', 'aArtName', 'aAutor', 'aAutor', 'oXKoord', 'oYKoord', 'oLagegenauigkeit', 'zDatum', 'zUhrzeit'].indexOf(FeldName) === -1) {
// In Hierarchiestufe Art muss die Artgruppe im Feld Artgruppen enthalten sein
// vorsicht: Erfasst jemand ein Feld der Hierarchiestufe Art ohne Artgruppe, sollte das keinen Fehler auslösen
if (Feld.Hierarchiestufe !== "Art" || (typeof Feld.ArtGruppe !== "undefined" && (Feld.ArtGruppe.indexOf(ArtGruppe) >= 0 || Feld.ArtGruppe[0] === "alle"))) {
if (localStorage.Status === "neu" && Feld.Standardwert && Feld.Standardwert[localStorage.Email]) {
FeldWert = Feld.Standardwert[localStorage.Email];
// Objekt Beob um den Standardwert ergänzen, um später zu speichern
window.em.Beobachtung[FeldName] = FeldWert;
} else {
// "" verhindert die Anzeige von undefined im Feld
FeldWert = window.em.Beobachtung[FeldName] || "";
}
htmlContainer += window.em.generiereHtmlFürFormularelement(Feld, FeldWert);
}
}
});
if (localStorage.Status === "neu") {
// in neuen Datensätzen dynamisch erstellte Standardwerte speichern
var $db = $.couch.db("evab");
$db.saveDoc(window.em.Beobachtung, {
success: function(data) {
window.em.Beobachtung._id = data.id;
window.em.Beobachtung._rev = data.rev;
localStorage.BeobId = data.id;
window.em.GetGeolocation(data.id, "Beobachtung");
}
});
delete localStorage.Status;
} else {
// Neue Datensätze haben keine Attachments
window.em.zeigeAttachments(window.em.Beobachtung, "BE");
}
return htmlContainer;
};
// BeobListe in BeobList.html vollständig neu aufbauen
window.em.initiiereBeobliste = function() {
'use strict';
// hat BeobEdit.html eine BeobListe übergeben?
if (window.em.BeobListe) {
// Beobliste aus globaler Variable holen - muss nicht geparst werden
window.em.initiiereBeobliste_2();
} else {
// Beobliste aus DB holen
var $db = $.couch.db("evab");
$db.view('evab/BeobListe?startkey=["' + localStorage.Email + '",{}]&endkey=["' + localStorage.Email + '"]&descending=true&include_docs=true', {
success: function(data) {
// BeobListe für BeobEdit bereitstellen
window.em.BeobListe = data;
window.em.initiiereBeobliste_2();
}
});
}
};
window.em.initiiereBeobliste_2 = function() {
'use strict';
var anzBeob = window.em.BeobListe.rows.length,
beob,
key,
listItemContainer = "",
Titel2,
artgruppenname;
// Im Titel der Seite die Anzahl Beobachtungen anzeigen
Titel2 = " Beobachtungen";
if (anzBeob === 1) {
Titel2 = " Beobachtung";
}
$("#BeobListePageHeader")
.find(".BeobListePageTitel")
.text(anzBeob + Titel2);
if (anzBeob === 0) {
listItemContainer = '<li><a href="#" class="erste NeueBeobBeobListe">Erste Beobachtung erfassen</a></li>';
} else {
_.each(window.em.BeobListe.rows, function(row) {
beob = row.doc;
key = row.key;
artgruppenname = encodeURIComponent(beob.aArtGruppe.replace('ü', 'ue').replace('ä', 'ae').replace('ö', 'oe')) + ".png";
if (beob.aArtGruppe === "DiverseInsekten") {
artgruppenname = "unbenannt.png";
}
listItemContainer += "<li class='beob ui-li-has-thumb' id='";
listItemContainer += beob._id;
listItemContainer += "'><a href='#'><img class='ui-li-thumb' src='";
listItemContainer += "Artgruppenbilder/" + artgruppenname;
listItemContainer += "' /><h3 class='aArtName'>";
listItemContainer += beob.aArtName;
listItemContainer += "<\/h3><p class='zUhrzeit'>";
listItemContainer += beob.zDatum;
listItemContainer += " ";
listItemContainer += beob.zUhrzeit;
listItemContainer += "<\/p><\/a> <\/li>";
});
}
$("#BeoblisteBL")
.html(listItemContainer)
.listview("refresh");
window.em.blendeMenus();
// Fokus in das Suchfeld setzen
$("#BeobListe")
.find(".ui-input-search")
.children("input")[0]
.focus();
window.em.speichereLetzteUrl();
};
// löscht Anhänge
// erwartet den Datensatz als Objekt und das Objekt, dass geklickt wurde
window.em.löscheAnhang = function(that, Objekt, id) {
'use strict';
if (Objekt) {
// Es wurde ein Objekt übergeben, keine DB-Abfrage nötig
window.em.löscheAnhang_2(that, Objekt);
} else {
// Objekt aus der DB holen
var $db = $.couch.db("evab");
$db.openDoc(id, {
success: function(data) {
window.em[Objekt.Typ] = data;
window.em.löscheAnhang_2(that, window.em[Objekt.Typ]);
},
error: function() {
window.em.melde("Fehler: Anhang wurde nicht entfernt");
}
});
}
};
window.em.löscheAnhang_2 = function(that, Objekt) {
'use strict';
var Dateiname = that.id;
// Anhang aus Objekt entfernen
delete window.em[Objekt.Typ]._attachments[Dateiname];
// Objekt in DB speichern
$db.saveDoc(window.em[Objekt.Typ], {
success: function(data) {
// rev im Objekt ergänzen
// die globale Variable heisst gleich, wie der Typ im Objekt
window.em[Objekt.Typ]._rev = data.rev;
// im Formular den Anhang und die Lösch-Schaltfläche entfernen
$(that).parent().parent().remove();
},
error: function() {
window.em.melde("Fehler: Anhänge werden nicht richtig angezeigt");
}
});
};
// initiiert UserEdit.html
window.em.initiiereUserEdit = function() {
'use strict';
$("#ue_Email").val(localStorage.Email);
$("[name='Datenverwendung']").checkboxradio();
if (localStorage.Autor) {
$("#Autor").val(localStorage.Autor);
}
$.couch.userDb(function(db) {
db.openDoc("org.couchdb.user:" + localStorage.Email, {
success: function(User) {
// fixe Felder aktualisieren
if (User.Datenverwendung) {
$("#" + User.Datenverwendung).prop("checked",true).checkboxradio("refresh");
localStorage.Datenverwendung = User.Datenverwendung;
} else {
// Standardwert setzen
$("#JaAber").prop("checked",true).checkboxradio("refresh");
}
window.em.blendeMenus();
window.em.speichereLetzteUrl();
},
error: function() {
console.log('Fehler in window.em.initiiereUserEdit');
// Standardwert setzen
$("#JaAber").prop("checked",true).checkboxradio("refresh");
}
});
});
};
// initiiert Installieren.html
// kurz, da keine Daten benötigt werden
window.em.initiiereInstallieren = function() {
'use strict';
window.em.blendeMenus();
window.em.speichereLetzteUrl();
};
// generiert in hProjektEdit.html dynamisch die von den Sichtbarkeits-Einstellungen abhängigen Felder
// Mitgeben: id des Projekts, Username
// bei neuen Projekten wird das zuvor erzeugte Projekt übernommen, um die DB-Anfrage zu sparen
window.em.initiiereProjektEdit = function() {
'use strict';
// Anhänge ausblenden, weil sonst beim Einblenden diejenigen des vorigen Datensatzes aufblitzen
//$('#AnhängehPE').hide().trigger('updatelayout');
// window.em.hProjekt existiert schon bei neuem Projekt
if (window.em.hProjekt) {
window.em.initiiereProjektEdit_2();
} else if (localStorage.Status === "neu" && localStorage.hProjekt) {
// wenn mit window.open von neu gekommen, existiert die globale Variable nicht mehr
window.em.hProjekt = JSON.parse(localStorage.hProjekt);
delete localStorage.hProjekt;
window.em.initiiereProjektEdit_2();
} else {
var $db = $.couch.db("evab");
$db.openDoc(localStorage.ProjektId, {
success: function(data) {
window.em.hProjekt = data;
window.em.initiiereProjektEdit_2();
},
error: function() {
// hoppla, zu dieser ID gibt es kein Projekt > Speicher löschen und Liste anzeigen
window.em.leereStorageProjektEdit("mitLatLngListe");
$.mobile.navigate("hProjektListe.html");
}
});
}
};
window.em.initiiereProjektEdit_2 = function() {
'use strict';
// fixe Felder aktualisieren
$("#pName").val(window.em.hProjekt.pName);
// Variabeln bereitstellen (bei neuen Projekten wird ProjektId später nachgeschoben)
if (window.em.hProjekt._id) {
localStorage.ProjektId = window.em.hProjekt._id;
} else {
localStorage.ProjektId = "neu";
}
// prüfen, ob die Feldliste schon geholt wurde
// wenn ja: deren globale Variable verwenden
if (window.em.FeldlisteProjekt) {
window.em.initiiereProjektEdit_3();
} else {
// das dauert länger - Hinweis einblenden
$("#hProjektEditFormHtml").html('<p class="HinweisDynamischerFeldaufbau">Die Felder werden aufgebaut...</p>');
// Feldliste aus der DB holen
var $db = $.couch.db("evab");
$db.view('evab/FeldListeProjekt?include_docs=true', {
success: function(Feldliste) {
window.em.FeldlisteProjekt = Feldliste;
window.em.initiiereProjektEdit_3();
}
});
}
};
window.em.initiiereProjektEdit_3 = function() {
'use strict';
var htmlContainer = window.em.generiereHtmlFürProjektEditForm();
// Linie nur anfügen, wenn Felder erstellt wurden
if (htmlContainer) {
htmlContainer = "<hr />" + htmlContainer;
}
$("#hProjektEditFormHtml").html(htmlContainer).trigger("create").trigger("refresh");
// jetzt alle Flipswitsches, die "nein" sind, aktiv setzen
window.em.aktiviereFlipswitches("#hProjektEditFormHtml", window.em.hProjekt);
window.em.blendeMenus();
// letzte url speichern - hier und nicht im pageshow, damit es bei jedem Datensatzwechsel passiert
window.em.speichereLetzteUrl();
};
// generiert das Html für das Formular in hProjektEdit.html
// erwartet Feldliste als Objekt; Projekt als Objekt
// der htmlContainer wird zurück gegeben
window.em.generiereHtmlFürProjektEditForm = function() {
'use strict';
var Feld = {},
FeldName,
FeldWert,
htmlContainer = "";
_.each(window.em.FeldlisteProjekt.rows, function(row) {
Feld = row.doc;
FeldName = Feld.FeldName;
// nur sichtbare eigene Felder. Bereits im Formular integrierte Felder nicht anzeigen
if ((Feld.User === localStorage.Email || Feld.User === "ZentrenBdKt") && Feld.SichtbarImModusHierarchisch.indexOf(localStorage.Email) !== -1 && FeldName !== "pName") {
if (localStorage.Status === "neu" && Feld.Standardwert && Feld.Standardwert[localStorage.Email]) {
FeldWert = Feld.Standardwert[localStorage.Email];
// window.em.hProjekt um den Standardwert ergänzen, um später zu speichern
window.em.hProjekt[FeldName] = FeldWert;
} else {
//"" verhindert die Anzeige von undefined im Feld
FeldWert = window.em.hProjekt[FeldName] || "";
}
htmlContainer += window.em.generiereHtmlFürFormularelement(Feld, FeldWert);
}
});
if (localStorage.Status === "neu") {
$("#pName").focus();
// in neuen Datensätzen dynamisch erstellte Standardwerte speichern
var $db = $.couch.db("evab");
$db.saveDoc(window.em.hProjekt, {
success: function(data) {
window.em.hProjekt._id = data.id;
window.em.hProjekt._rev = data.rev;
//
localStorage.ProjektId = data.id;
}
});
delete localStorage.Status;
} else {
// neue Datensätze haben keine Attachments
window.em.zeigeAttachments(window.em.hProjekt, "hPE");
}
return htmlContainer;