-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPersonInfoViewController.cs
1561 lines (1270 loc) · 69.4 KB
/
PersonInfoViewController.cs
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
using System;
using UIKit;
using Rock.Mobile.Animation;
using CoreGraphics;
using System.Drawing;
using Rock.Mobile.PlatformSpecific.Util;
using iOS;
using System.IO;
using Foundation;
using Rock.Mobile.IO;
using CoreAnimation;
using FamilyManager.UI;
using System.Collections.Generic;
using Rock.Mobile.PlatformSpecific.iOS.UI;
using Customization;
using Rock.Mobile.PlatformSpecific.iOS.Graphics;
using Rock.Mobile.Util;
using System.Linq;
using Rock.Mobile.Util.Strings;
using Rock.Mobile.Network;
using System.Net;
namespace FamilyManager
{
public class PersonInfoViewController : UIViewController
{
ContainerViewController Parent { get; set; }
/// <summary>
/// The background panel that will darken the parent view controllers
/// </summary>
/// <value>The background panel.</value>
UIView BackgroundPanel { get; set; }
/// <summary>
/// This will be our main UI panel.
/// </summary>
/// <value>The main panel.</value>
UIView MainPanel { get; set; }
/// <summary>
/// True if we're animating OUT the view.
/// </summary>
bool IsDismissing { get; set; }
/// We use this because setting an image on a button via SetImage causes the button to size to the image,
/// even with ContentMode set.
/// </summary>
/// <value>The profile image view.</value>
UIImageView ProfileImageView { get; set; }
UIButton EditPictureButton { get; set; }
UIToggle AdultChildToggle { get; set; }
UIScrollViewWrapper ScrollView { get; set; }
UIButton SubmitButton { get; set; }
class BaseMemberPanel
{
public class AllowedCheckinResult
{
public UIButton Button { get; set; }
public FamilySearchResultView FamilyView { get; set; }
}
protected static nfloat verticalControlSpacing = 30;
protected Dynamic_UITextField FirstName { get; set; }
protected Dynamic_UITextField MiddleName { get; set; }
protected Dynamic_UITextField LastName { get; set; }
protected Dynamic_UIDatePicker BirthdatePicker { get; set; }
protected Dynamic_UIToggle GenderToggle { get; set; }
protected Dynamic_UITextField PhoneNumber { get; set; }
protected Dynamic_UITextField EmailAddress { get; set; }
protected UIView RootView { get; set; }
protected List<IDynamic_UIView> Dynamic_RequiredControls { get; set; }
protected List<IDynamic_UIView> Dynamic_OptionalControls { get; set; }
public List<KeyValuePair<string, string>> PendingAttribUpdates { get; protected set; }
public UILabel AllowedCheckinsHeader { get; set; }
public List<AllowedCheckinResult> AllowedCheckins { get; set; }
public List<Rock.Client.Family> AllowedCheckinFamilies { get; set; }
public PersonInfoViewController Parent { get; set; }
public BaseMemberPanel( )
{
Dynamic_RequiredControls = new List<IDynamic_UIView>();
Dynamic_OptionalControls = new List<IDynamic_UIView>();
PendingAttribUpdates = new List<KeyValuePair<string, string>>();
AllowedCheckins = new List<AllowedCheckinResult>( );
}
public virtual void Copy( BaseMemberPanel rhs )
{
FirstName.SetCurrentValue( rhs.FirstName.GetCurrentValue( ).ToUpperWords( ) );
MiddleName.SetCurrentValue( rhs.MiddleName.GetCurrentValue( ).ToUpperWords( ) );
LastName.SetCurrentValue( rhs.LastName.GetCurrentValue( ).ToUpperWords( ) );
BirthdatePicker.SetCurrentValue( rhs.BirthdatePicker.GetCurrentValue( ) );
GenderToggle.SetCurrentValue( rhs.GenderToggle.GetCurrentValue( ) );
PhoneNumber.SetCurrentValue( rhs.PhoneNumber.GetCurrentValue( ) );
EmailAddress.SetCurrentValue( rhs.EmailAddress.GetCurrentValue( ) );
// copy the checkin buttons. First remove existing ones
RemoveAllowedCheckinList( );
// then add the new ones
if( rhs.AllowedCheckinFamilies != null )
{
AllowedCheckinFamilies = new List<Rock.Client.Family>( rhs.AllowedCheckinFamilies );
foreach( Rock.Client.Family family in AllowedCheckinFamilies )
{
CreateAllowedCheckinEntry( family );
}
}
else
{
AllowedCheckinFamilies = null;
}
}
public virtual void ViewDidLoad( PersonInfoViewController parentViewController )
{
Parent = parentViewController;
RootView = new UIView();
RootView.Layer.AnchorPoint = CGPoint.Empty;
FirstName = new Dynamic_UITextField( parentViewController, RootView, Strings.General_FirstName, false, true );
FirstName.GetTextField( ).AutocapitalizationType = UITextAutocapitalizationType.Words;
FirstName.GetTextField( ).AutocorrectionType = UITextAutocorrectionType.No;
FirstName.AddToView( RootView );
MiddleName = new Dynamic_UITextField( parentViewController, RootView, Strings.General_MiddleName, false, false );
MiddleName.GetTextField( ).AutocapitalizationType = UITextAutocapitalizationType.Words;
MiddleName.GetTextField( ).AutocorrectionType = UITextAutocorrectionType.No;
MiddleName.AddToView( RootView );
LastName = new Dynamic_UITextField( parentViewController, RootView, Strings.General_LastName, false, true );
LastName.GetTextField( ).AutocapitalizationType = UITextAutocapitalizationType.Words;
LastName.GetTextField( ).AutocorrectionType = UITextAutocorrectionType.No;
LastName.AddToView( RootView );
BirthdatePicker = new Dynamic_UIDatePicker( parentViewController, Strings.General_Birthday, false , "");
BirthdatePicker.AddToView( RootView );
GenderToggle = new Dynamic_UIToggle( parentViewController, RootView, Strings.Gender_Header, Strings.General_Male, Strings.General_Female, true );
GenderToggle.AddToView( RootView );
EmailAddress = new Dynamic_UITextField( parentViewController, RootView, Strings.General_Email, false, false );
EmailAddress.GetTextField( ).AutocorrectionType = UITextAutocorrectionType.No;
EmailAddress.GetTextField( ).Delegate = new KeyboardAdjustManager.TextFieldDelegate( );
EmailAddress.ShouldAdjustForKeyboard( true );
EmailAddress.AddToView( RootView );
PhoneNumber = new Dynamic_UITextField( parentViewController, RootView, Strings.General_PhoneNumber, false, false );
PhoneNumber.GetTextField( ).Delegate = new PhoneNumberFormatterDelegate( );
PhoneNumber.AddToView( RootView );
AllowedCheckinsHeader = new UILabel( );
AllowedCheckinsHeader.Layer.AnchorPoint = CGPoint.Empty;
AllowedCheckinsHeader.Text = Strings.PersonInfo_AllowCheckinsBy_Header;
AllowedCheckinsHeader.Font = FontManager.GetFont( Settings.General_BoldFont, Config.Instance.VisualSettings.SmallFontSize );
AllowedCheckinsHeader.SizeToFit( );
Theme.StyleLabel( AllowedCheckinsHeader, Config.Instance.VisualSettings.LabelStyle );
RootView.AddSubview( AllowedCheckinsHeader );
}
public virtual void ViewWillDisappear( )
{
RemoveAllowedCheckinList( );
}
public virtual void PersonInfoToUI( Rock.Client.Person workingPerson,
Rock.Client.PhoneNumber workingPhoneNumber,
Dictionary<string, Rock.Client.AttributeValue> attributeValues,
List<Rock.Client.Family> allowedCheckinList )
{
FirstName.SetCurrentValue( workingPerson.NickName );
MiddleName.SetCurrentValue( workingPerson.MiddleName );
LastName.SetCurrentValue( workingPerson.LastName );
if ( workingPerson.BirthDate.HasValue )
{
BirthdatePicker.SetCurrentValue( string.Format( "{0:MMMMM dd yyyy}", workingPerson.BirthDate.Value ) );
BirthdatePicker.SizeToFit( );
}
else
{
BirthdatePicker.SetCurrentValue( string.Empty );
}
PhoneNumber.SetCurrentValue( workingPhoneNumber.NumberFormatted );
EmailAddress.SetCurrentValue( workingPerson.Email );
string gender = RockActions.Genders[ (int)workingPerson.Gender ];
if ( gender == Strings.General_Male || gender == Strings.General_Female )
{
GenderToggle.SetCurrentValue( gender );
}
else
{
GenderToggle.SetCurrentValue( "" );
}
// lastly, create entries for each person that has checkin permissions
if( allowedCheckinList != null )
{
AllowedCheckinFamilies = new List<Rock.Client.Family>( allowedCheckinList );
foreach( Rock.Client.Family family in AllowedCheckinFamilies )
{
CreateAllowedCheckinEntry( family );
}
}
else
{
AllowedCheckinFamilies = null;
}
}
void CreateAllowedCheckinEntry( Rock.Client.Family family )
{
AllowedCheckinResult checkinResult = new AllowedCheckinResult( );
// create the overlay button that will let them tap the result.
checkinResult.Button = new UIButton( UIButtonType.System );
checkinResult.Button.Layer.AnchorPoint = CGPoint.Empty;
checkinResult.Button.TouchUpInside += (object sender, EventArgs e) =>
{
Parent.AllowedCheckinButtonClicked( family );
};
// create the familyView for the entry
checkinResult.FamilyView = new FamilySearchResultView( );
checkinResult.FamilyView.AddSubview( checkinResult.Button );
RootView.AddSubview( checkinResult.FamilyView );
AllowedCheckins.Add( checkinResult );
}
void RemoveAllowedCheckinList( )
{
// remove any dynamic buttons that were added for checkin permissions.
if ( AllowedCheckinFamilies != null )
{
foreach( AllowedCheckinResult checkinResult in AllowedCheckins )
{
checkinResult.Button.RemoveFromSuperview( );
checkinResult.FamilyView.RemoveFromSuperview( );
}
AllowedCheckins.Clear( );
AllowedCheckinFamilies.Clear( );
}
}
public virtual void UIInfoToPerson( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
workingPerson.NickName = FirstName.GetCurrentValue( ).ToUpperWords( );
workingPerson.MiddleName = MiddleName.GetCurrentValue( ).ToUpperWords( );
workingPerson.LastName = LastName.GetCurrentValue( ).ToUpperWords( );
workingPerson.Email = EmailAddress.GetCurrentValue( );
// take the birthday IF there's a value set.
string birthday = BirthdatePicker.GetCurrentValue( );
if ( string.IsNullOrWhiteSpace( birthday ) == false )
{
RockActions.SetBirthday( workingPerson, DateTime.Parse( birthday ) );
}
else
{
RockActions.SetBirthday( workingPerson, null );
}
// try to get their phone number. If it's null, create a new one for them (even if we just put an empty string in it)
RockActions.SetPhoneNumberDigits( workingPhoneNumber, PhoneNumber.GetCurrentValue( ).AsNumeric( ) );
// only change their gender if it's been set to something.
switch( GenderToggle.GetCurrentValue( ) )
{
case Strings.General_Male:
{
workingPerson.Gender = (Rock.Client.Enums.Gender) RockActions.Genders.IndexOf( Strings.General_Male );
break;
}
case Strings.General_Female:
{
workingPerson.Gender = (Rock.Client.Enums.Gender) RockActions.Genders.IndexOf( Strings.General_Female );
break;
}
}
}
public virtual bool IsInfoDirty( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
// if anything in the UI is different from the objects, then yeah, it's dirty
string workingNickName = workingPerson.NickName == null ? "" : workingPerson.NickName;
if ( workingNickName != FirstName.GetCurrentValue( ) )
{
return true;
}
// check middle name
string workingMiddleName = workingPerson.MiddleName == null ? "" : workingPerson.MiddleName;
if ( workingMiddleName != MiddleName.GetCurrentValue( ) )
{
return true;
}
// check last name
string workingLastName = workingPerson.LastName == null ? "" : workingPerson.LastName;
if ( workingLastName != LastName.GetCurrentValue( ) )
{
return true;
}
// check email
string workingEmail = workingPerson.Email == null ? "" : workingPerson.Email;
if ( workingEmail != EmailAddress.GetCurrentValue( ) )
{
return true;
}
// check their birthday. First, get the working birthday as a normal string (June 14 2008) style
string workingBirthday = "";
if ( workingPerson.BirthDate.HasValue == true )
{
workingBirthday = string.Format( "{0:MMMM dd yyyy}", workingPerson.BirthDate.Value );
}
if ( workingBirthday != BirthdatePicker.GetCurrentValue( ) )
{
return true;
}
// check their phone number. first, if either is NOT null, we need to inspect further
if ( string.IsNullOrWhiteSpace( workingPhoneNumber.Number ) == false || string.IsNullOrWhiteSpace( PhoneNumber.GetCurrentValue( ) ) == false )
{
// if they don't match, it's dirty. We can't ONLY do this, because if they dont' match due to one being null and the other being "", that isn't dirty.
if ( workingPhoneNumber.Number != PhoneNumber.GetCurrentValue( ).AsNumeric( ) )
{
return true;
}
}
// check gender
Rock.Client.Enums.Gender genderIndex = 0;
switch( GenderToggle.GetCurrentValue( ) )
{
case Strings.General_Male:
{
genderIndex = (Rock.Client.Enums.Gender) RockActions.Genders.IndexOf( Strings.General_Male );
break;
}
case Strings.General_Female:
{
genderIndex = (Rock.Client.Enums.Gender) RockActions.Genders.IndexOf( Strings.General_Female );
break;
}
}
if ( genderIndex != workingPerson.Gender )
{
return true;
}
return false;
}
protected bool AttributesDirty( Dictionary<string, Rock.Client.AttributeValue> workingAttributeValues )
{
// helper method that will take a list of attributes and compare them with what's in the UI panel.
if ( workingAttributeValues != null )
{
// check the attributes
List<KeyValuePair<string, string>> currentAttributeValues = new List<KeyValuePair<string, string>>();
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_RequiredControls, currentAttributeValues );
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_OptionalControls, currentAttributeValues );
// make sure that for each key, the value matches
foreach ( KeyValuePair<string, string> attrib in currentAttributeValues )
{
// find the matching key in their original attribute list, and compare.
KeyValuePair<string, Rock.Client.AttributeValue> workingAttrib = workingAttributeValues.Where( wa => wa.Key == attrib.Key ).SingleOrDefault( );
if ( workingAttrib.Key != null )
{
// before testing, make sure we take an empty string instead of null for the working attribute.
string workingAttribValue = workingAttrib.Value.Value == null ? string.Empty : workingAttrib.Value.Value;
if ( attrib.Value != workingAttribValue )
{
return true;
}
}
}
}
return false;
}
public virtual bool ValidateInfo( )
{
// ensure all required fields are filled out
if ( string.IsNullOrWhiteSpace( FirstName.GetCurrentValue( ) ) )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BlankFirstName_Header, Strings.PersonInfo_BlankFirstName_Message );
return false;
}
if ( string.IsNullOrWhiteSpace( LastName.GetCurrentValue( ) ) )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BlankLastName_Header, Strings.PersonInfo_BlankLastName_Message );
return false;
}
if( string.IsNullOrWhiteSpace( GenderToggle.GetCurrentValue( ) ) )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BlankGender_Header, Strings.PersonInfo_BlankGender_Message );
return false;
}
// Make sure if there IS an email address, it's a valid format.
if ( EmailAddress.GetCurrentValue( ) != string.Empty && EmailAddress.GetCurrentValue( ).IsEmailFormat( ) == false )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BadEmail_Header, Strings.PersonInfo_BadEmail_Message );
return false;
}
// add more here if needed
return true;
}
public virtual void TouchesEnded( )
{
BirthdatePicker.ResignFirstResponder( );
FirstName.ResignFirstResponder( );
MiddleName.ResignFirstResponder( );
LastName.ResignFirstResponder( );
PhoneNumber.ResignFirstResponder( );
EmailAddress.ResignFirstResponder( );
}
public virtual void ViewDidLayoutSubviews( CGRect parentBounds )
{
CGRect legalBounds = new CGRect( parentBounds.Left, parentBounds.Top, parentBounds.Width * .75f, parentBounds.Height );
FirstName.ViewDidLayoutSubviews( legalBounds );
FirstName.Layer.Position = new CGPoint( 10, 30 );
FirstName.ShouldAdjustForKeyboard( true );
MiddleName.ViewDidLayoutSubviews( legalBounds );
MiddleName.Layer.Position = new CGPoint( 10, FirstName.Frame.Bottom + verticalControlSpacing );
MiddleName.ShouldAdjustForKeyboard( true );
LastName.ViewDidLayoutSubviews( legalBounds );
LastName.Layer.Position = new CGPoint( 10, MiddleName.Frame.Bottom + verticalControlSpacing );
LastName.ShouldAdjustForKeyboard( true );
BirthdatePicker.ViewDidLayoutSubviews( legalBounds );
BirthdatePicker.SetPosition( new CGPoint( 10, LastName.Frame.Bottom + verticalControlSpacing ) );
// now do phone and email...
EmailAddress.ViewDidLayoutSubviews( new CGRect( 0, 0, parentBounds.Width / 2, parentBounds.Height ) );
EmailAddress.Layer.Position = new CGPoint( 10, BirthdatePicker.Frame.Bottom + verticalControlSpacing );
nfloat phoneNumberWidth = parentBounds.Width - EmailAddress.Bounds.Width - 40;
PhoneNumber.ViewDidLayoutSubviews( new CGRect( 0, 0, phoneNumberWidth, parentBounds.Height ) );
PhoneNumber.Layer.Position = new CGPoint( EmailAddress.Frame.Right + 20, BirthdatePicker.Frame.Bottom + verticalControlSpacing );
// and gender
GenderToggle.ViewDidLayoutSubviews( legalBounds );
GenderToggle.Layer.Position = new CGPoint( 10, EmailAddress.Frame.Bottom + verticalControlSpacing );
// leave it to the parent to do the "Allow Checkin By"
}
public UIView GetRootView( )
{
return RootView;
}
}
/// <summary>
/// This defines the panel to display when we're editing an adult
/// </summary>
class AdultMemberPanel : BaseMemberPanel
{
protected Dynamic_UIToggle MaritalStatusToggle { get; set; }
protected Dictionary<string, Rock.Client.AttributeValue> WorkingAttributeValues;
public AdultMemberPanel( ) : base( )
{
WorkingAttributeValues = new Dictionary<string, Rock.Client.AttributeValue>( );
}
public override void Copy( BaseMemberPanel rhs )
{
base.Copy( rhs );
// there's no way to copy this value, so simply clear it out.
// This could cause an adult that's loaded, switched to a child,
// and BACK to an adult to then have a blank marital status, but that
// is ok, because that results in it simply not being set to the person
// on Submission.
MaritalStatusToggle.SetCurrentValue( "" );
}
public override void PersonInfoToUI( Rock.Client.Person workingPerson,
Rock.Client.PhoneNumber workingPhoneNumber,
Dictionary<string, Rock.Client.AttributeValue> attributeValues,
List<Rock.Client.Family> allowedCheckinList )
{
base.PersonInfoToUI( workingPerson, workingPhoneNumber, attributeValues, allowedCheckinList );
// set the marital status. default to Unknown
MaritalStatusToggle.SetCurrentValue( "" );
if ( workingPerson.MaritalStatusValueId != null )
{
Rock.Client.DefinedValue maritalStatus = Config.Instance.MaritalStatus.Where( ms => ms.Id == workingPerson.MaritalStatusValueId ).SingleOrDefault( );
if ( maritalStatus != null )
{
MaritalStatusToggle.SetCurrentValue( maritalStatus.Value );
}
}
// reset the control values
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.SetCurrentValue( string.Empty );
}
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.SetCurrentValue( string.Empty );
}
// store the original attribute values so we can flag if they're dirty
WorkingAttributeValues = attributeValues;
FamilyManager.UI.Dynamic_UIFactory.AttributesToUI( attributeValues, Dynamic_RequiredControls );
FamilyManager.UI.Dynamic_UIFactory.AttributesToUI( attributeValues, Dynamic_OptionalControls );
}
public override void UIInfoToPerson( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
base.UIInfoToPerson( workingPerson, workingPhoneNumber );
// only update their marital status if it's set to something.
if ( MaritalStatusToggle.GetCurrentValue( ) != string.Empty )
{
string maritalStatusStr = MaritalStatusToggle.GetCurrentValue( );
// find the appropriate definef value
Rock.Client.DefinedValue maritalStatus = Config.Instance.MaritalStatus.Where( ms => ms.Value == maritalStatusStr ).SingleOrDefault( );
if ( maritalStatus != null )
{
workingPerson.MaritalStatusValueId = maritalStatus.Id;
}
}
// GET attribute values
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_RequiredControls, PendingAttribUpdates );
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_OptionalControls, PendingAttribUpdates );
}
public override bool IsInfoDirty( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
// check our attribute values.
if ( AttributesDirty( WorkingAttributeValues ) == true )
{
return true;
}
// check marital status
string maritalStatusStr = MaritalStatusToggle.GetCurrentValue( );
Rock.Client.DefinedValue maritalStatus = Config.Instance.MaritalStatus.Where( ms => ms.Value == maritalStatusStr ).SingleOrDefault( );
if ( maritalStatus != null )
{
if ( workingPerson.MaritalStatusValueId != maritalStatus.Id )
{
return true;
}
}
return base.IsInfoDirty( workingPerson, workingPhoneNumber );
}
public override bool ValidateInfo( )
{
// return false if our base control has a blank required field
if( base.ValidateInfo( ) == false )
{
return false;
}
// check the required attribs. If any of htem are blank, return false.
foreach ( IDynamic_UIView dynamicControl in Dynamic_RequiredControls )
{
if ( string.IsNullOrWhiteSpace( dynamicControl.GetCurrentValue( ) ) == true )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BlankAttrib_Header, Strings.PersonInfo_BlankAttrib_Message );
return false;
}
}
// if we made it here, all data is good. return true.
return true;
}
public override void ViewDidLoad( PersonInfoViewController parentViewController )
{
base.ViewDidLoad( parentViewController );
MaritalStatusToggle = new Dynamic_UIToggle( parentViewController, RootView, Strings.MaritalStatus_Header, Strings.MaritalStatus_Married, Strings.MaritalStatus_Single, false );
MaritalStatusToggle.AddToView( RootView );
// build the dynamic UI controls
for( int i = 0; i < Config.Instance.PersonAttributeDefines.Count; i++ )
{
// make sure this control is for an adult
if ( Config.Instance.PersonAttributes[ i ][ "filter" ] == null || Config.Instance.PersonAttributes[ i ][ "filter" ].ToLower( ) == "adult" )
{
// get the required flag and the attribs that define what type of UI control this is.
bool isRequired = bool.Parse( Config.Instance.PersonAttributes[ i ][ "required" ] );
Rock.Client.Attribute uiControlAttrib = Config.Instance.PersonAttributeDefines[ i ];
// build it and add it to our UI
IDynamic_UIView uiView = Dynamic_UIFactory.CreateDynamic_UIControl( parentViewController, RootView, uiControlAttrib, isRequired, Config.Instance.PersonAttributeDefines[ i ].Key );
if ( uiView != null )
{
if ( isRequired == true )
{
Dynamic_RequiredControls.Add( uiView );
Dynamic_RequiredControls[ Dynamic_RequiredControls.Count - 1 ].AddToView( RootView );
}
else
{
Dynamic_OptionalControls.Add( uiView );
Dynamic_OptionalControls[ Dynamic_OptionalControls.Count - 1 ].AddToView( RootView );
}
uiView.ShouldAdjustForKeyboard( true );
}
}
}
}
public override void TouchesEnded( )
{
base.TouchesEnded( );
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.ResignFirstResponder( );
}
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.ResignFirstResponder( );
}
}
public override void ViewDidLayoutSubviews( CGRect parentBounds )
{
base.ViewDidLayoutSubviews( parentBounds );
CGRect legalBounds = new CGRect( 0, 0, parentBounds.Width * .75f, parentBounds.Height );
//MaritalStatusToggle.SizeToFit( );
MaritalStatusToggle.ViewDidLayoutSubviews( legalBounds );
MaritalStatusToggle.Layer.Position = new CGPoint( parentBounds.Width - MaritalStatusToggle.Frame.Width - 10, EmailAddress.Frame.Bottom + verticalControlSpacing );
// now procedurally add all the REQUIRED person attributes
nfloat controlYPos = MaritalStatusToggle.Frame.Bottom + verticalControlSpacing;
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.ViewDidLayoutSubviews( legalBounds );
dynamicView.SetPosition( new CGPoint( 10, controlYPos ) );
controlYPos = dynamicView.GetFrame( ).Bottom + verticalControlSpacing;
}
// and now optional attributes
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.ViewDidLayoutSubviews( legalBounds );
dynamicView.SetPosition( new CGPoint( 10, controlYPos ) );
controlYPos = dynamicView.GetFrame( ).Bottom + verticalControlSpacing;
}
// finally add allowed checkin people
if( AllowedCheckins.Count > 0 )
{
// setup the header
AllowedCheckinsHeader.Hidden = false;
AllowedCheckinsHeader.Layer.Position = new CGPoint( 10, controlYPos );
controlYPos = AllowedCheckinsHeader.Frame.Bottom;
// add in each entry
int i;
for( i = 0; i < AllowedCheckins.Count; i++ )
{
AllowedCheckins[ i ].FamilyView.FormatCell( legalBounds.Width, AllowedCheckinFamilies[ i ] );
AllowedCheckins[ i ].Button.Bounds = AllowedCheckins[ i ].FamilyView.Bounds;
AllowedCheckins[ i ].FamilyView.Layer.Position = new CGPoint( 10, controlYPos );
controlYPos = AllowedCheckins[ i ].FamilyView.Frame.Bottom + verticalControlSpacing;
}
}
else
{
AllowedCheckinsHeader.Hidden = true;
}
// wrap our view around the control
RootView.Bounds = new CGRect( 0, 0, parentBounds.Width, controlYPos );
}
}
AdultMemberPanel AdultPanel { get; set; }
class ChildMemberPanel : BaseMemberPanel
{
Dynamic_UIDropDown GradeDropDown { get; set; }
protected Dictionary<string, Rock.Client.AttributeValue> WorkingAttributeValues;
public ChildMemberPanel( ) : base( )
{
WorkingAttributeValues = new Dictionary<string, Rock.Client.AttributeValue>( );
}
public override void Copy( BaseMemberPanel rhs )
{
base.Copy( rhs );
// there's no way to copy this value, so simply clear it out.
// If they loaded a child, switched to an adult, and went back to the child,
// the grade will be empty, but it's ok because that will simply
// cause the value to not be set when syncing with the person.
GradeDropDown.SetCurrentValue( string.Empty );
}
public override void PersonInfoToUI( Rock.Client.Person workingPerson,
Rock.Client.PhoneNumber workingPhoneNumber,
Dictionary<string, Rock.Client.AttributeValue> attributeValues,
List<Rock.Client.Family> allowedCheckinList )
{
base.PersonInfoToUI( workingPerson, workingPhoneNumber, attributeValues, allowedCheckinList );
// set their grade (if they have it)
GradeDropDown.SetCurrentValue( string.Empty );
if ( workingPerson.GradeOffset.HasValue && workingPerson.GradeOffset.Value >= 0 )
{
// get the defined value for their grade
Rock.Client.DefinedValue gradeValue = Config.Instance.SchoolGrades.Where( sg => int.Parse( sg.Value ) == workingPerson.GradeOffset.Value ).SingleOrDefault( );
GradeDropDown.SetCurrentValue( gradeValue.Description );
}
// reset the control values
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.SetCurrentValue( string.Empty );
}
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.SetCurrentValue( string.Empty );
}
// store the current attribute values so we can warn if they are changed
WorkingAttributeValues = attributeValues;
FamilyManager.UI.Dynamic_UIFactory.AttributesToUI( attributeValues, Dynamic_RequiredControls );
FamilyManager.UI.Dynamic_UIFactory.AttributesToUI( attributeValues, Dynamic_OptionalControls );
}
public override void UIInfoToPerson( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
base.UIInfoToPerson( workingPerson, workingPhoneNumber );
// update their grade
string gradeValueStr = GradeDropDown.GetCurrentValue( );
if ( string.IsNullOrWhiteSpace( gradeValueStr ) == false )
{
// find the defined value with the matching description
Rock.Client.DefinedValue gradeValue = Config.Instance.SchoolGrades.Where( sg => sg.Description == gradeValueStr ).SingleOrDefault( );
workingPerson.GradeOffset = int.Parse( gradeValue.Value );
}
// GET attribute values
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_RequiredControls, PendingAttribUpdates );
FamilyManager.UI.Dynamic_UIFactory.UIToAttributes( Dynamic_OptionalControls, PendingAttribUpdates );
}
public override bool IsInfoDirty( Rock.Client.Person workingPerson, Rock.Client.PhoneNumber workingPhoneNumber )
{
// check our attribute values.
if ( AttributesDirty( WorkingAttributeValues ) == true )
{
return true;
}
// check their grade
string gradeValueStr = GradeDropDown.GetCurrentValue( );
if ( string.IsNullOrWhiteSpace( gradeValueStr ) == false )
{
// find the defined value with the matching description
Rock.Client.DefinedValue gradeValue = Config.Instance.SchoolGrades.Where( sg => sg.Description == gradeValueStr ).SingleOrDefault( );
if ( int.Parse( gradeValue.Value ) != workingPerson.GradeOffset )
{
return true;
}
}
return base.IsInfoDirty( workingPerson, workingPhoneNumber );
}
public override void ViewDidLoad( PersonInfoViewController parentViewController )
{
base.ViewDidLoad( parentViewController );
// build the grade list.
string[] gradeList = new string[ Config.Instance.SchoolGrades.Count ];
for( int i = 0; i < Config.Instance.SchoolGrades.Count; i++ )
{
gradeList[ i ] = Config.Instance.SchoolGrades[ i ].Description;
}
GradeDropDown = new Dynamic_UIDropDown( parentViewController, RootView, Strings.PersonInfo_GradeHeader, Strings.PersonInfo_GradeMessage, gradeList, false );
RootView.AddSubview( GradeDropDown );
// build the dynamic UI controls
for( int i = 0; i < Config.Instance.PersonAttributeDefines.Count; i++ )
{
// make sure this control is for a child
if ( Config.Instance.PersonAttributes[ i ][ "filter" ] == null || Config.Instance.PersonAttributes[ i ][ "filter" ].ToLower( ) == "child" )
{
// get the required flag and the attribs that define what type of UI control this is.
bool isRequired = bool.Parse( Config.Instance.PersonAttributes[ i ][ "required" ] );
Rock.Client.Attribute uiControlAttrib = Config.Instance.PersonAttributeDefines[ i ];
// build it and add it to our UI
IDynamic_UIView uiView = Dynamic_UIFactory.CreateDynamic_UIControl( parentViewController, RootView, uiControlAttrib, isRequired, Config.Instance.PersonAttributeDefines[ i ].Key );
if ( uiView != null )
{
if ( isRequired == true )
{
Dynamic_RequiredControls.Add( uiView );
Dynamic_RequiredControls[ Dynamic_RequiredControls.Count - 1 ].AddToView( RootView );
}
else
{
Dynamic_OptionalControls.Add( uiView );
Dynamic_OptionalControls[ Dynamic_OptionalControls.Count - 1 ].AddToView( RootView );
}
uiView.ShouldAdjustForKeyboard( true );
}
}
}
}
public override bool ValidateInfo( )
{
// return false if our base control has a blank required field
if( base.ValidateInfo( ) == false )
{
return false;
}
// check the required attribs. If any of htem are blank, return false.
foreach ( IDynamic_UIView dynamicControl in Dynamic_RequiredControls )
{
if ( string.IsNullOrWhiteSpace( dynamicControl.GetCurrentValue( ) ) == true )
{
Rock.Mobile.Util.Debug.DisplayError( Strings.PersonInfo_BlankAttrib_Header, Strings.PersonInfo_BlankAttrib_Message );
return false;
}
}
// if we made it here, all data is good. return true.
return true;
}
public override void TouchesEnded( )
{
base.TouchesEnded( );
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.ResignFirstResponder( );
}
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.ResignFirstResponder( );
}
}
public override void ViewDidLayoutSubviews( CGRect parentBounds )
{
base.ViewDidLayoutSubviews( parentBounds );
// vertically center the grade drop down with the gender toggle, which is to its left.
GradeDropDown.ViewDidLayoutSubviews( parentBounds );
nfloat gradeYPos = ( EmailAddress.Frame.Bottom + verticalControlSpacing ) - ( (GradeDropDown.Frame.Height - GenderToggle.Frame.Height) / 2 );
GradeDropDown.Layer.Position = new CGPoint( parentBounds.Width - GradeDropDown.Frame.Width - 100, gradeYPos );
CGRect legalBounds = new CGRect( 0, 0, parentBounds.Width * .75f, parentBounds.Height );
// now procedurally add all the REQUIRED person attributes
nfloat controlYPos = GenderToggle.Frame.Bottom + verticalControlSpacing;
foreach ( IDynamic_UIView dynamicView in Dynamic_RequiredControls )
{
dynamicView.ViewDidLayoutSubviews( legalBounds );
dynamicView.SetPosition( new CGPoint( 10, controlYPos ) );
controlYPos = dynamicView.GetFrame( ).Bottom + verticalControlSpacing;
}
// and now optional attributes
foreach ( IDynamic_UIView dynamicView in Dynamic_OptionalControls )
{
dynamicView.ViewDidLayoutSubviews( legalBounds );
dynamicView.SetPosition( new CGPoint( 10, controlYPos ) );
controlYPos = dynamicView.GetFrame( ).Bottom + verticalControlSpacing;
}
// finally add allowed checkin people
if( AllowedCheckins.Count > 0 )
{
// setup the header
AllowedCheckinsHeader.Hidden = false;
AllowedCheckinsHeader.Layer.Position = new CGPoint( 10, controlYPos );
controlYPos = AllowedCheckinsHeader.Frame.Bottom;
// add in each entry
int i;
for( i = 0; i < AllowedCheckins.Count; i++ )
{
AllowedCheckins[ i ].FamilyView.FormatCell( legalBounds.Width, AllowedCheckinFamilies[ i ] );
AllowedCheckins[ i ].Button.Bounds = AllowedCheckins[ i ].FamilyView.Bounds;
AllowedCheckins[ i ].FamilyView.Layer.Position = new CGPoint( 10, controlYPos );
controlYPos = AllowedCheckins[ i ].FamilyView.Frame.Bottom + verticalControlSpacing;
}
}
else
{
AllowedCheckinsHeader.Hidden = true;
}
// wrap our view around the control
RootView.Bounds = new CGRect( 0, 0, parentBounds.Width, controlYPos );
}
}
ChildMemberPanel ChildPanel { get; set; }
/// <summary>
/// Reference to the currently active panel
/// </summary>
BaseMemberPanel ActivePanel { get; set; }
KeyboardAdjustManager KeyboardAdjustManager { get; set; }
bool Animating { get; set; }
UIButton CloseButton { get; set; }
/// <summary>
/// True if there's a profile picture that should be updated.
/// </summary>
bool ProfileImageViewDirty { get; set; }
bool Dirty { get; set; }
UIBlockerView BlockerView { get; set; }