forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStore.cs
More file actions
137 lines (117 loc) · 3.71 KB
/
SimpleStore.cs
File metadata and controls
137 lines (117 loc) · 3.71 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
/********
* @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.Text;
using System.Web.UI;
using Ext.Net.Utilities;
namespace Ext.Net
{
[ToolboxItem(false)]
class SimpleStore : Store, ICustomConfigSerialization
{
/// <summary>
///
/// </summary>
public SimpleStore()
{
}
BaseControl control;
/// <summary>
///
/// </summary>
public SimpleStore(BaseControl control, ListItemCollection items)
{
this.control = control;
this.items = items;
}
private ListItemCollection items;
/// <summary>
///
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("")]
public ListItemCollection Items
{
get
{
if (this.items == null)
{
this.items = new ListItemCollection();
}
return this.items;
}
set
{
this.items = value;
}
}
public override void AddScript(string script)
{
this.control.AddScript(script);
}
protected override void CallTemplate(ScriptPosition position, string template, string name, params object[] args)
{
StringBuilder sb = new StringBuilder();
if (args != null && args.Length > 0)
{
foreach (object arg in args)
{
sb.AppendFormat("{0},", JSON.Serialize(arg, JSON.ScriptConvertersInternal));
}
}
string script = template.FormatWith(this.control.ClientID+".store", name, sb.ToString().LeftOfRightmostOf(','));
switch (position)
{
case ScriptPosition.BeforeInit:
this.ResourceManager.RegisterBeforeClientInitScript(script);
break;
case ScriptPosition.AfterInit:
this.ResourceManager.RegisterAfterClientInitScript(script);
break;
default:
this.AddScript(script);
break;
}
}
public override object DataSource
{
get
{
return this.Items;
}
set
{
}
}
public override void DataBind()
{
StringBuilder sb = new StringBuilder("[");
if (this.Items != null && this.Items.Count > 0)
{
foreach (BaseItem item in this.Items)
{
Ext.Net.ListItem li = (Ext.Net.ListItem)item;
sb.Append("[");
sb.Append(JSON.Serialize(li.Value));
sb.Append(",");
sb.Append(JSON.Serialize(li.Text));
sb.Append("],");
}
sb.Remove(sb.Length - 1, 1);
}
sb.Append("]");
this.Call("loadData", new JRawValue(sb.ToString()));
}
#region ICustomConfigSerialization Members
public string ToScript(System.Web.UI.Control owner)
{
return "";
}
#endregion
}
}