forked from 2sic/2sxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditEntity.ascx.cs
207 lines (176 loc) · 6.78 KB
/
EditEntity.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToSic.Eav.ManagementUI;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using ToSic.SexyContent;
namespace ToSic.SexyContent
{
public partial class EditEntity : PortalModuleBase, IEditContentControl
{
#region Properties
/// <summary>
/// Gets or sets the EntityId
/// </summary>
public int? EntityId { get; set; }
public bool IsPublished
{
get { return EditItemControl.IsPublished; }
set { EditItemControl.IsPublished = value; }
}
/// <summary>
/// Gets or sets ModuleID
/// </summary>
public int ModuleID { get; set; }
/// <summary>
/// Gets or sets TabID
/// </summary>
public int TabID { get; set; }
public int AttributeSetID { get; set; }
public int ZoneId { get; set;}
public int AppId { get; set; }
private SexyContent _sexy;
public SexyContent Sexy {
get {
if (_sexy == null)
{
if (ZoneId == 0 || AppId == 0)
throw new ArgumentNullException("ZoneId and AppId must be set.");
_sexy = new SexyContent(ZoneId, AppId);
}
return _sexy;
}
}
private SexyContent _sexyUncached;
public SexyContent SexyUncached {
get {
if (_sexyUncached == null)
_sexyUncached = new SexyContent(ZoneId, AppId, false);
return _sexyUncached;
}
}
public int? LanguageID
{
get
{
if (!String.IsNullOrEmpty(Request.QueryString["CultureDimension"]))
{
int languageId;
if (int.TryParse(Request.QueryString["CultureDimension"], out languageId))
return languageId;
}
return new int?();
}
}
public int? DefaultLanguageID
{
get
{
return Sexy.ContentContext.GetLanguageId(PortalSettings.DefaultLanguage);
}
}
public int? KeyNumber
{
get
{
return !String.IsNullOrEmpty(Request.QueryString["KeyNumber"])
? int.Parse(Request.QueryString["KeyNumber"])
: new int?();
}
}
public Guid? KeyGuid
{
get
{
try { return Guid.Parse(Request.QueryString["KeyGuid"]); }
catch { return null; }
}
}
public int AssignmentObjectTypeId
{
get
{
return !String.IsNullOrEmpty(Request.QueryString["AssignmentObjectTypeId"])
? int.Parse(Request.QueryString["AssignmentObjectTypeId"])
: SexyContent.AssignmentObjectTypeIDDefault;
}
}
#endregion
private ItemForm EditItemControl;
public EventHandler OnSaved;
/// <summary>
/// Handles the control load. Will place NewItem or EditItem control into the placeholder.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// Make sure correct LocalResourceFile gets loaded
LocalResourceFile = LocalResourceFile + "EditEntity.ascx";
ProcessView();
hSectionHead.ID = "SexyContent-EditSection-Entity";
if (IsPostBack)
return;
lblNewOrEditItemHeading.Text = "Entity";
}
protected void ProcessView()
{
EditItemControl = (ItemForm)LoadControl(System.IO.Path.Combine(TemplateSourceDirectory, "SexyContent/EAV/Controls/ItemForm.ascx"));
EditItemControl.DefaultCultureDimension = DefaultLanguageID != 0 ? DefaultLanguageID : new int?();
EditItemControl.IsDialog = false;
EditItemControl.HideNavigationButtons = true;
EditItemControl.PreventRedirect = true;
EditItemControl.AttributeSetId = AttributeSetID;
EditItemControl.AssignmentObjectTypeId = AssignmentObjectTypeId;
EditItemControl.KeyNumber = KeyNumber;
EditItemControl.KeyGuid = KeyGuid;
EditItemControl.ZoneId = ZoneId;
EditItemControl.ReturnUrl = "";
EditItemControl.AppId = AppId;
EditItemControl.AddClientScriptAndCss = false;
EditItemControl.ItemHistoryUrl = "";
EditItemControl.PreventRedirect = Request.QueryString["PreventRedirect"] == "true";
var newItemUrl = EditUrl(this.TabID, SexyContent.ControlKeys.EditContentGroup, true, new string[] { });
EditItemControl.NewItemUrl = newItemUrl + (newItemUrl.Contains("?") ? "&" : "?") + "AppID=" + AppId.ToString() + "&mid=" + ModuleID.ToString() + "&AttributeSetId=[AttributeSetId]&EditMode=New&CultureDimension=" + this.LanguageID;
// If ContentGroupItem has Entity, edit that; else create new Entity
if (EntityId.HasValue)
{
EditItemControl.Updated += EditItem_OnEdited;
EditItemControl.EntityId = EntityId.Value;
EditItemControl.InitForm(FormViewMode.Edit);
hlkHistory.Visible = true;
hlkHistory.NavigateUrl = EditUrl("", "", SexyContent.ControlKeys.EavManagement, new string[] { "AppID", AppId.ToString(), "ManagementMode", "ItemHistory", "EntityId", EntityId.Value.ToString(), "mid", ModuleID.ToString() });
}
// Create a new Entity
else
{
EditItemControl.Inserted += NewItem_OnInserted;
EditItemControl.Visible = true;
EditItemControl.InitForm(FormViewMode.Insert);
}
phNewOrEditItem.Controls.Add(EditItemControl);
}
protected void EditItem_OnEdited(ToSic.Eav.Entity Entity)
{
}
protected void NewItem_OnInserted(ToSic.Eav.Entity Entity)
{
}
public void Save()
{
if(EditItemControl.Visible)
EditItemControl.Save();
if (OnSaved != null)
OnSaved(this, new EventArgs());
}
public void Cancel()
{
if(EditItemControl != null)
EditItemControl.Cancel();
}
}
}