EnVisageOnline/Main-RMO/Source/EnVisage/Views/Team/_editTeam.cshtml

179 lines
7.1 KiB
Plaintext

@model EnVisage.Models.TeamModel
@using EnVisage.Code.HtmlHelpers
@using EnVisage.Code
@{
ViewBag.Title = Model != null ? "Edit " + Model.Name : "Add Team";
var contributors = string.Join("','", Model.UserId == null ? new List<Guid>() : Model.UserId);
contributors = "'" + contributors + "'";
}
<script type="text/javascript">
var _teamDataChanged = false;
function onTeamDataChanged() {
_teamDataChanged = true;
}
function resetTeamDataChanged() {
_teamDataChanged = false;
}
function isTeamDataChanged() {
return _teamDataChanged;
}
emulateNavUrl = "/Team";
function fillSelect2(multik, preselected) {
var selected = [];
if (preselected != null)
selected = preselected;
else {
}
multik.select2('val', selected);
}
</script>
<script type="text/javascript">
function initTeam() {
StartEdit('Team', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
$("#@Html.ClientIdFor(model=>model.ReportToId)").select2({
allowClear: true,
placeholder: "Select"
});
$("#@Html.ClientIdFor(model=>model.CompanyId)").select2({
allowClear: true,
placeholder: "Select"
}).on('change', function () {
$.ajax({
url: "@Url.Action("LoadExternalContacts", "Project")",
data: { clientId: $("#@Html.ClientIdFor(model=>model.CompanyId)").val(), selectControlId: $("#@Html.ClientIdFor(model=>model.CompanyId)").id },
success: function (dt) {
var data = dt.contacts;
var markup = "<option value=''></option>";
for (var i = 0; i < data.length; i++) {
markup += "<option value=" + data[i].Id + ">" + data[i].FirstName + " " + data[i].LastName + "</option>";
}
$("#@Html.ClientIdFor(model=>model.ReportToId)").html(markup);
$("#@Html.ClientIdFor(model=>model.ReportToId)").select2("val", $("#" + dt.selectControlId).parents('.pm-container').data('ecurrentContacts'));
},
error: function (reponse) {
showErrorModal('Error.', reponse);
}
});
});
$("#@Html.ClientIdFor(model=>model.CostCenterId)").select2({
allowClear: true,
placeholder: "Select"
});
$("#@Html.ClientIdFor(model=>model.UserId)").select2({
allowClear: true,
placeholder: "Select contributors"
});
var contributors = [@Html.Raw(contributors)];
fillSelect2($("#@Html.ClientIdFor(model=>model.UserId)"), contributors);
$(".select2-input").css("min-width", "200px");
@if (Model.Id != Guid.Empty)
{
<text>
StartEdit('Team', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
</text>
}
$('#btnsave').click(function () {
if ($(this).parents('form').valid())
blockUI();
});
$('#editTeamForm').find('input[type=checkbox],input[type=text],select,textarea').on("change", function () {
if (typeof onTeamDataChanged === 'function')
onTeamDataChanged();
});
$.validator.unobtrusive.parseDynamicContent('form#editTeamForm');
}
function onFailure(xhr) {
unblockUI();
$('#editReload').html(xhr.responseText);
initTeam();
}
function onSuccess(data) {
unblockUI();
var href = document.location.href;
if (href.substr(href.length - 1) == '#')
href = href.substr(0, href.length - 1);
document.location.href = href;
}
</script>
<div id="erorMsgPlaceholder"></div>
@using (Ajax.BeginForm("Edit", "Team", new AjaxOptions { HttpMethod = "Post", OnSuccess = "onSuccess", OnFailure = "onFailure(xhr)", UpdateTargetId = "editReload" }, new { @id = "editTeamForm" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(t => t.Id)
@Html.HiddenFor(model => model.ActualCapacityScenarioId);
@Html.HiddenFor(model => model.PlannedCapacityScenarioId);
<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 Team")</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-6">
<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 class="col-sm-6">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.ReportToId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.ReportToId, Utils.GetTeamContacts(Model.CompanyId), new { @class = "form-control forselect2" })
@Html.ValidationMessageFor(model => model.ReportToId)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.CostCenterId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.CostCenterId, Utils.GetCreditDepartments(true), new { @class = "form-control forselect2" })
@Html.ValidationMessageFor(model => model.CostCenterId)
</div>
</div>
<div class="col-sm-6">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.CompanyId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.CompanyId, Utils.GetCompanies(true), new { @class = "form-control forselect2" })
@Html.ValidationMessageFor(model => model.CompanyId)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 ">
<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.OrderBy(x=>x.LastName).Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.FirstName + " " + x.LastName }).ToList() })
@Html.ValidationMessageFor(model => model.UserId)
</div>
</div>
<div class="col-sm-6"></div>
</div>
@Html.ValidationSummary(false, "The Team could not be saved due to the following errors:")
</div> <!-- / .modal-body -->
<div class="modal-footer">
<button type="submit" class="btn btn-success" id="btnsave"><i class="fa fa-save"></i> Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
}