EnVisageOnline/Main-RMO/Source/EnVisage/Views/Mix/_mixTeams.cshtml

299 lines
12 KiB
Plaintext

@model EnVisage.Models.TeamModel
@using EnVisage.Code.HtmlHelpers
@using Microsoft.AspNet.Identity
@using EnVisage.Code
@{
ViewBag.Title = !ViewBag.IsNewTeam ? "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;
}
var isNewTeam = @(ViewBag.IsNewTeam ? "true" : "false");
$('#CopyPlanned').switcher({
on_state_content: 'Planned',
off_state_content: 'Actual'
});
$('#CopyPlanned').parent().css("width", "80px");
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 initTeam() {
@* if (!isNewTeam) {
StartEdit('Team', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
}*@
$("#@Html.ClientIdFor(model=>model.ReportToId)").select2({
allowClear: true,
placeholder: "Select"
});
$("#@Html.ClientIdFor(model=>model.CapacityTeamId)").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 (!isNewTeam) {
StartEdit('Team', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
}*@
$('#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();
});
}
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;
}
$(document).ready(function () {
loadWidget('@Guid.Empty.ToString()', $('#CopyPlanned').val());
$('#modalbtn').on('click', function () {
if (teamEditFormIsValid()){
resetTeamDataChanged();
var scope = angular.element(document.getElementById('mixHeader')).scope();
scope.convertTeam();
$('#editTeam').modal('hide');
}
});
});
function teamEditFormIsValid() {
$.validator.unobtrusive.parseDynamicContent('#editTeamForm');
return $('#editTeamForm').valid();
};
function loadWidget(TeamId, planned) {
$.ajax({
url: '/Team/GetCapacitySimpleMode',
type: 'post',
data: { teamId: TeamId, planned: planned },
success: function (data) {
var categories = [];
for (var index = 0; index < data.data.length; index++) {
var catItem = {
Id: data.data[index].Id,
Name: data.data[index].Name,
InPlan: data.data[index].InPlan,
}
categories.push(catItem);
}
$("#team-container").capacityPlanner({
teamId: TeamId,
expenditureCategories: categories,
dataTableRenderingCallback: onDataTableBeforeRendering,
dataTableRenderedCallback: onDataTableRendered,
});
$("#team-container").capacityPlanner('setData', data);
$("#team-container").capacityPlanner('renderTable');
},
error: function (ret) {
showErrorModal("@(EnVisage.Code.Constants.ERROR_GENERAL_TITLE_TEMPLATE)", ret.statusText)
}
});
}
function onDataTableBeforeRendering() {
blockUI();
}
function onDataTableRendered() {
unblockUI();
}
$("#@Html.ClientIdFor(model=>model.CapacityTeamId)").on('change', function () {
var sourceTeamId = $("#@Html.ClientIdFor(model=>model.CapacityTeamId)").val();
var isPlannedData = $('#CopyPlanned').val();
if (sourceTeamId && (sourceTeamId.length > 0)) {
bootbox.confirm("Are you sure you want to load capacity from selected team and loose previously entered data?", function (result) {
if (result) loadWidget(sourceTeamId, isPlannedData);
});
}
else {
bootbox.confirm("Are you sure you want to reset all previously entered data?", function (result) {
if (result) loadWidget('@Guid.Empty.ToString()', isPlannedData);
});
}
});
$("#@Html.ClientIdFor(model=>model.CopyPlanned)").on('change', function () {
var sourceTeamId = $("#@Html.ClientIdFor(model=>model.CapacityTeamId)").val();
var isPlannedData = $('#CopyPlanned').val();
if (sourceTeamId && (sourceTeamId.length > 0)) {
bootbox.confirm("Are you sure you want to load capacity from selected team and loose previously entered data?", function (result) {
if (result) loadWidget(sourceTeamId, isPlannedData);
});
}
});
</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.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>
<div class="row">
<div class="col-sm-6">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.CapacityTeamId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.CapacityTeamId, Utils.GetTeamsAvailableForUser(Guid.Parse(User.Identity.GetID()), true, true), new { @class = "form-control forselect2" })
@Html.ValidationMessageFor(model => model.CapacityTeamId)
</div>
</div>
<div class="col-sm-6">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.CopyPlanned, new { @class = "control-label" })<br />
@Html.CheckBoxFor(model => model.CopyPlanned, new { @class = "switcher" })
@Html.ValidationMessageFor(model => model.CopyPlanned)
</div>
</div>
</div>
<h4>Capacity</h4>
<div class="table-light table-responsive" id="team-container">
@{
Html.RenderPartial("~/Views/CapacityManagement/_capacityPlanning.cshtml", Guid.Empty);
}
</div>
@Html.ValidationSummary(false, "The Team could not be saved due to the following errors:")
</div> <!-- / .modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-success" id="modalbtn" ><i class="fa fa-save"></i> Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
}