-
Notifications
You must be signed in to change notification settings - Fork 20
/
Default.ascx.cs
140 lines (128 loc) · 5.98 KB
/
Default.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
using System;
using System.IO;
using DotNetNuke.Entities.Icons;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Modules.UserDefinedTable.Components;
using DotNetNuke.Security;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using DotNetNuke.Framework;
using DotNetNuke.Framework.JavaScriptLibraries;
namespace DotNetNuke.Modules.UserDefinedTable
{
public partial class Default : PortalModuleBase, IActionable
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitViews();
JavaScript.RequestRegistration(CommonJs.DnnPlugins);
ClientAPI.RegisterClientReference(this.Page, ClientAPI.ClientNamespaceReferences.dnn);
}
void InitViews()
{
var sec = new ModuleSecurity(ModuleId, TabId, new Components.Settings(Settings));
switch (ModuleContext.Settings[SettingName.ListOrForm].AsString("Unknown"))
{
case "List":
LoadControlByKey("List");
break;
case "Form":
if (Request.QueryString["show"].AsString() == "records" && sec.IsAllowedToViewList())
{
LoadControlByKey("List");
}
else
{
LoadControlByKey("Edit");
}
break;
case "FormAndList":
LoadControlByKey("Edit");
if (sec.IsAllowedToViewList())
{
LoadControlByKey("List");
}
break;
case "ListAndForm":
if (sec.IsAllowedToViewList())
{
LoadControlByKey("List");
}
LoadControlByKey("Edit");
break;
default:
LoadControlByKey(IsNewModuleInstance() ? "TemplateList" : "List");
break;
}
}
public bool IsNewModuleInstance()
{
var settings = ModuleContext.Settings;
var mc = new ModuleController();
var minSettings = 0;
if (settings.ContainsKey(SettingName.ExcludeFromSearch)) minSettings++;
if (settings.ContainsKey(SettingName.CalculatedColumnsRenderExpressionInForm)) minSettings++;
if (settings.ContainsKey(SettingName.UseButtonsInForm)) minSettings++;
if (settings.Count > minSettings) return false;
mc.UpdateModuleSetting( ModuleId,SettingName.UseButtonsInForm, bool.TrueString );
mc.UpdateModuleSetting(ModuleId, SettingName.ExcludeFromSearch, bool.TrueString);
mc.UpdateModuleSetting(ModuleId, SettingName.CalculatedColumnsRenderExpressionInForm, bool.TrueString);
return true;
}
void LoadControlByKey(string controlKey)
{
var moduleToLoad = ModuleControlController.GetModuleControlByControlKey(controlKey,
ModuleContext.Configuration.
ModuleDefID);
if (moduleToLoad != null)
{
var controlSrc = string.Format("~/{0}", moduleToLoad.ControlSrc);
var view = (PortalModuleBase) (LoadControl(controlSrc));
view.ID = Path.GetFileNameWithoutExtension(controlSrc);
view.ModuleContext.Configuration = ModuleContext.Configuration;
PlaceHolderControl.Controls.Add(view);
}
}
public ModuleActionCollection ModuleActions
{
get
{
var viewType = ModuleContext.Settings[SettingName.ListOrForm].AsString("Undefined");
var actions = new ModuleActionCollection();
foreach (var view in PlaceHolderControl.Controls )
{
if ((view) is IActionable)
{
var viewactions = ((IActionable) view).ModuleActions;
foreach (ModuleAction action in viewactions)
{
action.ID = GetNextActionID();
actions.Add(action);
}
}
}
actions.Add(GetNextActionID(),
Localization.GetString(ModuleActionType.ContentOptions, LocalResourceFile),
ModuleActionType.ModuleSettings, "", "settings.gif", EditUrl("Manage"), false,
SecurityAccessLevel.Edit, true, false);
if (viewType != "Undefined")
{
actions.Add(GetNextActionID(), Localization.GetString("CreateTemplate.Action", LocalResourceFile),
"CreateTemplate", "", Utilities.IconURL("Save"), EditUrl("CreateTemplate"),
false, SecurityAccessLevel.Admin, true, false);
}
actions.Add(GetNextActionID(), Localization.GetString("ExportCSV.Action", LocalResourceFile),
ModuleActionType.ExportModule, "", ResolveUrl("~/images/action_export.gif"),
EditUrl("", "", "ExportCSV", "moduleid=" + ModuleId), false,
SecurityAccessLevel.Edit, true, false);
actions.Add(GetNextActionID(), Localization.GetString("ImportCSV.Action", LocalResourceFile),
ModuleActionType.ImportModule, "", ResolveUrl("~/images/action_import.gif"),
EditUrl("", "", "ImportCSV", "moduleid=" + ModuleId), false,
SecurityAccessLevel.Edit, true, false);
return actions;
}
}
}
}