-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrevalueEditor.cs
241 lines (198 loc) · 7.88 KB
/
PrevalueEditor.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Xml;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.datatype;
using umbraco.DataLayer;
using umbraco.interfaces;
using System.Web.Script.Serialization;
namespace uNews.GoogleMap
{
/// <summary>
/// This class is used to setup the datatype settings.
/// On save it will store these values (using the datalayer) in the database
/// </summary>
public class PrevalueEditor : System.Web.UI.UpdatePanel, IDataPrevalue
{
// referenced datatype
private umbraco.cms.businesslogic.datatype.BaseDataType _datatype;
private TextBox saveBox, address, lat, lng, zoom;//, width, height;
HtmlGenericControl settingsTable;
private JavaScriptSerializer jsonSerializer;
private Options savedOptions;
public PrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType DataType)
{
_datatype = DataType;
jsonSerializer = new JavaScriptSerializer();
savedOptions = Configuration;
}
public Control Editor
{
get
{
return this;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
saveBox = new TextBox();
saveBox.TextMode = TextBoxMode.MultiLine;
saveBox.CssClass = "saveBox";
ContentTemplateContainer.Controls.Add(saveBox);
string css = string.Format("<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" />", "/umbraco/plugins/uNewsGoogleMap/prevalue.css");
ScriptManager.RegisterClientScriptBlock(Page, typeof(DataEditor), "DataTypePrevalueCSS", css, false);
string js = string.Format("<script src=\"{0}\" ></script>", "/umbraco/plugins/uNewsGoogleMap/prevalue.js");
ScriptManager.RegisterClientScriptBlock(Page, typeof(DataEditor), "DataTypePrevalueJS", js, false);
settingsTable = new HtmlGenericControl("table");
settingsTable.Attributes["class"] = "settingsTable";
ContentTemplateContainer.Controls.Add(settingsTable);
HtmlGenericControl tr, th, td;
tr = new HtmlGenericControl("tr");
settingsTable.Controls.Add(tr);
th = new HtmlGenericControl("th");
tr.Controls.Add(th);
th.InnerHtml = "Address";
th.Attributes["colspan"] = "2";
th.InnerHtml = "Default Settings";
//address
tr = new HtmlGenericControl("tr");
settingsTable.Controls.Add(tr);
th = new HtmlGenericControl("th");
tr.Controls.Add(th);
th.InnerHtml = "Address";
address = new TextBox();
td = new HtmlGenericControl("td");
tr.Controls.Add(td);
td.Controls.Add(address);
address.Attributes["class"] = "address";
//lat
tr = new HtmlGenericControl("tr");
settingsTable.Controls.Add(tr);
th = new HtmlGenericControl("th");
tr.Controls.Add(th);
th.InnerHtml = "Lat";
lat = new TextBox();
td = new HtmlGenericControl("td");
tr.Controls.Add(td);
td.Controls.Add(lat);
lat.Attributes["class"] = "lat";
//lng
tr = new HtmlGenericControl("tr");
settingsTable.Controls.Add(tr);
th = new HtmlGenericControl("th");
tr.Controls.Add(th);
th.InnerHtml = "Lng";
lng = new TextBox();
td = new HtmlGenericControl("td");
tr.Controls.Add(td);
td.Controls.Add(lng);
lng.Attributes["class"] = "lng";
//zoom
tr = new HtmlGenericControl("tr");
settingsTable.Controls.Add(tr);
th = new HtmlGenericControl("th");
tr.Controls.Add(th);
th.InnerHtml = "Zoom";
zoom = new TextBox();
td = new HtmlGenericControl("td");
tr.Controls.Add(td);
td.Controls.Add(zoom);
zoom.Attributes["class"] = "zoom";
//height
//tr = new HtmlGenericControl("tr");
//settingsTable.Controls.Add(tr);
//th = new HtmlGenericControl("th");
//tr.Controls.Add(th);
//th.InnerHtml = "Height";
//height = new TextBox();
//td = new HtmlGenericControl("td");
//tr.Controls.Add(td);
//td.Controls.Add(height);
//height.Attributes["class"] = "height";
////width
//tr = new HtmlGenericControl("tr");
//settingsTable.Controls.Add(tr);
//th = new HtmlGenericControl("th");
//tr.Controls.Add(th);
//th.InnerHtml = "Width";
//width = new TextBox();
//td = new HtmlGenericControl("td");
//tr.Controls.Add(td);
//td.Controls.Add(width);
//width.Attributes["class"] = "width";
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void OnPreRender(EventArgs e)
{
Options renderingOptions;
//test for postback, decide to use db or saveBox for rendering
if (Page.IsPostBack)
{
//test for saveBox having a value, default if not
if (saveBox.Text != "")
{
renderingOptions = jsonSerializer.Deserialize<Options>(saveBox.Text);
}
else
{
renderingOptions = new Options();
}
}
else
{
renderingOptions = savedOptions;
}
address.Text = HttpUtility.UrlDecode(renderingOptions.address);
lat.Text = renderingOptions.lat;
lng.Text = renderingOptions.lng;
zoom.Text = renderingOptions.zoom.ToString();
//height.Text = renderingOptions.height.ToString();
//width.Text = renderingOptions.width.ToString();
}
public void Save()
{
_datatype.DBType = (umbraco.cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), DBTypes.Ntext.ToString(), true);
SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId));
SqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId), SqlHelper.CreateParameter("@value", saveBox.Text));
}
public Options Configuration
{
get
{
string dbValue = "";
try
{
object conf = SqlHelper.ExecuteScalar<object>("select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid", SqlHelper.CreateParameter("@datatypenodeid", _datatype.DataTypeDefinitionId));
dbValue = conf.ToString();
}
catch (Exception e)
{
}
if (dbValue.ToString() != "")
{
return jsonSerializer.Deserialize<Options>(dbValue.ToString());
}
else
{
return new Options();
}
}
}
public static ISqlHelper SqlHelper
{
get
{
return Application.SqlHelper;
}
}
}
}