2013-02-20 18:33:05 -07:00
|
|
|
|
var ScheduledTaskPage = {
|
|
|
|
|
|
|
|
|
|
refreshScheduledTask: function () {
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var id = getParameterByName('id');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiClient.getScheduledTask(id).done(ScheduledTaskPage.loadScheduledTask);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadScheduledTask: function (task) {
|
|
|
|
|
|
2014-07-21 18:29:06 -07:00
|
|
|
|
var page = $.mobile.activePage;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2014-07-21 18:29:06 -07:00
|
|
|
|
$('.taskName', page).html(task.Name);
|
|
|
|
|
|
|
|
|
|
$('#pTaskDescription', page).html(task.Description);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
ScheduledTaskPage.loadTaskTriggers(task);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadTaskTriggers: function (task) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
html += '<li data-role="list-divider"><h3>' + Globalize.translate('HeaderTaskTriggers') + '</h3></li>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
for (var i = 0, length = task.Triggers.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var trigger = task.Triggers[i];
|
|
|
|
|
|
|
|
|
|
html += '<li>';
|
|
|
|
|
|
|
|
|
|
html += '<a href="#">';
|
2015-03-05 11:54:04 -07:00
|
|
|
|
|
|
|
|
|
html += '<h3>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += ScheduledTaskPage.getTriggerFriendlyName(trigger);
|
2015-03-05 11:54:04 -07:00
|
|
|
|
html += '</h3>';
|
|
|
|
|
|
|
|
|
|
if (trigger.MaxRuntimeMs) {
|
|
|
|
|
html += '<p>';
|
|
|
|
|
|
|
|
|
|
var hours = trigger.MaxRuntimeMs / 3600000;
|
|
|
|
|
|
|
|
|
|
if (hours == 1) {
|
|
|
|
|
html += Globalize.translate('ValueTimeLimitSingleHour');
|
|
|
|
|
} else {
|
|
|
|
|
html += Globalize.translate('ValueTimeLimitMultiHour', hours);
|
|
|
|
|
}
|
|
|
|
|
html += '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += '</a>';
|
|
|
|
|
|
2014-07-09 20:48:08 -07:00
|
|
|
|
html += '<a href="#" onclick="ScheduledTaskPage.confirmDeleteTrigger(' + i + ');">';
|
|
|
|
|
html += Globalize.translate('Delete');
|
|
|
|
|
html += '</a>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
html += '</li>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#ulTaskTriggers', $.mobile.activePage).html(html).listview('refresh');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getTriggerFriendlyName: function (trigger) {
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'DailyTrigger') {
|
|
|
|
|
return 'Daily at ' + ScheduledTaskPage.getDisplayTime(trigger.TimeOfDayTicks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'WeeklyTrigger') {
|
|
|
|
|
|
|
|
|
|
return trigger.DayOfWeek + 's at ' + ScheduledTaskPage.getDisplayTime(trigger.TimeOfDayTicks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'SystemEventTrigger') {
|
|
|
|
|
|
|
|
|
|
if (trigger.SystemEvent == 'WakeFromSleep') {
|
|
|
|
|
return 'On wake from sleep';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'IntervalTrigger') {
|
|
|
|
|
|
|
|
|
|
var hours = trigger.IntervalTicks / 36000000000;
|
|
|
|
|
|
|
|
|
|
if (hours == .25) {
|
|
|
|
|
return "Every 15 minutes";
|
|
|
|
|
}
|
|
|
|
|
if (hours == .5) {
|
|
|
|
|
return "Every 30 minutes";
|
|
|
|
|
}
|
|
|
|
|
if (hours == .75) {
|
|
|
|
|
return "Every 45 minutes";
|
|
|
|
|
}
|
|
|
|
|
if (hours == 1) {
|
|
|
|
|
return "Every hour";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'Every ' + hours + ' hours';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'StartupTrigger') {
|
|
|
|
|
return 'On application startup';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return trigger.Type;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getDisplayTime: function (ticks) {
|
|
|
|
|
|
|
|
|
|
var hours = ticks / 36000000000;
|
|
|
|
|
|
|
|
|
|
if (hours < 1) {
|
|
|
|
|
hours = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 10:44:55 -07:00
|
|
|
|
hours = Math.floor(hours);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
ticks -= (hours * 36000000000);
|
|
|
|
|
|
2014-03-19 10:44:55 -07:00
|
|
|
|
var minutes = Math.floor((ticks / 600000000));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
var suffix = "am";
|
|
|
|
|
|
|
|
|
|
if (hours > 11) {
|
|
|
|
|
suffix = "pm";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hours = hours % 12;
|
|
|
|
|
|
|
|
|
|
if (hours == 0) {
|
|
|
|
|
hours = 12;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (minutes < 10) {
|
|
|
|
|
minutes = '0' + minutes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hours + ':' + minutes + ' ' + suffix;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showAddTriggerPopup: function () {
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
$('#selectTriggerType', page).val('DailyTrigger').trigger('change').selectmenu('refresh');
|
|
|
|
|
|
2015-06-07 18:23:56 -07:00
|
|
|
|
$('#popupAddTrigger', page).on("popupafteropen", function () {
|
2013-03-28 20:50:46 -07:00
|
|
|
|
$('#addTriggerForm input:first', this).focus();
|
|
|
|
|
}).popup("open").on("popupafterclose", function () {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
$('#addTriggerForm', page).off("submit");
|
|
|
|
|
$(this).off("popupafterclose");
|
|
|
|
|
});
|
2014-03-26 08:06:48 -07:00
|
|
|
|
},
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
confirmDeleteTrigger: function (index) {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
Dashboard.confirm(Globalize.translate('MessageDeleteTaskTrigger'), Globalize.translate('HeaderDeleteTaskTrigger'), function (result) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
ScheduledTaskPage.deleteTrigger(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteTrigger: function (index) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var id = getParameterByName('id');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiClient.getScheduledTask(id).done(function (task) {
|
|
|
|
|
|
|
|
|
|
task.Triggers.remove(index);
|
|
|
|
|
|
|
|
|
|
ApiClient.updateScheduledTaskTriggers(task.Id, task.Triggers).done(function () {
|
|
|
|
|
|
|
|
|
|
ScheduledTaskPage.refreshScheduledTask();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refreshTriggerFields: function (triggerType) {
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
if (triggerType == 'DailyTrigger') {
|
|
|
|
|
|
|
|
|
|
$('#fldTimeOfDay', page).show();
|
|
|
|
|
$('#fldDayOfWeek', page).hide();
|
|
|
|
|
$('#fldSelectSystemEvent', page).hide();
|
|
|
|
|
$('#fldSelectInterval', page).hide();
|
|
|
|
|
$('#txtTimeOfDay', page).attr('required', 'required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (triggerType == 'WeeklyTrigger') {
|
|
|
|
|
$('#fldTimeOfDay', page).show();
|
|
|
|
|
$('#fldDayOfWeek', page).show();
|
|
|
|
|
$('#fldSelectSystemEvent', page).hide();
|
|
|
|
|
$('#fldSelectInterval', page).hide();
|
|
|
|
|
$('#txtTimeOfDay', page).attr('required', 'required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (triggerType == 'SystemEventTrigger') {
|
|
|
|
|
$('#fldTimeOfDay', page).hide();
|
|
|
|
|
$('#fldDayOfWeek', page).hide();
|
|
|
|
|
$('#fldSelectSystemEvent', page).show();
|
|
|
|
|
$('#fldSelectInterval', page).hide();
|
|
|
|
|
$('#txtTimeOfDay', page).removeAttr('required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (triggerType == 'IntervalTrigger') {
|
|
|
|
|
$('#fldTimeOfDay', page).hide();
|
|
|
|
|
$('#fldDayOfWeek', page).hide();
|
|
|
|
|
$('#fldSelectSystemEvent', page).hide();
|
|
|
|
|
$('#fldSelectInterval', page).show();
|
|
|
|
|
$('#txtTimeOfDay', page).removeAttr('required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (triggerType == 'StartupTrigger') {
|
|
|
|
|
$('#fldTimeOfDay', page).hide();
|
|
|
|
|
$('#fldDayOfWeek', page).hide();
|
|
|
|
|
$('#fldSelectSystemEvent', page).hide();
|
|
|
|
|
$('#fldSelectInterval', page).hide();
|
|
|
|
|
$('#txtTimeOfDay', page).removeAttr('required');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getTriggerToAdd: function () {
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
var trigger = {
|
|
|
|
|
Type: $('#selectTriggerType', page).val()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (trigger.Type == 'DailyTrigger') {
|
|
|
|
|
trigger.TimeOfDayTicks = ScheduledTaskPage.getTimeOfDayTicks($('#txtTimeOfDay', page).val());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (trigger.Type == 'WeeklyTrigger') {
|
|
|
|
|
trigger.DayOfWeek = $('#selectDayOfWeek', page).val();
|
|
|
|
|
trigger.TimeOfDayTicks = ScheduledTaskPage.getTimeOfDayTicks($('#txtTimeOfDay', page).val());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (trigger.Type == 'SystemEventTrigger') {
|
|
|
|
|
trigger.SystemEvent = $('#selectSystemEvent', page).val();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (trigger.Type == 'IntervalTrigger') {
|
|
|
|
|
trigger.IntervalTicks = $('#selectInterval', page).val();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-05 11:54:04 -07:00
|
|
|
|
var timeLimit = $('#txtTimeLimit', page).val() || '0';
|
|
|
|
|
timeLimit = parseFloat(timeLimit) * 3600000;
|
|
|
|
|
|
|
|
|
|
trigger.MaxRuntimeMs = timeLimit || null;
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
return trigger;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getTimeOfDayTicks: function (val) {
|
|
|
|
|
|
|
|
|
|
var vals = val.split(':');
|
|
|
|
|
|
|
|
|
|
var hours = vals[0];
|
|
|
|
|
var minutes = vals[1];
|
|
|
|
|
|
|
|
|
|
// Add hours
|
|
|
|
|
var ticks = hours * 60 * 60 * 1000 * 10000;
|
|
|
|
|
|
|
|
|
|
ticks += minutes * 60 * 1000 * 10000;
|
|
|
|
|
|
|
|
|
|
return ticks;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-07 18:23:56 -07:00
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
|
|
function onSubmit() {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var id = getParameterByName('id');
|
|
|
|
|
|
|
|
|
|
ApiClient.getScheduledTask(id).done(function (task) {
|
|
|
|
|
|
|
|
|
|
task.Triggers.push(ScheduledTaskPage.getTriggerToAdd());
|
|
|
|
|
|
|
|
|
|
ApiClient.updateScheduledTaskTriggers(task.Id, task.Triggers).done(function () {
|
|
|
|
|
|
|
|
|
|
$('#popupAddTrigger').popup('close');
|
|
|
|
|
|
|
|
|
|
ScheduledTaskPage.refreshScheduledTask();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinitdepends', "#scheduledTaskPage", function () {
|
|
|
|
|
|
|
|
|
|
$('.addTriggerForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
|
|
|
|
|
|
}).on('pageshowready', "#scheduledTaskPage", function () {
|
|
|
|
|
|
|
|
|
|
ScheduledTaskPage.refreshScheduledTask();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|