168 lines
4.1 KiB
JavaScript
168 lines
4.1 KiB
JavaScript
|
|
|
||
|
|
// ========================
|
||
|
|
// Add Subscription To User
|
||
|
|
// ========================
|
||
|
|
|
||
|
|
$(document).ready(function () {
|
||
|
|
|
||
|
|
var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}");
|
||
|
|
|
||
|
|
// -----------
|
||
|
|
// Input Masks
|
||
|
|
// -----------
|
||
|
|
|
||
|
|
$(".date-mask").inputmask({alias: "datetime",
|
||
|
|
inputFormat: "mm/dd/yyyy",
|
||
|
|
placeholder: "MM/DD/YYYY",
|
||
|
|
showMaskOnHover: false});
|
||
|
|
|
||
|
|
// --------------
|
||
|
|
// Select Picker.
|
||
|
|
// --------------
|
||
|
|
|
||
|
|
$(".search-dropdown").selectpicker({noneSelectedText: "",
|
||
|
|
style: "",
|
||
|
|
styleBase: "form-select form-select-sm",
|
||
|
|
iconBase: "bi",
|
||
|
|
virtualScroll: true,
|
||
|
|
size: 10,
|
||
|
|
selectOnTab: true,
|
||
|
|
containter: "body",
|
||
|
|
liveSearch: true});
|
||
|
|
|
||
|
|
// ------------
|
||
|
|
// Date Pickers
|
||
|
|
// ------------
|
||
|
|
|
||
|
|
$("#subscription_start_date").datepicker({format: "mm-dd-yyyy",
|
||
|
|
container: "div.subscription_start_date",
|
||
|
|
keyboardNavigation: false,
|
||
|
|
showOnFocus: false,
|
||
|
|
autoclose: true,
|
||
|
|
orientation: "left bottom",
|
||
|
|
todayBtn: "linked",
|
||
|
|
todayHighlight: true});
|
||
|
|
|
||
|
|
$("#subscription_end_date").datepicker({format: "mm-dd-yyyy",
|
||
|
|
container: "div.subscription_end_date",
|
||
|
|
keyboardNavigation: false,
|
||
|
|
showOnFocus: false,
|
||
|
|
autoclose: true,
|
||
|
|
orientation: "left bottom",
|
||
|
|
todayBtn: "linked",
|
||
|
|
todayHighlight: true});
|
||
|
|
|
||
|
|
|
||
|
|
// ---------------------
|
||
|
|
// Show Calendar Buttons
|
||
|
|
// ---------------------
|
||
|
|
|
||
|
|
$(".btnSubscriptionStartDateCalendar").on("click", function (e) {
|
||
|
|
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
$("#subscription_start_date").focus().datepicker("show");
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
// ---------------------
|
||
|
|
// Show Calendar Buttons
|
||
|
|
// ---------------------
|
||
|
|
|
||
|
|
$(".btnSubscriptionEndDateCalendar").on("click", function (e) {
|
||
|
|
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
$("#subscription_end_date").focus().datepicker("show");
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
// -----------
|
||
|
|
// Save Button
|
||
|
|
// -----------
|
||
|
|
|
||
|
|
$(".btnSave").on("click", function (e) {
|
||
|
|
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
$("#addSubscriptionToUser").submit();
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
// --------------
|
||
|
|
// Cancel Button.
|
||
|
|
// --------------
|
||
|
|
|
||
|
|
$(".btnCancel").on("click", function () {
|
||
|
|
|
||
|
|
$sessionStorage.action = $sessionStorage.addSubscriptionToUser || "";
|
||
|
|
|
||
|
|
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
|
||
|
|
|
||
|
|
formSubmit($sessionStorage);
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
// ---------------
|
||
|
|
// Validate Inputs
|
||
|
|
// ---------------
|
||
|
|
|
||
|
|
$("#addSubscriptionToUser").submit(function (e) {
|
||
|
|
|
||
|
|
var subscription_title = $("#subscription_serial"), start_date = $("#subscription_start_date"), end_date = $("#subscription_end_date");
|
||
|
|
;
|
||
|
|
|
||
|
|
clearInputErrors();
|
||
|
|
|
||
|
|
if ($("option:selected", subscription_title).val() === "") {
|
||
|
|
createInputError(subscription_title, "Subscription is required");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isBlank(start_date)) {
|
||
|
|
createInputError(start_date, "Date is required");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((!isBlank(start_date)) && (!start_date.inputmask("isComplete"))) {
|
||
|
|
createInputError(start_date, "Date is incomplete");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isBlank(end_date)) {
|
||
|
|
createInputError(end_date, "Date is required");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((!isBlank(end_date)) && (!end_date.inputmask("isComplete"))) {
|
||
|
|
createInputError(end_date, "Date is incomplete");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
let startDate = new Date(start_date.val()),
|
||
|
|
endDate = new Date(end_date.val());
|
||
|
|
|
||
|
|
if (startDate > endDate) {
|
||
|
|
createInputError(start_date, "Date is after End Date");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
$.post("./", $(this).serialize())
|
||
|
|
|
||
|
|
.done(function () {
|
||
|
|
|
||
|
|
$sessionStorage.action = $sessionStorage.addSubscriptionToUser || "";
|
||
|
|
|
||
|
|
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
|
||
|
|
|
||
|
|
formSubmit($sessionStorage);
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|