forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiSelectBase.cs
More file actions
774 lines (705 loc) · 24.3 KB
/
MultiSelectBase.cs
File metadata and controls
774 lines (705 loc) · 24.3 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/********
* @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;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Web.UI;
using Ext.Net.Utilities;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Ext.Net
{
/// <summary>
///
/// </summary>
[Meta]
[Description("")]
public abstract partial class MultiSelectBase : Field, IPostBackEventHandler, IStore<Store>
{
/// <summary>
///
/// </summary>
[Description("")]
protected override void OnBeforeClientInit(Observable sender)
{
if (this.StoreID.IsNotEmpty() && this.Store.Primary != null)
{
throw new Exception(string.Format("Please do not set both the StoreID property on {0} and <Store> inner property at the same time.", this.ID));
}
}
private static readonly object EventSelectionChanged = new object();
/// <summary>
///
/// </summary>
[Category("Action")]
[Description("")]
public event EventHandler SelectionChanged
{
add
{
this.CheckForceId();
this.Events.AddHandler(EventSelectionChanged, value);
}
remove
{
this.Events.RemoveHandler(EventSelectionChanged, value);
}
}
/// <summary>
///
/// </summary>
[Description("")]
protected virtual void OnSelectionChanged(EventArgs e)
{
EventHandler handler = (EventHandler)this.Events[EventSelectionChanged];
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
///
/// </summary>
[Description("")]
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
this.HasLoadPostData = true;
string state = postCollection[this.UniqueName];
this.SuspendScripting();
this.RawValue = state;
this.ResumeScripting();
if (state == null)
{
return false;
}
if (state.IsNotEmpty())
{
try
{
List<ListItem> items = ComboBoxBase.ParseSelectedItems(state);
bool fireEvent = false;
foreach (ListItem item in items)
{
if (!this.SelectedItems.Contains(item))
{
fireEvent = true;
break;
}
}
this.SelectedItems.Clear();
this.SelectedItems.AddRange(items);
return fireEvent;
}
catch
{
this.SuccessLoadPostData = false;
if (this.RethrowLoadPostDataException)
{
throw;
}
}
}
else
{
if (this.SelectedItems.Count > 0)
{
this.SelectedItems.Clear();
return true;
}
}
return false;
}
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
this.OnSelectionChanged(EventArgs.Empty);
}
/// <summary>
/// The data store to use.
/// </summary>
[Meta]
[ConfigOption("store", JsonMode.ToClientID)]
[Category("6. MultiSelect")]
[DefaultValue("")]
[IDReferenceProperty(typeof(Store))]
[Description("The data store to use.")]
public virtual string StoreID
{
get
{
return this.State.Get<string>("StoreID", "");
}
set
{
this.State.Set("StoreID", value);
}
}
private StoreCollection<Store> store;
/// <summary>
/// The data store to use.
/// </summary>
[Meta]
[ConfigOption("store>Primary")]
[Category("7. MultiSelect")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The data store to use.")]
public virtual StoreCollection<Store> Store
{
get
{
if (this.store == null)
{
this.store = new StoreCollection<Store>();
this.store.AfterItemAdd += this.AfterItemAdd;
this.store.AfterItemRemove += this.AfterItemRemove;
}
return this.store;
}
}
private ListItemCollection items;
/// <summary>
///
/// </summary>
[Meta]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Category("8. ComboBox")]
[Description("")]
public ListItemCollection Items
{
get
{
if (items == null)
{
items = new ListItemCollection();
}
return items;
}
}
private Type type;
/// <summary>
///
/// </summary>
[Meta]
[TypeConverter(typeof(NetTypeConverter))]
[DefaultValue(null)]
public Type ItemsFromEnum
{
get
{
return this.type;
}
set
{
this.type = value;
this.Items.Clear();
this.Items.AddRange(ListItemCollection.FromEnum(value));
}
}
/// <summary>
///
/// </summary>
[ConfigOption("store", JsonMode.Raw)]
[DefaultValue("")]
[Description("")]
protected string ItemsProxy
{
get
{
if (this.StoreID.IsNotEmpty() || this.Store.Primary != null)
{
return "";
}
return this.ItemsToStore;
}
}
private string ItemsToStore
{
get
{
StringWriter sw = new StringWriter();
JsonTextWriter jw = new JsonTextWriter(sw);
ListItemCollectionJsonConverter converter = new ListItemCollectionJsonConverter();
converter.WriteJson(jw, this.Items, null);
return sw.GetStringBuilder().ToString();
}
}
private ListItemCollection selectedItems;
/// <summary>
///
/// </summary>
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("")]
public virtual ListItemCollection SelectedItems
{
get
{
if (this.selectedItems == null)
{
this.selectedItems = new ListItemCollection();
}
return this.selectedItems;
}
}
/// <summary>
///
/// </summary>
[DefaultValue(null)]
[Browsable(false)]
[Description("")]
public virtual ListItem SelectedItem
{
get
{
return this.SelectedItems.Count > 0 ? this.SelectedItems[0] : null;
}
}
/// <summary>
/// An optional title to be displayed at the top of the selection list.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("")]
[Description("An optional title to be displayed at the top of the selection list.")]
public virtual string ListTitle
{
get
{
return this.State.Get<string>("ListTitle", "");
}
set
{
this.State.Set("ListTitle", value);
}
}
/// <summary>
/// The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("")]
[Description("The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).")]
public virtual string DragGroup
{
get
{
return this.State.Get<string>("DragGroup", "");
}
set
{
this.State.Set("DragGroup", value);
}
}
/// <summary>
/// The ddgroup name(s) for the View's DropZone (defaults to undefined).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("")]
[Description("The ddgroup name(s) for the View's DropZone (defaults to undefined).")]
public virtual string DropGroup
{
get
{
return this.State.Get<string>("DropGroup", "");
}
set
{
this.State.Set("DropGroup", value);
}
}
/// <summary>
/// Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
/// </summary>
[Meta]
[ConfigOption("ddReorder")]
[Category("6. MultiSelect")]
[DefaultValue(false)]
[Description("Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).")]
public virtual bool DDReorder
{
get
{
return this.State.Get<bool>("DDReorder", false);
}
set
{
this.State.Set("DDReorder", value);
}
}
private ToolbarCollection topBar;
/// <summary>
/// An optional toolbar to be inserted at the top of the control's selection list.
/// </summary>
[Meta]
[ConfigOption("tbar", typeof(SingleItemCollectionJsonConverter))]
[Category("6. MultiSelect")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An optional toolbar to be inserted at the top of the control's selection list.")]
public virtual ToolbarCollection TopBar
{
get
{
if (this.topBar == null)
{
this.topBar = new ToolbarCollection();
this.topBar.AfterItemAdd += this.AfterItemAdd;
this.topBar.AfterItemRemove += this.AfterItemRemove;
}
return this.topBar;
}
}
/// <summary>
/// True if the list should only allow append drops when drag/drop is enabled (use for lists which are sorted, defaults to false).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(false)]
[Description("True if the list should only allow append drops when drag/drop is enabled (use for lists which are sorted, defaults to false).")]
public virtual bool AppendOnly
{
get
{
return this.State.Get<bool>("AppendOnly", false);
}
set
{
this.State.Set("AppendOnly", value);
}
}
/// <summary>
/// Name of the desired display field in the dataset (defaults to 'text').
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("text")]
[Description("Name of the desired display field in the dataset (defaults to 'text').")]
public virtual string DisplayField
{
get
{
return this.State.Get<string>("DisplayField", "text");
}
set
{
this.State.Set("DisplayField", value);
}
}
/// <summary>
/// Name of the desired value field in the dataset (defaults to the value of displayField).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("")]
[Description("Name of the desired value field in the dataset (defaults to the value of displayField).")]
public virtual string ValueField
{
get
{
return this.State.Get<string>("ValueField", "");
}
set
{
this.State.Set("ValueField", value);
}
}
/// <summary>
/// False to require at least one item in the list to be selected, true to allow no selection (defaults to true).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(true)]
[Description("False to require at least one item in the list to be selected, true to allow no selection (defaults to true).")]
public virtual bool AllowBlank
{
get
{
return this.State.Get<bool>("AllowBlank", true);
}
set
{
this.State.Set("AllowBlank", value);
}
}
/// <summary>
/// Maximum number of selections allowed (defaults to Number.MAX_VALUE).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(int.MaxValue)]
[Description("Maximum number of selections allowed (defaults to Number.MAX_VALUE).")]
public virtual int MaxSelections
{
get
{
return this.State.Get<int>("MaxSelections", int.MaxValue);
}
set
{
this.State.Set("MaxSelections", value);
}
}
/// <summary>
/// Minimum number of selections allowed (defaults to 0).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(0)]
[Description("Minimum number of selections allowed (defaults to 0).")]
public virtual int MinSelections
{
get
{
return this.State.Get<int>("MinSelections", 0);
}
set
{
this.State.Set("MinSelections", value);
}
}
/// <summary>
/// Default text displayed when the control contains no items (defaults to 'This field is required')
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("This field is required")]
[Localizable(true)]
[Description("Default text displayed when the control contains no items (defaults to 'This field is required')")]
public virtual string BlankText
{
get
{
return this.State.Get<string>("BlankText", "This field is required");
}
set
{
this.State.Set("BlankText", value);
}
}
/// <summary>
/// Validation message displayed when MaxSelections is not met (defaults to 'Maximum {0} item(s) allowed'). The {0} token will be replaced by the value of MaxSelections.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("Maximum {0} item(s) allowed")]
[Localizable(true)]
[Description("Validation message displayed when MaxSelections is not met (defaults to 'Maximum {0} item(s) allowed'). The {0} token will be replaced by the value of MaxSelections.")]
public virtual string MaxSelectionsText
{
get
{
return this.State.Get<string>("MaxSelectionsText", "Maximum {0} item(s) allowed");
}
set
{
this.State.Set("MaxSelectionsText", value);
}
}
/// <summary>
/// Validation message displayed when MinSelections is not met (defaults to 'Minimum {0} item(s) required'). The {0} token will be replaced by the value of MinSelections.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue("Minimum {0} item(s) required")]
[Localizable(true)]
[Description("Validation message displayed when MinSelections is not met (defaults to 'Minimum {0} item(s) required'). The {0} token will be replaced by the value of MinSelections.")]
public virtual string MinSelectionsText
{
get
{
return this.State.Get<string>("MinSelectionsText", "Minimum {0} item(s) required");
}
set
{
this.State.Set("MinSelectionsText", value);
}
}
/// <summary>
/// The string used to delimit the selected values when getSubmitValue submitting the field as part of a form. Defaults to ','. If you wish to have the selected values submitted as separate parameters rather than a single delimited parameter, set this to null.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(",")]
[Description("The string used to delimit the selected values when getSubmitValue submitting the field as part of a form. Defaults to ','. If you wish to have the selected values submitted as separate parameters rather than a single delimited parameter, set this to null.")]
public virtual string Delimiter
{
get
{
return this.State.Get<string>("Delimiter", ",");
}
set
{
this.State.Set("Delimiter", value);
}
}
/// <summary>
/// Causes drag operations to copy nodes rather than move (defaults to false).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(false)]
[Description("Causes drag operations to copy nodes rather than move (defaults to false).")]
public virtual bool Copy
{
get
{
return this.State.Get<bool>("Copy", false);
}
set
{
this.State.Set("Copy", value);
}
}
/// <summary>
/// True to allow selection of more than one item at a time, false to allow selection of only a single item at a time or no selection at all, depending on the value of singleSelect (defaults to false).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(false)]
[NotifyParentProperty(false)]
[Description("True to allow selection of more than one item at a time, false to allow selection of only a single item at a time or no selection at all, depending on the value of singleSelect (defaults to false).")]
public virtual bool MultiSelect
{
get
{
return this.State.Get<bool>("MultiSelect", false);
}
set
{
this.State.Set("MultiSelect", value);
}
}
/// <summary>
/// True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl, false to force the user to hold Ctrl or Shift to select more than on item (defaults to true).
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl, false to force the user to hold Ctrl or Shift to select more than on item (defaults to true).")]
public virtual bool SimpleSelect
{
get
{
return this.State.Get<bool>("SimpleSelect", true);
}
set
{
this.State.Set("SimpleSelect", value);
}
}
/// <summary>
/// True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false). Note that if multiSelect = true, this value will be ignored.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. MultiSelect")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false). Note that if multiSelect = true, this value will be ignored.")]
public virtual bool SingleSelect
{
get
{
return this.State.Get<bool>("SingleSelect", false);
}
set
{
this.State.Set("SingleSelect", value);
}
}
private BoundList listConfig;
/// <summary>
/// An optional set of configuration properties that will be passed to the Ext.view.BoundList's constructor. Any configuration that is valid for BoundList can be included.
/// </summary>
[Meta]
[DefaultValue(null)]
[ConfigOption("listConfig", typeof(LazyControlJsonConverter))]
[Category("8. ComboBox")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
[Description("")]
public BoundList ListConfig
{
get
{
return this.listConfig;
}
set
{
if (this.listConfig != null)
{
this.Controls.Remove(this.listConfig);
this.LazyItems.Remove(this.listConfig);
}
this.listConfig = value;
if (this.listConfig != null)
{
this.Controls.Add(this.listConfig);
this.LazyItems.Add(this.listConfig);
}
}
}
/// <summary>
///
/// </summary>
[Meta]
public virtual void UpdateSelectedItems()
{
this.Call("setSelectedItems", JRawValue.From(this.SelectedItems.Serialize()));
}
#region IStore Members
SimpleStore generatedStore;
/// <summary>
///
/// </summary>
/// <returns></returns>
public Store GetStore()
{
if (this.Store.Primary != null)
{
return this.Store.Primary;
}
if (this.StoreID.IsNotEmpty())
{
return ControlUtils.FindControl<Store>(this, this.StoreID, true);
}
if (this.generatedStore == null)
{
this.generatedStore = new SimpleStore(this, this.Items);
this.generatedStore.EnableViewState = false;
this.Controls.Add(this.generatedStore);
}
else
{
this.generatedStore.Items.Clear();
this.generatedStore.Items = this.Items;
}
return this.generatedStore;
}
#endregion
}
}