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

167 lines
6.5 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 + "'";
}
<script type="text/javascript">
var _viewDataChanged = false;
function onViewDataChanged() {
_viewDataChanged = true;
}
function resetViewDataChanged() {
_viewDataChanged = false;
}
function isViewDataChanged() {
return _viewDataChanged;
}
emulateNavUrl = "/View";
function fillSelect2(multik, preselected) {
var selected = [];
if (preselected != null)
selected = preselected;
else {
}
multik.select2('val', selected);
}
</script>
<script type="text/javascript">
//init.push(function () {
function initView() {
@*$(".formultiselect2").each(function (i, e) {
if ($(e).attr("id") != "@Html.ClientIdFor(model=>model.UserId)" && $(e).attr("id") != "@Html.ClientIdFor(model=>model.TeamId)") {
$(e).remove();
}
});*@
//var caption = ($(this).attr("id") == "@Html.ClientIdFor(model=>model.TeamId)" ? "Select teams" : "Select watchers");
$("#@Html.ClientIdFor(model=>model.TeamId)").select2({
allowClear: true,
placeholder: "Select teams"
});
$("#@Html.ClientIdFor(model=>model.UserId)").select2({
allowClear: true,
placeholder: "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();
});
$('#editViewForm').find('input[type=checkbox],input[type=text],select,textarea').on("change", function () {
if (typeof onViewDataChanged === 'function')
onViewDataChanged();
});
}
function onFailure(xhr) {
unblockUI();
$('#editReload').html(xhr.responseText);
initView();
}
function onSuccess(data) {
unblockUI();
var href = document.location.href;
if (href.substr(href.length - 1) == '#')
href = href.substr(0, href.length - 1);
if (href.indexOf('?') > 0)
href = href.substr(0, href.indexOf('?'));
document.location.href = URI(href).setQuery("viewId", data['viewId']);
}
</script>
<div id="erorMsgPlaceholder"></div>
@using (Ajax.BeginForm("Edit", "View", new AjaxOptions { HttpMethod = "Post", OnSuccess = "onSuccess", OnFailure = "onFailure(xhr)", UpdateTargetId = "editReload" }, new { @id = "editViewForm" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(t => t.Id)
@Html.HiddenFor(t => t.backController)
@Html.HiddenFor(t => t.backAction)
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title" >@(Model.Id != Guid.Empty ? "Edit " + Model.Name : "Add View")</h4>
</div>
<div class="modal-body">
<div class="row">
<!--Row1-->
<div class="col-sm-12">
<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-12">
<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.TeamId)
</div>
</div>
</div>
<div class="row">
<!--Row3-->
<div class="col-sm-12">
<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.FirstName + " " + x.LastName }).ToList() })
@Html.ValidationMessageFor(model => model.UserId)
</div>
</div>
</div>
@Html.ValidationSummary(false, "The View could not be saved due to the following errors:")
</div> <!-- / .modal-body -->
<div class="modal-footer">
<a style="display:none;" 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 style="display:none;" id="btnDelete" class="btn btn-danger disabled" href="javascript:void(0);"><i class="fa fa-trash-o"></i> Delete</a>
}
else
{
<a style="display:none;" id="btnDelete" class="btn btn-danger" href="@Url.Action("Delete", "View", new { @id = Model.Id })"><i class="fa fa-trash-o"></i> Delete</a>
}
}
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
}