EnVisageOnline/Main-RMO/Source/EnVisage/Views/Scenarios/_generalStep.cshtml

240 lines
11 KiB
Plaintext

@using EnVisage.Code
@using EnVisage.Models
@using Microsoft.AspNet.Identity
@model EnVisage.Models.CreateScenarioModel.GeneralInfoModel
@{
var user = (new EnVisage.Code.Cache.UsersCache()).Value.FirstOrDefault(x => x.Id == new Guid(User.Identity.GetID()));
var calendarModel = (new ScenarioDetailsCalendarModel(Model, user, ScenarioDetailsCalendarModel.ScenarioCalendarOpener.CreateScenarioWizard));
var json = Newtonsoft.Json.JsonConvert.SerializeObject(calendarModel);
}
<script type="text/javascript">
function onStep1Failure(xhr) {
$('#generalStep').html(xhr.responseText);
initStep1(false);
unblockUI();
$('#Action').val('');
}
function onStep1Success(data) {
if (data != "") {
$('#generalStep').html(data);
initStep1(true);
_detailsController.init(@Html.Raw(json), stepSubmitCallback);
return;
}
unblockUI();
$('#Action').val('');
}
function reloadProjectParts() {
var text = "@Url.Action("GetProjectPartsByProjectId", "Scenarios", new { Id = "JSVar" })";
text = text.replace("JSVar", $('#projects').val());
blockUI();
$('#project_parts_@Model.ScenarioId').load(text, function () {
var projectPart = $("#partNames");
projectPart.html($('#project_parts_@Model.ScenarioId').find("select").html());
if (projectPart.find("option").length > 0)
$("#divPartName_@Model.ScenarioId").show();
else
$("#divPartName_@Model.ScenarioId").hide();
unblockUI();
});
}
function initStep1(disableSliders) {
reloadProjectParts();
$("#generalStep #TemplateId").html('@Utils.GetTemplates(Model.TemplateId)');
$("#projects").select2({
allowClear: true
}).on('change', reloadProjectParts);
$("#partNames").select2({
allowClear: true
});
$("#generalStep .forselect2").select2({
allowClear: true
});
initDatePickers();
$('input.yes-no-switcher').switcher({
on_state_content: 'Yes',
off_state_content: 'No'
});
angular.bootstrap($("#teamsContainer")[0], ['app']);
$('input.yes-no-switcher').parent().css("width", "80px");
reloadEC(true);
$.validator.unobtrusive.parseDynamicContent("#generalStepForm");
if (disableSliders) {
// SA. ENV-1149. Shows fact team allocation on sliders
var slidersGroupContainer = $("#teamsContainer").find('*[data-slider-group]');
var slidersController = slidersGroupContainer ? angular.element(slidersGroupContainer.get(0)).scope() : undefined;
if (slidersController) {
slidersController.$apply(function () {
slidersController.setReadonly();
});
}
}
$('#generalStep').find('input[type=checkbox],input[type=text],select,textarea').on("change", function() {
if (typeof onScenarioDataChanged === 'function')
onScenarioDataChanged();
});
}
function reloadEC(overrideChecked) {
var templateId = $('#@Html.IdFor(x=> x.TemplateId)').val();
if (templateId == "") {
$("#fsCategories").hide();
$("#fsTeamAllocation").hide();
return;
}
$("#fsCategories").show();
var selectedCategories = $('#general-step-selected-expenditure-categories').val();
var scope = angular.element(document.getElementById('slidersGroupContainer_@(Model.Teams.GroupDisplayId)')).scope();
var scenarioTeams = scope.getTeamList();
$.post('@Url.Action("GetECsByTemplateId", "Scenarios")', {
'Id': templateId,
'selectedExpCats': (!selectedCategories || selectedCategories.trim().length <= 0) ? "" : JSON.parse(selectedCategories),
'teams': scenarioTeams,
'overrideChecked': overrideChecked
}, function(data) {
$('#expenditures_@Model.ScenarioId').html(data);
if (!($("#fsFinancial").is(':visible') || $("#fsDetails").is(':visible')))
$("#fsTeamAllocation").show();
unblockUI();
});
}
function lockGeneralForm(needToLock) {
if (needToLock) {
$('#@Html.IdFor(x=> x.StartDate)').attr('disabled', 'disabled');
$('[name=@Html.IdFor(x=> x.StartDate)].hdn').removeAttr('disabled');
$('#@Html.IdFor(x=> x.EndDate)').attr('disabled', 'disabled');
$('[name=@Html.IdFor(x=> x.EndDate)].hdn').removeAttr('disabled');
$('#@Html.IdFor(x=> x.TemplateId)').attr('disabled', 'disabled');
$('[name=@Html.IdFor(x=> x.TemplateId)].hdn').removeAttr('disabled');
}
else {
$('#@Html.IdFor(x=> x.StartDate)').removeAttr('disabled');
$('[name=@Html.IdFor(x=> x.StartDate)].hdn').attr('disabled', 'disabled');
$('#@Html.IdFor(x=> x.EndDate)').removeAttr('disabled');
$('[name=@Html.IdFor(x=> x.EndDate)].hdn').attr('disabled', 'disabled');
$('#@Html.IdFor(x=> x.TemplateId)').removeAttr('disabled');
$('[name=@Html.IdFor(x=> x.TemplateId)].hdn').attr('disabled', 'disabled');
}
}
</script>
@using (Ajax.BeginForm("SubmitCreateScenarioStep1", "Scenarios", new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "onStep1Success",
OnFailure = "onStep1Failure(xhr)",
UpdateTargetId = "generalStep"
}, new
{
@id = "generalStepForm",
@class = "form-horizontal",
}))
{
@Html.HiddenFor(m => m.ScenarioId)
@Html.HiddenFor(m => m.ProjectId)
@Html.HiddenFor(m => m.PartId)
@Html.HiddenFor(m => m.ProjectDeadline)
@Html.HiddenFor(m => m.StatusIsEditable)
@Html.Hidden("general-step-selected-expenditure-categories", Model.ScenarioExpenditures == null ? "" : Newtonsoft.Json.JsonConvert.SerializeObject(Model.ScenarioExpenditures.Where(x => x.Checked).Select(x => x.Id)), new { @id = "general-step-selected-expenditure-categories" })
@Html.HiddenFor(m => m.SerializedModel)
@Html.AntiForgeryToken()
<fieldset id="fsGeneral" class="form-group-margin">
<legend class="text-bold">Scenario Information</legend>
<div class="row">
<div class="col-sm-7">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.ProjectId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.ProjectId, Utils.GetProjects(new Guid(User.Identity.GetID())), new { @class = "form-control", @id = "projects", @disabled = "disabled" })
@Html.ValidationMessageFor(model => model.ProjectId)
</div>
</div>
<div class="col-sm-5" id="divPartName_@Model.ScenarioId">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.PartId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.PartId, Utils.GetProjectParts(Model.ProjectId, new Guid(User.Identity.GetID())), new { @class = "form-control", @id = "partNames", @disabled = "disabled" })
@Html.ValidationMessageFor(model => model.PartId)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-7">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.ScenarioName, new { @class = "control-label" })
@Html.TextBoxFor(model => model.ScenarioName, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ScenarioName)
</div>
</div>
<div class="col-sm-5">
<div class="form-group no-margin-hr">
<label class="control-label">Scenario Dates</label>
<div class="input-daterange input-group" id="bs-datepicker-scenario-range">
@Html.EditorFor(t => t.StartDate)
<div class="input-group-addon">to</div>
@Html.EditorFor(model => model.EndDate)
</div>
<div>
<input type="hidden" name="@Html.NameFor(t=>t.StartDate).ToString()" class="hdn" value="@(Model.StartDate.HasValue ? Model.StartDate.Value.ToShortDateString() : string.Empty)"/>
<input type="hidden" name="@Html.NameFor(t=>t.EndDate).ToString()" class="hdn" value="@(Model.EndDate.HasValue ? Model.EndDate.Value.ToShortDateString() : string.Empty)"/>
</div>
@Html.ValidationMessageFor(model => model.StartDate)
@Html.ValidationMessageFor(model => model.EndDate)
@if (Model.ProjectDeadline != null)
{
<i>(Project Deadline: @Model.ProjectDeadline.Value.ToShortDateString())</i>
}
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-7">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.TemplateId, new { @class = "control-label" })
@Html.DropDownListFor(model => model.TemplateId, new List<SelectListItem>(), new { @class = "form-control forselect2", @onchange = "$(this).parents('form').validate().element($(this)); reloadEC(false);" })
<input type="hidden" name="@Html.NameFor(t=>t.TemplateId).ToString()" class="hdn" value="@(Model.TemplateId.HasValue ? Model.TemplateId.Value.ToString() : string.Empty)"/>
@Html.ValidationMessageFor(model => model.TemplateId)
</div>
</div>
<div class="col-sm-3 col-md-2">
<div class="form-group no-margin-hr switcher-block @(Model.StatusIsEditable ? "" : "hidden")">
@Html.LabelFor(model => model.CreateAsActive, new { @class = "control-label" })
@Html.CheckBoxFor(model => model.CreateAsActive, new { @class = "switcher form-control yes-no-switcher" })
@Html.ValidationMessageFor(model => model.CreateAsActive)
</div>
</div>
</div>
</fieldset>
<fieldset id="fsCategories" class="form-group-margin">
<legend class="text-bold small-bottom-margin">Expenditure Categories</legend>
<div class="row" id="expenditures_@Model.ScenarioId">
</div>
</fieldset>
<fieldset id="fsTeamAllocation">
<legend class="text-bold small-bottom-margin">Teams</legend>
<div class="row">
<div class="col-sm-12" id="teamsContainer">
@Html.EditorFor(x => x.Teams)
</div>
</div>
</fieldset>
@Html.ValidationSummary(false, "The scenario could not be saved due to the following errors:")
}