/
cc_standardview.js
1286 lines (1131 loc) · 43.6 KB
/
cc_standardview.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
//Implementiert die Standard-Features fuer eine Table View: renderView und renderList
//Constructor
function StandardTableView(options) {
var t=this;
AbstractView.call(this);
this.name="StandardTableView";
this.init=false;
this.filter=new Object();
this.furtherFilterVisible=false;
this.listOffset=0;
this.sortVariable="id";
this.availableRowCounts=[10, 25, 50, 200];
this.overrideMaxRows=false;
this.showCheckboxes=true;
// Number of entries currently visible
this.counter=0;
// Der letzte ge�ffnet Eintrag, wird gemerkt, damit er nach einem renderList()
// auch wieder angezeigt wird.
this.testTimer=null; // Zeitmessung
this.renderListTimer=null;
this.listViewAggregate=false;
this.listViewTableHeight=null; // Wenn ja, hat die Tabelle eien fixen Titel
this.showPaging=true;
this.rowNumbering=true;
if (options!=null) {
$.each(options, function(k,a) {
t[k]=a;
});
}
}
Temp.prototype = AbstractView.prototype;
StandardTableView.prototype = new Temp();
StandardTableView.prototype.initView = function () {
};
StandardTableView.prototype.historyCreateStep = function () {
var str = "";
jQuery.each(this.filter, function(k,a) {
str=str+"/"+k+":"+a;
});
churchInterface.historyCreateStep(this.name+str+"/");
};
/*
* Ruft alle Functions auf, um die View komplett zu bauen
* Parameter: withMenu - default = true
*/
StandardTableView.prototype.renderView = function(withMenu) {
var t=this;
if (t.init==false) {
t.initView();
t.init=true;
}
if (!churchcore_handyformat()) {
if ((withMenu==null) || (withMenu)) {
this.renderMenu();
}
this.renderListMenu();
this.renderFilter();
if (!churchcore_touchscreen())
$("#searchEntry").focus();
}
else {
this.renderMenu();
this.renderListMenu();
$("#cdb_menu").append(" "+form_renderButton({label:_("filter")+" »", htmlclass:"togglefilter"})+"<br/><br/>");
$("#cdb_menu input.togglefilter").click(function() {
if ($("#cdb_filter").html()=="") {
t.renderFilter();
$(this).val(_("filter")+" "+String.fromCharCode(171));
}
else {
$("#cdb_filter").html("");
$(this).val(_("filter")+" "+String.fromCharCode(187));
}
});
}
if (this.furtherFilterVisible)
this.renderFurtherFilter();
this.renderList();
};
// Mit der Function kann man die Eintr�ge gruppieren. Einfach den Gruppenwert ausgeben
StandardTableView.prototype.groupingFunction = function() {
return null;
};
StandardTableView.prototype.getCountCols = function() {
return 1;
};
/**
* @param filterId
* @return Gibt den aktuellen Wert des Filters filterId zurueck oder "" wenn nicht gefuellt.
*/
StandardTableView.prototype.getFilter = function(filterId) {
if (this.filter[filterId]!=null)
return this.filter[filterId];
else return "";
};
// L�scht den Filter und gibt true zur�ck, wenn er gesetzt war
StandardTableView.prototype.deleteFilter = function(filterId) {
if (this.filter[filterId]!=null) {
delete this.filter[filterId];
return true;
}
else return false;
};
StandardTableView.prototype.renderFurtherFilter = function() {
};
/**
* Messages schicken an die Views
*/
StandardTableView.prototype.messageReceiver = function(message, args) {
};
/**
*
* @param this_object - Gibt die zu verwendene this an
* @param divid - Divid, fuer die der Callback installiert werden soll
*/
_aktiv=false;
StandardTableView.prototype.implantStandardFilterCallbacks = function(this_object, divid) {
var t=this;
var myfilter=t.filter;
$("#"+divid+" select").change(function(c) {
var oldVal=myfilter[$(this).attr("id")];
if ($(this).val()=="") {
delete myfilter[$(this).attr("id")];
}
else {
myfilter[$(this).attr("id")]=$(this).val();
}
churchInterface.sendMessageToAllViews("filterChanged",new Array($(this).attr("id"), oldVal));
t.listOffset=0;
t.renderList(null, false);
});
$("#"+divid+" input:checkbox").click(function(c) {
var oldVal=myfilter[$(this).attr("id")];
if ($(this).attr("checked")) {
myfilter[$(this).attr("id")]=true;
}
else {
delete myfilter[$(this).attr("id")];
}
churchInterface.sendMessageToAllViews("filterChanged",new Array($(this).attr("id"), oldVal));
t.listOffset=0;
t.renderList(null, false);
});
$("#"+divid+" input:text").keyup(function(c) {
if ((myfilter[$(this).attr("id")]!=$(this).val()) && (($(this).val().length>0) || $(this).val()=="")) {
var oldVal=myfilter[$(this).attr("id")];
var id=$(this).attr("id");
if ($(this).val()=="")
delete myfilter[$(this).attr("id")];
else
myfilter[$(this).attr("id")]=$(this).val();
t.listOffset=0;
// Ein Timeout erlaubt das entspannte Eintippen, ohne das immer sofort die Seite neu geladen wird.
if (_aktiv!=null)
_aktiv=window.clearTimeout(_aktiv);
_aktiv=window.setTimeout(function() {
churchInterface.sendMessageToAllViews("filterChanged",new Array(id, oldVal));
t.renderList(null, false);
_aktiv=false;
},300);
}
});
};
/*
* Erlaubt das Setzen des Filters einer View, filtername=value
*/
StandardTableView.prototype.setFilter = function(filterName, value) {
this.filter[filterName]=value;
};
/*
* Loescht alle Filter
*/
StandardTableView.prototype.clearFilter = function() {
this.filter=new Object();
this.listOffset=0;
};
/**
*
* @param {Object} data - Array type (Array mit Feldern id und bezeichnung)
* @param {Object} name - Anzeigename
* @param {Object} selected - Welches soll vorselektiert sien?
* @param {Object} func - möglihce Einschränkungsfunciton
*/
StandardTableView.prototype.getSelectFilter = function(data, name, selected, func, emptyentry) {
if (data==null) return "";
if (emptyentry==null) emptyentry=true;
if (name!="")
_text='<font style="font-size:8pt;">'+name+": </font><select id=\"filter"+name+"\" style=\"\">";
else
_text="<select id=\"filterVoid"+"\" style=\"\">";
if (emptyentry)
_text=_text+'<option value=""></option>';
jQuery.each(data, function (i,d) {
if ((typeof func !="function") || (func(d))) {
_text=_text+"<option value=\""+d.id+"\"";
if (selected==d.id) _text=_text+" selected ";
_text=_text+">"+d.bezeichnung.trim(25)+"</option>";
}
});
_text=_text+"</select> ";
return _text;
};
/*
* View kann noch ein Menu hinzufuegen fuer Extra-Funktionen abhaegngig von der aktuellen Sicht
*/
StandardTableView.prototype.addSecondMenu = function() {
return "";
};
StandardTableView.prototype.addFurtherListCallbacks = function() {
};
StandardTableView.prototype.renderOneListEntry = function(id) {
};
/*
* Generiert die Liste, verwendet dafuer getListHeader und renderListEntry und addSecondMenu
* entry wenn nur ein Eintrag neu gerendert werden soll. Sehr sinnvoll bei gro�en Listen (z.B. Dienstplan!)
* newSort (default true)
*/
StandardTableView.prototype.renderList = function(entry, newSort) {
t=this;
var rows = new Array();
// Wenn nur ein Eintrag neu gerendert werden soll
if (entry!=null) {
if (t.checkFilter(entry)) {
if (entry.checked == true)
rows[rows.length] = "<td><input type=\"checkbox\" id=\"check" + entry.id +
"\" checked=\"checked\" class=\"checked\">";
else
rows[rows.length] = "<td><input type=\"checkbox\" id=\"check" + entry.id +
"\" class=\"checked\">";
if (t.rowNumbering && t.groupingFunction(entry)==null) {
rows.push("<td><a href=\"\" id=\"detail" + entry.id + "\">" + $("tr[id="+entry.id+"]").find("td").next().first().text()+"</a>");
}
var txt=t.renderListEntry(entry);
if (txt!=null) {
rows.push(txt);
$("#cdb_content tr[id="+entry.id+"]").html(rows.join(""));
t.addTableContentCallbacks("#cdb_content tr[id="+entry.id+"]");
if (entry.open) t.renderEntryDetail(entry.id);
}
} // Wenn der Filter nicht mehr passt, dann l�sche es
else {
$("#cdb_content tr[id="+entry.id+"]").html("");
}
}
// Wenn die ganze Tabelle neu gerendert werden soll
else {
if (t.renderListTimer==null)
t.renderListTimer=window.setTimeout(function() {
if (debug) t.startTimer();
var current_id = 0;
listObject=t.getData(true, newSort);
$("#cdb_content").html("Render table...");
if ((masterData.settings==null) || (masterData.settings.listViewTableHeight==null) || (masterData.settings.listViewTableHeight==0))
t.listViewTableHeight=null;
else
t.listViewTableHeight=646;
if (masterData.settings==null) masterData.settings=new Object();
if (masterData.settings["listMaxRows"+t.name]==null)
masterData.settings["listMaxRows"+t.name]=25;
else masterData.settings["listMaxRows"+t.name]=masterData.settings["listMaxRows"+t.name]*1;
// Wenn es Handyformat ist dann zeige immer nur 10 Zeilen, au�er bei der Ressourcen-WeekView,
// denn hier macht es Sinn, das man alle sieht.
if ((!t.overrideMaxRows) && (churchcore_handyformat()) && (churchInterface.getCurrentView().name!="WeekView")) {
masterData.settings["listMaxRows"+t.name]=10;
}
var header=t.getListHeader();
if (listObject == null || churchcore_isObjectEmpty(listObject)) {
if (churchInterface.allDataLoaded)
rows[rows.length] = _("no.entry.found");
else
rows[rows.length] = '<br><p align="center">'+form_renderImage({src:"loading.gif"})+'<p>';
}
else {
var classes='view '+t.name+' table table-bordered table-condensed ';
rows[rows.length] = '<div style="" id="DivAddressTable"><table class="'+classes+'table-striped" style="tab_le-layout:fixed;margin-bottom:0px;" id="AddressTable">';
rows[rows.length] = '<thead>';
if (t.showCheckboxes)
rows.push('<tr><th width="12px"><input type="checkbox" class="checked" id="markAll" title="'+_("select.all")+'">');
rows.push(header);
rows.push('</thead>');
if (t.listViewTableHeight!=null) {
rows.push('</table></div>');
rows.push('<div style="min-height:300px; position:relative; max-height:'+t.listViewTableHeight+'px; overflow-y:auto; overflow-x:auto">');
rows.push('<table class="'+classes+'" style="margin-bottom:0px" id="AddressTableChild">');
}
rows.push('<tbody>');
t.counter = 0;
var lastGrouping=null;
$.each(listObject, function(k, entry) {
if ((entry!=null) && (t.checkFilter(entry))) {
t.counter++;
if ((t.counter>=t.listOffset) && (t.counter<=masterData.settings["listMaxRows"+t.name]+t.listOffset)) {
entry_txt=t.renderListEntry(entry);
if (entry_txt==null)
t.counter--;
else {
var r = t.groupingFunction(entry);
if (r!=lastGrouping) {
lastGrouping=r;
rows.push('<tr class="grouping"><td class="grouping" align="center" colspan="'+(t.getCountCols())+'">'+r);
}
rows.push("<tr class=\"data\" id=\"" + entry.id + "\">");
if (t.showCheckboxes) {
rows.push("<td width=\"12px\"><input type=\"checkbox\" class=\"checked\" id=\"check" + entry.id + "\"");
if (entry.checked) rows.push(" checked=checked");
rows.push(">");
}
if (t.rowNumbering && lastGrouping==null)
rows.push("<td><a href=\"\" id=\"detail" + entry.id + "\">" + t.counter + "</a>");
rows.push(entry_txt);
current_id = entry.id;
}
}
}
});
rows.push('<tbody>');
rows.push("</table>");
rows.push("</div>");
rows.push('<table class="table table-bordered table-condensed"><tr><td>');
if (t.counter>=masterData.settings["listMaxRows"+t.name]) {
if (!churchcore_handyformat()) {
rows[rows.length] = _("show.x.from.y.entries", masterData.settings["listMaxRows"+t.name], t.counter);
rows.push(" "+_("paging")+": <a id=\"offset0\" href=\"#\"><<</a> | <a id=\"offsetMinus\" href=\"#\"><</a> | <a id=\"offsetPlus\" href=\"#\">></a>");
}
else {
rows.push(_("paging")+": <a id=\"offset0\" href=\"#\"><<</a> | <a id=\"offsetMinus\" href=\"#\"><</a> | <a id=\"offsetPlus\" href=\"#\">></a>");
rows[rows.length] = '<span class="pull-right">'+
_("show.x.from.y.entries", masterData.settings["listMaxRows"+t.name], t.counter)+" </span><br/>";
}
}
else
rows[rows.length] = _("show.x.entries", t.counter);
if (t.showPaging) {
if (!churchcore_handyformat()) {
rows.push(" "+_("number.of.rows")+": ");
$.each(t.availableRowCounts, function(i,k) {
rows.push('<a href="#" class="changemaxrow" data-id="'+k+'">'+k+'</a> | ');
});
rows.push(" ");
if ((masterData.settings["listMaxRows"+t.name]<=20) || (t.counter<=20))
rows.push(" <a href=\"#\" id=\"showAll\">"+_("open.each")+"</a>");
rows.push(" <a href=\"#\" id=\"hideAll\">"+_("close.each")+"</a>");
}
else {
rows.push(_("show")+" ");
$.each(t.availableRowCounts, function(i,k) {
rows.push('<a href="#" class="changemaxrow" data-id="'+k+'">'+k+'</a> | ');
});
rows.push('<span class="pull-right"><a href="#" id="hideAll">'+_("close.each")+'</a></span>');
}
}
rows.push('</table>');
if (t.listViewTableHeight!=null) rows.push("<p></p>");
rows.push(t.addSecondMenu());
}
$("#cdb_content").html(rows.join(""));
if (debug) t.endTimer("renderTableView");
calcHeaderWidth(current_id);
// Callbacks auf die Header und Footer der Tabelle
$("#cdb_content a").click(function (_content_a) {
if ($(this).attr("id")=="orderby") loadList("","",$(this).attr("href"));
else if ($(this).attr("id")=="offset0") {
t.listOffset=0;
t.renderList();
}
else if ($(this).attr("id")=="offsetMinus") {
t.listOffset=t.listOffset-masterData.settings["listMaxRows"+t.name];
if (t.listOffset<0) t.listOffset=0;
t.renderList();
}
else if ($(this).attr("id")=="offsetPlus") {
t.listOffset=t.listOffset+masterData.settings["listMaxRows"+t.name];
t.renderList();
}
else if ($(this).attr("id")=="showAll") {
n=0; j=0;
$.each(listObject, function(k, a) {
n++;
if (t.checkFilter(a)) {
j++;
if ((n>=t.listOffset) && (j<=masterData.settings["listMaxRows"+t.name])) {
t.renderEntryDetail(a.id);
}
}
});
}
else if ($(this).attr("id")=="hideAll") {
$.each(listObject, function(k, entry) {
entry.open=false;
});
t.renderList();
}
});
$("#cdb_content a.changemaxrow").click(function () {
masterData.settings["listMaxRows"+t.name]=$(this).attr("data-id");
t.renderList();
if (!churchcore_handyformat())
churchInterface.jsendWrite({func:"saveSetting", sub:"listMaxRows"+t.name, val:$(this).attr("data-id")});
t.overrideMaxRows=true;
return false;
});
t.addTableContentCallbacks("#cdb_content");
$(window).resize(function() {
calcHeaderWidth();
});
if (listObject!=null)
$.each(listObject, function(k, entry) {
if ((entry!=null) && (t.checkFilter(entry)))
if ((entry.open) || (t.counter==1)) t.renderEntryDetail(entry.id);
});
if (debug) t.endTimer("renderTablecallback");
t.renderListTimer=null;
},10);
}
};
StandardTableView.prototype.startTimer = function() {
this.testTimer=new Date();
};
StandardTableView.prototype.endTimer = function(name) {
console.log(name+": "+churchcore_getTimeDiff(this.testTimer));
$("#cdb_content").prepend("<small><br>"+name+": "+churchcore_getTimeDiff(this.testTimer)+'</small>');
this.startTimer();
};
function calcHeaderWidth() {
// headerFromChild
var header=$("#cdb_content thead th");
$("#AddressTableChild tr").next(".data").first().children().each(function(k,a) {
header.first().width($(this).width());
header=header.next();
});
}
StandardTableView.prototype.entryDetailClick = function(id) {
var t=this;
var a=t.getData();
if ($("tr[id=detail"+id+"]").text()!="") {
$("tr[id=detail"+id+"]").remove();
a[id].open=false;
}
else {
a[id].open=true;
t.renderEntryDetail(id);
}
};
StandardTableView.prototype.addTableContentCallbacks = function(cssid) {
var t=this;
$(cssid+" input.checked").click(function (_content_input) {
var s=$(this).attr("id");
if (s=="markAll") {
if ((t.counter>=masterData.settings["listMaxRows"+t.name]) && (confirm("Es sind mehr Eintraege vorhanden, als momentan angezeigt. Sollen alle Eintraege markiert werden?"))) {
bol=$(this).is(":checked");
$.each(listObject, function(k,a) {
if ((a!=null) && (t.checkFilter(a))) {
a.checked=bol;
}
});
}
if ($(this).is(":checked")) {
$("#cdb_content input.checked").not("#markAll").each(function(a) {
$(this).attr("checked","true");
t.getData(false)[$(this).attr("id").substr(5,99)]["checked"]=true;
});
}
else {
$("#cdb_content input.checked").not("#markAll").each(function(a) {
$(this).removeAttr("checked");
t.getData(false)[$(this).attr("id").substr(5,99)]["checked"]=false;
});
}
}
else t.getData(false)[$(this).attr("id").substr(5,99)]["checked"]=$(this).is(":checked");
});
$(cssid+" a").click(function (_content_a) {
if ($(this).attr("id")==null)
return true;
else if ($(this).attr("id").indexOf("detail")==0) {
var id = $(this).attr("id").substr(6,99);
t.entryDetailClick(id);
}
else if ($(this).attr("id")=="mailto") return true;
else if ($(this).attr("id")=="extern") return true;
else if ($(this).attr("id").indexOf("sort")==0) {
t.sortVariable=$(this).attr("id").substr(4,99);
t.renderList();
}
return false;
});
$(".hoveractor").off("hover");
$(".hoveractor").hover(
function () {
$(this).find("span.hoverreactor").fadeIn('fast',function() {});
},
function () {
$(this).find("span.hoverreactor").fadeOut('fast');
}
);
this.addFurtherListCallbacks(cssid);
};
StandardTableView.prototype.mailPerson = function (personId, name, subject) {
var t=this;
var rows = new Array();
rows.push(form_renderInput({cssid:"betreff", label:_("subject"), type:"xlarge", text:(subject!=null?subject:"")}));
rows.push('<p>'+_("content")+'<span class="pull-right editor-status"></span><div id="inhalt" class="well">');
if (masterData.settings.signature!=null)
rows.push(masterData.settings.signature);
rows.push('</div>');
if (masterData.settings.sendBCCMail==null)
masterData.settings.sendBCCMail=1;
rows.push("<p>"+form_renderCheckbox({cssid:"sendBCCMail", checked: masterData.settings.sendBCCMail==1,
label:_("send.bcc.copy.to.myself")}));
var elem=this.showDialog(_("send.email.to.x", name!=null?name:"Person"), rows.join(""), 600,550);
elem.dialog("addbutton", _("send"), function() {
var arr=personId.split(",");
if ((arr.length<5) || (confirm(_("caution.that.email.will.be.send.to.x.persons", arr.length)))) {
var obj = new Object();
obj.ids=personId;
masterData.settings.sendBCCMail=($("#sendBCCMail").attr("checked")?1:0);
if (masterData.settings.sendBCCMail==1)
if (typeof(masterData.user_pid)=="string")
obj.ids=obj.ids+","+masterData.user_pid;
else
obj.ids=obj.ids+","+masterData.user_pid[0];
churchInterface.jsendWrite({func:"saveSetting", sub:"sendBCCMail", val: masterData.settings.sendBCCMail});
obj.betreff=$("#betreff").val();
obj.inhalt=CKEDITOR.instances.inhalt.getData();
obj.domain_id=null;
obj.func="sendEMailToPersonIds";
churchInterface.jsendWrite(obj, function(ok, data) {
if (ok) {
alert(_("email.was.sent"));
drafter.clear();
}
else alert(_("error.occured")+": "+data);
}, null, false);
$(this).dialog("close");
}
});
elem.dialog("addcancelbutton");
form_implantWysiwygEditor('inhalt', false);
//Save draft
var drafter=new Drafter("email", {
setStatus : function(status) {
elem.find('span.editor-status').html('<small><i>'+status+'</small></i>');
},
getContent : function() {
return CKEDITOR.instances.inhalt.getData();
},
setContent : function(content) {
CKEDITOR.instances.inhalt.setData(content);
}
});
CKEDITOR.instances.inhalt.on('change', function() { elem.find('span.editor-status').html('');});
if (subject!=null)
$("#inhalt").focus();
$("a").click(function(c) {
if (($(this).attr("id")=="Vorname") || ($(this).attr("id")=="Nachname")) {
$("#inhalt").insertAtCaret("["+$(this).attr("id")+"]");
}
});
};
StandardTableView.prototype.renderFile = function(file, filename_length) {
txt="";
if (file!=null) {
txt=txt+'<span class="tooltip-file file" data-id="'+file.id+'">';
var i = file.bezeichnung.lastIndexOf(".");
if (i>0) {
switch (file.bezeichnung.substr(i,99)) {
case '.mp3':
txt=txt+this.renderImage("mp3",18);
break;
case '.m4a':
txt=txt+this.renderImage("mp3",18);
break;
case '.pdf':
txt=txt+this.renderImage("pdf",18);
break;
case '.doc':
txt=txt+this.renderImage("word",18);
break;
case '.docx':
txt=txt+this.renderImage("word",18);
break;
case '.rtf':
txt=txt+this.renderImage("word",18);
break;
default:
txt=txt+this.renderImage("paperclip",18);
break;
}
}
else txt=txt+this.renderImage("paperclip",18);
if (filename_length==null) filename_length=25;
var filename=file.bezeichnung;
if (i>filename_length) {
var filetype=file.filename.substr(i,99);
filename=filename.substr(0,filename_length)+"[..]"+filetype;
}
txt=txt+' <a target="_blank" href="?q='+masterData.modulename+'/filedownload&id='+file.id+'&filename='+file.filename+'">'+filename+'</a>';
txt=txt+'</span><br/>';
}
return txt;
};
StandardTableView.prototype.renderTooltipForFiles = function (tooltip, f, editauth) {
var t=this;
var rows = new Array();
var i = f.bezeichnung.lastIndexOf(".");
if (i>0)
switch (f.bezeichnung.substr(i,99).toLowerCase()) {
case '.mp3':
rows.push('<audio style="width:300px" src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.wav':
rows.push('<audio style="width:300px" src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.m4a':
rows.push('<video src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.mp4':
rows.push('<video src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.avi':
rows.push('<video src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.mpeg':
rows.push('<video src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.jpg':
rows.push('<img style="max-width:200px;max-height:200px" src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
case '.png':
rows.push('<img style="max-width:200px;max-height:200px" src="'+masterData.files_url+"/files/"+f.domain_type+"/"+f.domain_id+"/"+f.filename+'"/>');
break;
default:
break;
}
if (f.modified_date!=null)
rows.push("<p>"+f.modified_date.toDateEn(true).toStringDe(true)+" ("+f.modified_username+")");
rows.push("<p>");
rows.push('<a class="btn btn-success btn-small" target="_blank" href="?q='+masterData.modulename+'/filedownload&id='+f.id+'&filename='+f.filename+'&type=download">'+_("download")+'</a> ');
var title=f.bezeichnung;
if (editauth) {
rows.push(form_renderButton({label:_("delete"), cssid:"file_delete", htmlclass:"btn-danger btn-small"})+" ");
title='<span id="file_name">'+f.bezeichnung+" "+form_renderImage({label:_("rename"), src:"options.png", width:20, cssid:"file_rename"})+'</span>';
}
rows.push(form_renderHidden({cssid:"file",value:"true"}));
return [rows.join(""), title]
};
StandardTableView.prototype.tooltipCallbackForFiles = function(id, tooltip, filecontainer, filecontainer_id) {
var t=this;
$('video,audio').mediaelementplayer({
// shows debug errors on screen
enablePluginDebug: false,
pluginPath: 'system/assets/mediaelements/',
// name of flash file
flashName: 'flashmediaelement.swf',
// name of silverlight file
silverlightName: 'silverlightmediaelement.xap',
autoplay:true,
//plugins: ['flash', 'silverlight'],
success: function(mediaElement, domObject) {
mediaElement.play();
},
error: function(a) {
//alert('Fehler beim Laden der Mediendaten!');
}
});
var f=filecontainer[filecontainer_id].files[id];
tooltip.find("#file_download").click(function() {
t.clearTooltip(true);
return false;
});
tooltip.find("#file_rename").click(function() {
tooltip.find("#file_name").html(form_renderInput({cssid:"newfilename", value:f.bezeichnung, controlgroup:false, type:"medium"}));
$('#newfilename').keyup(function(e) {
var newfilename=$(this).val();
// Enter
if (e.keyCode == 13) {
churchInterface.jsendWrite({func:"renameFile", id:f.id, filename:newfilename}, function(ok, data) {
if (ok) {
f.bezeichnung=newfilename;
t.renderFiles(filecontainer, filecontainer_id);
}
else alert("Fehler beim Speichern: "+data);
});
}
// Escape
else if (e.keyCode == 27) {
t.clearTooltip(true);
}
});
return false;
});
tooltip.find("#file_delete").click(function() {
if (confirm(_("really.delete.file"))) {
churchInterface.jsendWrite({func:"delFile", id:f.id}, function(ok, data) {
if (ok) {
delete filecontainer[filecontainer_id].files[id];
t.renderFiles(filecontainer, filecontainer_id);
}
else alert(_("error.occured")+": "+data);
});
t.clearTooltip(true);
}
});
};
/**
* Rendert alle div.filelist mit Inhalt von filecontainer.
* @param header
* @param filecontainer
* @param specific_domain_id oder null, wenn alle
* @param delete_func funtion(file_id)
*/
StandardTableView.prototype.renderFilelist = function(header, filecontainer, specific_domain_id, delete_func, filename_length) {
var t=this;
if (filename_length==null) filename_length=25;
var specialselector="";
if (specific_domain_id!=null)
specialselector="[data-id="+specific_domain_id+"]";
$("#cdb_content div.filelist"+specialselector).each(function() {
$(this).html("");
if ((filecontainer!=null) && (filecontainer[$(this).attr("data-id")]!=null)) {
var files=filecontainer[$(this).attr("data-id")].files;
if ((files!=null) && (churchcore_countObjectElements(files)>0)) {
var txt=header;
if (txt!="") txt=txt+"<br/>";
$.each(churchcore_sortData(files, "bezeichnung"), function(k,a) {
txt=txt+t.renderFile(a,filename_length);
});
$(this).html(txt);
}
}
});
};
/**
*
* @param title
* @param text
* @param width
* @param height
* @param buttons
* @return jQuery-Element
*/
StandardTableView.prototype.showDialog = function(title, text, width, height, buttons) {
return form_showDialog (title, text, width, height, buttons);
};
/**
*
* @param divid
* @param curDate aktuelles Datum
* @param func function fuer erfolgte Auswahl mit Arg func(dateText,divid)
*/
StandardTableView.prototype.implantDatePicker = function(divid, curDate, func, highlightDay) {
form_implantDatePicker("dp_"+divid, curDate, func, highlightDay);
};
StandardTableView.prototype.standardFieldCoder = function (typ, arr) {
alert("Keine Code gefunden fuer: "+typ);
return null;
};
/**
* Holt sich die Standardfelder und f�llt das Elem damit. Au�erdem wird ein Callback f�r Selects erzeugt,
* so dass �nderungen sofort beachtet werden (z.B. Code:XXX)
*/
StandardTableView.prototype.renderStandardFieldsAsSelect = function (elem, fieldname, arr, authArray) {
var this_object=this;
elem.html(this.getStandardFieldsAsSelect(fieldname, arr, authArray));
$("#standardFieldsAsSelect select").change(function(c) {
var obj=this_object.getSaveObjectFromInputFields(null, fieldname, arr);
this_object.renderStandardFieldsAsSelect(elem, fieldname, obj, authArray);
});
};
StandardTableView.prototype.checkFieldPermission = function (field, authArray) {
var res=true;
if (field.auth!=null && field.auth!="") {
res=false;
$.each(churchcore_getAuthAsArray(field.auth), function(k,auth) {
if (auth!=null)
if ((masterData.auth[auth]!=null) || (authArray!=null && churchcore_inArray(auth, authArray)))
res=true;
});
}
return res;
};
StandardTableView.prototype.getStandardFieldAsSelect = function (field, arr, elem, authArray) {
var t=this;
var value=arr[elem];
var o = new Object();
o.label=field.text;
o.cssid="Input"+field.sql;
if (!t.checkFieldPermission(field, authArray)) return null;
// changed in 2.49, now elements will be hide instead of disabled
// o.disabled=!t.checkFieldPermission(field, authArray);
switch (field.type) {
case "select":
var data = null;
if (field.selector.indexOf("code:")==0) {
data=this.standardFieldCoder(field.selector.substr(5,99), arr);
}
else
data=masterData[field.selector];
o.selected=value;
o.data=data;
return form_renderSelect(o);
case "date":
if ((value!=null) && (value!="")) o.value=value.toDateEn(false).toStringDe(false);
else o.value="";
return form_renderInput(o);
case "checkbox":
o.checked=((value!=null) && (value==1));
return form_renderCheckbox(o);
case "textarea":
o.maxlength=field.length;
o.data=value;
return form_renderTextarea(o);
default:
o.email=(field.sql=="email");
o.value=value;
o.maxlength=field.length;
return form_renderInput(o);
}
};
/**
*
* @param fieldname - z.Bsp. f_address
* @param arr - Array mit den zugeh�rigen Daten, z.Bsp. allPersons[x].details
* @param authArray - Array mit Strings, bei denen man das bearbeiten darf
*/
StandardTableView.prototype.getStandardFieldsAsSelect = function (fieldname, arr, authArray) {
var t=this;
var rows = new Array();
var form = new CC_Form(null, arr, "standardFieldAsSelect");
$.each(masterData.fields[fieldname].fields, function(elem, field) {
//TODO: Wechsel auf Formular. Problem ist noch die ccsid, denn diese ist hier ohne "Input..."
//form.addStandardField(f, authArray);
form.addHtml(t.getStandardFieldAsSelect(field, arr, elem, authArray));
});
return form.render(null, "horizontal");
};
/**
*
* @param id
* @param fieldname - Fields Name, also zum Beispiel f_address
* @param arr
* @return obj
*/
StandardTableView.prototype.getSaveObjectFromInputFields = function(id, fieldname, arr) {
var obj=new Object();
obj["id"]=id;
obj["func"] =fieldname;
// if field exists
if (masterData.fields[obj["func"]]!=null) {
// Set vars in the browser and prepare obj
for (var elem in masterData.fields[obj["func"]].fields) {
if ($("#Input" + elem).length>0 && !$("#Input" + elem).is(':disabled')) {
if (masterData.fields[obj["func"]].fields[elem].type=="date") {
if (($("#Input" + elem).val()!=null) && ($("#Input" + elem).val().toDateDe()!=null))
arr[elem] = $("#Input" + elem).val().toDateDe().toStringEn();
else arr[elem]=null;
}
else if (masterData.fields[obj["func"]].fields[elem].type=="checkbox") {
if ($("#Input" + elem).attr("checked")=="checked")
arr[elem] = 1;
else
arr[elem] = 0;
}
else {
if ($("#Input" + elem).val()!=null)
arr[elem] = $("#Input" + elem).val().trim();
else
arr[elem] =null;
}
obj[elem] = arr[elem];
}
}
}
return obj;
};
StandardTableView.prototype.renderImage = function(imageName, width, title) {
if (width==null) width=20;
if (title==null) title="";
return '<img width="'+width+'px" style="max-width:'+width+'px" title="'+title+'" src="'+masterData.modulespath+'/images/'+imageName+'.png"/>';
};
StandardTableView.prototype.renderYesNo = function(nr, width) {
return form_renderYesNo(nr, width);