Index.cshtml 3.55 KB
@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">
				&nbsp;<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>

}