Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6b9287

Browse files
author
KrzysztofPajak
committed
Implemented Contact form with custom attributes #253
1 parent 62a724f commit f6b9287

File tree

48 files changed

+4056
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4056
-19
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System.Collections.Generic;
2+
using Grand.Core.Domain.Catalog;
3+
using Grand.Core.Domain.Localization;
4+
using Grand.Core.Domain.Stores;
5+
using Grand.Core.Domain.Security;
6+
7+
namespace Grand.Core.Domain.Messages
8+
{
9+
/// <summary>
10+
/// Represents a contact attribute
11+
/// </summary>
12+
public partial class ContactAttribute : BaseEntity, ILocalizedEntity, IStoreMappingSupported, IAclSupported
13+
{
14+
private ICollection<ContactAttributeValue> _contactAttributeValues;
15+
16+
public ContactAttribute()
17+
{
18+
Stores = new List<string>();
19+
Locales = new List<LocalizedProperty>();
20+
CustomerRoles = new List<string>();
21+
}
22+
/// <summary>
23+
/// Gets or sets the name
24+
/// </summary>
25+
public string Name { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the text prompt
29+
/// </summary>
30+
public string TextPrompt { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets a value indicating whether the entity is required
34+
/// </summary>
35+
public bool IsRequired { get; set; }
36+
37+
38+
/// <summary>
39+
/// Gets or sets the attribute control type identifier
40+
/// </summary>
41+
public int AttributeControlTypeId { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets the display order
45+
/// </summary>
46+
public int DisplayOrder { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets a value indicating whether the entity is limited/restricted to certain stores
50+
/// </summary>
51+
public bool LimitedToStores { get; set; }
52+
public IList<string> Stores { get; set; }
53+
54+
55+
/// <summary>
56+
/// Gets or sets the collection of locales
57+
/// </summary>
58+
public IList<LocalizedProperty> Locales { get; set; }
59+
60+
//validation fields
61+
62+
/// <summary>
63+
/// Gets or sets the validation rule for minimum length (for textbox and multiline textbox)
64+
/// </summary>
65+
public int? ValidationMinLength { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets the validation rule for maximum length (for textbox and multiline textbox)
69+
/// </summary>
70+
public int? ValidationMaxLength { get; set; }
71+
72+
/// <summary>
73+
/// Gets or sets the validation rule for file allowed extensions (for file upload)
74+
/// </summary>
75+
public string ValidationFileAllowedExtensions { get; set; }
76+
77+
/// <summary>
78+
/// Gets or sets the validation rule for file maximum size in kilobytes (for file upload)
79+
/// </summary>
80+
public int? ValidationFileMaximumSize { get; set; }
81+
82+
/// <summary>
83+
/// Gets or sets the default value (for textbox and multiline textbox)
84+
/// </summary>
85+
public string DefaultValue { get; set; }
86+
87+
/// <summary>
88+
/// Gets or sets a condition (depending on other attribute) when this attribute should be enabled (visible).
89+
/// </summary>
90+
public string ConditionAttributeXml { get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets a value indicating whether the entity is subject to ACL
94+
/// </summary>
95+
public bool SubjectToAcl { get; set; }
96+
public IList<string> CustomerRoles { get; set; }
97+
98+
99+
100+
/// <summary>
101+
/// Gets the attribute control type
102+
/// </summary>
103+
public AttributeControlType AttributeControlType
104+
{
105+
get
106+
{
107+
return (AttributeControlType)this.AttributeControlTypeId;
108+
}
109+
set
110+
{
111+
this.AttributeControlTypeId = (int)value;
112+
}
113+
}
114+
/// <summary>
115+
/// Gets the checkout attribute values
116+
/// </summary>
117+
public virtual ICollection<ContactAttributeValue> ContactAttributeValues
118+
{
119+
get { return _contactAttributeValues ?? (_contactAttributeValues = new List<ContactAttributeValue>()); }
120+
protected set { _contactAttributeValues = value; }
121+
}
122+
}
123+
124+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Grand.Core.Domain.Localization;
2+
using System.Collections.Generic;
3+
4+
namespace Grand.Core.Domain.Messages
5+
{
6+
/// <summary>
7+
/// Represents a contact attribute value
8+
/// </summary>
9+
public partial class ContactAttributeValue : SubBaseEntity, ILocalizedEntity
10+
{
11+
public ContactAttributeValue()
12+
{
13+
Locales = new List<LocalizedProperty>();
14+
}
15+
16+
/// <summary>
17+
/// Gets or sets the checkout attribute mapping identifier
18+
/// </summary>
19+
public string ContactAttributeId { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the checkout attribute name
23+
/// </summary>
24+
public string Name { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the color RGB value (used with "Color squares" attribute type)
28+
/// </summary>
29+
public string ColorSquaresRgb { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets a value indicating whether the value is pre-selected
33+
/// </summary>
34+
public bool IsPreSelected { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the display order
38+
/// </summary>
39+
public int DisplayOrder { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the collection of locales
43+
/// </summary>
44+
public IList<LocalizedProperty> Locales { get; set; }
45+
}
46+
47+
}

Grand.Core/Domain/Messages/ContactUs.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,15 @@ public partial class ContactUs : BaseEntity
5858
/// </summary>
5959
public string VendorId { get; set; }
6060

61+
/// <summary>
62+
/// Gets or sets the contact attribute description
63+
/// </summary>
64+
public string ContactAttributeDescription { get; set; }
65+
66+
/// <summary>
67+
/// Gets or sets the contact attributes in XML format
68+
/// </summary>
69+
public string ContactAttributesXml { get; set; }
70+
6171
}
6272
}

Grand.Framework/Infrastructure/DependencyRegistrar.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, G
237237
builder.RegisterType<InteractiveFormService>().As<IInteractiveFormService>().InstancePerLifetimeScope();
238238
builder.RegisterType<EmailAccountService>().As<IEmailAccountService>().InstancePerLifetimeScope();
239239
builder.RegisterType<WorkflowMessageService>().As<IWorkflowMessageService>().InstancePerLifetimeScope();
240+
builder.RegisterType<ContactAttributeFormatter>().As<IContactAttributeFormatter>().InstancePerLifetimeScope();
241+
builder.RegisterType<ContactAttributeParser>().As<IContactAttributeParser>().InstancePerLifetimeScope();
242+
builder.RegisterType<ContactAttributeService>().As<IContactAttributeService>().InstancePerLifetimeScope();
240243
builder.RegisterType<MessageTokenProvider>().As<IMessageTokenProvider>().InstancePerLifetimeScope();
241244
builder.RegisterType<Tokenizer>().As<ITokenizer>().InstancePerLifetimeScope();
242245
builder.RegisterType<EmailSender>().As<IEmailSender>().InstancePerLifetimeScope();

Grand.Services/ExportImport/ExportManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ private PropertyByName<ContactUs>[] PropertyByContactForm()
13341334
new PropertyByName<ContactUs>("FullName", p => p.FullName),
13351335
new PropertyByName<ContactUs>("Subject", p => p.Subject),
13361336
new PropertyByName<ContactUs>("Enquiry", p => p.Enquiry),
1337+
new PropertyByName<ContactUs>("ContactAttributeDescription", p => p.ContactAttributeDescription),
13371338
};
13381339
return properties;
13391340
}

Grand.Services/Installation/CodeFirstInstallationService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9984,6 +9984,12 @@ protected virtual void InstallActivityLogTypes()
99849984
Enabled = true,
99859985
Name = "Add a new checkout attribute"
99869986
},
9987+
new ActivityLogType
9988+
{
9989+
SystemKeyword = "AddNewContactAttribute",
9990+
Enabled = true,
9991+
Name = "Add a new contact attribute"
9992+
},
99879993
new ActivityLogType
99889994
{
99899995
SystemKeyword = "AddNewCustomer",
@@ -10068,6 +10074,12 @@ protected virtual void InstallActivityLogTypes()
1006810074
Enabled = true,
1006910075
Name = "Delete a checkout attribute"
1007010076
},
10077+
new ActivityLogType
10078+
{
10079+
SystemKeyword = "DeleteContactAttribute",
10080+
Enabled = true,
10081+
Name = "Delete a contact attribute"
10082+
},
1007110083
new ActivityLogType
1007210084
{
1007310085
SystemKeyword = "DeleteCustomer",
@@ -10158,6 +10170,12 @@ protected virtual void InstallActivityLogTypes()
1015810170
Enabled = true,
1015910171
Name = "Edit a checkout attribute"
1016010172
},
10173+
new ActivityLogType
10174+
{
10175+
SystemKeyword = "EditContactAttribute",
10176+
Enabled = true,
10177+
Name = "Edit a contact attribute"
10178+
},
1016110179
new ActivityLogType
1016210180
{
1016310181
SystemKeyword = "EditCustomer",

Grand.Services/Installation/UpgradeService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,24 @@ private void From410To420()
903903
Enabled = true,
904904
Name = "Delete knowledgebase category"
905905
});
906+
_activityLogTypeRepository.Insert(new ActivityLogType
907+
{
908+
SystemKeyword = "AddNewContactAttribute",
909+
Enabled = true,
910+
Name = "Add a new contact attribute"
911+
});
912+
_activityLogTypeRepository.Insert(new ActivityLogType
913+
{
914+
SystemKeyword = "EditContactAttribute",
915+
Enabled = true,
916+
Name = "Edit a contact attribute"
917+
});
918+
_activityLogTypeRepository.Insert(new ActivityLogType
919+
{
920+
SystemKeyword = "DeleteContactAttribute",
921+
Enabled = true,
922+
Name = "Delete a contact attribute"
923+
});
906924

907925
#endregion
908926

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Grand.Core.Domain.Catalog;
5+
using Grand.Core.Domain.Messages;
6+
7+
namespace Grand.Services.Messages
8+
{
9+
/// <summary>
10+
/// Extensions
11+
/// </summary>
12+
public static class ContactAttributeExtensions
13+
{
14+
/// <summary>
15+
/// Gets a value indicating whether this contact attribute should have values
16+
/// </summary>
17+
/// <param name="contactAttribute">Contact attribute</param>
18+
/// <returns>Result</returns>
19+
public static bool ShouldHaveValues(this ContactAttribute contactAttribute)
20+
{
21+
if (contactAttribute == null)
22+
return false;
23+
24+
if (contactAttribute.AttributeControlType == AttributeControlType.TextBox ||
25+
contactAttribute.AttributeControlType == AttributeControlType.MultilineTextbox ||
26+
contactAttribute.AttributeControlType == AttributeControlType.Datepicker ||
27+
contactAttribute.AttributeControlType == AttributeControlType.FileUpload)
28+
return false;
29+
30+
//other attribute controle types support values
31+
return true;
32+
}
33+
34+
/// <summary>
35+
/// A value indicating whether this contact attribute can be used as condition for some other attribute
36+
/// </summary>
37+
/// <param name="contactAttribute">Contact attribute</param>
38+
/// <returns>Result</returns>
39+
public static bool CanBeUsedAsCondition(this ContactAttribute contactAttribute)
40+
{
41+
if (contactAttribute == null)
42+
return false;
43+
44+
if (contactAttribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ||
45+
contactAttribute.AttributeControlType == AttributeControlType.TextBox ||
46+
contactAttribute.AttributeControlType == AttributeControlType.MultilineTextbox ||
47+
contactAttribute.AttributeControlType == AttributeControlType.Datepicker ||
48+
contactAttribute.AttributeControlType == AttributeControlType.FileUpload)
49+
return false;
50+
51+
//other attribute controle types support it
52+
return true;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)