EnVisageOnline/Beta/Source/EnVisage/Views/PeopleResource/Edit.cshtml

275 lines
12 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@using EnVisage.Code.HtmlHelpers
@model EnVisage.Models.PeopleResourceModel
@{
ViewBag.Title = Model.Id != Guid.Empty ? "Edit People Resource" : "Add New People Resource";
}
@{
var projects = EnVisage.Code.Utils.GetResourceProjects(Model.Id, User.Identity.Name);
}
@section Scripts
{
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script type="text/javascript">
init.push(function () {
$('input#@Html.ClientIdFor(x => x.IsActiveEmployee)').switcher({
on_state_content: 'Active',
off_state_content: 'Inactive'
});
$('input#@Html.ClientIdFor(x => x.IsActiveEmployee)').parent().css("width", "80px");
$('.datepicker').datepicker();
@if (Model.Id != Guid.Empty)
{
<text>
StartEdit('PeopleResource', '@Model.Id', null, "#btnsave", "erorMsgPlaceholder");
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", true);
</text>
}
if ($("#@Html.ClientIdFor(t => t.FullTimeResource)").prop("checked") == true)
$("#enddaterow").hide();
});
$("#@Html.ClientIdFor(t => t.FullTimeResource)").change(function () {
if ($(this).prop("checked") == true)
$("#enddaterow").hide();
else
$("#enddaterow").show();
});
$("#@Html.ClientIdFor(t => t.IsActiveEmployee)").change(function () {
if ($(this).prop("checked") == true) {
if ($("#@Html.ClientIdFor(t => t.Id)").val() == '00000000-0000-0000-0000-000000000000') {
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("checked", true);
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", false);
}
else {
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", false);
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("checked", true);
// $('#capacitylabel').text('(will increase planned capacity by expenditure category\'s UoM value)');
}
}
else {
if ($("#@Html.ClientIdFor(t => t.Id)").val() == '00000000-0000-0000-0000-000000000000') {
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("checked", false);
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", true);
}
else {
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", false);
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("checked", true);
//$('#capacitylabel').html('(will decrease planned capacity by expenditure category\'s UoM value)');
}
}
});
$("#@Html.ClientIdFor(t => t.ExpenditureCategoryId)").change(function () {
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("disabled", false);
$("#@Html.ClientIdFor(t => t.ChangeCapacity)").prop("checked", "checked");
//$('#capacitylabel').text('(when category changed, changes planned capacity for both categories)');
});
</script>
<script type="text/javascript">
//fix modal force focus
$.fn.modal.Constructor.prototype.enforceFocus = function () {
var that = this;
$(document).on('focusin.modal', function (e) {
if ($(e.target).hasClass('select2-input')) {
return true;
}
if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
that.$element.focus();
}
});
};
init.push(function () {
$(".forselect2").each(function (i, e) {
$(e).select2({
allowClear: true,
placeholder: "Select resource",
});
});
});
function submitReassign() {
blockUI();
var form = $('#frmReassign');
var form1 = $('#frmEdit');
$.ajax({
cache: false,
async: true,
type: "POST",
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
form1.submit();
}
});
}
$('#btnsave').click(function () {
if ($(this).parents('form').valid()) {
if (!$("#@Html.ClientIdFor(t => t.IsActiveEmployee)").prop("checked") && '@projects.Count()' != '0') {
$('#modalProjectAssign').modal();
}
else
{
blockUI();
$('#frmEdit').submit();
}
}
});
</script>
}
<div id="erorMsgPlaceholder"></div>
@using (Html.BeginForm("Edit", "PeopleResource", FormMethod.Post, new { @class = "panel form-horizontal", id = "frmEdit" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
<div class="panel-body">
<div class="form-group">
@Html.LabelFor(model => model.FirstName, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.FirstName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastName, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.LastName)
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Number">Expenditure Category</label>
<div class="col-sm-9">
@Html.DropDownListFor(model => model.ExpenditureCategoryId, (IEnumerable<SelectListItem>)ViewBag.ExpendituresList, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ExpenditureCategoryId)
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Number">Team</label>
<div class="col-sm-9">
@Html.DropDownListFor(model => model.TeamId, (IEnumerable<SelectListItem>)ViewBag.TeamsList, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IsActiveEmployee, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.CheckBoxFor(model => model.IsActiveEmployee, new { @class = "switcher" })
@Html.ValidationMessageFor(model => model.IsActiveEmployee)
</div>
</div>
<div class="form-group">
<label class = "col-sm-3 control-label">Change planned capacity</label>
<div class="col-sm-9">
<div class="checkbox">
@Html.CheckBoxFor(model => model.ChangeCapacity)
<i>(when category changed, changes planned capacity for both categories; when state changed, allows to maintain planned capacity)</i>
@*@if (Model.Id == Guid.Empty)
{
<i>(will increase planned capacity by expenditure category's UoM value)</i>
}
else
{
<i id="capacitylabel">(when category changed, changes planned capacity for both categories)</i>
}*@
</div>
</div>
</div>
<div class="form-group">
<label class = "col-sm-3 control-label">Full time</label>
<div class="col-sm-9">
<div class="checkbox">
@Html.CheckBoxFor(model => model.FullTimeResource)
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.StartDate, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.EditorFor(model => model.StartDate, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
</div>
<div class="form-group" id="enddaterow">
@Html.LabelFor(model => model.EndDate, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.EditorFor(model => model.EndDate, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.EndDate)
</div>
</div>
@Html.ValidationSummary(false, "The Scenario could not be saved due to the following errors:")
<div class="form-group" style="margin-bottom: 0;">
<div class="col-sm-offset-3 col-sm-9">
<a class="btn btn-primary" href="@Url.Action("Board", "Team")"><i class="fa fa-backward"></i> Back to people resources</a>
@if (Model.Id != Guid.Empty)
{
<a class="btn btn-primary" href="@Url.Action("Details", "PeopleResource", new { resourceId = Model.Id })"><i class="fa fa-backward"></i> Back to people resource details</a>
}
<button type="button" class="btn btn-success" id="btnsave"><i class="fa fa-save"></i> Save</button>
@if (Model.Id == Guid.Empty)
{
<div style="display: inline-block; margin-left: 10px; vertical-align: middle;">
@Html.CheckBoxFor(model => model.AddMore)
<label for="@Html.ClientIdFor(model => model.AddMore)" style="vertical-align: top;">@Html.DisplayNameFor(model => model.AddMore)</label>
</div>
}
</div>
</div>
</div>
}
@using (Html.BeginForm("Reassign", "PeopleResource", FormMethod.Post, new {id = "frmReassign" }))
{
<div id="modalProjectAssign" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Assign Resources</h4>
</div>
<div class="modal-body" style="padding: 0 15px;">
<div class="panel-body form-horizontal">
<p>
This people resource is assigned to one or more projects.
Inactive resources cannot be assigned to projects, please reassign the following projects to other resources.
Please note that you can only choose resources from teams that project is already assigned to.
</p>
@foreach (var project in projects)
{
<div class="form-group">
<label class = "col-sm-5 control-label">@project.Name</label>
<div class="col-sm-7">
@Html.DropDownList(project.Id.ToString(), EnVisage.Code.Utils.GetSubstituteResources(User.Identity.Name, Model.Id, Model.ExpenditureCategoryId, project.Id), new { @class = "form-control forselect2", @id = project.Id.ToString() })
@Html.ValidationMessageFor(model => model.SubstituteResources)
</div>
</div>
}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="submitReassign()" >Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
<!-- / .modal-content -->
</div>
<!-- / .modal-dialog -->
</div>
}