forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.cs
More file actions
261 lines (241 loc) · 8.7 KB
/
Renderer.cs
File metadata and controls
261 lines (241 loc) · 8.7 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System.ComponentModel;
using System.Globalization;
using System.Web.UI.WebControls;
using Ext.Net.Utilities;
namespace Ext.Net
{
/// <summary>
/// A function used to generate HTML markup for a cell given the cell's data value.
/// If not specified, the default renderer uses the raw data value.
///
/// Sets the rendering (formatting) function for a column.
/// See Ext.util.Format for some default formatting functions.
///
/// The render function is called with the following parameters:
/// value : Object
/// The data value for the cell.
/// metadata : Object
/// An object in which you may set the following attributes:
///
/// tdCls : String
/// A CSS class name to add to the cell's TD element.
/// tdAttr : String
/// An HTML attribute definition string to apply to the data container element
/// within the table cell (e.g. 'style="color:red;"').
/// style : String
///
/// record : Ext.data.record
/// The Ext.data.Record from which the data was extracted.
/// rowIndex : Number
/// Row index
/// colIndex : Number
/// Column index
/// store : Ext.data.Store
/// The Ext.data.Store object from which the Record was extracted.
/// view : Ext.grid.View
/// Returns:
/// void
/// </summary>
[DefaultProperty("Handler")]
[TypeConverter(typeof(RendererConverter))]
[ToolboxItem(false)]
[Description("")]
public partial class Renderer : BaseItem
{
private string[] args;
/// <summary>
///
/// </summary>
[Description("")]
public Renderer() { }
/// <summary>
///
/// </summary>
[Description("")]
public Renderer(string handler)
{
this.Handler = handler;
}
/// <summary>
///
/// </summary>
[TypeConverter(typeof(StringArrayConverter))]
[DefaultValue(null)]
[NotifyParentProperty(true)]
[Description("")]
public string[] Args
{
get
{
if (this.args == null && !this.DesignMode)
{
this.args = new string[] { "value", "metadata", "record", "rowIndex", "colIndex", "store", "view" };
}
return this.args;
}
set
{
this.args = value;
}
}
/// <summary>
///
/// </summary>
[Description("")]
public virtual string ToConfigString()
{
if (this.Format != RendererFormat.None)
{
if (this.FormatArgs != null && this.FormatArgs.Length > 0)
{
return new JFunction("return Ext.util.Format.".ConcatWith(
this.Format.ToString().ToLowerCamelCase(),
"(value,",
this.FormatArgs.Join(),
");"), "value").ToScript();
}
if (this.Handler.IsEmpty())
{
return "Ext.util.Format.".ConcatWith(this.Format.ToString().ToLowerCamelCase());
}
}
if (this.Handler.IsNotEmpty())
{
string temp = TokenUtils.ParseTokens(this.Handler, this.Owner);
if (TokenUtils.IsRawToken(temp))
{
return TokenUtils.ReplaceRawToken(temp);
}
return new JFunction(
temp,
this.Args)
.ToScript();
}
return TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Fn));
}
/// <summary>
/// The raw JavaScript function to be called when this Renderer fires.
/// </summary>
[ConfigOption(JsonMode.Raw)]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The raw JavaScript function to be called when this Renderer fires.")]
public virtual string Fn
{
get
{
return this.State.Get<string>("Fn", "");
}
set
{
this.State.Set("Fn", value);
}
}
/// <summary>
/// The JavaScript logic to be called when this Renderer fires. The Handler will be automatically wrapped in a proper function{} template and passed the correct arguments for this event.
/// </summary>
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The JavaScript logic to be called when this Renderer fires. The Handler will be automatically wrapped in a proper function{} template and passed the correct arguments for this event.")]
public virtual string Handler
{
get
{
return this.State.Get<string>("Handler", "");
}
set
{
this.State.Set("Handler", value);
}
}
/// <summary>
/// The JavaScript logic to be called when this Renderer fires. The Handler will be automatically wrapped in a proper function{} template and passed the correct arguments for this event.
/// </summary>
[ConfigOption(JsonMode.Raw)]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The JavaScript logic to be called when this Renderer fires. The Handler will be automatically wrapped in a proper function{} template and passed the correct arguments for this event.")]
public virtual string Scope
{
get
{
return this.State.Get<string>("Scope", "");
}
set
{
this.State.Set("Scope", value);
}
}
/// <summary>
/// A simple helper type to format the value. For custom renderer formating please use .Fn or .Handler.
/// </summary>
[DefaultValue(RendererFormat.None)]
[NotifyParentProperty(true)]
[Description("A simple helper type to format the value. For custom renderer formating please use .Fn or .Handler.")]
public virtual RendererFormat Format
{
get
{
return this.State.Get<RendererFormat>("Format", RendererFormat.None);
}
set
{
this.State.Set("Format", value);
}
}
/// <summary>
/// Custom arguments passed to Format. Required if Format is Date, DateRenderer, DefaultValue, Ellipsis or Substr.
/// </summary>
[TypeConverter(typeof(StringArrayConverter))]
[DefaultValue(null)]
[NotifyParentProperty(true)]
[Description("Custom arguments passed to Format. Required if Format is Date, DateRenderer, DefaultValue, Ellipsis or Substr.")]
public virtual string[] FormatArgs
{
get
{
return this.State.Get<string[]>("FormatArgs", null);
}
set
{
this.State.Set("FormatArgs", value);
}
}
/// <summary>
/// Are all the properties still set with thier default values.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Description("Are all the properties still set with thier default values.")]
public override bool IsDefault
{
get
{
return this.Fn.IsEmpty() && this.Handler.IsEmpty() && this.Format == RendererFormat.None;
}
}
/// <summary>
///
/// </summary>
[Description("")]
public override string ToString()
{
return this.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
///
/// </summary>
[Description("")]
public string ToString(CultureInfo culture)
{
return TypeDescriptor.GetConverter(this.GetType()).ConvertToString(null, culture, this);
}
}
}