Index.cshtml
2.9 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
@using CWA.CpoOnline.Models
@using GridMvc.Html
@model List<SectorViewModel>
@{
ViewBag.Title = "Manage Sectors";
}
<h3><i class="fa fa-folder"></i> @ViewBag.Title</h3>
<div class="card mb-2">
<div class="card-body">
<div class="row">
<div class="col text-lg">
<b>Total Sectors :</b>
@Model.Count()
</div>
<div class="col-auto">
<a class="btn btn-success" href="@Url.Action("add")"><i class="fa fa-plus-circle"></i> Add Sector</a>
</div>
</div>
</div>
</div>
<div class="table-cpo">
@Html.Grid(Model.OrderBy(s=>s.Name)).Columns(columns =>
{
columns.Add(row => row.Name).Titled("Sector");
columns.Add().RenderValueAs(row => SymbolLink(row)).Encoded(false).Sanitized(false).Titled("Symbols");
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 SymbolLink(SectorViewModel sector)
{
var count = sector.Symbols.Count;
var symbolText = (count > 1) ? "symbols": "symbol";
<a href="@Url.Action("index","symbols")?id=@sector.Id">@count @symbolText</a>
}
@helper Controls(SectorViewModel sector)
{
<a class="btn btn-xs btn-secondary"
data-target="#deleteModal"
href="#"
data-href="@Url.Action("delete", new {id = sector.Id})"
data-toggle="modal"
data-deleteid="@sector.Id"><span class="fa fa-trash-o"></span></a>
<span class="d-none" id="deleteText_@sector.Id">@sector.Name</span>
<a class="btn btn-xs btn-secondary" title="Edit Sector" href="@Url.Action("edit","sectors", new { id = sector.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 Sector</a>
</div>
</div>
</div>
</div>
@section scripts{
<script>
$("#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>
}