Files

1011 lines
41 KiB
JavaScript
Executable File

IDrive.Scheduler = {
Ready: function() {
IDrive.LocalDirList = [];
IDrive.Scheduler.Page = "scheduler.php";
IDrive.Scheduler.Outer = "body div.wrapper section#content";
IDrive.Scheduler.SchedulerList = "div.excludeContainer div#job_list_table";
$("div.wrapper section#content").on("click", IDrive.Scheduler.SchedulerList+" table"+" tr, "+IDrive.Scheduler.SchedulerList+" td span.shdeuledDelete_job, "+IDrive.Scheduler.SchedulerList+" td span.ScheduledCancel_job, "+IDrive.Scheduler.SchedulerList+" td span.DisableCancelJob, input#delete_scheduler, img#vaultCancelJobButton", { type : 'scheduler' }, IDrive.Scheduler.SelectJob);
$("div.wrapper section#content").on("click", "input#update_scheduler", IDrive.Scheduler.UpdateJob);
$("div.wrapper section#content").on("click", "div#scheduler_div .schedule_checkbox,div#scheduler_div .schedule_radiobtn", IDrive.Scheduler.UserAction);
$("div.wrapper section#content").on("click", "input#deleteJobButton,input#cancelJobButton", { type : 'scheduler' }, IDrive.Scheduler.confirmBox);
$("div.wrapper section#content").on("change", "select#select_restore_job", { type : 'scheduler' }, IDrive.Scheduler.SelectRestoreJob);
$("div.wrapper section#content").on("change", "select#select_job, select#select_restore_job", IDrive.Scheduler.SetScheduleTime);
IDrive.Scheduler.LogPollID = setInterval(IDrive.Scheduler.WatchLogs, timeForWatcher);
},
dynamicSort: function(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? 1 : (a[property] > b[property]) ? -1 : 0;
return result * sortOrder;
}
},
WatchLogs: function() {
var divExists = $("div.wrapper section#content div#log_list").length;
if(divExists > 0) {
var params = {};
params.action = "watch_logs";
$.ajax({
url: "action.php",
type: "POST",
data: params,
beforeSend: function() {
},
success: function(data) {
if(data.indexOf('<html>')>0){
window.location.href='../index.php';
}
var sort_flag = 0;
var update_flag = false;
data = JSON.parse(data);
$.each(data.watcher, function(k_watcher, v_watcher) {
update_flag = true;
if(typeof(IDrive.LogList[k_watcher]) != 'undefined') {
IDrive.LogList[k_watcher].status = v_watcher.status;
}else {
sort_flag++;
IDrive.LogList[k_watcher] = v_watcher;
}
});
if(update_flag) {
IDrive.Scheduler.UpdateLogs(IDrive.LogList);
checkSelectedLogs();
}
},
error: function() {
window.location.href='../index.php';
}
});
}
},
SortObject: function(output) {
output.sort(function(a,b) {
return(a.datetime - b.datetime);
});
return output;
},
UpdateLogStatus: function(status, id) {
var id_r = id.replace(/:/g, "_");
$("table#logRows tr#"+id_r+" td.job_status span").html(status);
},
UpdateLogs: function(data) {
if(Object.keys(data).length>0){
var array_data = [];
var i=0;
$.each(data, function(k, v) {
array_data[i] = {};
array_data[i]["key"] = k;
array_data[i]["datetime"] = v.datetime;
array_data[i]["timestamp"] = v.timestamp;
array_data[i]["job_name"] = v.job_name;
array_data[i]["job_type"] = v.job_type;
array_data[i]["status"] = v.status;
array_data[i]["type"] = v.type;
array_data[i]["meridian"] = v.meridian;
i++;
});
array_data.sort(IDrive.Scheduler.dynamicSort("timestamp"));
html = '';
$.each(array_data, function(k, v) {
var jobStatus = v["status"].toLowerCase();
var capitalized = jobStatus.substr(0, 1).toUpperCase() + jobStatus.substr(1);
var status = '';
if(jobStatus != "in progress") {
status = "_";
status += jobStatus.toUpperCase();
}
var className = '';
if(jobStatus=='success' || jobStatus=='success*'){
className = 'green';
deleteClassName = 'logsDeleteJob';
} else if(jobStatus=='failure' || jobStatus=='aborted'){
className = 'red';
deleteClassName = 'logsDeleteJob';
} else {
className = 'blue';
deleteClassName = 'logsDeleteJob';
}
var jobTypeTxt = '';
var jobName = '';
var jobType = v["job_type"];
if(v["job_name"] != "+ManualTask" && v["job_name"] != "+TrashManualTask" && v["job_name"] != ""){
if(jobType == "Archive"){
jobTypeTxt += AR_PERIODIC+"<br>Job name: "+v["job_name"];
}
else if(machine=='twotier'){
jobTypeTxt += "Schedule "+jobType;
}else{
jobTypeTxt += "Schedule "+jobType+"<br>Job name: "+v["job_name"];
jobName = v["job_name"];
}
} else {
if(v["type"] == "TRASHDELETE") jobTypeTxt = "Trash Delete";
else jobTypeTxt += jobType;
}
var rowId = v["key"];
var logFile = encodeURIComponent((rowId+status));
var checked = '';
var checkedClass = '';
if(logFileList.length>0){
if(logFileList.indexOf('All')>=0){
checked = ' checked="checked"';
checkedClass = ' class="label_checked"';
} else if(logFileList.indexOf(logFile)>=0){
checked = ' checked="checked"';
checkedClass = ' class="label_checked"';
}
}
html +='<tr class="logs_row_list" id="'+rowId+'">';
html +='<td class="file_check"><input type="checkbox" name="chk_elements[]" value="'+logFile+'"'+checked+'><label'+checkedClass+'> files </label></td>';
if(jobTypeTxt == "Archive"){
jobTypeTxt = ARCHIVECLEANUP_TITLE;
}
html +='<td class="job_status"><span class="'+className+'">'+capitalized+'</span></td>';
html +='<td class="scheduled_type" style="width:28%;" title="'+jobName+'">'+jobTypeTxt+'</td>';
html +='<td class="scheduled_time" style="width:28%">'+v["datetime"]+ '</td>';
html +='<td class="sheduled_view" style="width:11%"><a target="_blank" href="viewLog.php?FILE_NAME='+logFile+'"><img src="include/images/idq_ico_viewlog.png" width="20" height="21" border="0" style="padding-left: 0px;"></a></td>';
html +='<td class="sheduled_clear"> <span class="'+deleteClassName+'" >Clear Log</span> </td>';
html +='</tr>';
});
$("table#logRows").html(html);
checkSelectedLogs();
} else {
jQuery('.logs-icon-row,.delete_all_disabled').hide();
jQuery('#log_list .header_part').find('label').removeAttr('class');
}
},
LoadLogs: function() {
var divExists = $("div.wrapper section#content div#log_list").length;
if(divExists > 0) {
var params = {};
params.action = "log_list_table";
$.ajax({
url: "action.php",
type: "GET",
dataType: "html",
data: params,
beforeSend: function() {},
success: function(html) {
if(html.indexOf('<html>')>0){
window.location.href='../index.php';
}
$("div.wrapper section#content div#log_list_table").html(html);
IDrive.Scheduler.UpdateLogs(IDrive.LogList);
}
});
}
},
LoadSchedulerList: function(showFirstJob) {
if(machine=='twotier'){
return false;
}
var divExists = $("div.wrapper section#content div#job_list_table").length;
if(divExists > 0) {
var params = {};
params.action = "scheduler_list_table";
if(typeof(IDrive.Scheduler.SelectedJob) != "undefined") {
params.selected_job = IDrive.Scheduler.SelectedJob;
}
$.ajax({
url: "action.php",
type: "GET",
dataType: "html",
data: params,
beforeSend: function() {},
success: function(html) {
if(html.indexOf('<html>')>0){
window.location.href='../index.php';
}
$("div.wrapper section#content div#job_list_table").html(html);
if(showFirstJob==true){
jQuery('.jobs_table tr:eq(0)').trigger('click');
jQuery('.ajax_loader').hide();
}
scheduleWatcherTimeoutVar = setTimeout(function(){ IDrive.Scheduler.LoadSchedulerList(false); },timeForWatcher);
}
});
}
},
ScheduledTaskWatcher: function(){
$.ajax({
url: "action.php?action=ScheduledTaskWatcher",
type: "GET",
success: function(dataSet) {
if(dataSet.indexOf('<html>')>0){
window.location.href='../index.php';
}
dataArray=$.parseJSON(dataSet);
if(dataArray[0]==true && dataArray[1]==false){
jQuery('#vaultCancelJobButton').show();
startImmediateRunning = true;
} else if(dataArray[0]==true && dataArray[1]==true){
jQuery('#vaultCancelJobButton').hide();
$('.head_search .alert p').html("Cancelling job...Please wait");
$('.head_search .alert').show();
startImmediateRunning = true;
jobCancelling=true;
} else {
if(jobCancelling == true){
showErrorMessages('.head_search .welcome_message',JOB_CANCELED);
}
jobCancelling=false;
jQuery('#vaultCancelJobButton,.alert').hide();
startImmediateRunning = false;
}
scheduleWatcherTimeoutVar = setTimeout(function(){ IDrive.Scheduler.ScheduledTaskWatcher(); },timeForWatcher);
}
});
},
AjaxPoll: function() {
IDrive.Scheduler.LoadPage(IDrive.Scheduler.Page);
},
SetScheduleTime: function() {
var job = $(this).val();
if(jQuery('.body_wrap').hasClass('backup_page')){
currentBackupJob = job;
} else if(jQuery('.body_wrap').hasClass('localbackup_page')){
currentLocalBackupJob = job;
} else {
if(jQuery('#sourcePath').val()=='Online Account'){
currentRestoreJob = job;
} else {
currentLocalRestoreJob = job;
}
}
if(job != "" && job != 0) {
var sel_job = IDrive.Jobs[job].scheduler;
var html = '';
if(sel_job && typeof(sel_job.start_minute) != "undefined") {
var st_min;
if(sel_job.start_minute.length == 1) {
st_min = "0"+sel_job.start_minute;
}else {
st_min = sel_job.start_minute;
}
if(typeof(sel_job.start_hour) != "undefined"){
html += sel_job.start_hour+':'+st_min+' '+sel_job.start_meridian;
} else if(typeof(sel_job.start_meridian) != "undefined") {
html += '00:'+st_min+' '+sel_job.start_meridian;
} else {
html += '00:'+st_min;
}
if(typeof(sel_job.scheduler_selection) != "undefined") {
var capitalized = sel_job.scheduler_selection.charAt(0).toUpperCase() + sel_job.scheduler_selection.substring(1);
html += ' '+capitalized;
} else if(typeof(sel_job.weekday_selection) != "undefined") {
var capitalized = 'Weekly';
html += ' '+capitalized;
}
html += ' &nbsp;<img src="include/images/idq_ico_schedarrow.png">';
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").show();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html(html);
} else {
html = ' &nbsp;<img src="include/images/idq_ico_schedarrow.png">';
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").show();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html(html);
}
}else {
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").hide();
if(backupModeSet == 'relative')
jQuery(".archive_menu").hide();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html('');
}
},
SelectJob: function(event, data) {
if(machine=='twotier'){
var job=DEFAULT_BACKUPSET_NAME;
var delete_schedule = $(this).attr("id");
if(delete_schedule == 'delete_scheduler') {
var jobName = 'Default Backup Set';
jQuery('#clearLogObject').val(job);
$.popContainer();
jQuery('.delete_job_popup .popup_header h4').html('Delete Schedule');
jQuery('.delete_job_popup p span').html('scheduler settings');
jQuery(secPosCont).append(jQuery('.delete_job_popup').show());
return false;
} else if(delete_schedule == 'vaultCancelJobButton') {
var jobName = 'Default Backup Set';
jQuery('#clearLogObject').val(job);
$.popContainer();
jQuery('.cancel_job_popup p span').html(jobName);
jQuery(secPosCont).append(jQuery('.cancel_job_popup').show());
return false;
}
} else {
var topValue=$('#scheduler_div').offset().top;
var delete_job = $(this).attr("class");
var delete_schedule = $(this).attr("id");
var alt = $(this).attr("alt");
var job,jobType,jobName;
if(delete_job == 'shdeuledDelete_job') {
job = $(this).closest('tr').attr('id');
jobType = $(this).closest('tr').find('td.action_jobtype').html();
jobName = job.replace(jobType+'_','');
jQuery('#clearLogObject').val(job);
jQuery('.delete_job_popup .popup_header h4').html('Delete Job');
$.popContainer();
jQuery('.delete_job_popup .job_bold').html(jobName);
if(alt == "ScheduledCancel_job")
jQuery('.delete_job_popup .msg').html("Job is in progress. Do you really want to delete ");
else
jQuery('.delete_job_popup .msg').html("Are you sure you want to delete ");
jQuery(secPosCont).append(jQuery('.delete_job_popup').show());
jQuery('#deleteJobButton').attr('action', 'delete');
return false;
} else if(delete_job == 'ScheduledCancel_job') {
job = $(this).closest('tr').attr('id');
jobType = $(this).closest('tr').find('td.action_jobtype').html();
jobName = job.replace(jobType+'_','');
jQuery('#clearLogObject').val(job);
$.popContainer();
jQuery('.cancel_job_popup p span').html(jobName);
jQuery(secPosCont).append(jQuery('.cancel_job_popup').show());
return false;
} else if(delete_job == 'DisableCancelJob') {
return false;
} else if(delete_schedule == 'delete_scheduler') {
var jobName = event.data.job;
jQuery('#clearLogObject').val(job);
$.popContainer();
jQuery('.delete_job_popup .popup_header h4').html('Delete Schedule');
jQuery('.delete_job_popup p span').html('scheduler settings');
jQuery(secPosCont).append(jQuery('.delete_job_popup').show());
$('#deleteJobButton').removeAttr('action');
return false;
}
var type = event.data.type;
switch(type) {
case "scheduler":
job = $(this).attr('id');
$(this).parent().find("tr").attr("bgcolor", "#ffffff");
$(this).attr("bgcolor", "#EFF9FF");
break;
case "edit backup":
job = event.data.job;
break;
case "add backup":
job = event.data.job;
break;
}
}
if ((typeof job === 'undefined') && (typeof event.job !== 'undefined')) job = event.job;
IDrive.Scheduler.SelectedJob = job;
$("#scheduler_div").show();
$('html,body').scrollTop(topValue-50);
var jobName = job.replace(IDrive.Jobs[job].job_type+'_','');
var job_title = jobName;
$(".schedule_title span").html(job_title);
$("#start_immediately li:eq(1) span").html("Start "+IDrive.Jobs[job].job_type+" Immediately");
$("#start_time div.backup_start_time").html("Start "+IDrive.Jobs[job].job_type+" Time");
$('form#frm_update_schedule')[0].reset(); //Reset Scheduler Form
$('form#frm_update_schedule input[type="checkbox"]').removeAttr("checked");
$('form#frm_update_schedule input[type="radio"]').next().removeAttr('class');
$('form#frm_update_schedule input[type="radio"]').removeAttr('checked');
$(".backup_set_time select").removeAttr("disabled").removeClass('pvtKey_grey');
$('input#start_immediately').removeAttr('checked').next().removeAttr('class');
$('input:checkbox[name="cut_off_time"]').attr('disabled','disabled').next().removeAttr('class');
$('input:checkbox[name="weekday_selection"]').prop('checked', false).next().removeAttr('class');
if(IDrive.Jobs[job].scheduler != undefined) {
var scheduler = IDrive.Jobs[job].scheduler;
$("#scheduler_div select#start_hour").val(scheduler.start_hour);
$("#scheduler_div select#start_minute").val(scheduler.start_minute);
$("#scheduler_div select#start_meridian").val(scheduler.start_meridian);
$("#scheduler_div select#day_of_month").val(scheduler.day_of_month);
if(scheduler.scheduler_selection != undefined) {
$('input:radio[name="scheduler_selection"][value="'+scheduler.scheduler_selection+'"]').prop('checked', true).next().addClass('label_checked');
if(scheduler.scheduler_selection == "hourly") {
$("input[name^='cut_off_time']").attr("disabled", "disabled");
$("select[id^='cutoff_']").attr("disabled", "disabled").addClass('pvtKey_grey');
$("select[id^='cutoff_']").closest('li').addClass("cutofftime");
$("#start_minute").removeAttr("disabled").removeClass('pvtKey_grey');
$("#start_hour,#start_meridian").attr("disabled", "disabled").addClass('pvtKey_grey');
}
} else if(scheduler.weekday_selection == undefined) {
$('input:radio[name="scheduler_selection"]').prop('checked', false).next().removeAttr('class');
} else {
$('input:radio[name="scheduler_selection"]').prop('checked', false).next().removeAttr('class');
$('.backup_set_time select,#day_of_month').attr("disabled","disabled").addClass('pvtKey_grey');
}
if(scheduler.scheduler_selection!='monthly'){
$('select#day_of_month').attr('disabled','disabled').addClass('pvtKey_grey');
} else {
$('select#day_of_month').removeAttr('disabled').removeClass('pvtKey_grey');
$('input:checkbox[name="cut_off_time"]').removeAttr('disabled').next().removeAttr('class');
}
if(scheduler.weekday_selection != undefined && JSON.parse(scheduler.weekday_selection).length > 0) {
$('input:checkbox[name="weekday_selection"]').prop('checked', false).next().removeAttr('class');
$('input:checkbox[name="cut_off_time"]').removeAttr('disabled').next().removeAttr('class');
$('.backup_set_time select').removeClass('pvtKey_grey').removeAttr('disabled');
if(scheduler.weekday_selection.length < 7) {
$('input:radio[name="scheduler_selection"][value="daily"]').prop('checked', false).next().removeAttr('class');
}
else {
$('input:checkbox[name="weekday_selection"]').prop('checked', false).next().removeAttr('class');
}
$.each(JSON.parse(scheduler.weekday_selection), function(k, v) {
$('input:checkbox[name="weekday_selection"][value="'+v+'"]').prop('checked', true).next().addClass('label_checked');
});
}
if(scheduler.cut_off_time != undefined) {
$('input:checkbox[name="cut_off_time"][value="'+scheduler.cut_off_time+'"]').prop('checked', true).next().addClass('label_checked');
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
$("select[id^='cutoff_']").closest('li').removeClass("cutofftime");
$("#scheduler_div select#cutoff_hour").val(scheduler.cutoff_hour);
$("#scheduler_div select#cutoff_minute").val(scheduler.cutoff_minute);
$("#scheduler_div select#cutoff_meridian").val(scheduler.cutoff_meridian);
} else {
$("select[id^='cutoff_']").attr("disabled", "disabled").addClass('pvtKey_grey');
$("select[id^='cutoff_']").closest('li').addClass("cutofftime");
$('input:checkbox[name="cut_off_time"]').prop('checked', false).next().removeAttr('class');
}
if(scheduler.email_notify != undefined) {
$('input:checkbox[name="email_notify"][value="'+scheduler.email_notify+'"]').prop('checked', true).next().addClass('label_checked');
$("input#notify_option").removeAttr("disabled").next().removeAttr('class');
$("input#email").removeAttr("disabled");
$("input#email_notify").removeAttr("disabled");
$("input#email").val(scheduler.email);
$('input:radio[name="notify_option"][value="'+scheduler.notify_option+'"]').prop('checked', true).next().addClass('label_checked');
} else {
$("input#notify_option").attr("disabled", "disabled").next().removeAttr('class');
$("input#email").attr("disabled", "disabled");
$("input#email").val("");
$('input:checkbox[name="email_notify"]').prop('checked', false).removeAttr("disabled").removeClass('pvtKey_grey').next().removeAttr('class');
}
//Enable/Disable the Delete schedule button
jQuery('#disableDelete').hide();
jQuery('#delete_scheduler').show();
} else {
$('form#frm_update_schedule')[0].reset(); //Reset Scheduler Form
$('form#frm_update_schedule input[type="checkbox"]').removeAttr("checked");
$('form#frm_update_schedule input[type="radio"]').next().removeAttr('class');
$('form#frm_update_schedule input[type="radio"]').removeAttr('checked');
$('#day_of_month').attr("disabled","disabled").addClass('pvtKey_grey');
$("input[name^='email_notify']").attr("disabled", "disabled").addClass('pvtKey_grey').next().removeAttr('class');
$('.notify_box input[type="radio"]').attr("disabled", "disabled").addClass('pvtKey_grey').next().removeAttr('class');
$('form input#email').attr("disabled", "disabled");
$('#start_immediately ul:eq(1) li:eq(1)').addClass('cutofftime').find('select').attr("disabled", "disabled");
$('form input[name="weekday_selection"]').removeAttr("checked").next().removeAttr('class');
$("select[id^='cutoff_']").attr("disabled", "disabled").addClass('pvtKey_grey');
//Enable/Disable the Delete schedule button
jQuery('#disableDelete').show();
jQuery('#delete_scheduler').hide();
}
},
RunJobImmediately: function(job, job_type) {
var params = {};
params.job = job;
params.action = "run_job_immediately";
params.job_type = job_type;
$.ajax({
url: "action.php",
type: "POST",
data: params,
beforeSend: function() {},
success: function(data) {
if(data.indexOf('<html>')>0){
window.location.href='../index.php';
}
}
});
var delay=2000;//5 seconds
setTimeout(function(){
//your code to be executed after 5 seconds
IDrive.Scheduler.LoadPage(IDrive.Scheduler.Page);
},delay);
},
UpdateJob: function() {
var form_data_arr = {};
if (typeof jobListArray[IDrive.Scheduler.SelectedJob] == "undefined" || jobListArray[IDrive.Scheduler.SelectedJob].length<1) {
if(machine=='twotier' && jobListArray[0])
jobListArray[IDrive.Scheduler.SelectedJob] = jobListArray[0];
else
jobListArray[IDrive.Scheduler.SelectedJob] = [];
}
if(removeScheduler==true){
var alertMsg = "Removing scheduler...Please wait";
var succMsg = "Scheduler has been removed successfully";
} else if(machine == 'twotier' && jobListArray[IDrive.Scheduler.SelectedJob].length==0){
showErrorMessages('.head_search .error_msg',SELECT_FILE_FOLDER_SCHECULE_BK);
return false;
} else {
/* Validating Multiple Email Addresses - Start */
if($('#email_notify').is(':checked')){
var emailIds = jQuery('.mail_notify input#email').val();
if(emailIds.trim()!=''){
var regex = /(?:[^\,\;]+|\\)+/g;
var matched = null;
while (matched = regex.exec(emailIds)) {
if(IDrive.Scheduler.validateSchedulerEmailAddress(matched[0].trim())==false){
if(jQuery('#scheduler_div').hasClass('manage_wrap')){
showErrorMessages('.error_msg',INVALID_EMAIL+': <b>'+matched[0].trim()+'<b>');
} else {
showErrorMessages('#popupError',INVALID_EMAIL+': <b>'+matched[0].trim()+'<b>');
}
return false;
break;
}
}
} else {
if(jQuery('#scheduler_div').hasClass('manage_wrap')){
showErrorMessages('.error_msg',ENTER_VALID_EMAIL);
} else {
showErrorMessages('#popupError',ENTER_VALID_EMAIL);
}
return false;
}
}
/* Validating Multiple Email Addresses - End */
var form_data = $("form#frm_update_schedule").serializeArray();
var weekday_selection = [];
$("input[name='weekday_selection']:checked").each(function() {
weekday_selection.push($(this).val());
});
$.each(form_data, function(k, v) {
if(v.name != "weekday_selection[]") {
form_data_arr[v.name] = v.value;
}
});
if(!form_data_arr['scheduler_selection'] && !form_data_arr['weekday_selection'] && !form_data_arr['start_immediately']){
if(jQuery('#scheduler_div').hasClass('manage_wrap')){
showErrorMessages('.error_msg',SELECT_OPTION_TO_SCHEDULE);
} else {
showErrorMessages('#popupError',SELECT_OPTION_TO_SCHEDULE);
}
return false;
}
var alertMsg = "Updating scheduler...Please wait";
}
var params = {};
params.weekday_selection = weekday_selection;
params.action = "update_job";
params.data = form_data_arr;
params.job = IDrive.Scheduler.SelectedJob;
params.data.job_type = IDrive.Jobs[params.job].job_type;
$.ajax({
url: "action.php",
type: "POST",
data: params,
beforeSend: function() {
$('html,body').scrollTop(0);
$('.common_msg').hide();
showErrorMessages('.head_search .alert',alertMsg);
$.popContainerHide();
},
success: function(data) {
processNextScheduledEvent();
if(data.indexOf('<html>')>0){
window.location.href='../index.php';
}
data = JSON.parse(data);
if(removeScheduler==true){
removeScheduler=false;
jQuery('.common_msg').hide();
IDrive.Jobs = JSON.parse(data.jobs);
showErrorMessages('.head_search .welcome_message',succMsg);
IDrive.Scheduler.SelectJob(params, IDrive.Jobs[params.job].job_type);
IDrive.Scheduler.LoadSchedulerList(false);
//Enable/Disable the Delete schedule button
jQuery('#disableDelete').show();
jQuery('#delete_scheduler').hide();
} else if(data.msg == "Job updated successfully.") {
IDrive.Jobs = JSON.parse(data.jobs);
jQuery('.alert').hide();
showErrorMessages('.head_search .welcome_message',SCHEDULAR_UPDATED);
//Added for schduler page only
if(jQuery('.body_wrap').hasClass('scheduler_page')){
IDrive.Scheduler.LoadSchedulerList(false);
//Enable/Disable the Delete schedule button
jQuery('#disableDelete').hide();
jQuery('#delete_scheduler').show();
} else {
IDrive.Scheduler.selectSchedule(IDrive.Scheduler.SelectedJob,IDrive.Jobs[params.job].job_type);
}
} else if(data.msg == "Job started successfully"){
IDrive.Jobs = JSON.parse(data.jobs);
jQuery('.alert').hide();
showErrorMessages('.head_search .welcome_message',data.msg);
//Added for schduler page only
if(jQuery('.body_wrap').hasClass('scheduler_page')){
if(machine=='twotier'){
jQuery('#vaultCancelJobButton').show();
startImmediateRunning = true;
}
}
} else {
jQuery('.alert').hide();
//Added for schduler page only
if(jQuery('.body_wrap').hasClass('scheduler_page')){
if(machine=='twotier'){
IDrive.Scheduler.SelectJob(DEFAULT_BACKUPSET_NAME, 'Backup');
} else {
IDrive.Scheduler.SelectJob(params, IDrive.Jobs[params.job].job_type);
}
}
showErrorMessages('.head_search .error_msg',data.msg);
}
}
});
},
UserAction: function() {
var selection = $(this).find('input').attr("id");
var checkFieldDisabled = jQuery('#'+selection).attr('disabled');
if(checkFieldDisabled==true || checkFieldDisabled=='disabled'){
return false;
}
// Schedule Manage page - Update check box and radio button
if($(this).hasClass('schedule_checkbox')){
$(this).find('label').toggleClass('label_checked');
if($(this).find('label').hasClass('label_checked')){
$(this).find('input').attr('checked', true);
} else {
$(this).find('input').removeAttr('checked');
}
}
if(selection=='scheduler_selection'){
$('.schedulerOption .schedule_radiobtn').find('label').removeClass('label_checked')
$(this).find('label').addClass('label_checked');
if($(this).find('label').hasClass('label_checked')){
$(this).find('input').attr('checked', true);
} else {
$(this).find('input').removeAttr('checked');
}
}
if(selection=='notify_option'){
$('.notifyOption .schedule_radiobtn').find('input').removeAttr('checked');
$('.notifyOption .schedule_radiobtn').find('label').removeClass('label_checked');
$(this).find('label').addClass('label_checked');
if($(this).find('label').hasClass('label_checked')){
$(this).find('input').attr('checked', true);
} else {
$(this).find('input').removeAttr('checked');
}
}
if($('input:radio[name="scheduler_selection"][value="monthly"]').prop('checked')==false){
$('select#day_of_month').attr('disabled','disabled').addClass('pvtKey_grey');
}
switch(selection) {
case "email_notify":
if($(this).find('input').is(':checked')) {
$("input#notify_option").removeAttr("disabled").eq(0).attr('checked', true).next().addClass('label_checked');
$("input#email").removeAttr("disabled");
$("input#email").val($("input#email").attr('placeholder'));
} else {
$("input#notify_option").attr("disabled", "disabled").next().removeAttr('class');
$("input#email").attr("disabled", "disabled");
$("input#email").val('');
}
break;
case "cut_off_time":
if($(this).find('input').is(':checked')) {
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
$("select[id^='cutoff_']").closest('li').removeClass("cutofftime");
}else {
$("select[id^='cutoff_']").attr("disabled", "disabled").addClass('pvtKey_grey');
$("select[id^='cutoff_']").closest('li').addClass("cutofftime");
}
break;
case "weekday_selection":
$("input[name^='start_immediately']").removeAttr("checked").next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="daily"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="monthly"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="hourly"]').prop('checked', false).next().removeAttr('class');
jQuery('#start_hour,#start_meridian,#start_minute').removeAttr('disabled').removeClass('pvtKey_grey');
$("#day_of_month").attr("disabled", "disabled").addClass('pvtKey_grey');
var weekday_selection = [];
$("input[name='weekday_selection']:checked").each(function() {
weekday_selection.push($(this).find('input').val());
});
if(weekday_selection.length == 7) {
$('input:radio[name="scheduler_selection"][value="daily"]').prop('checked', true).next().addClass('label_checked');
} else if(weekday_selection.length <= 0){
$('input:radio[name="scheduler_selection"][value="monthly"]').prop('checked', true).next().addClass('label_checked');
$('select#day_of_month').removeAttr('disabled').removeClass('pvtKey_grey');
$("#start_minute").removeAttr("disabled","disabled").removeClass('pvtKey_grey');
}
$("input[name^='cut_off_time']").removeAttr("disabled");
if($("input[name^='cut_off_time']").is(':checked')) {
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
}
$("input[name^='email_notify']").removeAttr("disabled");
if($("input[name^='email_notify']").is(':checked')) {
$("input[name^='notify_option']").removeAttr("disabled").removeClass('pvtKey_grey');
}
break;
case "scheduler_selection":
$("input[name^='start_immediately']").removeAttr("checked").next().removeAttr('class');
$("#start_hour,#start_minute,#start_meridian").removeAttr("disabled","disabled").removeClass('pvtKey_grey');
var scheduler = $('input:radio[name="scheduler_selection"]:checked').val();
if(scheduler == "monthly") {
$("input[name^='weekday_selection']").removeAttr("checked").next().removeAttr('class');
$("input[name^='cut_off_time']").removeAttr("disabled");
if($("input[name^='cut_off_time']").is(':checked')) {
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
}
$("#start_hour,#start_meridian").removeAttr("disabled").removeClass('pvtKey_grey');
$('select#day_of_month').removeAttr('disabled').removeClass('pvtKey_grey');
}else if(scheduler == "hourly") {
$("input[name^='weekday_selection']").removeAttr("checked").next().removeAttr('class');
$("input[name^='cut_off_time']").removeAttr("checked").attr("disabled", "disabled").next().removeAttr('class');
$("select[id^='cutoff_']").attr("disabled", "disabled").addClass('pvtKey_grey');
$("#start_minute").removeAttr("disabled").removeClass('pvtKey_grey');
$("#start_hour,#start_meridian").attr("disabled", "disabled").addClass('pvtKey_grey');
}else if(scheduler == "daily") {
$("input[name^='weekday_selection']").attr("checked", "checked").next().addClass('label_checked');
$("input[name^='cut_off_time']").removeAttr("disabled");
if($("input[name^='cut_off_time']").is(':checked')) {
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
}
$("#start_hour,#start_meridian").removeAttr("disabled").removeClass('pvtKey_grey');
}
$("input[name^='email_notify']").removeAttr("disabled");
if($("input[name^='email_notify']").is(':checked')) {
$("input[name^='notify_option']").removeAttr("disabled").removeClass('pvtKey_grey');
}
break;
case "start_immediately":
if($(this).find('input').is(':checked')) {
$('input:radio[name="scheduler_selection"][value="daily"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="monthly"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="hourly"]').prop('checked', false).next().removeAttr('class');
$("input[name^='weekday_selection']").removeAttr("checked").next().removeAttr('class');
$("#start_hour,#start_minute,#start_meridian,#day_of_month").attr("disabled","disabled").addClass('pvtKey_grey');
$("input[name^='cut_off_time']").removeAttr("disabled");
if($("input[name^='cut_off_time']").is(':checked')) {
$("select[id^='cutoff_']").removeAttr("disabled").removeClass('pvtKey_grey');
}
$("input[name^='email_notify']").removeAttr("disabled");
if($("input[name^='email_notify']").is(':checked')) {
$("input[name^='notify_option']").removeAttr("disabled").removeClass('pvtKey_grey');
}
} else {
$('.backup_set_time select').removeClass('pvtKey_grey').removeAttr('disabled');
$("select[id^='cutoff_']").attr("disabled","disabled").addClass('pvtKey_grey');
$('input:checkbox[name="cut_off_time"]').attr('disabled','disabled').removeAttr("checked").next().removeAttr('class');
$('#start_immediately ul:eq(1) li:eq(1)').addClass('cutofftime').find('select').attr("disabled", "disabled");
}
break;
}
},
DeleteJob: function(job) {
if(machine=='twotier'){
removeScheduler=true;
IDrive.Scheduler.removeScheduler();
IDrive.Scheduler.UpdateJob();
return;
}
var jobType = IDrive.Jobs[job].job_type
var jobName = job.substring((jobType.length+1));
var index = jobListArray[job];
if(index!='undefined' || index!=''){
delete jobListArray[job];
delete jobListTypeArray[job];
delete jobListSizeArray[job];
delete jobListLMTimeArray[job];
}
var params = {};
params.action = "delete_job";
params.job = job;
$.ajax({
url: "action.php",
type: "POST",
data: params,
beforeSend: function() {
$('.alert').show();
$(".alert").focus();
$(".alert").blur();
$('.alert p').html("Deleting <b>"+jobName+"</b> ...Please wait");
},
success: function(data) {
if(data.indexOf('<html>')>0){
window.location.href='../index.php';
}
data = JSON.parse(data);
if(data.msg == "Job deleted successfully.") {
IDrive.Jobs = JSON.parse(data.jobs);
$('.alert').hide();
showErrorMessages('.head_search .welcome_message','<b>'+jobName+'</b> has been deleted successfully');
IDrive.Scheduler.LoadPage(IDrive.Scheduler.Page);
}
processNextScheduledEvent();
}
});
},
DeleteSchedule: function() {
removeScheduler=true;
IDrive.Scheduler.removeScheduler();
IDrive.Scheduler.UpdateJob();
return;
},
LoadPage: function(page) {
jQuery('#content').load(page,function(){
var delay=5000;//5 seconds
setTimeout(function(){
//your code to be executed after 5 seconds
$('.alert').hide();
},delay);
setTimeout(function(){
//your code to be executed after 5 seconds
$('.alert p').html("Loading...Please wait");
},delay);
});
},
SelectRestoreJob: function() {
var val = $(this).val();
var type = "restore";
loadExistingJob(val,type);
},
CancelJob: function(job) {
clearTimeout(msgTimeoutVar);
$('.common_msg').hide();
var jobType = IDrive.Jobs[job].job_type;
var jobName = job.substring((jobType.length+1));
jobCancelling=true;
var params = {};
params.action = "cancel_job";
params.job = job;
$.ajax({
url: "action.php",
type: "POST",
data: params,
beforeSend: function() {
$('.alert').show();
$(".alert").focus();
$(".alert").blur();
$('.alert p').html("Cancelling job...Please wait");
$('#vaultCancelJobButton').hide();
},
success: function(data) {
if(data.indexOf('<html>')>0){
window.location.href='../index.php';
}
data = JSON.parse(data);
if(machine=='twotier'){
$('.alert').show();
} else if(data.msg == "Job cancelled successfully.") {
//$('.alert').hide();
//showErrorMessages('.head_search .welcome_message',data.msg);
IDrive.Scheduler.LoadPage(IDrive.Scheduler.Page);
}
}
});
},
confirmBox:function(){
var buttonId = jQuery(this).attr('id');
var job = jQuery('#clearLogObject').val();
if(buttonId=='deleteJobButton'){
if (machine != 'twotier' && $(this).attr('action') &&
$(this).attr('action') == 'delete') {
IDrive.Scheduler.DeleteJob(job);
$(this).removeAttr('action');
}
else {
IDrive.Scheduler.DeleteSchedule();
}
$.popContainerHide(); // Close popup box
return false;
} else if(buttonId=='cancelJobButton') {
$(this).removeAttr('action');
IDrive.Scheduler.CancelJob(job);
$.popContainerHide(); // Close popup box
return false;
}
},
selectSchedule:function(job,job_type) {
if(job_type == 'Backup') {
if(jQuery('.body_wrap').hasClass('backup_page')) {
var existingJob = $("#select_job").val();
} else {
var existingJob = 'Backup_LocalBackupSet';
}
} else if(job_type == 'Restore') {
var existingJob = $("#select_restore_job").val();
}
if(typeof job != "undefined" && job == existingJob) {
if(job != "" && job != 0 && typeof IDrive.Jobs[job] != "undefined") {
var sel_job = IDrive.Jobs[job].scheduler;
var html = '';
if(sel_job && typeof(sel_job.start_minute) != "undefined") {
var st_min;
if(sel_job.start_minute.length == 1) {
st_min = "0"+sel_job.start_minute;
}else {
st_min = sel_job.start_minute;
}
if(typeof(sel_job.start_hour) != "undefined"){
html += sel_job.start_hour+':'+st_min+' '+sel_job.start_meridian;
} else if(typeof(sel_job.start_meridian) != "undefined") {
html += '00:'+st_min+' '+sel_job.start_meridian;
} else {
html += '00:'+st_min;
}
if(typeof(sel_job.scheduler_selection) != "undefined") {
var capitalized = sel_job.scheduler_selection.charAt(0).toUpperCase() + sel_job.scheduler_selection.substring(1);
html += ' '+capitalized;
} else if(typeof(sel_job.weekday_selection) != "undefined") {
var capitalized = 'Weekly';
html += ' '+capitalized;
}
html += ' &nbsp;<img src="include/images/idq_ico_schedarrow.png">';
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").show();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html(html);
} else {
html = ' &nbsp;<img src="include/images/idq_ico_schedarrow.png">';
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").show();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html(html);
}
} else {
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn").hide();
$("div.wrapper section#content table.main_chk_table1 td.scheduleChangeBtn span.backuptime").html('');
}
}
},
validateSchedulerEmailAddress:function(emailAddress){
var strEmailAddress = emailAddress;
var emailAddressRegex = /^([\w-+]+(?:\.[+\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,}?)$/i
if(!emailAddressRegex.test(strEmailAddress))
{
return false;
}
},
removeScheduler:function(){
$('input:radio[name="scheduler_selection"][value="daily"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="monthly"]').prop('checked', false).next().removeAttr('class');
$('input:radio[name="scheduler_selection"][value="hourly"]').prop('checked', false).next().removeAttr('class');
$("input[name^='weekday_selection']").removeAttr("checked").next().removeAttr('class');
$('#start_hour,#start_minute,#start_meridian,#day_of_month').attr("disabled","disabled").addClass('pvtKey_grey');
$('#start_hour,#start_minute,#start_meridian,#day_of_month').children('option:first-child').attr("selected","selected");
jQuery('input#start_immediately').prop('checked', false).next().removeAttr('class');
$("input[name^='cut_off_time']").attr("disabled","disabled").addClass('pvtKey_grey').prop('checked', false).next().removeAttr('class');
$("select[id^='cutoff_']").attr("disabled","disabled").addClass('pvtKey_grey');
$('#email_notify').attr("disabled","disabled").addClass('pvtKey_grey').prop('checked', false).next().removeAttr('class');
$("input#email").val('');
}
}
$(document).ready(IDrive.Scheduler.Ready);