-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProductSaleRow.cs
65 lines (53 loc) · 2.3 KB
/
ProductSaleRow.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
using SerratedSharp.SerratedJQ.Plain;
using System;
namespace Sample.Wasm.ClientSideModels
{
/// <summary>
/// This is a rough example of an unrefined UI component.
/// It provides its own data model, a data driven HTML template, and events where appropriate.
/// </summary>
internal class ProductSaleRow
{
public ProductSaleRow(ProductSalesModel productSalesModel){
Model = productSalesModel;
}
public ProductSalesModel Model { get; set; }
private JQueryPlainObject jQueryObject;
public JQueryPlainObject JQueryObject
{
get
{
if (this.jQueryObject == null)
{
jQueryObject = JQueryPlain.ParseHtmlAsJQuery(GetHtml(Model).Trim() );
jQueryObject.OnClick += JQRowOnClick;
}
return jQueryObject;
}
set => jQueryObject = value;
}
private static string GetHtml(ProductSalesModel model)
{
return $@"
<div class='row border rounded my-1'>
<div class='col-xl px-1 px-sm-3'><span>{model.Rep.Name}</span> sold <span class='br-{nameof(model.Quantity)}'>{model.Quantity}</span> of the <span>{model.Product.Name}</span> at $<span class='br-{nameof(model.Price)}'>{model.Price:0.##}</span> each.</div>
</div>
";
}
// Exposes click event with strongly typed model included
private void JQRowOnClick(JQueryPlainObject sender, object e)
{
// Pass thru event from JQueryPlainObject to our strongly typed event
var ourEvent = OnClick;
if (ourEvent != null)
{
ourEvent(sender, this, e); //include strongly typed `this`/ ProductSalesRow for subscribers
}
}
public delegate void JQueryTypedEventHandler<in TSender, in TComponent, in TEventArgs>
(TSender sender, TComponent component, TEventArgs e)
where TSender : JQueryPlainObject;
// We use explicit event so that we can only create the JQuery listener when necessary
public event JQueryTypedEventHandler<JQueryPlainObject, ProductSaleRow, object> OnClick;
}
}