This repository was archived by the owner on Feb 26, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTextstringArrayPrevalueEditor.cs
More file actions
190 lines (162 loc) · 6.43 KB
/
Copy pathTextstringArrayPrevalueEditor.cs
File metadata and controls
190 lines (162 loc) · 6.43 KB
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
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using umbraco.editorControls;
using umbraco.editorControls.MultipleTextstring;
namespace uComponents.DataTypes.TextstringArray
{
/// <summary>
/// The PreValue Editor for the Textstring Array data-type.
/// </summary>
public class TextstringArrayPrevalueEditor : uComponents.DataTypes.Shared.PrevalueEditors.AbstractJsonPrevalueEditor
{
/// <summary>
/// The TextBox control for the maximum rows value of the control.
/// </summary>
private TextBox TextBoxMaximumRows;
/// <summary>
/// The TextBox control for the minimum rows value of the control.
/// </summary>
private TextBox TextBoxMinimumRows;
/// <summary>
/// The CheckBox control for determining whether to show the column labels.
/// </summary>
private CheckBox CheckBoxShowColumnLabels;
/// <summary>
/// A <div> wrapper/container for the column labels control.
/// </summary>
private HtmlGenericControl MtcContainer;
/// <summary>
/// A MultipleTextstringControl for defining the column labels.
/// </summary>
private MultipleTextstringControl MtcColumnLabels;
/// <summary>
/// The CheckBox control for determining whether to disable row sorting.
/// </summary>
private CheckBox CheckBoxDisableSorting;
/// <summary>
/// Initializes a new instance of the <see cref="TextstringArrayPrevalueEditor"/> class.
/// </summary>
/// <param name="dataType">Type of the data.</param>
public TextstringArrayPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
: base(dataType, umbraco.cms.businesslogic.datatype.DBTypes.Ntext)
{
}
/// <summary>
/// Gets the documentation URL.
/// </summary>
/// <value>
/// The documentation URL.
/// </value>
public override string DocumentationUrl
{
get
{
return string.Concat(base.DocumentationUrl, "/data-types/textstring-array/");
}
}
/// <summary>
/// Saves this instance.
/// </summary>
public override void Save()
{
// set the options
var options = new TextstringArrayOptions(true);
// save the column label options
options.ShowColumnLabels = this.CheckBoxShowColumnLabels.Checked;
options.ColumnLabels = this.MtcColumnLabels.Values;
// parse the number of items per row; based on the number of labels.
int itemsPerRow = options.ColumnLabels.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length;
if (itemsPerRow == 0)
{
itemsPerRow = 2;
}
options.ItemsPerRow = itemsPerRow;
options.DisableSorting = this.CheckBoxDisableSorting.Checked;
// parse the maximum rows
int maximumRows;
if (int.TryParse(this.TextBoxMaximumRows.Text, out maximumRows))
{
if (maximumRows == 0)
{
maximumRows = -1;
}
options.MaximumRows = maximumRows;
}
// parse the minimum rows
int minimumRows;
if (int.TryParse(this.TextBoxMinimumRows.Text, out minimumRows))
{
if (minimumRows == 0)
{
minimumRows = -1;
}
options.MinimumRows = minimumRows;
}
// save the options as JSON
this.SaveAsJson(options);
}
/// <summary>
/// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
/// </summary>
protected override void CreateChildControls()
{
base.CreateChildControls();
// set-up child controls
this.CheckBoxShowColumnLabels = new CheckBox() { ID = "ShowColumnLabels" };
this.MtcColumnLabels = new MultipleTextstringControl() { ID = "ColumnLabels" };
this.TextBoxMaximumRows = new TextBox() { ID = "MaximumRows", CssClass = "guiInputText" };
this.TextBoxMinimumRows = new TextBox() { ID = "MinimumRows", CssClass = "guiInputText" };
this.CheckBoxDisableSorting = new CheckBox() { ID = "CheckBoxDisableSorting" };
// HACK: [LK] The 'MultipleTextstring.js' requires a wrapper container with a class of 'propertyItemContent'
this.MtcContainer = new HtmlGenericControl("div");
this.MtcContainer.Attributes.Add("class", "propertyItemContent");
this.MtcContainer.Attributes.Add("style", "float: left;");
this.MtcContainer.Controls.Add(this.MtcColumnLabels);
// add the child controls
this.Controls.AddPrevalueControls(
this.CheckBoxShowColumnLabels,
this.MtcContainer,
this.TextBoxMaximumRows,
this.TextBoxMinimumRows,
this.CheckBoxDisableSorting);
}
/// <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);
// get PreValues, load them into the controls.
var options = this.GetPreValueOptions<TextstringArrayOptions>();
// no options? use the default ones.
if (options == null)
{
options = new TextstringArrayOptions(true);
}
// set the values
this.CheckBoxShowColumnLabels.Checked = options.ShowColumnLabels;
this.MtcColumnLabels.Options = new MultipleTextstringOptions() { Minimum = options.ItemsPerRow };
this.MtcColumnLabels.Values = options.ColumnLabels;
this.TextBoxMaximumRows.Text = options.MaximumRows.ToString();
this.TextBoxMinimumRows.Text = options.MinimumRows.ToString();
this.CheckBoxDisableSorting.Checked = options.DisableSorting;
}
/// <summary>
/// Renders the contents of the control to the specified writer. This method is used primarily by control developers.
/// </summary>
/// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
protected override void RenderContents(HtmlTextWriter writer)
{
writer.AddPrevalueHeading("Columns");
writer.AddPrevalueRow("Show Column Labels?", "Enter a label for each column; you may also use dictionary item syntax (e.g. <code>[#dictionaryItem]</code>). (Optional - blank labels are acceptable)", this.CheckBoxShowColumnLabels);
writer.AddPrevalueRow("Labels:", this.MtcContainer);
writer.AddPrevalueHeading("Rows");
writer.AddPrevalueRow("Minimum:", "Minimum number of rows to display.", this.TextBoxMinimumRows);
writer.AddPrevalueRow("Maximum:", "Maximum number of rows to display. Use -1 for unlimited rows.", this.TextBoxMaximumRows);
writer.AddPrevalueRow("Disable sorting?", "Disables the ability to sort the rows.", this.CheckBoxDisableSorting);
}
}
}