| 1 |
jQuery(document).ready(function($) { |
| 2 |
|
| 3 |
// Edit Timestamp Toggle |
| 4 |
$(".edit-timestamp").click(function(e) { |
| 5 |
$(".expiry-date-fields").slideDown('fast'); |
| 6 |
$(this).css('visibility','hidden'); |
| 7 |
$(".cancel-timestamp").css('visibility','visible'); |
| 8 |
}); |
| 9 |
|
| 10 |
// Cancel Timestamp Toggle |
| 11 |
$(".cancel-timestamp").click(function(e) { |
| 12 |
e.preventDefault(); |
| 13 |
$(".expiry-date-fields").slideUp('fast'); |
| 14 |
$(this).css('visibility','hidden'); |
| 15 |
$(".edit-timestamp").css('visibility','visible'); |
| 16 |
}); |
| 17 |
|
| 18 |
// specific script element |
| 19 |
$('.r8_tsm_page_select').select2({ |
| 20 |
data: tsm_data, |
| 21 |
placeholder: 'Select page(s) or post(s) where the script should be output', |
| 22 |
width: '400' |
| 23 |
}); |
| 24 |
|
| 25 |
// active/inactive status |
| 26 |
var previousSelectedStatus = null; |
| 27 |
$("#r8_tsm_script_active .inside").hover( |
| 28 |
function() { |
| 29 |
previousSelectedStatus = $("input[name=r8_tsm_active]:checked").val(); |
| 30 |
}, function() { |
| 31 |
previousSelectedStatus = null; |
| 32 |
} |
| 33 |
); |
| 34 |
$('input[type=radio][name=r8_tsm_active]').click(function(){ |
| 35 |
if (previousSelectedStatus == 'active') { |
| 36 |
if (this.value == 'inactive') { |
| 37 |
let previousSelectedVal = $("input[name=r8_tsm_script_expiry]:checked").val(); |
| 38 |
if( previousSelectedVal == 'Schedule' ){ |
| 39 |
var r = confirm('If you Inactive this script the Schedule will be set to "Never expires". Active Scheduled script can\'t be inactive.' ); |
| 40 |
if( r == true ){ |
| 41 |
$("input[name=r8_tsm_script_expiry]").each(function() { |
| 42 |
if( $(this).val() == 'Schedule' ){ |
| 43 |
$('#expire_date_type_never').prop( "checked", true ); |
| 44 |
$(".schedule-row").addClass('hidden'); |
| 45 |
$('.expiration-status strong').text('Never expires'); |
| 46 |
} |
| 47 |
}); |
| 48 |
}else{ |
| 49 |
return false; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
if (previousSelectedStatus == 'inactive') { |
| 55 |
if (this.value == 'active') { |
| 56 |
let previousSelectedVal = $("input[name=r8_tsm_script_expiry]:checked").val(); |
| 57 |
if( previousSelectedVal == 'Schedule' ){ |
| 58 |
let start = $("#schedule-start").datepicker("getDate"); |
| 59 |
let end = $("#schedule-end").datepicker("getDate"); |
| 60 |
let todayDate = new Date(); |
| 61 |
let formatTodayDate = (todayDate.getMonth()+1) + "/" + todayDate.getDate() + "/" + todayDate.getFullYear(); |
| 62 |
let currentDate = new Date(start.getTime()); |
| 63 |
let between = []; |
| 64 |
while (currentDate <= end) { |
| 65 |
let d = new Date(currentDate); |
| 66 |
let strDate = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear(); |
| 67 |
between.push(strDate); |
| 68 |
currentDate.setDate(currentDate.getDate() + 1); |
| 69 |
} |
| 70 |
let status = false; |
| 71 |
for (var i = 0; i < between.length; i++) { |
| 72 |
if (between[i] == formatTodayDate) { |
| 73 |
status = true; |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
if( status == false ){ |
| 78 |
var r = confirm('If you Active this script the Schedule will be set to "Never expires". Inative Scheduled script can\'t be active.' ); |
| 79 |
if( r == true ){ |
| 80 |
$("input[name=r8_tsm_script_expiry]").each(function() { |
| 81 |
if( $(this).val() == 'Schedule' ){ |
| 82 |
$('#expire_date_type_never').prop( "checked", true ); |
| 83 |
$(".schedule-row").addClass('hidden'); |
| 84 |
$('.expiration-status strong').text('Never expires'); |
| 85 |
} |
| 86 |
}); |
| 87 |
}else{ |
| 88 |
return false; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
}); |
| 95 |
|
| 96 |
// schedule switcher |
| 97 |
$('input[type=radio][name=r8_tsm_script_expiry]').change(function() { |
| 98 |
if (this.value == 'Never') { |
| 99 |
$(".schedule-row").addClass('hidden'); |
| 100 |
} |
| 101 |
if (this.value == 'Schedule') { |
| 102 |
$(".schedule-row").removeClass('hidden'); |
| 103 |
} |
| 104 |
}); |
| 105 |
$("#schedule-start").datepicker({ |
| 106 |
dateFormat : "M d, yy", |
| 107 |
minDate: 0, |
| 108 |
onClose: function (selectedDate) { |
| 109 |
$("#schedule-end").datepicker("option", "minDate", selectedDate); |
| 110 |
} |
| 111 |
}); |
| 112 |
$("#schedule-end").datepicker({ |
| 113 |
dateFormat : "M d, yy", |
| 114 |
minDate: 0 |
| 115 |
}); |
| 116 |
|
| 117 |
// set schedule |
| 118 |
$(".button.schedule").click(function(e) { |
| 119 |
e.preventDefault(); |
| 120 |
let pass = true; |
| 121 |
$("input[type=radio][name=r8_tsm_script_expiry]").each(function() { |
| 122 |
if( $(this).is(":checked") ){ |
| 123 |
if( $(this).val() == 'Never' ){ |
| 124 |
$('.expiration-status strong').text($(this).data('title')); |
| 125 |
} |
| 126 |
if( $(this).val() == 'Schedule' ){ |
| 127 |
let status = `Scheduled ${$("#schedule-start").val()} to ${$("#schedule-end").val()}`; |
| 128 |
start = $("#schedule-start").val(); |
| 129 |
end = $("#schedule-end").val(); |
| 130 |
var startDate = new Date(start); |
| 131 |
var endDate = new Date(end); |
| 132 |
if (startDate <= endDate) { |
| 133 |
$('.expiration-status strong').text(status); |
| 134 |
$(".schedule-row .err-msg").addClass('hidden'); |
| 135 |
} else { |
| 136 |
pass = false; |
| 137 |
$(".schedule-row .err-msg").text('Start date must be less than of End date.'); |
| 138 |
$(".schedule-row .err-msg").removeClass('hidden'); |
| 139 |
} |
| 140 |
} |
| 141 |
if( pass ){ |
| 142 |
$(".expiry-date-fields").slideUp('fast'); |
| 143 |
$(".edit-timestamp").css('visibility','visible'); |
| 144 |
} |
| 145 |
} |
| 146 |
}); |
| 147 |
}); |
| 148 |
|
| 149 |
}); |
| 150 |
|