-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParametrizedRangeActionMenuActionItem.cs
328 lines (320 loc) · 12.8 KB
/
ParametrizedRangeActionMenuActionItem.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web;
using DevExpress.ExpressApp.Web;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Web.SystemModule;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Web.Templates.ActionContainers.Menu;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Web.Templates;
using Solution28.Module.Web;
using DevExpress.ExpressApp.Templates;
namespace Solution28.Module.Web {
public struct Range<T> {
public T From;
public T To;
public override bool Equals(object obj) {
if (obj is Range<T>) {
return Equals(((Range<T>)obj).From, From) && Equals(((Range<T>)obj).To, To);
}
return false;
}
public override int GetHashCode() {
return From.GetHashCode() ^ To.GetHashCode();
}
}
}
namespace DevExpress.ExpressApp.Web.Templates.ActionContainers {
public class ParametrizedRangeActionMenuActionItem : TemplatedMenuActionItem {
private ActionContainerOrientation _orientation;
private bool isExecuted = false;
private int executionLockCount;
private string clientClickHandler;
private void UpdateEditorValue() {
executionLockCount++;
try {
if (Control != null) {
Control.Value = ((ParametrizedAction)Action).Value;
}
} finally {
executionLockCount--;
}
}
private void action_CurrentValueChanged(object sender, EventArgs e) {
UpdateEditorValue();
}
private void ExecuteWithCurrentValue() {
if (executionLockCount == 0 && !isExecuted) {
isExecuted = true;
((ParametrizedAction)Action).DoExecute(Control.Value);
}
}
protected override void SetImage(ImageInfo imageInfo) {
if (Control != null) {
Control.SetImage(imageInfo, Action.ShortCaption);
}
}
protected override void SetCaption(string caption) {
if (Control != null) {
Control.Caption = caption;
if (Control.Button.Image.IsEmpty) {
Control.Button.Text = Action.ShortCaption;
}
Control.SetNullValuePrompt(Action.NullValuePrompt);
}
}
protected override void SetPaintStyle(ActionItemPaintStyle paintStyle) {
base.SetPaintStyle(paintStyle);
if (Control != null) {
Control.CaptionVisible = !Equals(paintStyle, ActionItemPaintStyle.Image);
}
}
protected override void SetEnabled(bool enabled) {
if (Control != null) {
Control.ClientEnabled = enabled;
}
}
protected override void SetToolTip(string toolTip) {
if (Control != null) {
Control.ToolTip = toolTip;
}
}
protected override void SetConfirmationMessage(string message) { }
protected override Control CreateControlCore() {
isExecuted = false;
ParametrizedActionDateRangeControl result = new ParametrizedActionDateRangeControl(Orientation);
result.ID = WebIdHelper.GetCorrectedActionId(Action);
result.Value = ((ParametrizedAction)Action).Value;
result.SetNullValuePrompt(Action.NullValuePrompt);
result.Button.AutoPostBack = false;
result.Button.ClientSideEvents.Click = clientClickHandler;
return result;
}
public ParametrizedRangeActionMenuActionItem(ParametrizedAction action)
: base(action) {
action.ValueChanged += action_CurrentValueChanged;
}
public override void Dispose() {
if (Action != null) {
Action.ValueChanged -= action_CurrentValueChanged;
}
base.Dispose();
}
public override void ProcessAction() {
ExecuteWithCurrentValue();
}
public override void SetClientClickHandler(XafCallbackManager callbackManager, string controlID) {
string clientScript = callbackManager.GetScript(controlID, string.Format("'{0}'", MenuItem.IndexPath), Action.GetFormattedConfirmationMessage(), IsPostBackRequired);
clientClickHandler = string.Format("function(s, e) {{ {0}e.processOnServer = false;}}", clientScript);
if (Control != null) {
Control.Button.ClientSideEvents.Click = clientClickHandler;
}
}
public new ParametrizedActionDateRangeControl Control {
get { return (ParametrizedActionDateRangeControl)base.Control; }
}
public new ParametrizedAction Action {
get { return (ParametrizedAction)base.Action; }
}
public ActionContainerOrientation Orientation {
get { return _orientation; }
set { _orientation = value; }
}
public override string GetClientUpdateScript(string clientItemInnerState, string menuItemName, string indexPath, XafCallbackManager callbackManager, string actionContainerUniqueID) {
return "";
}
public override string InnerState {
get { return ""; }
}
}
public class ParametrizedActionDateRangeControl : WebControl, INamingContainer, IDisposableExt {
private ASPxDateEdit calendarFrom;
private ASPxDateEdit calendarTo;
private ASPxButton _button;
private ASPxLabel label;
private TableCell labelCell;
private bool isPrerendered;
private Boolean _isDisposed;
private bool _clientEnabled = true;
private void button_Click(object sender, EventArgs e) {
OnClick();
}
private void UpdateEnabled() {
if (Button != null) {
Button.ClientEnabled = ClientEnabled;
}
if (calendarFrom != null) {
calendarFrom.ClientEnabled = ClientEnabled;
}
if (calendarTo != null) {
calendarTo.ClientEnabled = ClientEnabled;
}
}
protected string GetForceButtonClickScript() {
return string.Format("function(s, e) {{ {0}(e, '{1}'); }}", RenderHelper.GetForceButtonClickFunctionName(), _button.ClientID);
}
protected virtual string GetClientControlClassName() {
return "ParametrizedActionClientControl";
}
protected override void OnPreRender(EventArgs e) {
isPrerendered = true;
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer) {
if (!isPrerendered) {
OnPreRender(EventArgs.Empty);
}
base.Render(writer);
DevExpress.Web.Internal.RenderUtils.WriteScriptHtml(writer, string.Format(@"window.{0} = new {1}('{2}');", ClientID, GetClientControlClassName(), ClientID));
}
protected virtual void OnClick() {
if (Click != null) {
Click(this, new EventArgs());
}
}
public void SetConfirmationMessage(string message) {
ConfirmationsHelper.SetConfirmationScript(Button, message);
}
public void SetImage(ImageInfo imageInfo, string buttonText) {
if (!imageInfo.IsEmpty) {
ASPxImageHelper.SetImageProperties(Button.Image, imageInfo);
Button.Text = "";
CssClass = "ParametrizedActionWithImage";
}
else {
ASPxImageHelper.ClearImageProperties(Button.Image);
Button.Text = buttonText;
CssClass = "ParametrizedAction";
}
}
public ParametrizedActionDateRangeControl() : this(ActionContainerOrientation.Horizontal) { }
public ParametrizedActionDateRangeControl(ActionContainerOrientation orientation) {
_button = RenderHelper.CreateASPxButton();
_button.AutoPostBack = false;
_button.Click += button_Click;
_button.EnableClientSideAPI = true;
_button.ID = "B";
Control editor = CreateEditorBody();
editor.ID = "Ed";
label = RenderHelper.CreateASPxLabel();
label.ID = "L";
label.Wrap = DevExpress.Utils.DefaultBoolean.False;
Table table = RenderHelper.CreateTable();
table.CssClass = "ParametrizedActionControl";
table.ID = "T";
labelCell = new TableCell();
TableCell editorCell = new TableCell();
TableCell buttonCell = new TableCell();
FillTemplateTable(orientation, table, labelCell, editorCell, buttonCell);
labelCell.Controls.Add(label);
labelCell.CssClass = "ControlCaption";
editorCell.Controls.Add(editor);
editorCell.CssClass = "Label";
buttonCell.Controls.Add(_button);
buttonCell.CssClass = "Editor";
Controls.Add(table);
}
private Control CreateEditorBody() {
calendarFrom = RenderHelper.CreateASPxDateEdit();
calendarFrom.ID = "EdF";
calendarTo = RenderHelper.CreateASPxDateEdit();
calendarTo.ID = "EdT";
Table table = RenderHelper.CreateTable();
TableRow trow = new TableRow();
TableCell tcell1 = new TableCell();
tcell1.Controls.Add(calendarFrom);
trow.Cells.Add(tcell1);
TableCell tcell2 = new TableCell();
tcell2.Controls.Add(calendarTo);
trow.Cells.Add(tcell2);
table.Rows.Add(trow);
return table;
}
protected Table FillTemplateTable(ActionContainerOrientation orientation, Table table, TableCell labelCell,
TableCell editorCell, TableCell buttonCell) {
if (Equals(orientation, ActionContainerOrientation.Horizontal)) {
return FillHTemplateTable(table, labelCell, editorCell, buttonCell);
} else {
return FillVTemplateTable(table, labelCell, editorCell, buttonCell);
}
}
protected virtual Table FillHTemplateTable(Table table, TableCell labelCell, TableCell editorCell, TableCell buttonCell) {
table.Rows.Add(new TableRow());
table.Rows[0].Cells.Add(labelCell);
table.Rows[0].Cells.Add(editorCell);
table.Rows[0].Cells.Add(buttonCell);
return table;
}
protected virtual Table FillVTemplateTable(Table table, TableCell labelCell, TableCell editorCell, TableCell buttonCell) {
table.Rows.Add(new TableRow());
table.Rows[0].Cells.Add(labelCell);
table.Rows.Add(new TableRow());
table.Rows[1].Cells.Add(editorCell);
table.Rows[1].Cells.Add(buttonCell);
return table;
}
public void SetNullValuePrompt(string nullValuePrompt) {
calendarFrom.NullText = nullValuePrompt;
calendarTo.NullText = nullValuePrompt;
}
public override void Dispose() {
if (_button != null) {
_button.Click -= button_Click;
}
base.Dispose();
_button = null;
_isDisposed = true;
}
public bool ClientEnabled {
get {
return _clientEnabled;
}
set {
_clientEnabled = value;
UpdateEnabled();
}
}
public override string ToolTip {
get { return Button.ToolTip; }
set { Button.ToolTip = value; }
}
public ASPxButton Button {
get {
return _button;
}
}
public string Caption {
get { return label.Text; }
set {
label.Text = value;
CaptionVisible = !String.IsNullOrEmpty(value);
}
}
public bool CaptionVisible {
get { return labelCell.Visible; }
set { labelCell.Visible = value; }
}
public virtual object Value {
get {
return new Range<DateTime>() { From = calendarFrom.Date, To = calendarTo.Date };
}
set {
if (value is Range<DateTime>) {
calendarFrom.Date = ((Range<DateTime>)value).From;
calendarTo.Date = ((Range<DateTime>)value).To;
}
}
}
public event EventHandler Click;
#region IDisposableExt Members
public bool IsDisposed {
get { return _isDisposed; }
}
#endregion
}
}