forked from xuxiaowei007/FoxOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableButton.cs
89 lines (76 loc) · 2.51 KB
/
TableButton.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
using FoxOne.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using FoxOne.Core;
using System.Globalization;
namespace FoxOne.Controls
{
public class TableButton : ComponentBase
{
public TableButton()
{
Visiable = true;
Target = TableButtonTarget.Self;
}
public string Name
{
get;
set;
}
public string Href { get; set; }
public TableButtonTarget Target { get; set; }
[DisplayName("过滤器")]
public IDataFilter Filter { get; set; }
[DisplayName("按钮点击事件")]
[FormField(ControlType = ControlType.TextArea)]
public string OnClick { get; set; }
public TableButtonType TableButtonType { get; set; }
[DisplayName("数据字段")]
public string DataFields { get; set; }
public IDictionary<string, object> RowData { get; set; }
public override string Render()
{
if(Filter!=null && Filter.Filter(RowData))
{
return string.Empty;
}
var a = new TagBuilder("a");
a.AddCssClass(CssClass);
a.Attributes["trButton"] = Id;
a.SetInnerText(Name);
if (!OnClick.IsNullOrEmpty())
{
a.Attributes.Add("onclick", FormatAttribute(OnClick));
}
if (!Href.IsNullOrEmpty())
{
a.Attributes.Add("href", FormatAttribute(Href));
}
else
{
a.Attributes.Add("href", "javascript:void(0);");
}
a.Attributes.Add("target", "_{0}".FormatTo(Target.ToString().ToLower()));
return a.ToString();
}
private string FormatAttribute(string formatString)
{
var buttonClick = formatString;
if (!DataFields.IsNullOrEmpty())
{
var dataFields = DataFields.Split(',');
object[] param = new object[dataFields.Length];
for (int i = 0; i < dataFields.Length; i++)
{
param[i] = RowData[dataFields[i]];
}
buttonClick = string.Format(CultureInfo.CurrentCulture, buttonClick, param);
}
return buttonClick;
}
}
}