EnVisageOnline/Main-RMO/Source/EnVisage/Views/View/Edit.cshtml

123 lines
5.0 KiB
Plaintext

@model EnVisage.Models.ViewModel
@using EnVisage.Code.HtmlHelpers
@using Microsoft.AspNet.Identity
@using EnVisage.Code
@{
ViewBag.Title = Model.Id != Guid.Empty ? "Edit " + Model.Name : "Add View";
var teams = string.Join("','", Model.TeamId == null ? new List<Guid>() : Model.TeamId);
teams = "'" + teams + "'";
var watchers = string.Join("','", Model.UserId == null ? new List<Guid>() : Model.UserId);
watchers = "'" + watchers + "'";
}
@section Scripts
{
<script type="text/javascript">
emulateNavUrl = "/View";
function fillSelect2(multik, preselected) {
var selected = [];
if (preselected != null)
selected = preselected;
else {
}
multik.select2('val', selected);
}
init.push(function () {
$(".formultiselect2").each(function (i, e) {
$(e).select2({
allowClear: true,
placeholder: $(this).attr("id") == "@Html.ClientIdFor(model=>model.TeamId)" ? "Select teams" : "Select watchers"
});
});
var teams = [@Html.Raw(teams)];
fillSelect2($("#@Html.ClientIdFor(model=>model.TeamId )"), teams);
var watchers = [@Html.Raw(watchers)];
fillSelect2($("#@Html.ClientIdFor(model=>model.UserId)"), watchers);
@if (Model.Id != Guid.Empty)
{
<text>
StartEdit('View', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
</text>
}
$('#btnsave').click(function () {
if ($(this).parents('form').valid())
blockUI();
});
});
</script>
}
<div id="erorMsgPlaceholder"></div>
@using (Html.BeginForm("Edit", "View", FormMethod.Post, new { @class = "panel form-horizontal" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(t => t.Id)
@Html.HiddenFor(t => t.backController)
@Html.HiddenFor(t => t.backAction)
<div class="panel-body">
@*<fieldset id="fsBasic">*@
<legend class="text-bold small-bottom-margin">@(Model.Id != Guid.Empty ? "Edit " + Model.Name : "Add View")</legend>
<div class="row">
<!--Row1-->
<div class="col-sm-7 col-lg-5">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.Name, new { @class = "control-label" })
@Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name)
</div>
</div>
</div>
<div class="row">
<!--Row2-->
<div class="col-sm-7 col-lg-5">
<div class="form-group no-margin-hr select2-primary">
@Html.LabelFor(model => model.TeamId, new { @class = "control-label" })
@Html.EditorFor(model => model.TeamId, string.Empty, new { List = Utils.GetTeamsAvailableForUser(Guid.Parse(User.Identity.GetID())) })
@Html.ValidationMessageFor(model => model.UserId)
</div>
</div>
</div>
<div class="row">
<!--Row3-->
<div class="col-sm-7 col-lg-5">
<div class="form-group no-margin-hr select2-primary">
@Html.LabelFor(model => model.UserId, new { @class = "control-label" })
@Html.EditorFor(model => model.UserId, string.Empty, new { List = Model.Users.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.UserName }).ToList() })
@Html.ValidationMessageFor(model => model.UserId)
</div>
</div>
@Html.ValidationSummary(false, "The View could not be saved due to the following errors:")
<div class="form-group" style="margin-bottom: 0;">
<div class="col-sm-offset-1 col-sm-7 col-lg-5">
<a class="btn btn-primary" href="@Url.Action(string.IsNullOrEmpty( Model.backAction) ? "Index" : Model.backAction, string.IsNullOrEmpty(Model.backController) ? "View": Model.backController)"><i class="fa fa-backward"></i> Back to list</a>
<button type="submit" class="btn btn-success" id="btnsave"><i class="fa fa-save"></i> Save</button>
@if (Model != null && Model.Id != Guid.Empty)
{
if (Model.TeamCount > 0)
{
<a id="btnDelete" class="btn btn-danger disabled" href="javascript:void(0);"><i class="fa fa-trash-o"></i> Delete</a>
}
else
{
<a id="btnDelete" class="btn btn-danger" href="@Url.Action("Delete", "View", new { @id = Model.Id })"><i class="fa fa-trash-o"></i> Delete</a>
}
}
</div>
</div>
<div><span class="h1">&nbsp;</span></div>
<div><span class="h1">&nbsp;</span></div>
</div>
</div>
}