forked from DNN-Connect/MailChimpConnector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.ascx.vb
146 lines (106 loc) · 5.62 KB
/
Settings.ascx.vb
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
' Copyright (c) 2014 Philipp Becker
' All rights reserved.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Localization
Imports PerceptiveMCAPI.Types
Imports PerceptiveMCAPI.Methods
Imports PerceptiveMCAPI
Public Class Settings
Inherits ModuleSettingsBase
#Region "Base Method Implementations"
Private Sub cmdLoadLists_Click(sender As Object, e As EventArgs) Handles cmdLoadLists.Click
BindLists()
End Sub
Public Overrides Sub LoadSettings()
cmdLoadLists.Text = Localization.GetString("cmdLoadLists", LocalResourceFile)
Try
If (Page.IsPostBack = False) Then
If Settings.Contains("Mailchimp_ApiKey") Then
txtApiKey.Text = CType(Settings("Mailchimp_ApiKey"), String)
If txtApiKey.Text.Length > 0 Then
BindLists()
End If
End If
If Settings.Contains("Mailchimp_UseDoubleOptIn") Then
chkUseDoubleOptIn.Checked = CType(Settings("Mailchimp_UseDoubleOptIn"), Boolean)
End If
If Settings.Contains("Mailchimp_SendWelcomeEmailOnSubscribe") Then
chkSendWelcomeEmailOnSubscribe.Checked = CType(Settings("Mailchimp_SendWelcomeEmailOnSubscribe"), Boolean)
End If
If Settings.Contains("Mailchimp_DeleteMemberOnUnsubscribe") Then
chkDeleteMemberOnUnsubscribe.Checked = CType(Settings("Mailchimp_DeleteMemberOnUnsubscribe"), Boolean)
End If
If Settings.Contains("Mailchimp_SendGoodbyEmailOnUnSubscribe") Then
chkSendGoodbyEmailOnUnSubscribe.Checked = CType(Settings("Mailchimp_SendGoodbyEmailOnUnSubscribe"), Boolean)
End If
If Settings.Contains("Mailchimp_SendAdminNotificationOnUnsubscribe") Then
chkSendAdminNotificationOnUnsubscribe.Checked = CType(Settings("Mailchimp_SendAdminNotificationOnUnsubscribe"), Boolean)
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Public Overrides Sub UpdateSettings()
Try
Dim objModules As New Entities.Modules.ModuleController
If txtApiKey.Text.Length > 0 Then
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_ApiKey", txtApiKey.Text)
End If
If drpLists.Items.Count > 0 Then
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_ListId", drpLists.SelectedValue)
End If
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_UseDoubleOptIn", chkUseDoubleOptIn.Checked)
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_SendWelcomeEmailOnSubscribe", chkSendWelcomeEmailOnSubscribe.Checked)
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_DeleteMemberOnUnsubscribe", chkDeleteMemberOnUnsubscribe.Checked)
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_SendGoodbyEmailOnUnSubscribe", chkSendGoodbyEmailOnUnSubscribe.Checked)
objModules.UpdateModuleSetting(ModuleId, "Mailchimp_SendAdminNotificationOnUnsubscribe", chkSendAdminNotificationOnUnsubscribe.Checked)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub BindLists()
drpLists.Items.Clear()
Dim input As New listsInput(txtApiKey.Text)
Dim cmd As lists = New lists
Dim output As listsOutput = cmd.Execute(input)
If Not output Is Nothing Then
If output.result.Count > 0 Then
For Each item As listsResults In output.result
drpLists.Items.Add(New ListItem(item.name, item.id))
Next
'lists found, set label
lblList.Text = Localization.GetString("ListsFound", LocalResourceFile)
lblList.HelpText = Localization.GetString("ListsFound.Help", LocalResourceFile)
drpLists.Text = Localization.GetString("SelectList", LocalResourceFile)
If Settings.Contains("Mailchimp_ListId") Then
'get listid from settings
Dim strList As String = CType(Settings("Mailchimp_ListId"), String)
'try to load list id in dropdown
If Not drpLists.Items.FindByValue(strList) Is Nothing Then
drpLists.Items.FindByValue(strList).Selected = True
Else
'no list itme with that id
lblList.Text = Localization.GetString("ListRemoved", LocalResourceFile)
End If
End If
Else
'lists list is empty
lblList.Text = Localization.GetString("NoListFound", LocalResourceFile)
End If
Else
'no connection?
lblList.Text = Localization.GetString("NoResponseFromChimp", LocalResourceFile)
End If
End Sub
#End Region
End Class