-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.js
2298 lines (1994 loc) · 103 KB
/
interface.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
/*
CardDavMATE - the open source CardDAV Web Client
Copyright (C) 2011-2015
Jan Mate <[email protected]>
Andrej Lezo <[email protected]>
Matej Mihalik <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// reorder countries according to localization (returns array becaouse object are unsorted according to ECMA)
function sortCountries(obj)
{
var arr=[];
for(var prop in obj)
if(obj.hasOwnProperty(prop))
arr.push({'key': prop, 'value': obj[prop], 'translated_value': localization[globalInterfaceLanguage]['txtAddressCountry'+prop.toUpperCase()]});
return arr.sort(function(a, b){return a.translated_value.customCompare(b.translated_value, globalSortAlphabet, 1, false)});
}
function loadAdditionalCardDAVCollections()
{
if(globalSettingsSaving!='')
return false;
globalSettingsSaving='addressbook';
var inSettings = $.extend({},globalSettings);
var rex = new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
var key='loadedaddressbookcollections';
inSettings.loadedaddressbookcollections = {value : new Array(), locked: globalSettings[key].locked};
$('#ResourceCardDAVList').find('.unloadCheck').each(function(cin,cel)
{
if($(cel).prop('checked'))
{
var uidParts=$(cel).attr('data-id').match(rex);
inSettings.loadedaddressbookcollections.value.splice(inSettings.loadedaddressbookcollections.value.length , 0, uidParts[1]+uidParts[3]);
}
});
if($(inSettings[key]).not(globalSettings[key].value).length > 0 || $(globalSettings[key].value).not(inSettings[key]).length > 0)
{
$('#AddressbookOverlay').removeClass('loader_hidden');
$('#ResourceCardDAVList').find('input[type="checkbox"]').prop('disabled',true);
var setC=0;
for(var i=0;i<globalAccountSettings.length;i++)
if(globalAccountSettings[i].href.indexOf(globalLoginUsername)!=-1 && globalAccountSettings[i].settingsAccount)
{
setC++;
netSaveSettings(globalAccountSettings[i], inSettings, false, true);
break;
}
if(setC==0)
cancelUnloadedCardDAVCollections();
}
else
hideUnloadedCardDAVCollections(true);
}
function showUnloadedCardDAVCollections()
{
if(globalAddressbookCollectionsLoading)
return false;
globalAddressbookCollectionsLoading=true;
if(isAvaible('CalDavZAP'))
{
$('#showUnloadedCalendars').css('display','none');
$('#showUnloadedCalendarsTODO').css('display','none');
}
$('#ResourceCardDAVList').find('input[type="checkbox"]').prop('disabled',true);
$('#AddressbookOverlay').children('.loaderInfo').text(localization[globalInterfaceLanguage].loadingCollectionList).parent().fadeIn(300);
var resList=$('#ResourceCardDAVList');
var resHeader='.resourceCardDAV_header';
var resItem='.resourceCardDAV';
$('#ResourceCardDAVList').find('input[type="checkbox"]').prop('disabled',false);
$('#AddressbookOverlay').children('.loaderInfo').text('').parent().addClass('loader_hidden');
resList.find('.resourceCardDAV_selected').removeClass('resourceCardDAV_selected');
resList.find('input').css('display','none');
// header display
resList.children('.resourceCardDAV_header').each(function(){
if($(this).css('display')=='none')
$(this).addClass('unloaded').css('display','');
var headerClickElm = $('<input type="checkbox" class="unloadCheckHeader" style="position:absolute;top:3px;right:0px;margin-right:6px;"/>');
headerClickElm.change(function(){
loadResourceChBoxClick(this, '#ResourceCardDAVList', resHeader, resItem, '.resourceCardDAV_item');
});
$(this).addClass('load_mode').append(headerClickElm);
});
// carddav_item display
resList.find('.resourceCardDAV').each(function(){
if(typeof $(this).attr('data-id') != 'undefined')
{
var newInputElm = $('<input type="checkbox" class="unloadCheck" data-id="'+$(this).attr('data-id')+'" style="position:absolute;top:8px;right:0px;margin-right:6px;"/>');
newInputElm.change(function(){
loadCollectionChBoxClick(this, '#ResourceCardDAVList', resHeader, resItem, '.resourceCardDAV_item');
});
$(this).siblings('.contact_group').addBack().addClass('load_mode');
$(this).append(newInputElm);
if($(this).parent().css('display')=='none')
$(this).addClass('unloaded');
else
newInputElm.prop('checked',true);
newInputElm.trigger('change');
}
});
$('#showUnloadedAddressbooks').css('display','none');
$('.resourcesCardDAV_h').text(localization[globalInterfaceLanguage].txtEnabledAddressbooks);
var origH = resList.find('.resourceCardDAV_header.unloaded').eq(0).css('height');
var origC = resList.find('.resourceCardDAV.unloaded').parent().eq(0).css('height');
resList.find('.resourceCardDAV_header.unloaded').css({'height':0,'display':''}).animate({height:origH},300);
resList.find('.resourceCardDAV.unloaded').parent().css({'height':0,'display':''}).animate({height:origC},300);
resList.animate({'top':49},300);
}
function cancelUnloadedCardDAVCollections()
{
$('#ResourceCardDAVList').children('.resourceCardDAV_item').children('.resourceCardDAV ').each(function(){
var uidParts=$(this).attr('data-id').match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
var checkHref=uidParts[1]+uidParts[3];
var isLoaded=false;
if(typeof globalCrossServerSettingsURL!='undefined'&&globalCrossServerSettingsURL!=null&globalCrossServerSettingsURL)
{
var uidParts=$(this).attr('data-id').match(RegExp('/([^/]+/[^/]+/)$'));
var tmpParts = uidParts[1].match('^(.*/)([^/]+)/$');
var checkHref=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
var found=false;
for(var l=0;l<globalSettings.loadedaddressbookcollections.value.length;l++)
{
var tmpParts2 = globalSettings.loadedaddressbookcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
if(checkHref==checkHref2)
{
found=true;
break;
}
}
isLoaded=found;
}
else
isLoaded=(globalSettings.loadedaddressbookcollections.value.indexOf(checkHref)!=-1)
var unloadCh=$(this).find('.unloadCheck');
var checked=unloadCh.prop('checked');
if((isLoaded && !checked) || (!isLoaded && checked))
unloadCh.prop('checked',!checked).trigger('change');
});
hideUnloadedCardDAVCollections(true);
}
function hideUnloadedCardDAVCollections(withCallback)
{
var resList=$('#ResourceCardDAVList');
resList.find(':input.unloadCheck').remove();
resList.find(':input.unloadCheckHeader').remove();
resList.find('.load_mode').removeClass('load_mode');
resList.find(':input').css('display','');
resList.find('.resourceCardDAV').not('.unloaded').parent().css('height','');
$('.resourcesCardDAV_h').text(localization[globalInterfaceLanguage].txtAddressbooks);
resList.find('.resourceCardDAV_header.unloaded').animate({height:0},300).promise().done(function(){
resList.find('.resourceCardDAV_header.unloaded').css({'display':'none','height':''});
});
resList.find('.resourceCardDAV.unloaded').parent().animate({height:0},300).promise().done(function(){
resList.find('.resourceCardDAV.unloaded').parent().css({'display':'none','height':''});
resList.find('.resourceCardDAV_header').not('.unloaded').each(function(){
var triggerInput=$(this).nextUntil('.resourceCardDAV_header').filter(':visible').first().find('input[type="checkbox"]');
collectionChBoxClick(triggerInput.get(0), '#ResourceCardDAVList', '.resourceCardDAV_header', '.resourceCardDAV', null, false);
});
resList.find('.unloaded').removeClass('unloaded');
globalAddressbookCollectionsLoading=false;
if(withCallback)
hideUnloadedCardDAVCollectionsCallBack();
});
resList.animate({'top':24},300);
if(withCallback)
$('#AddressbookOverlay').fadeOut(300,function(){
$(this).removeClass('loader_hidden');
});
if(isAvaible('CalDavZAP'))
{
$('#showUnloadedCalendars').css('display','block');
$('#showUnloadedCalendarsTODO').css('display','block');
}
}
function hideUnloadedCardDAVCollectionsCallBack()
{
if(globalAddressbookList.contactLoaded!=null)
globalAddressbookList.loadContactByUID(globalAddressbookList.contactLoaded.uid);
$('#showUnloadedAddressbooks').css('display','');
globalFirstHideLoader=true;
globalSettingsSaving='';
selectActiveAddressbook();
$('#AddressbookOverlay').css('display','none');
$('#ResourceCardDAVList').find('input[type="checkbox"]').prop('disabled',false);
}
function selectActiveAddressbook()
{
if(globalAddressbookCollectionsLoading)
return false;
for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
if(globalResourceCardDAVList.collections[i].uid!=undefined)
{
var inputResource=globalResourceCardDAVList.collections[i].uid;
var par=inputResource.split('/');
if(globalSettings.addressbookselected.value!='')
{
if(typeof globalSettings.addressbookselected.value=='string' && inputResource==globalSettings.addressbookselected.value.substring(0,globalSettings.addressbookselected.value.lastIndexOf('/')+1))
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('.resourceCardDAV[data-id="'+globalSettings.addressbookselected.value+'"]:visible').addClass('resourceCardDAV_selected');
}
else if(typeof globalSettings.addressbookselected.value=='string' && globalSettings.addressbookselected.value.charAt(globalSettings.addressbookselected.value.length-1)=='/' && (par[par.length-3]+'/'+par[par.length-2]+'/')==globalSettings.addressbookselected.value)
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('.resourceCardDAV[data-id="'+inputResource+'"]:visible').addClass('resourceCardDAV_selected');
}
else if(typeof globalSettings.addressbookselected.value=='string' && globalSettings.addressbookselected.value.charAt(globalSettings.addressbookselected.value.length-1)!='/')
{
if((par[par.length-3]+'/'+par[par.length-2]+'/') == globalSettings.addressbookselected.value.substring(0,globalSettings.addressbookselected.value.lastIndexOf('/')+1) && $('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
{
if($('#ResourceCardDAVList').find('.resourceCardDAV[data-id="'+inputResource+globalSettings.addressbookselected.value.substring(globalSettings.addressbookselected.value.lastIndexOf('/')+1,globalSettings.addressbookselected.value.length)+'"]:visible').length>0)
$('#ResourceCardDAVList').find('.resourceCardDAV[data-id="'+inputResource+globalSettings.addressbookselected.value.substring(globalSettings.addressbookselected.value.lastIndexOf('/')+1,globalSettings.addressbookselected.value.length)+'"]:visible').addClass('resourceCardDAV_selected');
}
}
else if (typeof globalSettings.addressbookselected.value=='object' && inputResource.match(globalSettings.addressbookselected.value)!=null)
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('.resourceCardDAV[data-id="'+inputResource+'"]:visible').addClass('resourceCardDAV_selected');
}
}
}
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length==0)
for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
if(globalResourceCardDAVList.collections[i].uid!=undefined)
{
var inputResource=globalResourceCardDAVList.collections[i].uid;
var par=inputResource.split('/');
if(typeof globalAddressbookSelected!='undefined' && globalAddressbookSelected!=null && globalAddressbookSelected!='')
{
globalSettings.addressbookselected.value = globalAddressbookSelected;
if(typeof globalAddressbookSelected=='string' && inputResource==globalAddressbookSelected.substring(0,globalAddressbookSelected.lastIndexOf('/')+1))
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('[data-id="'+globalAddressbookSelected+'"]:visible').addClass('resourceCardDAV_selected');
}
else if(typeof globalAddressbookSelected=='string' && globalAddressbookSelected.charAt(globalAddressbookSelected.length-1)=='/' && (par[par.length-3]+'/'+par[par.length-2]+'/')==globalAddressbookSelected)
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('[data-id="'+inputResource+'"]:visible').addClass('resourceCardDAV_selected');
}
else if(typeof globalAddressbookSelected=='string' && globalAddressbookSelected.charAt(globalAddressbookSelected.length-1)!='/')
{
if((par[par.length-3]+'/'+par[par.length-2]+'/') == globalAddressbookSelected.substring(0,globalAddressbookSelected.lastIndexOf('/')+1) && $('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
{
if($('#ResourceCardDAVList').find('[data-id="'+inputResource+globalAddressbookSelected.substring(globalAddressbookSelected.lastIndexOf('/')+1,globalAddressbookSelected.length)+'"]:visible').length>0)
$('#ResourceCardDAVList').find('[data-id="'+inputResource+globalAddressbookSelected.substring(globalAddressbookSelected.lastIndexOf('/')+1,globalAddressbookSelected.length)+'"]:visible').addClass('resourceCardDAV_selected');
}
}
else if (typeof globalAddressbookSelected=='object' && inputResource.match(globalAddressbookSelected)!=null)
{
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
$('#ResourceCardDAVList').find('[data-id="'+inputResource+'"]:visible').addClass('resourceCardDAV_selected');
}
else if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0)
{
globalSettings.addressbookselected.value=par[par.length-3]+'/'+par[par.length-2]+'/';
$('#ResourceCardDAVList').find('[data-id="'+inputResource+'"]:visible').addClass('resourceCardDAV_selected');
}
}
}
if($('#ResourceCardDAVList').find('.resourceCardDAV_selected:visible').length == 0 && $('#ResourceCardDAVList').find('.resourceCardDAV[data-id]:visible').length > 0)
{
var ui_d = $('#ResourceCardDAVList').find('.resourceCardDAV[data-id]:visible').eq(0).attr('data-id');
var part_u = ui_d.split('/');
globalSettings.addressbookselected.value=part_u[part_u.length-3]+'/'+part_u[part_u.length-2]+'/';
$('#ResourceCardDAVList').find('.resourceCardDAV[data-id]:visible').eq(0).addClass('resourceCardDAV_selected');
}
var selColl=globalResourceCardDAVList.getCollectionByUID($('#ResourceCardDAVList').find('.resourceCardDAV[data-id].resourceCardDAV_selected').attr('data-id'));
if(selColl!=null)
{
selColl.filterUID=selColl.uid;
if(selColl.permissions.read_only==true)
globalRefAddContact.addClass('element_no_display');
else
globalRefAddContact.removeClass('element_no_display');
globalRefAddContact.attr('data-url', selColl.uid.replace(RegExp('[^/]+$'),''));
globalRefAddContact.attr('data-filter-url',selColl.filterUID); // Set the current addressbook filter uid
globalRefAddContact.attr('data-account-uid',selColl.accountUID);
globalRefAddContact.attr('data-color',selColl.color);
// Make the selected collection active
if(!globalCardDAVInitLoad)
{
if(typeof(globalContactsABChange)=='function')
globalContactsABChange(selColl.uid);
$('#ResourceCardDAVList').find('.resourceCardDAV_item').find('.resourceCardDAV_selected').removeClass('resourceCardDAV_selected');
$('#ResourceCardDAVList').find('[data-id='+jqueryEscapeSelector(selColl.uid)+']').addClass('resourceCardDAV_selected');
if(selColl.filterUID[selColl.filterUID.length-1]!='/')
$('#ResourceCardDAVList').find('[data-id='+jqueryEscapeSelector(selColl.filterUID)+']').addClass('resourceCardDAV_selected');
}
}
}
function CardDAVUpdateMainLoader(inputCollection)
{
if(!globalCardDAVInitLoad)
{
if(globalSettingsSaving=='addressbook')
{
globalLoadedCollectionsCount++;
$('#AddressbookOverlay').children('.loaderInfo').text(localization[globalInterfaceLanguage].loadingAddressbooks.replace('%act%', globalLoadedCollectionsCount).replace('%total%', globalLoadedCollectionsNumber));
if(globalSettingsSaving!='' && globalLoadedCollectionsCount==globalLoadedCollectionsNumber)
setTimeout(function(){hideUnloadedCardDAVCollectionsCallBack();if(isAvaible('Settings'))hideSettingsOverlay();},300);
}
selectActiveAddressbook();
for(var adr in globalAddressbookList.vcard_groups)
{
if(globalAddressbookList.vcard_groups[adr].length>0)
{
extendDestSelect();
if(typeof $('#vCardEditor').attr('data-vcard-uid')=='undefined')
$('#vCardEditor').find('[data-attr-name="_DEST_"]').find('optiotn[data-type$="'+$('#ResourceCardDAVList').find('.resourceCardDAV_selected').find(':input[data-id]').attr('data-id')+'"]').prop('selected',true)
}
}
return false;
}
if(inputCollection.makeLoaded)
{
globalAddressbookNumberCount++;
$('#MainLoaderInner').html(localization[globalInterfaceLanguage].loadingAddressbooks.replace('%act%', (globalAddressbookNumberCount)).replace('%total%', globalAddressbookNumber));
}
inputCollection.isLoaded=true;
$('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
var unloadedCount=0;
for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
if(globalResourceCardDAVList.collections[i].uid!=undefined && !globalResourceCardDAVList.collections[i].isLoaded)
unloadedCount++;
if(unloadedCount==0 && !isCardDAVLoaded)
{
globalCardDAVInitLoad=false;
globalAddressbookList.renderContacs();
var rexo=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
if(!globalDefaultAddressbookCollectionActiveAll)
{
for(var i=0;i<globalSettings.activeaddressbookcollections.value.length;i++)
{
if(typeof globalCrossServerSettingsURL!='undefined'&&globalCrossServerSettingsURL!=null&globalCrossServerSettingsURL)
{
var tmpParts2 = globalSettings.activeaddressbookcollections.value[i].match('^(.*/)([^/]+)/([^/]+)/$');
var checkHref2=tmpParts2[2]+'/'+tmpParts2[3]+'/';
if($('#ResourceCardDAVList input[data-id$="'+checkHref2+'"]:visible').length>0)
$('#ResourceCardDAVList input[data-id$="'+checkHref2+'"]').trigger('click');
}
else
{
var uidPart=globalSettings.activeaddressbookcollections.value[i].match(RegExp('^(https?://)(.*)', 'i'))[1];
var uidPart2=globalSettings.activeaddressbookcollections.value[i].match(RegExp('^(https?://)(.*)', 'i'))[2];
var uidPart3=getAccount(inputCollection.accountUID).userAuth.userName;
var uid = uidPart+uidPart3+'@'+uidPart2;
if($('#ResourceCardDAVList .resourceCardDAV input[data-id="'+uid+'"]:visible').length>0)
$('#ResourceCardDAVList .resourceCardDAV input[data-id="'+uid+'"]').trigger('click');
}
}
if(globalSettings.activeaddressbookcollections.value.length>0 && $('#ResourceCardDAVList .resourceCardDAV input:checked').length==0)
globalDefaultAddressbookCollectionActiveAll=true;
}
if(globalDefaultAddressbookCollectionActiveAll)
for(var i=0;i<globalResourceCardDAVList.collections.length;i++)
if(globalResourceCardDAVList.collections[i].uid!=undefined && $('#ResourceCardDAVList .resourceCardDAV input[data-id="'+globalResourceCardDAVList.collections[i].uid+'"]:visible').length>0)
$('#ResourceCardDAVList input[data-id="'+globalResourceCardDAVList.collections[i].uid+'"]').trigger('click');
selectActiveAddressbook();
globalRefAddContact.prop('disabled', false);
loadNextApplication(true);
}
}
function applyAddrSettings(abContactRef, remValues)
{
var addrVals = new Array();
if(typeof remValues!= 'undefined')
{
abContactRef.find('[data-type="\\%address"]').find('[data-type="country_type"]').each(function(){
addrVals[$(this).parents('[data-type="%address"]').attr('data-id')] = $(this).val();
});
}
var country_option=abContactRef.find('[data-type="\\%address"]').find('[data-type="country_type"]').find('option').last().clone();
abContactRef.find('[data-type="\\%address"]').find('[data-type="country_type"]').html('');
// we need a copy of the object because of the next "delete" operation
var addressTypesTmp=jQuery.extend({}, addressTypes);
// delete custom ordered element before the sort (then we will add them back)
if(globalSettings.addresscountryfavorites.value.length>0)
for(var i=globalSettings.addresscountryfavorites.value.length-1;i>=0;i--)
delete addressTypesTmp[globalSettings.addresscountryfavorites.value[i]];
var addressTypesArr=sortCountries(addressTypesTmp);
// re-add custom ordered elements from the original addressTypes (where all elements are still present)
if(globalSettings.addresscountryfavorites.value.length>0)
for(var i=globalSettings.addresscountryfavorites.value.length-1;i>=0;i--)
addressTypesArr.unshift({'key': globalSettings.addresscountryfavorites.value[i], 'value': addressTypes[globalSettings.addresscountryfavorites.value[i]], 'translated_value': localization[globalInterfaceLanguage]['txtAddressCountry'+globalSettings.addresscountryfavorites.value[i].toUpperCase()]});
for(var i=0;i<addressTypesArr.length;i++)
{
var tmp=country_option;
tmp.attr('data-type',addressTypesArr[i].key);
tmp.attr('data-full-name',addressTypesArr[i].value[0]);
tmp.text(addressTypesArr[i].translated_value); // translation
abContactRef.find('[data-type="\\%address"]').find('[data-type="country_type"]').append(tmp.clone());
}
abContactRef.find('[data-type="\\%address"]').find('[data-type="country_type"]').attr('data-autoselect',globalSettings.defaultaddresscountry.value);
for(var key in addrVals)
abContactRef.find('[data-type="\\%address"][data-id="'+key+'"]').find('[data-type="country_type"]').val(addrVals[key]);
}
function localizeCardDAV()
{
// frequently used
var abContactRef=$('#ABContact');
// restore original templates
$('#ResourceCardDAVList').empty().append(globalOrigCardDAVListTemplate.clone());
abContactRef.empty().append(globalOrigVcardTemplate.clone());
localizeAddressTypes();
// interface translation
$('[data-type="system_logo"]').attr('alt',localization[globalInterfaceLanguage].altLogo);
$('[data-type="system_username"]').attr('placeholder',localization[globalInterfaceLanguage].pholderUsername);
$('[data-type="system_password"]').attr('placeholder',localization[globalInterfaceLanguage].pholderPassword);
$('[data-type="resourcesCardDAV_txt"]').text(localization[globalInterfaceLanguage].txtAddressbooks);
$('[data-type="contact_txt"]').text(localization[globalInterfaceLanguage].txtContact);
$('[data-type="search"]').attr('placeholder',localization[globalInterfaceLanguage].txtSearch);
$('#AddContact').attr('alt',localization[globalInterfaceLanguage].altAddContact);
$('#AddContact').attr('title',localization[globalInterfaceLanguage].altAddContact);
$('#Logout').attr('alt',localization[globalInterfaceLanguage].altLogout);
$('#Logout').attr('title',localization[globalInterfaceLanguage].altLogout);
$('#showUnloadedAddressbooks').attr({title:capitalize(localization[globalInterfaceLanguage].txtEnabledAddressbooks),alt:capitalize(localization[globalInterfaceLanguage].txtEnabledAddressbooks)});
$('#loadUnloadedAddressbooks').val(localization[globalInterfaceLanguage].buttonSave);
$('#loadUnloadedAddressbooksCancel').val(localization[globalInterfaceLanguage].buttonCancel);
abContactRef.find('#photoBox').find('h1').text(localization[globalInterfaceLanguage].txtRemoteImage);
abContactRef.find('#photoURL').attr('placeholder',localization[globalInterfaceLanguage].pholderUrlVal);
abContactRef.find('[data-type="photo"]').text(localization[globalInterfaceLanguage].altPhoto);
abContactRef.find('[data-type="given"]').attr('placeholder',localization[globalInterfaceLanguage].pholderGiven);
abContactRef.find('[data-type="family"]').attr('placeholder',localization[globalInterfaceLanguage].pholderFamily);
abContactRef.find('[data-type="middle"]').attr('placeholder',localization[globalInterfaceLanguage].pholderMiddle);
abContactRef.find('[data-type="nickname"]').attr('placeholder',localization[globalInterfaceLanguage].pholderNickname);
abContactRef.find('[data-type="ph_firstname"]').attr('placeholder',localization[globalInterfaceLanguage].pholderPhGiven);
abContactRef.find('[data-type="ph_lastname"]').attr('placeholder',localization[globalInterfaceLanguage].pholderPhFamily);
abContactRef.find('[data-type="prefix"]').attr('placeholder',localization[globalInterfaceLanguage].pholderPrefix);
abContactRef.find('[data-type="suffix"]').attr('placeholder',localization[globalInterfaceLanguage].pholderSuffix);
abContactRef.find('[data-type="date_bday"]').attr('placeholder',localization[globalInterfaceLanguage].pholderBday);
abContactRef.find('[data-type="title"]').attr('placeholder',localization[globalInterfaceLanguage].pholderTitle);
abContactRef.find('[data-type="org"]').attr('placeholder',localization[globalInterfaceLanguage].pholderOrg);
abContactRef.find('[data-type="department"]').attr('placeholder',localization[globalInterfaceLanguage].pholderDepartment);
abContactRef.find('span[data-type="company_contact"]').text(localization[globalInterfaceLanguage].txtCompanyContact);
abContactRef.find('[data-type="\\%del"]').attr('alt',localization[globalInterfaceLanguage].altDel);
abContactRef.find('[data-type="\\%add"]').attr('alt',localization[globalInterfaceLanguage].altAdd);
abContactRef.find('[data-type="value_handler"]').attr('alt',localization[globalInterfaceLanguage].altValueHandler);
abContactRef.find('[data-type=":custom"]').text(localization[globalInterfaceLanguage].txtCustom);
abContactRef.find('[data-type="custom_value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderCustomVal);
abContactRef.find('[data-type="dates_txt"]').text(localization[globalInterfaceLanguage].txtDates);
abContactRef.find('[data-type="\\%date"]').find('input[data-type="date_value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderDate);
abContactRef.find('[data-type="\\%date"]').find('[data-type=":_$!<anniversary>!$_:"]').text(localization[globalInterfaceLanguage].txtDatesAnniversary);
abContactRef.find('[data-type="\\%date"]').find('[data-type=":_$!<other>!$_:"]').text(localization[globalInterfaceLanguage].txtDatesOther);
abContactRef.find('[data-type="phone_txt"]').text(localization[globalInterfaceLanguage].txtPhone);
abContactRef.find('[data-type="\\%phone"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderPhoneVal);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="work"]').text(localization[globalInterfaceLanguage].txtPhoneWork);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="home"]').text(localization[globalInterfaceLanguage].txtPhoneHome);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="cell"]').text(localization[globalInterfaceLanguage].txtPhoneCell);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="cell,work"]').text(localization[globalInterfaceLanguage].txtPhoneCellWork);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="cell,home"]').text(localization[globalInterfaceLanguage].txtPhoneCellHome);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="main"]').text(localization[globalInterfaceLanguage].txtPhoneMain);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="pager"]').text(localization[globalInterfaceLanguage].txtPhonePager);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="fax"]').text(localization[globalInterfaceLanguage].txtPhoneFax);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="fax,work"]').text(localization[globalInterfaceLanguage].txtPhoneFaxWork);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="fax,home"]').text(localization[globalInterfaceLanguage].txtPhoneFaxHome);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="iphone"]').text(localization[globalInterfaceLanguage].txtPhoneIphone);
abContactRef.find('[data-type="\\%phone"]').find('[data-type="other"]').text(localization[globalInterfaceLanguage].txtPhoneOther);
abContactRef.find('[data-type="email_txt"]').text(localization[globalInterfaceLanguage].txtEmail);
abContactRef.find('[data-type="\\%email"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderEmailVal);
abContactRef.find('[data-type="\\%email"]').find('[data-type="internet,work"]').text(localization[globalInterfaceLanguage].txtEmailWork);
abContactRef.find('[data-type="\\%email"]').find('[data-type="home,internet"]').text(localization[globalInterfaceLanguage].txtEmailHome);
abContactRef.find('[data-type="\\%email"]').find('[data-type=":mobileme:,internet"]').text(localization[globalInterfaceLanguage].txtEmailMobileme);
abContactRef.find('[data-type="\\%email"]').find('[data-type=":_$!<other>!$_:,internet"]').text(localization[globalInterfaceLanguage].txtEmailOther);
abContactRef.find('[data-type="url_txt"]').text(localization[globalInterfaceLanguage].txtUrl);
abContactRef.find('[data-type="\\%url"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderUrlVal);
abContactRef.find('[data-type="\\%url"]').find('[data-type="work"]').text(localization[globalInterfaceLanguage].txtUrlWork);
abContactRef.find('[data-type="\\%url"]').find('[data-type="home"]').text(localization[globalInterfaceLanguage].txtUrlHome);
abContactRef.find('[data-type="\\%url"]').find('[data-type=":_$!<homepage>!$_:"]').text(localization[globalInterfaceLanguage].txtUrlHomepage);
abContactRef.find('[data-type="\\%url"]').find('[data-type=":_$!<other>!$_:"]').text(localization[globalInterfaceLanguage].txtUrlOther);
abContactRef.find('[data-type="related_txt"]').text(localization[globalInterfaceLanguage].txtRelated);
abContactRef.find('[data-type="\\%person"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderRelatedVal);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<manager>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedManager);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<assistant>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedAssistant);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<father>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedFather);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<mother>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedMother);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<parent>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedParent);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<brother>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedBrother);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<sister>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedSister);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<child>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedChild);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<friend>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedFriend);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<spouse>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedSpouse);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<partner>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedPartner);
abContactRef.find('[data-type="\\%person"]').find('[data-type=":_$!<other>!$_:"]').text(localization[globalInterfaceLanguage].txtRelatedOther);
abContactRef.find('[data-type="im_txt"]').text(localization[globalInterfaceLanguage].txtIm);
abContactRef.find('[data-type="\\%im"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderImVal);
abContactRef.find('[data-type="\\%im"]').find('[data-type="work"]').text(localization[globalInterfaceLanguage].txtImWork);
abContactRef.find('[data-type="\\%im"]').find('[data-type="home"]').text(localization[globalInterfaceLanguage].txtImHome);
abContactRef.find('[data-type="\\%im"]').find('[data-type=":mobileme:"]').text(localization[globalInterfaceLanguage].txtImMobileme);
abContactRef.find('[data-type="\\%im"]').find('[data-type=":_$!<other>!$_:"]').text(localization[globalInterfaceLanguage].txtImOther);
abContactRef.find('[data-type="\\%im"]').find('[data-type="aim"]').text(localization[globalInterfaceLanguage].txtImProtAim);
abContactRef.find('[data-type="\\%im"]').find('[data-type="icq"]').text(localization[globalInterfaceLanguage].txtImProtIcq);
abContactRef.find('[data-type="\\%im"]').find('[data-type="irc"]').text(localization[globalInterfaceLanguage].txtImProtIrc);
abContactRef.find('[data-type="\\%im"]').find('[data-type="jabber"]').text(localization[globalInterfaceLanguage].txtImProtJabber);
abContactRef.find('[data-type="\\%im"]').find('[data-type="msn"]').text(localization[globalInterfaceLanguage].txtImProtMsn);
abContactRef.find('[data-type="\\%im"]').find('[data-type="yahoo"]').text(localization[globalInterfaceLanguage].txtImProtYahoo);
abContactRef.find('[data-type="\\%im"]').find('[data-type="facebook"]').text(localization[globalInterfaceLanguage].txtImProtFacebook);
abContactRef.find('[data-type="\\%im"]').find('[data-type="gadugadu"]').text(localization[globalInterfaceLanguage].txtImProtGadugadu);
abContactRef.find('[data-type="\\%im"]').find('[data-type="googletalk"]').text(localization[globalInterfaceLanguage].txtImProtGoogletalk);
abContactRef.find('[data-type="\\%im"]').find('[data-type="qq"]').text(localization[globalInterfaceLanguage].txtImProtQq);
abContactRef.find('[data-type="\\%im"]').find('[data-type="skype"]').text(localization[globalInterfaceLanguage].txtImProtSkype);
abContactRef.find('[data-type="profile_txt"]').text(localization[globalInterfaceLanguage].txtProfile);
abContactRef.find('[data-type="\\%profile"]').find('input[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderProfileVal);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="twitter"]').text(localization[globalInterfaceLanguage].txtProfileTwitter);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="facebook"]').text(localization[globalInterfaceLanguage].txtProfileFacebook);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="flickr"]').text(localization[globalInterfaceLanguage].txtProfileFlickr);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="linkedin"]').text(localization[globalInterfaceLanguage].txtProfileLinkedin);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="myspace"]').text(localization[globalInterfaceLanguage].txtProfileMyspace);
abContactRef.find('[data-type="\\%profile"]').find('[data-type="sinaweibo"]').text(localization[globalInterfaceLanguage].txtProfileSinaweibo);
abContactRef.find('[data-type="address_txt"]').text(localization[globalInterfaceLanguage].txtAddress);
abContactRef.find('[data-type="\\%address"]').find('[data-type="work"]').text(localization[globalInterfaceLanguage].txtAddressWork);
abContactRef.find('[data-type="\\%address"]').find('[data-type="home"]').text(localization[globalInterfaceLanguage].txtAddressHome);
abContactRef.find('[data-type="\\%address"]').find('[data-type=":_$!<other>!$_:"]').text(localization[globalInterfaceLanguage].txtAddressOther);
abContactRef.find('[data-type="categories_txt"]').text(localization[globalInterfaceLanguage].txtCategories);
abContactRef.find('[data-type="note_txt"]').text(localization[globalInterfaceLanguage].txtNote);
abContactRef.find('[data-type="\\%note"]').find('textarea[data-type="value"]').attr('placeholder',localization[globalInterfaceLanguage].pholderNoteVal);
abContactRef.find('[data-type="edit"]').val(localization[globalInterfaceLanguage].buttonEdit);
abContactRef.find('[data-type="add_contact"]').val(localization[globalInterfaceLanguage].altAddContact);
abContactRef.find('[data-type="save"]').val(localization[globalInterfaceLanguage].buttonSave);
abContactRef.find('[data-type="cancel"]').val(localization[globalInterfaceLanguage].buttonCancel);
abContactRef.find('[data-type="delete_from_group"]').val(localization[globalInterfaceLanguage].buttonDeleteFromGroup);
abContactRef.find('[data-type="delete"]').val(localization[globalInterfaceLanguage].buttonDelete);
// hook for extension specific localization
if(typeof(globalContactsExtLocalize)=='function')
globalContactsExtLocalize(abContactRef);
globalTranslCardDAVListTemplate=$('#ResourceCardDAVListTemplate').clone();
globalTranslCardDAVListHeader=globalTranslCardDAVListTemplate.find('.resourceCardDAV_header').clone();
globalTranslCardDAVListItem=globalTranslCardDAVListTemplate.find('.resourceCardDAV_item').clone();
globalTranslVcardTemplate=$('#vCardTemplate').contents().clone();
// CUSTOM PLACEHOLDER (initialization for the whole page)
$('input[placeholder],textarea[placeholder]').placeholder();
}
function processEditorElements(inputEditorRef, processingType, inputIsReadonly, inputIsCompany)
{
var cssShowAsTxtClass='element_show_as_text';
var cssGrayedTxt='element_grayed';
var cssElementNoDisplay='element_no_display';
var cssElementHide='element_hide';
var tmp_ref=inputEditorRef;
if(processingType=='hide')
{
tmp_ref.attr('data-editor-state', 'show');
var disabled=true;
var readonly=true;
}
else
{
tmp_ref.attr('data-editor-state', 'edit');
var disabled=false;
var readonly=false;
}
var inputLockedElements=[];
if(typeof(globalContactsExtGetLockedElements)=='function')
inputLockedElements=globalContactsExtGetLockedElements(inputIsCompany);
var inputDisabledElements=[];
if(typeof(globalContactsExtGetDisabledElements)=='function')
inputDisabledElements=globalContactsExtGetDisabledElements(inputIsCompany);
// show "drag" border on photo & delete button
tmp_ref.find('#photo_drag').css('display', (disabled || readonly ? 'none' : 'inline'));
// if the editor state is "edit" show the "delete" button
if(!tmp_ref.find('#photo').hasClass('photo_blank'))
tmp_ref.find('#reset_img').css('display', (disabled || readonly ? 'none': 'inline'));
// checkboxes
var tmp=tmp_ref.find('[type="checkbox"]');
tmp.each(
function(index,element)
{
var tmp=$(element);
var tmp_data_type=tmp.attr('data-type');
tmp.prop('disabled', disabled || inputLockedElements.indexOf('[data-type="'+tmp_data_type+'"]')!=-1);
if(!tmp.prop('checked') && (processingType=='hide' || inputLockedElements.indexOf('[data-type="'+tmp_data_type+'"]')!=-1))
tmp.parent().addClass(cssGrayedTxt);
else
tmp.parent().removeClass(cssGrayedTxt);
}
);
tmp_ref.find('input[data-type^="date_"]').prop('disabled', disabled || readonly);
// family name, given name, and organization name
var typeList=['given', 'family', 'middle', 'nickname', 'prefix', 'suffix', 'ph_firstname', 'ph_lastname', 'date_bday', 'tags', 'title', 'department', 'org'];
for(var i=0; i<typeList.length; i++)
{
var elementRef = tmp_ref.find('[data-type="'+typeList[i]+'"]');
var elementDisabled = inputDisabledElements.indexOf('[data-type="'+typeList[i]+'"]')!=-1 && (processingType=='add' || elementRef.val()=='');
var elementReadOnly = readonly || inputLockedElements.indexOf('[data-type="'+typeList[i]+'"]')!=-1 || elementDisabled;
elementRef.prop({'readonly':elementReadOnly, 'disabled':elementDisabled}).toggleClass('non_editable', elementDisabled);
}
var tmp_tags_prefix=['#tags'];
var typeList=new Array({sel: '[data-type="\\%address"]'}, {sel: '[data-type="\\%phone"]'}, {sel: '[data-type="\\%email"]'}, {sel: '[data-type="\\%url"]'}, {sel: '[data-type="\\%date"]'}, {sel: '[data-type="\\%person"]'}, {sel: '[data-type="\\%im"]'}, {sel: '[data-type="\\%profile"]'}, {sel: '[data-type="\\%categories"]'}, {sel: '[data-type="\\%note"]'});
// hook for extending the list of editor elements
if(typeof(globalContactsExtGetAdditionalElements)=='function')
{
tmp_tags_prefix=tmp_tags_prefix.concat(globalContactsExtGetAdditionalElements('tags'));
typeList=typeList.concat(globalContactsExtGetAdditionalElements('common'));
}
tmp_ref.find('select').prop('disabled', disabled);
/*************************** BAD HACKS SECTION ***************************/
if($.browser.msie || $.browser.mozilla)
{
var newSVG=$((disabled ? SVG_select_dis : SVG_select)).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': (disabled ? '-22px' : '-19px'), 'vertical-align': 'top', 'background-color': '#ffffff'}); // background-color = stupid IE9 bug
//XXXX check this - was $('#ABContact')
tmp_ref.find('select').parent().find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
}
/*************************** END OF BAD HACKS SECTION ***************************/
for(var i=0; i<tmp_tags_prefix.length; i++)
{
var tmp=tmp_ref.find(tmp_tags_prefix[i]+'_tag');
tmp.prop('readonly', readonly);
if(readonly)
tmp.closest('div.tagsinput').addClass('readonly');
else
tmp.closest('div.tagsinput').removeClass('readonly');
}
for(var i=0; i<typeList.length; i++)
{
var found_non_empty=0;
var empty = false;
tmp=tmp_ref.find(typeList[i].sel);
tmp.each(
function(index, element)
{
var tmp=$(element).find('[data-type="value"]');
if(tmp.length==0)
tmp=$(element).find('[data-type="date_value"]');
var found=0;
// check if there is any data present (if not, whe hide the element)
if($(element).attr('data-type')=='%address') // address is handled specially
tmp.each(
function(index,element)
{
if($(element).attr('data-addr-field')!='' && $(element).attr('data-addr-field')!='country' && $(element).val()!='')
{
found=1;
return false;
}
}
);
else if(tmp.val()!='') // other elements (not address)
found=1;
if(processingType=='hide')
{
if(found)
{
$(element).find('[data-type="\\%add"]').find('input[type="image"]').addClass(cssElementNoDisplay);
$(element).find('[data-type="\\%del"]').find('input[type="image"]').addClass(cssElementNoDisplay);
$(element).find('select').prop('disabled', disabled);
$(element).find('textarea').prop('disabled', disabled);
/*************************** BAD HACKS SECTION ***************************/
if($.browser.msie || $.browser.mozilla)
{
var newSVG=$((disabled ? SVG_select_dis : SVG_select)).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': (disabled ? '-22px' : '-19px'), 'vertical-align': 'top', 'background-color': '#ffffff'}); // background-color = stupid IE9 bug
//XXXX check this - was $('#ABContact')
$(element).find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
}
/*************************** END OF BAD HACKS SECTION ***************************/
tmp.prop('readonly', readonly);
found_non_empty=1;
}
else
$(element).addClass(cssElementNoDisplay);
}
else // 'show'
{
empty = empty || $(element).hasClass(cssElementNoDisplay);
$(element).removeClass(cssElementNoDisplay);
$(element).find('[data-type="\\%add"]').find('input[type="image"]').removeClass(cssElementNoDisplay);
$(element).find('[data-type="\\%del"]').find('input[type="image"]').removeClass(cssElementNoDisplay);
$(element).find('select').prop('disabled', disabled);
$(element).find('textarea').prop('disabled', disabled);
/*************************** BAD HACKS SECTION ***************************/
if($.browser.msie || $.browser.mozilla)
{
var newSVG=$((disabled ? SVG_select_dis : SVG_select)).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': (disabled ? '-22px' : '-19px'), 'vertical-align': 'top', 'background-color': '#ffffff'}); // background-color = stupid IE9 bug
//XXXX check this - was $('#ABContact')
$(element).find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
}
/*************************** END OF BAD HACKS SECTION ***************************/
tmp.prop('readonly', readonly);
}
}
);
if(processingType==='show' && !empty) {
if(typeList[i].sel==='[data-type="\\%address"]') {
tmp.each(function() {
var street = $(this).find('[data-addr-field="street"]');
if(street.val()) {
street.trigger('keyup.street');
}
});
}
if(typeof globalContactAutoExpand=='undefined' || globalContactAutoExpand!=false)
tmp.last().find('[data-type="\\%add"]').find('.op').trigger('click');
}
// set the visibility of the buttons
if(processingType=='hide')
{
if(inputIsReadonly!=true)
{
if(typeof globalGroupContactsByCompanies!='undefined' && globalGroupContactsByCompanies==true && inputIsCompany)
tmp_ref.find('[data-type="add_contact"]').removeClass(cssElementNoDisplay);
else
tmp_ref.find('[data-type="add_contact"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="edit"]').removeClass(cssElementNoDisplay);
}
else
{
tmp_ref.find('[data-type="add_contact"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="edit"]').addClass(cssElementNoDisplay);
}
tmp_ref.find('[data-type="save"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="cancel"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="delete_from_group"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="delete"]').addClass(cssElementNoDisplay);
}
else if(processingType=='add')
{
tmp_ref.find('[data-type="add_contact"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="edit"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="save"]').removeClass(cssElementNoDisplay);
tmp_ref.find('[data-type="cancel"]').removeClass(cssElementNoDisplay);
tmp_ref.find('[data-type="delete_from_group"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="delete"]').addClass(cssElementNoDisplay);
}
else
{
tmp_ref.find('[data-type="add_contact"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="edit"]').addClass(cssElementNoDisplay);
tmp_ref.find('[data-type="save"]').removeClass(cssElementNoDisplay);
tmp_ref.find('[data-type="cancel"]').removeClass(cssElementNoDisplay);
// show "Delete from Group" only if there is an active contact group
// XXX we need to use another identificator
// if(globalResourceCardDAVList.getLoadedAddressbook().filterUID[globalResourceCardDAVList.getLoadedAddressbook().filterUID.length-1]!='/')
// tmp.find('[data-type="delete_from_group"]').removeClass(cssElementNoDisplay);
tmp_ref.find('[data-type="delete"]').removeClass(cssElementNoDisplay);
}
if(!found_non_empty)
{
if(processingType=='hide')
tmp.prev().addClass(cssElementNoDisplay);
else
tmp.prev().removeClass(cssElementNoDisplay);
}
}
// set editor "process" hook
if(typeof(globalContactsExtEditorProcess)=='function')
globalContactsExtEditorProcess(tmp_ref, 'post', processingType, inputIsCompany);
}
function loadImage(image)
{
var canvas = $('#photo');
var canvasElement = canvas.get(0);
var imageWidth = image.width;
var imageHeight = image.height;
var canvasWidth = canvas.width()*globalContactPhotoScaleFactor;
var canvasHeight = canvas.height()*globalContactPhotoScaleFactor;
var clipStartX = 0;
var clipStartY = 0;
var clipWidth = imageWidth;
var clipHeight = imageHeight;
canvasElement.width = canvasWidth;
canvasElement.height = canvasHeight;
if(imageWidth-canvasWidth < imageHeight-canvasHeight) {
var clipLength = Math.ceil((imageHeight-imageWidth/canvasWidth*canvasHeight)/2);
clipStartY = clipLength;
clipHeight = imageHeight-clipLength*2;
}
else {
var clipLength = Math.ceil((imageWidth-imageHeight/canvasHeight*canvasWidth)/2);
clipStartX = clipLength;
clipWidth = imageWidth-clipLength*2;
}
canvasElement.getContext('2d').drawImage(image, clipStartX, clipStartY, clipWidth, clipHeight, 0, 0, canvasWidth, canvasHeight);
canvas.removeClass('photo_blank');
}
function CardDAVeditor_cleanup(inputLoadEmpty, inputIsCompany)
{
CardDAVcleanupRegexEnvironment();
// Cleanup the editor and store reference to the editor object
globalRefVcardEditor=globalTranslVcardTemplate.clone();
// cleanup old data form address fields
globalAddressElementOldData={};
if(typeof(globalContactsExtEditorProcess)=='function')
globalContactsExtEditorProcess(globalRefVcardEditor, 'pre', null, inputIsCompany);
/*************************** BAD HACKS SECTION ***************************/
/* IE or FF */
if($.browser.msie || $.browser.mozilla)
{
// ADD empty SVG to interface (we will replace it later)
$('<svg data-type="select_icon"></svg>').css('display', 'none').insertAfter(globalRefVcardEditor.find('select[data-type$="_type"]'));
if($.browser.msie && parseInt($.browser.version, 10)==10) /* IE 10 (because there are no more conditional comments) */
globalRefVcardEditor.find('[data-type="\\%note"]').find('textarea[data-type="value"]').text('').attr('placeholder',$('[data-type="\\%note"]').find('textarea[data-type="value"]').attr('placeholder'));
}
/*************************** END OF BAD HACKS SECTION ***************************/
// bind events (see also add_elements())
// hide the "-" button (we maybe change this in future)
globalRefVcardEditor.find('[data-type="\\%del"]').css('visibility', 'hidden');
var tmp_arr=['[data-type="\\%phone"]', '[data-type="\\%email"]', '[data-type="\\%url"]', '[data-type="\\%date"]', '[data-type="\\%person"]', '[data-type="\\%im"]', '[data-type="\\%profile"]', '[data-type="\\%address"]'];
for(var i=0; i<tmp_arr.length; i++)
{
globalABEditorCounter[tmp_arr[i]]=1; // restart id counters for editor objects
globalRefVcardEditor.find(tmp_arr[i]+' [data-type="\\%add"] input').data('customSelector', tmp_arr[i]).click(function(){add_element($(this).parent(), $(this).data('customSelector'), $(this).data('customSelector'), '[data-type="\\%add"]','[data-type="\\%del"]', globalABEditorCounter[$(this).data('customSelector')]++);checkContactFormScrollBar();});
globalRefVcardEditor.find(tmp_arr[i]+' [data-type="\\%del"] input').data('customSelector', tmp_arr[i]).click(function(){del_element($(this).parent(), $(this).data('customSelector'), '[data-type="\\%add"]','[data-type="\\%del"]');checkContactFormScrollBar();});
if(typeof globalContactAutoExpand=='undefined' || globalContactAutoExpand!=false)
{
globalRefVcardEditor.find(tmp_arr[i]+' input[type="text"]').bind('keyup', function() {
var el = $(this);
var row = el.closest('tr[data-type^="%"]');
var isLast = row.attr('data-type')!==row.next().attr('data-type');
if(isLast && el.val()) {
row.find('[data-type="\\%add"] input').trigger('click');
}
});
}
//globalRefVcardEditor.find(tmp_arr[i]).children().filter('[data-type="\\%add"]').click();
}
// one special thing for address
globalRefVcardEditor.find('[data-type="\\%address"] [data-type="country_type"]').change(function(){set_address_country(this);checkContactFormScrollBar();});
var tmp=globalRefVcardEditor.find('[data-type="\\%address"]');
var tmp_select=tmp.find('[data-type="country_type"]').attr('data-autoselect');
if(tmp_select!='')
{
tmp.find('[data-type="country_type"]').children('[data-type="'+jqueryEscapeSelector(tmp_select)+'"]').prop('selected', true);
tmp.find('[data-autoselect]').change();
}
globalRefVcardEditor.find('[data-type="custom_value"]').bind('keyup change', function(){
$(this).parent().find('[data-type="invalid"]').css('display', (vCard.pre['custom_type'].test($(this).val()) ? 'none' : 'inline'));
});
// init image uploader
globalRefVcardEditor.find('.photo_div').bind('dragover dragenter', function(event){
event.stopPropagation();
event.preventDefault();
// allow image manipulation only if the editor is in "edit" state
if($('#vCardEditor').attr('data-editor-state')!="edit")
return false;
event.originalEvent.dataTransfer.dropEffect='copy'; // explicitly show this is a copy
});
globalRefVcardEditor.find('.photo_div').bind('drop', function(event) {
process_image(event);
});
globalRefVcardEditor.find('#upload_file').bind('change', function(event) {
process_image(event);
});
globalRefVcardEditor.find('#photoBoxButton').bind('click', function(event) {
var photo = $('#photoURL').val();
var newImg = new Image();
newImg.src = photo;
newImg.onload = function() {
// show the image "delete" button
$('#reset_img').css('display', 'inline');
// remove the template related to previous image (start with clean one)
vCard.tplM['contentline_PHOTO'][0]=null;
$('#photoURLHidden').val($('#photoURL').val());
loadImage(this);
hidePhotoBox();
};
newImg.onerror = function() {
$('#photoURL').addClass('invalid');
$('#photoBoxContent').find('[data-type="invalid"]').css('display', 'inline');
};
});
// initialize tagsinput
globalRefVcardEditor.find('#tags').tagsInput({
'height': null,
'width': '530px',
'color': '#2d2d2d',
'placeholderColor': '#e0e0e0',
'useNativePlaceholder': true,
'defaultText': localization[globalInterfaceLanguage].addCategory,
'delimiter': ',',
'allowDelimiterInValue': true, // if true delimiter is escaped with '\' ('\' is escaped as '\\')
'trimInput': false,
'autocomplete_url': globalAddressbookList.getABCategories(true),
'autocomplete': {
'autoFocus': true,
'minLength': 0
},
'onChange' : function(tag, tagImported)
{
// copy the array
var xList=globalAddressbookList.getABCategories(true);
var currentTags=$(this).val().splitCustom(',');
for(var i=xList.length-1; i>=0; i--)
{
for(var j=0; j<currentTags.length; j++)