-
-
Notifications
You must be signed in to change notification settings - Fork 347
/
RegistrationTemplateDetail.ascx.cs
4238 lines (3636 loc) · 198 KB
/
RegistrationTemplateDetail.ascx.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
// <copyright>
// Copyright by the Spark Development Network
//
// Licensed under the Rock Community License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.rockrms.com/license
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Rock;
using Rock.Attribute;
using Rock.Constants;
using Rock.Data;
using Rock.Model;
using Rock.Security;
using Rock.Web;
using Rock.Web.Cache;
using Rock.Web.UI;
using Rock.Web.UI.Controls;
using Attribute = Rock.Model.Attribute;
namespace RockWeb.Blocks.Event
{
[DisplayName( "Registration Template Detail" )]
[Category( "Event" )]
[Description( "Displays the details of the given registration template." )]
[LinkedPage(
"Registration Template Placement Page",
Key = AttributeKey.RegistrationTemplatePlacementPage,
DefaultValue = Rock.SystemGuid.Page.REGISTRATION_TEMPLATE_PLACEMENT + "," + Rock.SystemGuid.PageRoute.REGISTRATION_TEMPLATE_PLACEMENT,
Order = 0
)]
[CodeEditorField( "Default Confirmation Email", "The default Confirmation Email Template value to use for a new template", CodeEditorMode.Lava, CodeEditorTheme.Rock, 300, false, @"{{ 'Global' | Attribute:'EmailHeader' }}
<h1>{{ RegistrationInstance.RegistrationTemplate.RegistrationTerm }} Confirmation: {{ RegistrationInstance.Name }}</h1>
{% assign registrants = Registration.Registrants | Where:'OnWaitList', false %}
{% assign registrantCount = registrants | Size %}
{% if registrantCount > 0 %}
<p>
The following {{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
{% if registrantCount > 1 %}have{% else %}has{% endif %} been registered for {{ RegistrationInstance.Name }}:
</p>
<ul>
{% for registrant in registrants %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
{% if registrant.Cost > 0 %}
- {{ registrant.Cost | FormatAsCurrency }}
{% endif %}
{% assign feeCount = registrant.Fees | Size %}
{% if feeCount > 0 %}
<br/>{{ RegistrationInstance.RegistrationTemplate.FeeTerm | PluralizeForQuantity:registrantCount }}:
<ul>
{% for fee in registrant.Fees %}
<li>
{{ fee.RegistrationTemplateFee.Name }} {% if fee.RegistrationTemplateFee.FeeType == 'Multiple' %} - {{ fee.Option }} {% endif %}
{% if fee.Quantity > 1 %} ({{ fee.Quantity }} @ {{ fee.Cost | FormatAsCurrency }}){% endif %}: {{ fee.TotalCost | FormatAsCurrency }}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% assign waitlist = Registration.Registrants | Where:'OnWaitList', true %}
{% assign waitListCount = waitlist | Size %}
{% if waitListCount > 0 %}
<p>
The following {{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
{% if waitListCount > 1 %}have{% else %}has{% endif %} been added to the wait list for {{ RegistrationInstance.Name }}:
</p>
<ul>
{% for registrant in waitlist %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
{% if Registration.TotalCost > 0 %}
<p>
Total Cost: {{ Registration.TotalCost | FormatAsCurrency }}<br/>
{% if Registration.DiscountedCost != Registration.TotalCost %}
Discounted Cost: {{ Registration.DiscountedCost | FormatAsCurrency }}<br/>
{% endif %}
{% for payment in Registration.Payments %}
Paid {{ payment.Amount | FormatAsCurrency }} on {{ payment.Transaction.TransactionDateTime| Date:'M/d/yyyy' }}
<small>(Acct #: {{ payment.Transaction.FinancialPaymentDetail.AccountNumberMasked }}, Ref #: {{ payment.Transaction.TransactionCode }})</small><br/>
{% endfor %}
{% assign paymentCount = Registration.Payments | Size %}
{% if paymentCount > 1 %}
Total Paid: {{ Registration.TotalPaid | FormatAsCurrency }}<br/>
{% endif %}
Balance Due: {{ Registration.BalanceDue | FormatAsCurrency }}
</p>
{% endif %}
<p>
{{ RegistrationInstance.AdditionalConfirmationDetails }}
</p>
<p>
If you have any questions please contact {{ RegistrationInstance.ContactPersonAlias.Person.FullName }} at {{ RegistrationInstance.ContactEmail }}.
</p>
{{ 'Global' | Attribute:'EmailFooter' }}", "", 1 )]
[CodeEditorField( "Default Reminder Email", "The default Reminder Email Template value to use for a new template", CodeEditorMode.Lava, CodeEditorTheme.Rock, 300, false, @"{{ 'Global' | Attribute:'EmailHeader' }}
{% capture externalSite %}{{ 'Global' | Attribute:'PublicApplicationRoot' }}{% endcapture %}
{% assign registrantCount = Registration.Registrants | Size %}
<h1>{{ RegistrationInstance.RegistrationTemplate.RegistrationTerm }} Reminder</h1>
<p>
{{ RegistrationInstance.AdditionalReminderDetails }}
</p>
{% assign registrants = Registration.Registrants | Where:'OnWaitList', false %}
{% assign registrantCount = registrants | Size %}
{% if registrantCount > 0 %}
<p>
The following {{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
{% if registrantCount > 1 %}have{% else %}has{% endif %} been registered for {{ RegistrationInstance.Name }}:
</p>
<ul>
{% for registrant in registrants %}
<li>{{ registrant.PersonAlias.Person.FullName }}</li>
{% endfor %}
</ul>
{% endif %}
{% assign waitlist = Registration.Registrants | Where:'OnWaitList', true %}
{% assign waitListCount = waitlist | Size %}
{% if waitListCount > 0 %}
<p>
The following {{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
{% if waitListCount > 1 %}are{% else %}is{% endif %} still on the waiting list:
</p>
<ul>
{% for registrant in waitlist %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
{% if Registration.BalanceDue > 0 %}
<p>
This {{ RegistrationInstance.RegistrationTemplate.RegistrationTerm | Downcase }} has a remaining balance
of {{ Registration.BalanceDue | FormatAsCurrency }}.
You can complete the payment for this {{ RegistrationInstance.RegistrationTemplate.RegistrationTerm | Downcase }}
using our <a href='{{ externalSite }}Registration?RegistrationId={{ Registration.Id }}&rckipid={{ Registration.PersonAlias.Person | PersonTokenCreate }}'>
online registration page</a>.
</p>
{% endif %}
<p>
If you have any questions please contact {{ RegistrationInstance.ContactPersonAlias.Person.FullName }} at {{ RegistrationInstance.ContactEmail }}.
</p>
{{ 'Global' | Attribute:'EmailFooter' }}", "", 2 )]
[CodeEditorField( "Default Success Text", "The success text default to use for a new template", CodeEditorMode.Lava, CodeEditorTheme.Rock, 300, false, @"
{% assign registrants = Registration.Registrants | Where:'OnWaitList', false %}
{% assign registrantCount = registrants | Size %}
{% if registrantCount > 0 %}
<p>
You have successfully registered the following
{{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
for {{ RegistrationInstance.Name }}:
</p>
<ul>
{% for registrant in registrants %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
{% if registrant.Cost > 0 %}
- {{ registrant.Cost | FormatAsCurrency }}
{% endif %}
{% assign feeCount = registrant.Fees | Size %}
{% if feeCount > 0 %}
<br/>{{ RegistrationInstance.RegistrationTemplate.FeeTerm | PluralizeForQuantity:registrantCount }}:
<ul class='list-unstyled'>
{% for fee in registrant.Fees %}
<li>
{{ fee.RegistrationTemplateFee.Name }} {% if fee.RegistrationTemplateFee.FeeType == 'Multiple' %} - {{ fee.Option }} {% endif %}
{% if fee.Quantity > 1 %} ({{ fee.Quantity }} @ {{ fee.Cost | FormatAsCurrency }}){% endif %}: {{ fee.TotalCost | FormatAsCurrency }}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% assign waitlist = Registration.Registrants | Where:'OnWaitList', true %}
{% assign waitListCount = waitlist | Size %}
{% if waitListCount > 0 %}
<p>
You have successfully added the following
{{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
to the waiting list for {{ RegistrationInstance.Name }}:
</p>
<ul>
{% for registrant in waitlist %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
{% if Registration.TotalCost > 0 %}
<p>
Total Cost: {{ Registration.TotalCost | FormatAsCurrency }}<br/>
{% if Registration.DiscountedCost != Registration.TotalCost %}
Discounted Cost: {{ Registration.DiscountedCost | FormatAsCurrency }}<br/>
{% endif %}
{% for payment in Registration.Payments %}
Paid {{ payment.Amount | FormatAsCurrency }} on {{ payment.Transaction.TransactionDateTime| Date:'M/d/yyyy' }}
<small>(Acct #: {{ payment.Transaction.FinancialPaymentDetail.AccountNumberMasked }}, Ref #: {{ payment.Transaction.TransactionCode }})</small><br/>
{% endfor %}
{% assign paymentCount = Registration.Payments | Size %}
{% if paymentCount > 1 %}
Total Paid: {{ Registration.TotalPaid | FormatAsCurrency }}<br/>
{% endif %}
Balance Due: {{ Registration.BalanceDue | FormatAsCurrency }}
</p>
{% endif %}
<p>
A confirmation email has been sent to {{ Registration.ConfirmationEmail }}. If you have any questions
please contact {{ RegistrationInstance.ContactPersonAlias.Person.FullName }} at {{ RegistrationInstance.ContactEmail }}.
</p>", "", 3 )]
[CodeEditorField( "Default Payment Reminder Email", "The default Payment Reminder Email Template value to use for a new template", CodeEditorMode.Lava, CodeEditorTheme.Rock, 300, false, @"{{ 'Global' | Attribute:'EmailHeader' }}
{% capture externalSite %}{{ 'Global' | Attribute:'PublicApplicationRoot' }}{% endcapture %}
<h1>{{ RegistrationInstance.RegistrationTemplate.RegistrationTerm }} Payment Reminder</h1>
<p>
This {{ RegistrationInstance.RegistrationTemplate.RegistrationTerm | Downcase }} for {{ RegistrationInstance.Name }} has a remaining balance
of {{ Registration.BalanceDue | FormatAsCurrency }}. The
{{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | Downcase | Pluralize }} for this
{{ RegistrationInstance.RegistrationTemplate.RegistrationTerm }} are below.
</p>
{% assign registrants = Registration.Registrants | Where:'OnWaitList', false %}
{% assign registrantCount = registrants | Size %}
{% if registrantCount > 0 %}
<ul>
{% for registrant in registrants %}
<li>{{ registrant.PersonAlias.Person.FullName }}</li>
{% endfor %}
</ul>
{% endif %}
{% assign waitlist = Registration.Registrants | Where:'OnWaitList', true %}
{% assign waitListCount = waitlist | Size %}
{% if waitListCount > 0 %}
<p>
The following {{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | PluralizeForQuantity:registrantCount | Downcase }}
{% if waitListCount > 1 %}are{% else %}is{% endif %} still on the wait list:
</p>
<ul>
{% for registrant in waitlist %}
<li>
<strong>{{ registrant.PersonAlias.Person.FullName }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
<p>
You can complete the payment for this {{ RegistrationInstance.RegistrationTemplate.RegistrationTerm | Downcase }}
using our <a href='{{ externalSite }}Registration?RegistrationId={{ Registration.Id }}&rckipid={{ Registration.PersonAlias.Person | PersonTokenCreate }}'>
online registration page</a>.
</p>
<p>
If you have any questions please contact {{ RegistrationInstance.ContactPersonAlias.Person.FullName }} at {{ RegistrationInstance.ContactEmail }}.
</p>
{{ 'Global' | Attribute:'EmailFooter' }}", "", 4 )]
[CodeEditorField( "Default Wait List Transition Email", "The default Wait List Transition Email Template value to use for a new template", CodeEditorMode.Lava, CodeEditorTheme.Rock, 300, false, @"{{ 'Global' | Attribute:'EmailHeader' }}
{% capture externalSite %}{{ 'Global' | Attribute:'PublicApplicationRoot' }}{% endcapture %}
<h1>{{ RegistrationInstance.Name }} Wait List Update</h1>
<p>
{{ Registration.FirstName }}, the following individuals have been moved from the {{ RegistrationInstance.Name }} wait list to a full
{{ RegistrationInstance.RegistrationTemplate.RegistrantTerm | Downcase }}.
</p>
<ul>
{% for registrant in TransitionedRegistrants %}
<li>{{ registrant.PersonAlias.Person.FullName }}</li>
{% endfor %}
</ul>
{% if AdditionalFieldsNeeded %}
<p>
<strong>Addition information is needed in order to process this registration. Please visit the
<a href='{{ externalSite }}Registration?RegistrationId={{ Registration.Id }}&rckipid={{ Registration.PersonAlias.Person | PersonTokenCreate }}&StartAtBeginning=True'>
online registration page</a> to complete the registration.</strong>
</p>
{% endif %}
{% if Registration.BalanceDue > 0 %}
<p>
A balance of {{ Registration.BalanceDue | FormatAsCurrency }} remains on this registration. You can complete the payment for this {{ RegistrationInstance.RegistrationTemplate.RegistrationTerm | Downcase }}
using our <a href='{{ externalSite }}Registration?RegistrationId={{ Registration.Id }}&rckipid={{ Registration.PersonAlias.Person | PersonTokenCreate }}'>
online registration page</a>.
</p>
{% endif %}
<p>
If you have any questions please contact {{ RegistrationInstance.ContactPersonAlias.Person.FullName }} at {{ RegistrationInstance.ContactEmail }}.
</p>
{{ 'Global' | Attribute:'EmailFooter' }}", "", 5 )]
[Rock.SystemGuid.BlockTypeGuid( Rock.SystemGuid.BlockType.EVENT_REGISTRATION_TEMPLATE_DETAIL )]
public partial class RegistrationTemplateDetail : RockBlock
{
#region Attribute Keys
private static class AttributeKey
{
public const string RegistrationTemplatePlacementPage = "RegistrationTemplatePlacementPage";
public const string DefaultConfirmationEmail = "DefaultConfirmationEmail";
public const string DefaultReminderEmail = "DefaultReminderEmail";
public const string DefaultSuccessText = "DefaultSuccessText";
public const string DefaultPaymentReminderEmail = "DefaultPaymentReminderEmail";
public const string DefaultWaitListTransitionEmail = "DefaultWaitListTransitionEmail";
}
#endregion
#region PageParameter Keys
private static class PageParameterKey
{
public const string ParentCategoryId = "ParentCategoryId";
public const string RegistrationTemplateId = "RegistrationTemplateId";
}
#endregion
#region ViewState Keys
private static class ViewStateKey
{
public const string FormStateJSON = "FormStateJSON";
public const string FormFieldsStateJSON = "FormFieldsStateJSON";
public const string RegistrationAttributesStateJSON = "RegistrationAttributesStateJSON";
public const string ExpandedForms = "ExpandedFormsJSON";
public const string DiscountStateJSON = "DiscountStateJSON";
public const string RegistrationTemplatePlacementStateJSON = "RegistrationTemplatePlacementStateJSON";
public const string RegistrationTemplatePlacementGuidGroupIdsStateJSON = "RegistrationTemplatePlacementGuidGroupIdsStateJSON";
public const string FeeStateJSON = "FeeStateJSON";
public const string FeeItemsEditStateJSON = "FeeItemsEditStateJSON";
public const string SignatureDocumentTemplateStateJSON = "SignatureDocumentTemplateState";
}
#endregion ViewState Keys
#region Properties
private List<RegistrationTemplateForm> FormState { get; set; }
private Dictionary<Guid, List<RegistrationTemplateFormField>> FormFieldsState { get; set; }
private List<Guid> ExpandedForms = new List<Guid>();
private List<RegistrationTemplateDiscount> DiscountState { get; set; }
private List<RegistrationTemplatePlacement> RegistrationTemplatePlacementState { get; set; }
/// <summary>
/// The list of Placement GroupIds for each RegistrationTemplatePlacement
/// </summary>
/// <value>
/// The state of the registration template placement group.
/// </value>
private Dictionary<Guid, List<int>> RegistrationTemplatePlacementGuidGroupIdsState { get; set; }
private List<RegistrationTemplateFee> FeeState { get; set; }
private List<Attribute> RegistrationAttributesState { get; set; }
/// <summary>
/// The State of the RegistrationTemplateFeeItems in the Fees Dialog while it is being edited
/// </summary>
private List<RegistrationTemplateFeeItem> FeeItemsEditState { get; set; }
/// <summary>
/// Gets or sets the state of the signature document template.
/// </summary>
/// <value>
/// The state of the signature document template.
/// </value>
private List<SignatureDocumentTemplate> SignatureDocumentTemplateState { get; set; }
private int? GridFieldsDeleteIndex { get; set; }
#endregion
#region Base Control Methods
/// <summary>
/// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
/// </summary>
/// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
protected override void LoadViewState( object savedState )
{
base.LoadViewState( savedState );
string json = ViewState[ViewStateKey.FormStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
FormState = new List<RegistrationTemplateForm>();
}
else
{
FormState = JsonConvert.DeserializeObject<List<RegistrationTemplateForm>>( json );
}
json = ViewState[ViewStateKey.FormFieldsStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
FormFieldsState = new Dictionary<Guid, List<RegistrationTemplateFormField>>();
}
else
{
FormFieldsState = JsonConvert.DeserializeObject<Dictionary<Guid, List<RegistrationTemplateFormField>>>( json );
}
json = ViewState[ViewStateKey.RegistrationAttributesStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
RegistrationAttributesState = new List<Attribute>();
}
else
{
RegistrationAttributesState = JsonConvert.DeserializeObject<List<Attribute>>( json );
}
ExpandedForms = ViewState[ViewStateKey.ExpandedForms] as List<Guid>;
if ( ExpandedForms == null )
{
ExpandedForms = new List<Guid>();
}
json = ViewState[ViewStateKey.DiscountStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
DiscountState = new List<RegistrationTemplateDiscount>();
}
else
{
DiscountState = JsonConvert.DeserializeObject<List<RegistrationTemplateDiscount>>( json );
}
json = ViewState[ViewStateKey.RegistrationTemplatePlacementStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
RegistrationTemplatePlacementState = new List<RegistrationTemplatePlacement>();
}
else
{
RegistrationTemplatePlacementState = JsonConvert.DeserializeObject<List<RegistrationTemplatePlacement>>( json );
}
json = ViewState[ViewStateKey.RegistrationTemplatePlacementGuidGroupIdsStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
RegistrationTemplatePlacementGuidGroupIdsState = new Dictionary<Guid, List<int>>();
}
else
{
RegistrationTemplatePlacementGuidGroupIdsState = JsonConvert.DeserializeObject<Dictionary<Guid, List<int>>>( json );
}
json = ViewState[ViewStateKey.FeeStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
FeeState = new List<RegistrationTemplateFee>();
}
else
{
FeeState = JsonConvert.DeserializeObject<List<RegistrationTemplateFee>>( json );
}
json = ViewState[ViewStateKey.FeeItemsEditStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
FeeItemsEditState = new List<RegistrationTemplateFeeItem>();
}
else
{
FeeItemsEditState = JsonConvert.DeserializeObject<List<RegistrationTemplateFeeItem>>( json );
}
json = ViewState[ViewStateKey.SignatureDocumentTemplateStateJSON] as string;
if ( string.IsNullOrWhiteSpace( json ) )
{
SignatureDocumentTemplateState = new List<SignatureDocumentTemplate>();
}
else
{
SignatureDocumentTemplateState = JsonConvert.DeserializeObject<List<SignatureDocumentTemplate>>( json );
}
BuildControls( false );
}
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
gRegistrationAttributes.DataKeyNames = new string[] { "Guid" };
gRegistrationAttributes.Actions.ShowAdd = true;
gRegistrationAttributes.Actions.AddClick += gRegistrationAttributes_AddClick;
gRegistrationAttributes.EmptyDataText = Server.HtmlEncode( None.Text );
gRegistrationAttributes.GridRebind += gRegistrationAttributes_GridRebind;
gRegistrationAttributes.GridReorder += gRegistrationAttributes_GridReorder;
SecurityField registrationAttributeSecurityField = gRegistrationAttributes.Columns.OfType<SecurityField>().FirstOrDefault();
registrationAttributeSecurityField.EntityTypeId = EntityTypeCache.GetId<Attribute>() ?? 0;
// assign discounts grid actions
gDiscounts.DataKeyNames = new string[] { "Guid" };
gDiscounts.Actions.ShowAdd = true;
gDiscounts.Actions.AddClick += gDiscounts_AddClick;
gDiscounts.GridRebind += gDiscounts_GridRebind;
gDiscounts.GridReorder += gDiscounts_GridReorder;
// assign fees grid actions
gFees.DataKeyNames = new string[] { "Guid" };
gFees.Actions.ShowAdd = true;
gFees.Actions.AddClick += gFees_AddClick;
gFees.GridRebind += gFees_GridRebind;
gFees.GridReorder += gFees_GridReorder;
gPlacementConfigurations.DataKeyNames = new string[] { "Guid" };
gPlacementConfigurations.Actions.ShowAdd = true;
gPlacementConfigurations.Actions.AddClick += gPlacementConfigurations_AddClick;
gPlacementConfigurations.GridRebind += gPlacementConfigurations_GridRebind;
gPlacementConfigurations.GridReorder += gPlacementConfigurations_GridReorder;
gPlacementConfigurationSharedGroups.DataKeyNames = new string[] { "Id" };
gPlacementConfigurationSharedGroups.Actions.ShowAdd = true;
gPlacementConfigurationSharedGroups.Actions.AddClick += gPlacementConfigurationSharedGroups_AddClick;
btnSecurity.EntityTypeId = EntityTypeCache.Get( typeof( Rock.Model.RegistrationTemplate ) ).Id;
ddlRegistrarOption.Help = @"How should the registrar's information be collected?
<strong>Prompt For Registrar</strong>
Registrar information will be collected at the end.
<strong>Pre-fill First Registrant</strong>
The first registrant's information will be used to complete the registrar information form but can be changed if needed.
<strong>Use First Registrant</strong>
The first registrant's information will be used to complete the registrar information form and the form will not be displayed. (If the first registrant's name and email is not provided the registrar information form will still display.)
<strong>Use Logged In Person</strong>
The logged-in person's information will be used to complete the registrar information form and the form will not be displayed. (If the logged in person's email is not known, a prompt for email will be shown.)
";
string deleteScript = @"
$('a.js-delete-template').click(function( e ){
e.preventDefault();
Rock.dialogs.confirm('Are you sure you want to delete this registration template? All of the instances, and the registrations and registrants from each instance will also be deleted!', function (result) {
if (result) {
if ( $('input.js-has-registrations').val() == 'True' ) {
Rock.dialogs.confirm('This template has existing instances with existing registrations. Are you sure that you want to delete the template?<br/><small>(Payments will not be deleted, but they will no longer be associated with a registration.)</small>', function (result) {
if (result) {
window.location = e.target.href ? e.target.href : e.target.parentElement.href;
}
});
} else {
window.location = e.target.href ? e.target.href : e.target.parentElement.href;
}
}
});
});
";
ScriptManager.RegisterStartupScript( btnDelete, btnDelete.GetType(), "deleteInstanceScript", deleteScript, true );
}
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
if ( !Page.IsPostBack )
{
ShowDetail();
}
else
{
nbValidationError.Visible = false;
ShowDialog();
string postbackArgs = Request.Params["__EVENTARGUMENT"];
if ( !string.IsNullOrWhiteSpace( postbackArgs ) )
{
string[] nameValue = postbackArgs.Split( new char[] { ':' } );
if ( nameValue.Count() == 2 )
{
string[] values = nameValue[1].Split( new char[] { ';' } );
if ( values.Count() == 2 )
{
Guid guid = values[0].AsGuid();
int newIndex = values[1].AsInteger();
switch ( nameValue[0] )
{
case "re-order-form":
{
SortForms( guid, newIndex + 1 );
break;
}
}
}
}
}
}
}
/// <summary>
/// Gets the bread crumbs.
/// </summary>
/// <param name="pageReference">The page reference.</param>
/// <returns></returns>
public override List<BreadCrumb> GetBreadCrumbs( PageReference pageReference )
{
var breadCrumbs = new List<BreadCrumb>();
int? registrationTemplateId = PageParameter( pageReference, PageParameterKey.RegistrationTemplateId ).AsIntegerOrNull();
if ( registrationTemplateId.HasValue )
{
RegistrationTemplate registrationTemplate = GetRegistrationTemplate( registrationTemplateId.Value );
if ( registrationTemplate != null )
{
breadCrumbs.Add( new BreadCrumb( registrationTemplate.ToString(), pageReference ) );
return breadCrumbs;
}
}
breadCrumbs.Add( new BreadCrumb( this.PageCache.PageTitle, pageReference ) );
return breadCrumbs;
}
/// <summary>
/// Saves any user control view-state changes that have occurred since the last page postback.
/// </summary>
/// <returns>
/// Returns the user control's current view state. If there is no view state associated with the control, it returns null.
/// </returns>
protected override object SaveViewState()
{
var jsonSetting = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ContractResolver = new Rock.Utility.IgnoreUrlEncodedKeyContractResolver()
};
ViewState[ViewStateKey.FormStateJSON] = JsonConvert.SerializeObject( FormState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.FormFieldsStateJSON] = JsonConvert.SerializeObject( FormFieldsState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.RegistrationAttributesStateJSON] = JsonConvert.SerializeObject( RegistrationAttributesState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.ExpandedForms] = ExpandedForms;
ViewState[ViewStateKey.DiscountStateJSON] = JsonConvert.SerializeObject( DiscountState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.RegistrationTemplatePlacementStateJSON] = JsonConvert.SerializeObject( RegistrationTemplatePlacementState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.RegistrationTemplatePlacementGuidGroupIdsStateJSON] = JsonConvert.SerializeObject( RegistrationTemplatePlacementGuidGroupIdsState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.FeeStateJSON] = JsonConvert.SerializeObject( FeeState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.FeeItemsEditStateJSON] = JsonConvert.SerializeObject( FeeItemsEditState, Formatting.None, jsonSetting );
ViewState[ViewStateKey.SignatureDocumentTemplateStateJSON] = JsonConvert.SerializeObject( SignatureDocumentTemplateState, Formatting.None, jsonSetting );
return base.SaveViewState();
}
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.PreRender" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnPreRender( EventArgs e )
{
if ( pnlEditDetails.Visible )
{
var sameFamily = rblRegistrantsInSameFamily.SelectedValueAsEnum<RegistrantsSameFamily>();
divCurrentFamilyMembers.Attributes["style"] = sameFamily == RegistrantsSameFamily.No ? "display:none" : "display:block";
}
base.OnPreRender( e );
}
#endregion
#region Events
#region Form Events
/// <summary>
/// Handles the Click event of the btnEdit control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnEdit_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var registrationTemplate = new RegistrationTemplateService( rockContext ).Get( hfRegistrationTemplateId.Value.AsInteger() );
if ( registrationTemplate != null && ( UserCanEdit || registrationTemplate.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) ) )
{
LoadStateDetails( registrationTemplate, rockContext );
ShowEditDetails( registrationTemplate, rockContext );
}
}
/// <summary>
/// Handles the Click event of the btnDelete control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnDelete_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var service = new RegistrationTemplateService( rockContext );
var registrationTemplate = service.Get( hfRegistrationTemplateId.Value.AsInteger() );
if ( registrationTemplate != null )
{
if ( !UserCanEdit && !registrationTemplate.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) )
{
mdDeleteWarning.Show( "You are not authorized to delete this registration template.", ModalAlertType.Information );
return;
}
rockContext.WrapTransaction( () =>
{
new RegistrationService( rockContext ).DeleteRange( registrationTemplate.Instances.SelectMany( i => i.Registrations ) );
new RegistrationInstanceService( rockContext ).DeleteRange( registrationTemplate.Instances );
service.Delete( registrationTemplate );
rockContext.SaveChanges();
} );
}
// reload page
var qryParams = new Dictionary<string, string>();
NavigateToPage( RockPage.Guid, qryParams );
}
/// <summary>
/// Handles the Click event of the btnPlacements control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void btnPlacements_Click( object sender, EventArgs e )
{
var queryParams = new Dictionary<string, string>();
if ( hfRegistrationTemplateId.Value.AsIntegerOrNull().HasValue )
{
queryParams.Add( PageParameterKey.RegistrationTemplateId, hfRegistrationTemplateId.Value );
}
NavigateToLinkedPage( AttributeKey.RegistrationTemplatePlacementPage, queryParams );
}
/// <summary>
/// Handles the Click event of the btnCopy control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void btnCopy_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var registrationTemplate = new RegistrationTemplateService( rockContext ).Get( hfRegistrationTemplateId.Value.AsInteger() );
if ( registrationTemplate != null )
{
// Load the state objects for the source registration template
LoadStateDetails( registrationTemplate, rockContext );
// clone the registration template
var newRegistrationTemplate = registrationTemplate.CloneWithoutIdentity();
newRegistrationTemplate.Name = registrationTemplate.Name + " - Copy";
// Create temporary state objects for the new registration template
var newFormState = new List<RegistrationTemplateForm>();
var newFormFieldsState = new Dictionary<Guid, List<RegistrationTemplateFormField>>();
var newDiscountState = new List<RegistrationTemplateDiscount>();
var newFeeState = new List<RegistrationTemplateFee>();
var newAttributeState = new List<Attribute>();
var newRegistrationTemplatePlacementState = new List<RegistrationTemplatePlacement>();
foreach ( var form in FormState )
{
var newForm = form.Clone( false );
newForm.RegistrationTemplateId = 0;
newForm.Id = 0;
newForm.Guid = Guid.NewGuid();
newFormState.Add( newForm );
if ( FormFieldsState.ContainsKey( form.Guid ) )
{
newFormFieldsState.Add( newForm.Guid, new List<RegistrationTemplateFormField>() );
var mapKeys = new Dictionary<Guid, Guid>();
foreach ( var formField in FormFieldsState[form.Guid] )
{
var newFormField = formField.Clone( false );
newFormField.RegistrationTemplateFormId = 0;
newFormField.Id = 0;
newFormField.Guid = Guid.NewGuid();
newFormFieldsState[newForm.Guid].Add( newFormField );
mapKeys.Add( formField.Guid, newFormField.Guid );
if ( formField.FieldSource != RegistrationFieldSource.PersonField )
{
newFormField.Attribute = formField.Attribute;
}
if ( formField.FieldSource == RegistrationFieldSource.RegistrantAttribute && formField.Attribute != null )
{
var newAttribute = formField.Attribute.Clone( false );
newAttribute.Id = 0;
newAttribute.Guid = Guid.NewGuid();
newAttribute.IsSystem = false;
newFormField.AttributeId = null;
newFormField.Attribute = newAttribute;
foreach ( var qualifier in formField.Attribute.AttributeQualifiers )
{
var newQualifier = qualifier.Clone( false );
newQualifier.Id = 0;
newQualifier.Guid = Guid.NewGuid();
newQualifier.IsSystem = false;
newAttribute.AttributeQualifiers.Add( qualifier );
}
}
}
var newFormFieldsWithRules = newFormFieldsState[newForm.Guid]
.Where( a => a.FieldVisibilityRules.RuleList
.Any( b => b.ComparedToFormFieldGuid.HasValue ) );
foreach ( var newFormField in newFormFieldsWithRules )
{
foreach ( var rule in newFormField.FieldVisibilityRules.RuleList.Where( a => a.ComparedToFormFieldGuid.HasValue ) )
{
rule.ComparedToFormFieldGuid = mapKeys.GetValueOrNull( rule.ComparedToFormFieldGuid.Value );
}
}
}
}
foreach ( var discount in DiscountState )
{
var newDiscount = discount.Clone( false );
newDiscount.RegistrationTemplateId = 0;
newDiscount.Id = 0;
newDiscount.Guid = Guid.NewGuid();
newDiscountState.Add( newDiscount );
}
foreach ( var fee in FeeState )
{
var newFee = fee.Clone( false );
newFee.RegistrationTemplateId = 0;
newFee.Id = 0;
newFee.Guid = Guid.NewGuid();
newFeeState.Add( newFee );
foreach ( var item in fee.FeeItems )
{
var feeItem = item.Clone( false );
feeItem.Id = 0;
feeItem.Guid = Guid.NewGuid();
newFee.FeeItems.Add( feeItem );
}
}
foreach ( var attribute in RegistrationAttributesState )
{
var newAttribute = attribute.Clone( false );
newAttribute.EntityTypeQualifierValue = null;
newAttribute.Id = 0;
newAttribute.Guid = Guid.NewGuid();
newAttributeState.Add( newAttribute );
}
foreach ( var registrationTemplatePlacement in RegistrationTemplatePlacementState )
{
var newRegistrationTemplatePlacement = registrationTemplatePlacement.Clone( false );
newRegistrationTemplatePlacement.Id = 0;
newRegistrationTemplatePlacement.Guid = Guid.NewGuid();
newRegistrationTemplatePlacementState.Add( newRegistrationTemplatePlacement );
// Find the existing Guid in the list of group ids and update it.
if (RegistrationTemplatePlacementGuidGroupIdsState.ContainsKey(registrationTemplatePlacement.Guid))
{
// Remove the old Guid and then replace it with the new Guid in the GuidGroupIds State.
var intList = new List<int>();
if (RegistrationTemplatePlacementGuidGroupIdsState.TryGetValue( registrationTemplatePlacement.Guid, out intList ))
{
RegistrationTemplatePlacementGuidGroupIdsState.AddOrReplace( newRegistrationTemplatePlacement.Guid, intList );
RegistrationTemplatePlacementGuidGroupIdsState.Remove( registrationTemplatePlacement.Guid );
}
}
}
FormState = newFormState;
FormFieldsState = newFormFieldsState;
DiscountState = newDiscountState;
FeeState = newFeeState;
RegistrationAttributesState = newAttributeState;
RegistrationTemplatePlacementState = newRegistrationTemplatePlacementState;
hfRegistrationTemplateId.Value = newRegistrationTemplate.Id.ToString();
ShowEditDetails( newRegistrationTemplate, rockContext );
}
}
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
ParseControls( true );
var rockContext = new RockContext();
var registrationTemplateService = new RegistrationTemplateService( rockContext );
RegistrationTemplate registrationTemplate = null;
SignatureDocumentTemplate documentTemplate = GetSelectedTemplate();
int? registrationTemplateId = hfRegistrationTemplateId.Value.AsIntegerOrNull();
if ( registrationTemplateId.HasValue )
{
registrationTemplate = registrationTemplateService.Get( registrationTemplateId.Value );
}
bool newTemplate = false;
if ( registrationTemplate == null )
{
newTemplate = true;
registrationTemplate = new RegistrationTemplate();
}