EnVisageOnline/Main-RMO/Source/EnVisage/Views/Calendar/_editHoliday.cshtml

206 lines
7.3 KiB
Plaintext

@using EnVisage.Code
@using EnVisage.Code.HtmlHelpers
@using EnVisage.Code.BLL
@using EnVisage.Models
@model EnVisage.Models.HolidayModel
@{
ViewBag.Title = @Model.HolidayId.Equals(Guid.Empty) ? "Add Holiday" : "Change Holiday";
}
<script type="text/javascript">
emulateNavUrl = "/Calendar";
var holidayFormDataChanged = false;
var isNewItem = @(Model.HolidayId.Equals(Guid.Empty) ? "true;" : "false;")
function initEditHolidayForm(holidayId) {
if (holidayId && (holidayId != '@Guid.Empty')) {
StartEdit('Holiday', holidayId, null, '#btnsave', 'erorMsgPlaceholder');
}
// Limits for date value fields
var todayDate = new Date();
todayDate = new Date(todayDate.getFullYear(), todayDate.getMonth(), todayDate.getDate());
var firstYearDay = new Date(todayDate.getFullYear(), 0, 1);
$('#@Html.ClientIdFor(model => model.EffectiveChangeDate)').parents('.datepicker').datepicker({
startDate: todayDate,
@(Model.HolidayId.Equals(Guid.Empty) ? "endDate: todayDate" : "")
});
if (isNewItem) {
$('#effectiveChangeDateBlock').hide();
}
$("#@Html.ClientIdFor(t => t.OccurrenceType)").change(onHolidayTypeChange);
$("#@Html.ClientIdFor(t => t.OccurrenceMonth)").change(onHolidayMonthChange);
$("#@Html.ClientIdFor(t => t.NonWorkingWeek)").change(onHolidayNonWorkingChange);
$('#btnsave').click(function () {
if ($('form#holidayEditForm').valid())
blockUI();
});
$('#holidayEditForm').find('input[type=checkbox],input[type=text],select,textarea').on("change", function () {
onHolidayFormDataChanged();
});
$.validator.unobtrusive.parseDynamicContent('form#holidayEditForm');
};
function onHolidayTypeChange() {
var value = $("#@Html.ClientIdFor(t => t.OccurrenceType)").val();
if (value == '@HolidayModel.HolidayOccurrence.OnlyOnce.ToString()' ||
value == '@HolidayModel.HolidayOccurrence.SameDayEveryYear.ToString()' ||
value == '@HolidayModel.HolidayOccurrence.VariesEveryYear.ToString()') {
$("#holidayEditForm").find("#divWeekDay").hide();
$("#holidayEditForm").find("#divMonthDay").show();
}
else {
$("#holidayEditForm").find("#divWeekDay").show();
$("#holidayEditForm").find("#divMonthDay").hide();
}
$("@Html.ClientIdFor(t => t.OccurrenceMonth)").change();
}
function onHolidayMonthChange() {
var value = $("#@Html.ClientIdFor(t => t.OccurrenceMonth)").val();
var curDayValue = $("#@Html.ClientIdFor(t => t.OccurrenceMonthDay)").val();
var numDays = 31;
if (value == '2') {
numDays = 28;
}
if (value == '4' || value == '6' || value == '9' || value == '11') {
numDays = 30;
}
var items = "";
for (var i = 1; i <= numDays; i++) {
items += "<option value=\"" + i + "\" " + ((i == parseInt(curDayValue)) ? "selected" : "") + ">" + i + "</option>";
};
$("#@Html.ClientIdFor(t => t.OccurrenceMonthDay)").html(items);
}
function onHolidayNonWorkingChange(value, data, context) {
var nonWorkingWeekChecked = document.getElementById('@Html.ClientIdFor(t => t.NonWorkingWeek)').checked;
document.getElementById('@Html.ClientIdFor(t => t.WorkingDay)').checked = !nonWorkingWeekChecked;
$("#@Html.ClientIdFor(t => t.WorkingDay)").prop('disabled', nonWorkingWeekChecked);
}
function onEditHolidaySuccess(data) {
unblockUI();
document.location.reload();
};
function onEditHolidayFailure(xhr) {
unblockUI();
$('#editHolidayReload').html(xhr.responseText);
initEditHolidayForm();
holidayFormDataChanged = true;
};
function onHolidayFormDataChanged() {
holidayFormDataChanged = true;
}
</script>
<div id="erorMsgPlaceholder"></div>
@using (Ajax.BeginForm("EditHoliday", "Calendar", new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "onEditHolidaySuccess",
OnFailure = "onEditHolidayFailure(xhr)",
UpdateTargetId = "editHolidayReload"
},
new
{
@id = "holidayEditForm"
}))
{
@Html.HiddenFor(t => t.Id)
@Html.HiddenFor(t => t.HolidayId)
@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 class="row" id="effectiveChangeDateBlock">
<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.Name, new { @class = "col-sm-2 control-label" })
@Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name)
</div>
</div>
</div>
<div class="row">
<div class="form-group no-margin-hr">
<div class="col-sm-12">
@Html.LabelFor(model => model.OccurrenceType, new { @class = "col-sm-2 control-label" })
</div>
<div class="col-sm-4">
@Html.DropDownListFor(t => t.OccurrenceType, Utils.GetOccurrenceTypes(), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OccurrenceType)
</div>
<div class="col-sm-3">
<div id="divWeekDay" style="display: @(Model.ShowWeekDayDdl ? "block" : "none")">
@Html.DropDownListFor(model => model.OccurrenceWeekDay, Utils.GetWeekDays(), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OccurrenceWeekDay)
</div>
<div id="divMonthDay" style="display: @(!Model.ShowWeekDayDdl ? "block" : "none")">
@Html.DropDownListFor(model => model.OccurrenceMonthDay, Utils.GetMonthDays(Model.OccurrenceMonth ?? 1), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OccurrenceMonthDay)
</div>
</div>
<div class="col-sm-1">
<div style="text-align: center; margin-top: 8px;">of</div>
</div>
<div class="col-sm-4">
@Html.DropDownListFor(model => model.OccurrenceMonth, Utils.GetMonths(), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.OccurrenceMonth)
</div>
</div>
</div>
<div class="row">
<div class="form-group no-margin-hr">
<div class="col-sm-3">
@Html.LabelFor(model => model.WorkingDay, new { @class = "control-label" })
</div>
<div class="col-sm-9">
@Html.EditorFor(model => model.WorkingDay, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.WorkingDay)
</div>
</div>
</div>
<div class="row">
<div class="form-group no-margin-hr">
<div class="col-sm-3">
@Html.LabelFor(model => model.NonWorkingWeek, new { @class = "control-label" })
</div>
<div class="col-sm-9">
@Html.EditorFor(model => model.NonWorkingWeek, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NonWorkingWeek)
</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>&nbsp;Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
}