var ScheduledTasksPage = { onPageShow: function () { Dashboard.showLoadingMsg(); ScheduledTasksPage.reloadList(true); $(ApiClient).on("websocketmessage", ScheduledTasksPage.onWebSocketMessage).on("websocketopen", ScheduledTasksPage.onWebSocketConnectionChange).on("websocketerror", ScheduledTasksPage.onWebSocketConnectionChange).on("websocketclose", ScheduledTasksPage.onWebSocketConnectionChange); }, onPageHide: function () { $(ApiClient).off("websocketmessage", ScheduledTasksPage.onWebSocketMessage).off("websocketopen", ScheduledTasksPage.onWebSocketConnectionChange).off("websocketerror", ScheduledTasksPage.onWebSocketConnectionChange).off("websocketclose", ScheduledTasksPage.onWebSocketConnectionChange); ScheduledTasksPage.stopInterval(); }, startInterval: function () { if (ApiClient.isWebSocketOpen()) { ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1500,1500"); } }, stopInterval: function () { if (ApiClient.isWebSocketOpen()) { ApiClient.sendWebSocketMessage("ScheduledTasksInfoStop"); } }, onWebSocketMessage: function (e, msg) { if (msg.MessageType == "ScheduledTasksInfo") { ScheduledTasksPage.populateList(msg.Data); } }, onWebSocketConnectionChange: function() { ScheduledTasksPage.reloadList(true); }, reloadList: function (updateInterval) { if (updateInterval) { ScheduledTasksPage.stopInterval(); } ApiClient.getScheduledTasks().done(function (tasks) { ScheduledTasksPage.populateList(tasks); Dashboard.hideLoadingMsg(); if (updateInterval) { ScheduledTasksPage.startInterval(); } }); }, populateList: function (tasks) { tasks = tasks.sort(function (a, b) { a = a.Category + " " + a.Name; b = b.Category + " " + b.Name; if (a == b) { return 0; } if (a < b) { return -1; } return 1; }); var page = $($.mobile.activePage); var html = ""; html += '"; $('#divScheduledTasks', page).html(html).trigger('create'); }, startTask: function (id) { ApiClient.startScheduledTask(id).done(function (result) { ScheduledTasksPage.reloadList(); }); }, stopTask: function (id) { ApiClient.stopScheduledTask(id).done(function (result) { ScheduledTasksPage.reloadList(); }); } }; $(document).on('pageshow', "#scheduledTasksPage", ScheduledTasksPage.onPageShow).on('pagehide', "#scheduledTasksPage", ScheduledTasksPage.onPageHide);