Index.cshtml
3.55 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
@using CWA.CpoOnline.Models
@using GridMvc.Html
@model List<SectorViewModel>
@{
ViewBag.Title = "Manage Symbols";
string activeSectorId = ViewBag.ActiveSectorId ?? "0";
List<SymbolViewModel> allSymbols = ViewBag.AllSymbols;
}
<h3><i class="fa fa-star"></i> @ViewBag.Title</h3>
@using (Html.BeginForm("index", "symbols", FormMethod.Get, new { id="symbolsForm", @class = "", role = "form" }))
{
<div class="card mb-2">
<div class="card-body">
<div class="row">
<div class="col-12 col-md-auto text-lg">
<label for="sectorList" class="form-control-label"><b>Sectors :</b></label>
</div>
<div class="col">
<select class="form-control" id="sectorList" name="id">
<option value="0">All (@allSymbols.Count)</option>
@foreach (var sector in Model.OrderBy(s => s.Name))
{
if (activeSectorId.Equals(sector.Id))
{
<option selected="selected" value="@sector.Id">@sector.Name (@sector.Symbols.Count)</option>
}
else
{
<option value="@sector.Id">@sector.Name (@sector.Symbols.Count)</option>
}
}
</select>
</div>
<div class="col-12 col-md-auto mt-2 mt-md-0">
<a class="btn btn-success" href="@Url.Action("add")"><i class="fa fa-plus-circle"></i> Add Symbol</a>
</div>
</div>
</div>
</div>
}
<div class="table-cpo">
@Html.Grid(allSymbols).Columns(columns =>
{
columns.Add(row => row.Symbol).Titled("Symbol");
columns.Add(row => row.Name).Titled("Name");
columns.Add().RenderValueAs(row => Controls(row)).Encoded(false).Sanitized(false).Css("col-auto text-right").SetWidth(90);
}).WithPaging(50).Sortable(true).Filterable(true).WithMultipleFilters()
</div>
@helper Controls(SymbolViewModel symbol)
{
<a class="btn btn-xs btn-secondary"
data-target="#deleteModal"
href="#"
data-href="@Url.Action("delete", new {id = symbol.Id})"
data-toggle="modal"
data-deleteid="@symbol.Id"><span class="fa fa-trash-o"></span></a>
<span class="d-none" id="deleteText_@symbol.Id">@symbol.Symbol - @symbol.Name</span>
<a class="btn btn-xs btn-secondary" title="Edit Symbol" href="@Url.Action("edit","symbols", new { id = symbol.Id })">Edit</a>
}
@* Modal Delete Window *@
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Confirm Delete
</div>
<div class="modal-body">
<b class="modal-deletetext"></b>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<a class="btn btn-danger btn-delete">Delete Symbol</a>
</div>
</div>
</div>
</div>
@section scripts{
<script>
$("#sectorList").change(UpdateSector);
function UpdateSector() {
$("#symbolsForm").submit();
}
$("#deleteModal").on("show.bs.modal",
function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var deleteId = button.data("deleteid"); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this);
var $deleteText = $("#deleteText_" + deleteId).text();
console.log(deleteId);
console.log($deleteText);
modal.find('.modal-deletetext').text($deleteText);
modal.find('.btn-delete').attr('href', $(event.relatedTarget).data('href'));
});
</script>
}