EnVisageOnline/Main/Source/EnVisage/Views/PeopleResource/_edit.cshtml

522 lines
24 KiB
Plaintext
Raw 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;
@model EnVisage.Models.PeopleResourceModel
@{
ViewBag.Title = !Model.IsNew ? "Edit People Resource" : "Add New People Resource";
var weekendingsNextDays = new SortedList<long, string>(ViewBag.WeekendingsNextDays as Dictionary<long, string>).ToDictionary(x => x.Key.ToString(), x => x.Value);
}
<script>
var C_EDIT_ACTION_DEACTIVATION_UNASSIGN = 1;
var C_EDIT_ACTION_DEACTIVATION_REASSIGN = 2;
var C_EDIT_ACTION_TEAM_CHANGING = 3;
var C_EDIT_ACTION_EDIT_PROPS = 4;
var datePickerOptions = {
format: 'm/d/yyyy',
autoclose: true,
startDate: '@(Constants.MIN_SELECTABLE_DATE)',
endDate: '@(Constants.MAX_SELECTABLE_DATE)'
};
// Initial status of the resource: active or inactive. And initial resource team
var isNewItem = @(Model.IsNew ? "true" : "false");
var hasCurrentTeam = @(Model.TeamId.HasValue ? "true" : "false");
var initialResourceTeamId = '@(Model.TeamId.HasValue ? Model.TeamId.Value.ToString() : "")';
var initialResourceIsActive = @(Model.IsActiveEmployee ? "true" : "false");
var weekendings = @Html.Raw(Json.Encode(weekendingsNextDays));
var editFrmModal = $("#frmEdit-peopleresource");
function initDatePickers() {
editFrmModal.find('.datepicker').datepicker(datePickerOptions);
var efcDatePickerControl = editFrmModal.find('#@Html.IdFor(model => model.EffectiveChangeDate)');
efcDatePickerControl.prop("disabled", true);
efcDatePickerControl.on('change', function (event) {
var dateAsDate = $(this).datepicker('getDate');
dateAsDate.setDate(dateAsDate.getDate() - 1); // Changes at first day of a fiscal week must start at this day
var dateAsMs = dateAsDate.getTime();
var weKeys = Object.keys(weekendings);
var index = 0;
var count = weKeys.length - 1;
var currentWe = count >= 0 ? weKeys[0] : 0;
while ((currentWe < dateAsMs) && (index < count)) {
index++;
currentWe = weKeys[index];
}
if (currentWe > 0)
{
var weAsText = weekendings[currentWe];
editFrmModal.find('#effectiveDateOfChangeText').text(weAsText);
}
else
editFrmModal.find('#effectiveChangeDateWarning').hide();
});
if (!isNewItem) {
// Effective date of change set automatically for new item
efcDatePickerControl.trigger('change');
editFrmModal.find('#effectiveChangeDateBlock').show();
}
}
function initSwitchers() {
$('input#@Html.IdFor(x => x.IsActiveEmployee)').switcher({
on_state_content: 'Active',
off_state_content: 'Inactive'
});
// Perform interactivity for the only active resource on edit
editFrmModal.find('input#@Html.IdFor(x => x.IsActiveEmployee)').switcher().on('change', function (event) {
var value = $(this).prop('checked');
var saveAction = getResourceReassignmentAction();
if (initialResourceIsActive) {
// Show or hide Reassign Action switcher
var correspondingReassignBlock = editFrmModal.find('input#@Html.IdFor(x => x.ReassignOnDeactivation)').parents(".form-group");
if (value)
correspondingReassignBlock.hide();
else
correspondingReassignBlock.show();
}
var enableEffectiveDatePicker =
((saveAction == C_EDIT_ACTION_TEAM_CHANGING) || (saveAction == C_EDIT_ACTION_DEACTIVATION_UNASSIGN) ||
(saveAction == C_EDIT_ACTION_DEACTIVATION_REASSIGN))
setEffectiveDateState(enableEffectiveDatePicker);
if (value) {
if (isNewItem) {
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("checked", true);
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", false);
}
else {
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", false);
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("checked", true);
}
}
else {
if (isNewItem) {
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("checked", false);
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", true);
}
else {
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", false);
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("checked", true);
}
}
});
editFrmModal.find('input#@Html.IdFor(x => x.ReassignOnDeactivation)').switcher({
on_state_content: 'Reassign',
off_state_content: 'Unassign'
});
editFrmModal.find('input#@Html.IdFor(x => x.IsActiveEmployee)').parent().css("width", "80px");
editFrmModal.find('input#@Html.IdFor(x => x.ReassignOnDeactivation)').parent().css("width", "80px");
}
function initSelects() {
editFrmModal.find('select').select2();
editFrmModal.find('#@Html.IdFor(x => x.TeamId)').on('change', function (event) {
var saveAction = getResourceReassignmentAction();
var enableEffectiveDatePicker =
((saveAction == C_EDIT_ACTION_TEAM_CHANGING) || (saveAction == C_EDIT_ACTION_DEACTIVATION_UNASSIGN) ||
(saveAction == C_EDIT_ACTION_DEACTIVATION_REASSIGN))
setEffectiveDateState(enableEffectiveDatePicker);
});
if (!isNewItem)
{
// Block Expenditure Category change for existing resource record
editFrmModal.find('#@Html.IdFor(x => x.ExpenditureCategoryId)').select2('disable');
}
}
function initPeopleResourceEditForm() {
initDatePickers();
initSwitchers();
initSelects();
var isNew = @Model.IsNew.ToString().ToLower();
if (!isNew) {
$('#editPeopleResourceModal').on('hidden.bs.modal', function () {
StopEdit();
RemoveLock("PeopleResource", "@Model.Id");
});
}
//todo: this code not functionlity
@*editFrmModal.find('#@Html.IdFor(x => x.PermanentResource)').on('change', function (event) {
var value = $(this).prop('checked');
var endDateControl = $('#@Html.IdFor(x => x.EndDate)');
var endDateValue = endDateControl.val();
});*@
@if (!Model.IsNew)
{
<text>
StartEdit('PeopleResource', '@Model.Id', null, "#btnsave-peopleresource", "errorMsgPlaceholder-peopleresource");
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", true);
</text>
}
if (editFrmModal.find("#@Html.IdFor(t => t.PermanentResource)").prop("checked") == true)
$("#enddaterow").hide();
editFrmModal.find("#@Html.IdFor(model => model.FirstName)").autocomplete({
source: '@Url.Action("PeopleResourceFNameSearch", "PeopleResource")',
minLength: 1,
select: function (evt, ui) {
$.ajax({
type: "get",
data: { name: ui.item.value },
url: siteRoot + "/PeopleResource/PeopleResourceFullRecord",
async: false,
error: function (response) {
ShowPopover($("#@Html.IdFor(model => model.FirstName)"), serverErrorText);
result = false;
},
success: function (data) {
editFrmModal.find("#@Html.IdFor(model => model.FirstName)").val( data.FirstName).change();
editFrmModal.find("#@Html.IdFor(model => model.LastName)").val(data.LastName).change();
editFrmModal.find("#@Html.IdFor(model => model.StartDate)").val(data.StartDate).change();
editFrmModal.find("#@Html.IdFor(model => model.EndDate)").val(data.EndDate).change();
editFrmModal.find("#@Html.IdFor(model => model.ExpenditureCategoryId)").val(data.ExpenditureCategoryId).change().change();
editFrmModal.find("#@Html.IdFor(model => model.Id)").val(data.Id).change();
editFrmModal.find("#@Html.IdFor(model => model.IsNew)").val(false).change();
editFrmModal.find("#@Html.IdFor(model => model.EmployeeID)").val(data.EmployeeID).change();
editFrmModal.find("#@Html.IdFor(model => model.EmailAddress)").val(data.EmailAddress).change();
}
});
return false;
}
});
}
function activatePlannedCapacityChange() {
if (!isNewItem && editFrmModal.find("#@Html.IdFor(t => t.IsActiveEmployee)").prop("checked") == true) {
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("disabled", false);
editFrmModal.find("#@Html.IdFor(t => t.ChangeCapacity)").prop("checked", "checked");
}
}
editFrmModal.find("#@Html.IdFor(t => t.ExpenditureCategoryId)").change(activatePlannedCapacityChange);
editFrmModal.find("#@Html.IdFor(t => t.TeamId)").change(activatePlannedCapacityChange);
editFrmModal.find("#@Html.IdFor(t => t.StartDate)").change(activatePlannedCapacityChange);
editFrmModal.find("#@Html.IdFor(t => t.EndDate)").change(activatePlannedCapacityChange);
editFrmModal.find("#@Html.IdFor(t => t.PermanentResource)").change(function () {
activatePlannedCapacityChange();
if ($(this).prop("checked") == true)
editFrmModal.find("#enddaterow").hide();
else
editFrmModal.find("#enddaterow").show();
});
//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();
}
});
};
$('#btnsave-peopleresource').click(function () {
var saveAction = getResourceReassignmentAction();
if ($("#frmEdit-peopleresource").valid()) {
if (!isNewItem && hasCurrentTeam && (saveAction == C_EDIT_ACTION_DEACTIVATION_REASSIGN || saveAction == C_EDIT_ACTION_TEAM_CHANGING)) {
// Loading resource reassignment form
blockUI();
// We get from datepicker date with no time component, but in local time zone.
// We should take date components and create UTC date for these year, month and date.
var effectiveDateAsDate = editFrmModal.find('#@(Html.IdFor(model => model.EffectiveChangeDate))').datepicker('getDate');
var year = effectiveDateAsDate.getFullYear();
var month = effectiveDateAsDate.getMonth();
var day = effectiveDateAsDate.getDate();
var effectiveDateAsMs = Date.UTC(year, month, day);
var formAction = saveAction;
var destTeamId = editFrmModal.find('#@Html.IdFor(x => x.TeamId)').val();
var data2send = {
id: '@Model.Id',
date: effectiveDateAsMs,
action: formAction,
newTeamId: destTeamId
}
$('#modalResourceReassign').off('hide.bs.modal').off('shown.bs.modal');
$('#reassignResourceReload').html("");
$.ajax({
url: '@Url.Action("DisplayResourceReassignForm", "PeopleResource")',
cache: false,
dataType: "html",
data: data2send,
type: "post",
success: function (data) {
if (data && (data.length > 0))
{
$('#reassignResourceReload').html(data);
var frmRoot = $("#modalResourceReassign");
if (typeof initReasourceReassignForm === 'function')
initReasourceReassignForm(frmRoot, saveAction);
unblockUI();
$('#modalResourceReassign').modal('show');
}
else
{
// No project to perform reassignment was found
unblockUI();
savePeopleResource();
}
}
});
}
else
{
// Resource properties changed only. Saving without any additional questions
savePeopleResource();
}
}
});
function savePeopleResource(reassignmentPlan) {
$('#modalResourceReassign').modal('hide');
if ($("#frmEdit-peopleresource").valid()) {
blockUI();
var values = $("#frmEdit-peopleresource").serializeArray() || [];
if (reassignmentPlan && $.isArray(reassignmentPlan)){
values = values.concat(reassignmentPlan);
}
$.post('@Url.Action("Edit", "PeopleResource")', values, onPeopleResourceEditSuccess)
.fail(function() { showErrorModal(); })
.always(unblockUI);
}
}
function setEffectiveDateState(enabled) {
$('#@Html.IdFor(x => x.EffectiveChangeDate)').prop("disabled", !enabled);
if (enabled)
editFrmModal.find('#effectiveChangeDateWarning').show();
else
editFrmModal.find('#effectiveChangeDateWarning').hide();
}
// Returns changes for current editable resource, performed by user in context of allocations reassignment
function getResourceReassignmentAction() {
var isActiveControl = editFrmModal.find('#@Html.IdFor(x => x.IsActiveEmployee)');
var allocationsControl = editFrmModal.find('#@Html.IdFor(x => x.ReassignOnDeactivation)');
var teamControl = editFrmModal.find('#@Html.IdFor(x => x.TeamId)');
var currentIsActiveStatus = isActiveControl.prop("checked");
var currentAllocationsStatus = allocationsControl.prop("checked");
var currentTeamId = teamControl.val();
if (!isNewItem && initialResourceIsActive == true && initialResourceIsActive != currentIsActiveStatus) {
return currentAllocationsStatus ? C_EDIT_ACTION_DEACTIVATION_REASSIGN : C_EDIT_ACTION_DEACTIVATION_UNASSIGN;
}
if (!isNewItem && initialResourceTeamId != currentTeamId) {
return C_EDIT_ACTION_TEAM_CHANGING;
}
return C_EDIT_ACTION_EDIT_PROPS;
}
function onPeopleResourceEditSuccess(data, status, xhr) {
var isJson = xhr.responseJSON != null;
var isValid = $.isFunction(data.indexOf) && data.indexOf("field-validation-error") < 0;
if(!isJson && !isValid) {
$("#editPeopleResourceForm").html(data);
$.validator.unobtrusive.parseDynamicContent('#editPeopleResourceForm form');
initPeopleResourceEditForm();
return;
}
var isNew = @Model.IsNew.ToString().ToLower();
if (!isNew) {
StopEdit();
RemoveLock("PeopleResource", "@Model.Id");
}
var $addMore = editFrmModal.find('#@Html.IdFor(model => model.AddMore)');
if($addMore.length == 0 || !$addMore[0].checked) {
$("#editPeopleResourceModal").modal("hide");
} else {
var url = '@Url.Action("Edit", "PeopleResource", new { teamId = Request.QueryString["teamId"] })';
$("#editPeopleResourceForm").load(url, function(e1, e2, e3) {
$.validator.unobtrusive.parseDynamicContent("#editPeopleResourceForm form");
initPeopleResourceEditForm();
});
}
if (typeof loadTeamResourcesData === "function") {
setTimeout(loadTeamResourcesData, 0);
}
if (typeof loadActivityCalendar === "function") {
setTimeout(loadActivityCalendar, 0, 'resourceEdited', data);
}
if(typeof loadCapacityPlanner === "function") {
setTimeout(loadCapacityPlanner, 0);
}
if(typeof refreshPeopleResourceInfo === "function") {
refreshPeopleResourceInfo();
}
}
</script>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">@ViewBag.Title</h4>
</div>
<form id="frmEdit-peopleresource" class="form-horizontal">
<div class="modal-body">
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.IsNew)
<div class="panel-body">
<div id="errorMsgPlaceholder-peopleresource"></div>
<div class="alert alert-warning" id="effectiveChangeDateWarning" style="display: none;">
Reminder: PREVU works on weekly assignments for your team members. This change will be effective at the start of the next work week on <span id="effectiveDateOfChangeText">DATE</span>
</div>
<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">
@Html.LabelFor(model => model.EmployeeID, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.TextBoxFor(model => model.EmployeeID, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.EmployeeID)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EmailAddress, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.TextBoxFor(model => model.EmailAddress, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.EmailAddress)
</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" })
@if (Model.TeamChangeQueued != null)
{
<i>From @(Model.TeamChangeQueued.ChangeDate.ToShortDateString()) this resource will be a member of the Team '@(Model.TeamChangeQueued.Name)'</i>
}
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Number">Work Week</label>
<div class="col-sm-9">
@Html.DropDownListFor(model => model.WorkWeekId, (IEnumerable<SelectListItem>)ViewBag.WorkWeeks, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.Label("Employee Status", 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" style="display: none;">
@Html.Label("On Deactivation", new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.CheckBoxFor(model => model.ReassignOnDeactivation, new { @class = "switcher" })
@Html.ValidationMessageFor(model => model.ReassignOnDeactivation)
</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>(allows to keep planned capacity up to date after changes; when category or team changed, changes planned capacity for both categories/teams)</i>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Permanent</label>
<div class="col-sm-9">
<div class="checkbox">
@Html.CheckBoxFor(model => model.PermanentResource)
</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>
<div class="form-group" id="effectiveChangeDateBlock" style="display:none;">
@Html.LabelFor(model => model.EffectiveChangeDate, new { @class = "col-sm-3 control-label" })
<div class="col-sm-9">
@Html.EditorFor(model => model.EffectiveChangeDate, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.EffectiveChangeDate)
</div>
</div>
@Html.ValidationSummary(false, "The People Resource 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">
@if (Model.IsNew)
{
<div style="display: inline-block; margin-left: 10px; vertical-align: middle;">
@Html.CheckBoxFor(model => model.AddMore)
<label for="@Html.IdFor(model => model.AddMore)" style="vertical-align: top;">@Html.DisplayNameFor(model => model.AddMore)</label>
</div>
}
</div>
</div>
</div>
</div>
<div class="modal-footer" style="margin-bottom: 0;">
<div class="col-sm-offset-3 col-sm-9">
<button type="button" class="btn btn-success" id="btnsave-peopleresource"><i class="fa fa-save"></i> Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</form>
<div id="modalResourceReassign" class="modal fade" tabindex="-1" data-width="860" role="dialog" data-backdrop="static">
<div class="modal-content" id="reassignResourceReload">
</div>
</div>