195 lines
7.0 KiB
Plaintext
195 lines
7.0 KiB
Plaintext
@using EnVisage.Code
|
|
@using EnVisage.Code.BLL
|
|
@using EnVisage.Models
|
|
@model FiscalCalendarModel
|
|
@{
|
|
ViewBag.Title = "Change Calendar Settings";
|
|
}
|
|
|
|
<script type="text/javascript">
|
|
emulateNavUrl = "/Calendar";
|
|
var calendarFormDataChanged = false;
|
|
|
|
var lastWeekendingDayOptTemplate = '@FiscalCalendarModel.CalendarYearType.LastWeekDay.ToDisplayValue()';
|
|
|
|
function initEditCalendarForm() {
|
|
if ('@Model.Id' != '@Guid.Empty') {
|
|
StartEdit('FiscalCalendarSettings', '@Model.Id', null, '#btnsave', 'erorMsgPlaceholder');
|
|
}
|
|
|
|
// Limits for date value fields
|
|
var todayDate = new Date();
|
|
var maxStartingPointDate = new Date(todayDate.getFullYear(), todayDate.getMonth(), todayDate.getDate());
|
|
var minStartingPointDate = new Date(todayDate.getFullYear() - 1, todayDate.getMonth(), todayDate.getDate());
|
|
|
|
$('#@Html.IdFor(model => model.EffectiveChangeDate)').parents('.datepicker').datepicker({
|
|
startDate: maxStartingPointDate
|
|
});
|
|
|
|
$('#@Html.IdFor(model => model.StartingPoint)').parents('.datepicker').datepicker({
|
|
startDate: minStartingPointDate,
|
|
endDate: maxStartingPointDate
|
|
});
|
|
|
|
$('#btnsave').click(function () {
|
|
var calYearValue = $("#@Html.IdFor(t => t.CalendarType)").val();
|
|
|
|
if (calYearValue == '@FiscalCalendarModel.FiscalCalendarType.CalendarYear.ToString()') {
|
|
// If selected Calendar Year, we set StartingPoint as first day of the year and WeekendingDay as Sunday
|
|
var startingPointDate = new Date();
|
|
startingPointDate = '01/01/' + startingPointDate.getFullYear(); // Set any date to prevent RequiredValue error
|
|
|
|
var effStartDateTxt = $('#@Html.IdFor(model => model.EffectiveChangeDate)').val();
|
|
|
|
if (effStartDateTxt && (effStartDateTxt.length > 0)) {
|
|
var effStartDateAsDate = new Date(effStartDateTxt);
|
|
var year = effStartDateAsDate.getFullYear();
|
|
startingPointDate = '01/01/' + year; // First day of the calendar year
|
|
}
|
|
|
|
$('#@Html.IdFor(model => model.StartingPoint)').val(startingPointDate);
|
|
$('#@Html.IdFor(model => model.WeekendingDay)').val('@DayOfWeek.Sunday.ToDisplayValue()');
|
|
}
|
|
|
|
if ($('form#calendarSettingEditForm').valid())
|
|
blockUI();
|
|
});
|
|
|
|
$("#@Html.IdFor(t => t.CalendarType)").change(onCalendarTypeChanged);
|
|
onCalendarTypeChanged();
|
|
|
|
$("#@Html.IdFor(t => t.WeekendingDay)").change(onWeekendingDayChanged);
|
|
onWeekendingDayChanged();
|
|
|
|
$('#calendarSettingEditForm').find('input[type=checkbox],input[type=text],select,textarea').on("change", function () {
|
|
onCalendarFormDataChanged();
|
|
});
|
|
$.validator.unobtrusive.parseDynamicContent('form#calendarSettingEditForm');
|
|
};
|
|
|
|
function onCalendarTypeChanged() {
|
|
var value = $("#@Html.IdFor(t => t.CalendarType)").val();
|
|
|
|
if (value == '@FiscalCalendarModel.FiscalCalendarType.CalendarYear.ToString()') {
|
|
$("#fcsOptionalBlock").hide();
|
|
} else {
|
|
$("#fcsOptionalBlock").show();
|
|
}
|
|
}
|
|
|
|
function onWeekendingDayChanged() {
|
|
var selector = "#@Html.IdFor(model => model.YearType) [value='LastWeekDay']";
|
|
var targetOption = $(selector);
|
|
|
|
if (targetOption && (targetOption.text().length > 0)) {
|
|
var sourceWeekDay = $("#@Html.IdFor(t => t.WeekendingDay)").val();
|
|
var newOptionText = lastWeekendingDayOptTemplate.replace(new RegExp('Weekending day', 'g'), sourceWeekDay);
|
|
targetOption.text(newOptionText);
|
|
|
|
var selectedYearType = $("#@Html.IdFor(model => model.YearType) option:selected").val();
|
|
if (selectedYearType == 'LastWeekDay') {
|
|
$("#@Html.IdFor(model => model.YearType)").val("");
|
|
$("#@Html.IdFor(model => model.YearType)").val('LastWeekDay');
|
|
}
|
|
}
|
|
}
|
|
|
|
function onEditCalendarSuccess(result) {
|
|
handleAjaxResponse(result, function () {
|
|
document.location.reload();
|
|
}, null, null, $('#calendarSettingEditForm'));
|
|
};
|
|
|
|
function onEditCalendarFailure(xhr) {
|
|
showErrorModal();
|
|
calendarFormDataChanged = true;
|
|
};
|
|
|
|
function onCalendarFormDataChanged() {
|
|
calendarFormDataChanged = true;
|
|
}
|
|
</script>
|
|
@using (Ajax.BeginForm("EditCalendar", "Calendar", new AjaxOptions
|
|
{
|
|
HttpMethod = "Post",
|
|
OnSuccess = "onEditCalendarSuccess",
|
|
OnFailure = "onEditCalendarFailure(xhr)",
|
|
OnComplete = "unblockUI",
|
|
},
|
|
new {
|
|
id = "calendarSettingEditForm"
|
|
}))
|
|
{
|
|
@Html.HiddenFor(t => t.Id)
|
|
@Html.AntiForgeryToken()
|
|
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
|
|
<h4 class="modal-title">@ViewBag.Title</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div id="erorMsgPlaceholder"></div>
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.LabelFor(model => model.EffectiveChangeDate, new { @class = "control-label" })
|
|
@Html.EditorFor(model => model.EffectiveChangeDate, new { @class = "form-control" })
|
|
@Html.ValidationMessageFor(model => model.EffectiveChangeDate)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.LabelFor(model => model.CalendarType, new { @class = "control-label" })
|
|
@Html.DropDownListFor(t => t.CalendarType, FiscalCalendarManager.GetCalendarTypes(), new { @class = "form-control" })
|
|
@Html.ValidationMessageFor(model => model.CalendarType)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="fcsOptionalBlock">
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.LabelFor(model => model.StartingPoint, new { @class = "control-label" })
|
|
@Html.EditorFor(model => model.StartingPoint, new { @class = "form-control" })
|
|
@Html.ValidationMessageFor(model => model.StartingPoint)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.LabelFor(model => model.WeekendingDay, new { @class = "control-label" })
|
|
@Html.DropDownListFor(t => t.WeekendingDay, FiscalCalendarManager.GetWeekendings(), new { @class = "form-control" })
|
|
@Html.ValidationMessageFor(model => model.WeekendingDay)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.LabelFor(model => model.YearType, new { @class = "control-label" })
|
|
@Html.DropDownListFor(t => t.YearType, FiscalCalendarManager.GetYearTypes(), new { @class = "form-control" })
|
|
@Html.ValidationMessageFor(model => model.YearType)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm-12">
|
|
<div class="form-group no-margin-hr">
|
|
@Html.EditorFor(model => model.UseAdjustingPeriod, new { @class = "form-control" })
|
|
@Html.LabelFor(model => model.UseAdjustingPeriod, new { @class = "control-label" })
|
|
@Html.ValidationMessageFor(model => model.UseAdjustingPeriod)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@Html.ValidationSummary(false, "The record 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>
|
|
}
|