-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1760 from riganti/add-AddTemplateDecorator
New AddTemplateDecorator control
- Loading branch information
Showing
5 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using DotVVM.Framework.Hosting; | ||
using DotVVM.Framework.Binding; | ||
|
||
namespace DotVVM.Framework.Controls | ||
{ | ||
/// <summary> Adds a template before or after the decorated control. </summary> | ||
[ControlMarkupOptions(AllowContent = false)] | ||
public class AddTemplateDecorator: Decorator | ||
{ | ||
/// <summary> Template is rendered after the decorated control. </summary> | ||
[MarkupOptions(MappingMode = MappingMode.InnerElement)] | ||
public ITemplate AfterTemplate | ||
{ | ||
get => (ITemplate)GetValue(AfterTemplateProperty)!; | ||
set => SetValue(AfterTemplateProperty, value); | ||
} | ||
public static readonly DotvvmProperty AfterTemplateProperty = | ||
DotvvmProperty.Register<ITemplate, AddTemplateDecorator>(nameof(AfterTemplate)); | ||
|
||
/// <summary> Template is rendered before the decorated control. </summary> | ||
[MarkupOptions(MappingMode = MappingMode.InnerElement)] | ||
public ITemplate BeforeTemplate | ||
{ | ||
get => (ITemplate)GetValue(BeforeTemplateProperty)!; | ||
set => SetValue(BeforeTemplateProperty, value); | ||
} | ||
public static readonly DotvvmProperty BeforeTemplateProperty = | ||
DotvvmProperty.Register<ITemplate, AddTemplateDecorator>(nameof(BeforeTemplate)); | ||
|
||
protected internal override void OnInit(IDotvvmRequestContext context) | ||
{ | ||
var after = this.AfterTemplate; | ||
var before = this.BeforeTemplate; | ||
|
||
if (after is {}) | ||
{ | ||
Children.Add(new TemplateHost(after)); | ||
} | ||
if (before is {}) | ||
{ | ||
Children.Insert(0, new TemplateHost(before)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Tests/ControlTests/testoutputs/GridViewTests.GridView_RowDecorators_AddChildren.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
|
||
<!-- ko if: Customers()?.Items()?.length --> | ||
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':Customers()}"> | ||
<thead> | ||
<tr> | ||
<th> | ||
<span>Name</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody data-bind="foreach: Customers()?.Items"> | ||
|
||
<!-- ko if: Enabled --> | ||
<tr colspan="3"> | ||
<td> | ||
vvv enabled customer vvv | ||
</td> | ||
</tr> | ||
<!-- /ko --> | ||
<tr data-bind="css: { enabled: Enabled }"> | ||
<td> | ||
<span data-bind="text: Name"></span> | ||
</td> | ||
</tr> | ||
|
||
<!-- ko if: Enabled --> | ||
<tr colspan="3"> | ||
<td> | ||
^^^ enabled customer ^^^ | ||
</td> | ||
</tr> | ||
<!-- /ko --> | ||
</tbody> | ||
</table> | ||
<!-- /ko --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters