fix sync task button

This commit is contained in:
Luke Pulverenti 2016-08-17 16:32:39 -04:00
parent f6b89286dc
commit 9ebe643e87
9 changed files with 66 additions and 48 deletions

View File

@ -1,4 +1,4 @@
<div id="libraryFileOrganizerLogPage" data-role="page" class="page type-interior organizePage withTabs fullWidthContent" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Auto-Organize" data-require="jqmtable,scripts/autoorganizelog,scripts/taskbutton,detailtablecss"> <div id="libraryFileOrganizerLogPage" data-role="page" class="page type-interior organizePage withTabs fullWidthContent" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Auto-Organize" data-require="jqmtable,scripts/autoorganizelog,detailtablecss">
<div data-role="content"> <div data-role="content">
<div class="content-primary"> <div class="content-primary">

View File

@ -1,4 +1,4 @@
<div id="mediaLibraryPage" data-role="page" class="page type-interior mediaLibraryPage librarySectionPage withTabs fullWidthContent" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Library%20setup" data-require="scripts/medialibrarypage,scripts/taskbutton"> <div id="mediaLibraryPage" data-role="page" class="page type-interior mediaLibraryPage librarySectionPage withTabs fullWidthContent" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Library%20setup" data-require="scripts/medialibrarypage">
<div data-role="content"> <div data-role="content">
<div class="content-primary"> <div class="content-primary">

View File

@ -1,4 +1,4 @@
<div id="liveTvStatusPage" data-role="page" class="page type-interior liveTvSettingsPage withTabs" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Live%20TV" data-require="scripts/livetvstatus,scripts/taskbutton,emby-button"> <div id="liveTvStatusPage" data-role="page" class="page type-interior liveTvSettingsPage withTabs" data-helpurl="https://github.com/MediaBrowser/Wiki/wiki/Live%20TV" data-require="scripts/livetvstatus,emby-button">
<div data-role="content"> <div data-role="content">
<div class="content-primary"> <div class="content-primary">

View File

@ -1,4 +1,4 @@
define(['jQuery', 'datetime', 'paper-icon-button-light'], function ($, datetime) { define(['jQuery', 'scripts/taskbutton', 'datetime', 'paper-icon-button-light'], function ($, taskButton, datetime) {
var query = { var query = {
@ -309,11 +309,12 @@
reloadItems(page); reloadItems(page);
// on here // on here
$('.btnOrganize', page).taskButton({ taskButton({
mode: 'on', mode: 'on',
progressElem: page.querySelector('.organizeProgress'), progressElem: page.querySelector('.organizeProgress'),
panel: page.querySelector('.organizeTaskPanel'), panel: page.querySelector('.organizeTaskPanel'),
taskKey: 'AutoOrganize' taskKey: 'AutoOrganize',
button: page.querySelector('.btnOrganize')
}); });
Events.on(ApiClient, 'websocketmessage', onWebSocketMessage); Events.on(ApiClient, 'websocketmessage', onWebSocketMessage);
@ -325,8 +326,9 @@
currentResult = null; currentResult = null;
// off here // off here
$('.btnOrganize', page).taskButton({ taskButton({
mode: 'off' mode: 'off',
button: page.querySelector('.btnOrganize')
}); });
Events.off(ApiClient, 'websocketmessage', onWebSocketMessage); Events.off(ApiClient, 'websocketmessage', onWebSocketMessage);

View File

@ -674,7 +674,7 @@
return; return;
} }
viewMenuBarTabs.querySelector('is=["emby-tabs"]').selectedIndex(selectedIndex); viewMenuBarTabs.querySelector('[is="emby-tabs"]').selectedIndex(selectedIndex);
LibraryMenu.tabType = type; LibraryMenu.tabType = type;
}); });

View File

@ -1,4 +1,4 @@
define(['jQuery', 'listViewStyle'], function ($) { define(['jQuery', 'scripts/taskbutton', 'listViewStyle'], function ($, taskButton) {
function resetTuner(page, id) { function resetTuner(page, id) {
@ -595,10 +595,11 @@
reload(page); reload(page);
// on here // on here
$('.btnRefresh', page).taskButton({ taskButton({
mode: 'on', mode: 'on',
progressElem: page.querySelector('.refreshGuideProgress'), progressElem: page.querySelector('.refreshGuideProgress'),
taskKey: 'RefreshGuide' taskKey: 'RefreshGuide',
button: page.querySelector('.btnRefresh')
}); });
}).on('pagehide', "#liveTvStatusPage", function () { }).on('pagehide', "#liveTvStatusPage", function () {
@ -606,8 +607,11 @@
var page = this; var page = this;
// off here // off here
$('.btnRefreshGuide', page).taskButton({ taskButton({
mode: 'off' mode: 'off',
progressElem: page.querySelector('.refreshGuideProgress'),
taskKey: 'RefreshGuide',
button: page.querySelector('.btnRefresh')
}); });
}); });

View File

@ -1,4 +1,4 @@
define(['jQuery', 'apphost', 'cardStyle'], function ($, appHost) { define(['jQuery', 'apphost', 'scripts/taskbutton', 'cardStyle'], function ($, appHost, taskButton) {
function changeCollectionType(page, virtualFolder) { function changeCollectionType(page, virtualFolder) {
@ -461,10 +461,11 @@
var page = this; var page = this;
// on here // on here
$('.btnRefresh', page).taskButton({ taskButton({
mode: 'on', mode: 'on',
progressElem: page.querySelector('.refreshProgress'), progressElem: page.querySelector('.refreshProgress'),
taskKey: 'RefreshLibrary' taskKey: 'RefreshLibrary',
button: page.querySelector('.btnRefresh')
}); });
}); });
@ -474,8 +475,11 @@
var page = this; var page = this;
// off here // off here
$('.btnRefresh', page).taskButton({ taskButton({
mode: 'off' mode: 'off',
progressElem: page.querySelector('.refreshProgress'),
taskKey: 'RefreshLibrary',
button: page.querySelector('.btnRefresh')
}); });
}); });

View File

@ -1,4 +1,4 @@
define(['loading', 'apphost', 'globalize', 'syncJobList', 'events', 'localsync', 'emby-button', 'paper-icon-button-light'], function (loading, appHost, globalize, syncJobList, events) { define(['loading', 'apphost', 'globalize', 'syncJobList', 'events', 'scripts/taskbutton', 'localsync', 'emby-button', 'paper-icon-button-light'], function (loading, appHost, globalize, syncJobList, events, taskButton) {
function getTabs() { function getTabs() {
return [ return [
@ -57,6 +57,22 @@
view.addEventListener('viewshow', function () { view.addEventListener('viewshow', function () {
LibraryMenu.setTabs('syncadmin', 0, getTabs); LibraryMenu.setTabs('syncadmin', 0, getTabs);
taskButton({
mode: 'on',
progressElem: view.querySelector('.syncProgress'),
taskKey: 'SyncPrepare',
button: view.querySelector('.btnSync')
});
});
view.addEventListener('viewbeforehide', function () {
taskButton({
mode: 'off',
taskKey: 'SyncPrepare',
button: view.querySelector('.btnSync')
});
}); });
view.addEventListener('viewdestroy', function () { view.addEventListener('viewdestroy', function () {

View File

@ -1,21 +1,19 @@
define(['appStorage', 'jQuery', 'emby-button'], function (appStorage, $) { define(['appStorage', 'emby-button'], function (appStorage) {
$.fn.taskButton = function (options) { return function (options) {
function pollTasks(button) { var button = options.button;
function pollTasks() {
ApiClient.getScheduledTasks({ ApiClient.getScheduledTasks({
IsEnabled: true IsEnabled: true
}).then(function (tasks) { }).then(updateTasks);
updateTasks(button, tasks);
});
} }
function updateTasks(button, tasks) { function updateTasks(tasks) {
var task = tasks.filter(function (t) { var task = tasks.filter(function (t) {
@ -36,12 +34,12 @@
} }
if (task.State == 'Idle') { if (task.State == 'Idle') {
$(button).removeAttr('disabled'); button.removeAttribute('disabled');
} else { } else {
$(button).attr('disabled', 'disabled'); button.setAttribute('disabled', 'disabled');
} }
$(button).attr('data-taskid', task.Id); button.setAttribute('data-taskid', task.Id);
var progress = (task.CurrentProgressPercentage || 0).toFixed(1); var progress = (task.CurrentProgressPercentage || 0).toFixed(1);
@ -72,11 +70,8 @@
} }
} }
function onScheduledTaskMessageConfirmed(instance, id) { function onScheduledTaskMessageConfirmed(id) {
ApiClient.startScheduledTask(id).then(function () { ApiClient.startScheduledTask(id).then(pollTasks);
pollTasks(instance);
});
} }
function onButtonClick() { function onButtonClick() {
@ -88,7 +83,7 @@
var expectedValue = new Date().getMonth() + '6'; var expectedValue = new Date().getMonth() + '6';
if (appStorage.getItem(key) == expectedValue) { if (appStorage.getItem(key) == expectedValue) {
onScheduledTaskMessageConfirmed(button, id); onScheduledTaskMessageConfirmed(id);
} else { } else {
var msg = Globalize.translate('ConfirmMessageScheduledTaskButton'); var msg = Globalize.translate('ConfirmMessageScheduledTaskButton');
@ -107,7 +102,7 @@
}).then(function () { }).then(function () {
appStorage.setItem(key, expectedValue); appStorage.setItem(key, expectedValue);
onScheduledTaskMessageConfirmed(button, id); onScheduledTaskMessageConfirmed(id);
}); });
}); });
@ -123,17 +118,16 @@
var tasks = msg.Data; var tasks = msg.Data;
updateTasks(self, tasks); updateTasks(tasks);
} }
} }
var self = this;
var pollInterval; var pollInterval;
function onPollIntervalFired() { function onPollIntervalFired() {
if (!ApiClient.isWebSocketOpen()) { if (!ApiClient.isWebSocketOpen()) {
pollTasks(self); pollTasks();
} }
} }
@ -162,23 +156,21 @@
if (options.mode == 'off') { if (options.mode == 'off') {
this.off('click', onButtonClick); button.removeEventListener('click', onButtonClick);
Events.off(ApiClient, 'websocketmessage', onSocketMessage); Events.off(ApiClient, 'websocketmessage', onSocketMessage);
Events.off(ApiClient, 'websocketopen', onSocketOpen); Events.off(ApiClient, 'websocketopen', onSocketOpen);
stopInterval(); stopInterval();
} else if (this.length) { } else {
this.on('click', onButtonClick); button.addEventListener('click', onButtonClick);
pollTasks(self); pollTasks();
startInterval(); startInterval();
Events.on(ApiClient, 'websocketmessage', onSocketMessage); Events.on(ApiClient, 'websocketmessage', onSocketMessage);
Events.on(ApiClient, 'websocketopen', onSocketOpen); Events.on(ApiClient, 'websocketopen', onSocketOpen);
} }
return this;
}; };
}); });