diff --git a/dashboard-ui/scripts/autoorganizelog.js b/dashboard-ui/scripts/autoorganizelog.js
index 4367256a76..9e826fb082 100644
--- a/dashboard-ui/scripts/autoorganizelog.js
+++ b/dashboard-ui/scripts/autoorganizelog.js
@@ -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 = {
@@ -309,11 +309,12 @@
reloadItems(page);
// on here
- $('.btnOrganize', page).taskButton({
+ taskButton({
mode: 'on',
progressElem: page.querySelector('.organizeProgress'),
panel: page.querySelector('.organizeTaskPanel'),
- taskKey: 'AutoOrganize'
+ taskKey: 'AutoOrganize',
+ button: page.querySelector('.btnOrganize')
});
Events.on(ApiClient, 'websocketmessage', onWebSocketMessage);
@@ -325,8 +326,9 @@
currentResult = null;
// off here
- $('.btnOrganize', page).taskButton({
- mode: 'off'
+ taskButton({
+ mode: 'off',
+ button: page.querySelector('.btnOrganize')
});
Events.off(ApiClient, 'websocketmessage', onWebSocketMessage);
diff --git a/dashboard-ui/scripts/librarymenu.js b/dashboard-ui/scripts/librarymenu.js
index 3c9d8a9f9f..23baf529cf 100644
--- a/dashboard-ui/scripts/librarymenu.js
+++ b/dashboard-ui/scripts/librarymenu.js
@@ -674,7 +674,7 @@
return;
}
- viewMenuBarTabs.querySelector('is=["emby-tabs"]').selectedIndex(selectedIndex);
+ viewMenuBarTabs.querySelector('[is="emby-tabs"]').selectedIndex(selectedIndex);
LibraryMenu.tabType = type;
});
diff --git a/dashboard-ui/scripts/livetvstatus.js b/dashboard-ui/scripts/livetvstatus.js
index edb11396e2..aead5dcb3f 100644
--- a/dashboard-ui/scripts/livetvstatus.js
+++ b/dashboard-ui/scripts/livetvstatus.js
@@ -1,4 +1,4 @@
-define(['jQuery', 'listViewStyle'], function ($) {
+define(['jQuery', 'scripts/taskbutton', 'listViewStyle'], function ($, taskButton) {
function resetTuner(page, id) {
@@ -595,10 +595,11 @@
reload(page);
// on here
- $('.btnRefresh', page).taskButton({
+ taskButton({
mode: 'on',
progressElem: page.querySelector('.refreshGuideProgress'),
- taskKey: 'RefreshGuide'
+ taskKey: 'RefreshGuide',
+ button: page.querySelector('.btnRefresh')
});
}).on('pagehide', "#liveTvStatusPage", function () {
@@ -606,8 +607,11 @@
var page = this;
// off here
- $('.btnRefreshGuide', page).taskButton({
- mode: 'off'
+ taskButton({
+ mode: 'off',
+ progressElem: page.querySelector('.refreshGuideProgress'),
+ taskKey: 'RefreshGuide',
+ button: page.querySelector('.btnRefresh')
});
});
diff --git a/dashboard-ui/scripts/medialibrarypage.js b/dashboard-ui/scripts/medialibrarypage.js
index 6bfb87fca6..c96392fc05 100644
--- a/dashboard-ui/scripts/medialibrarypage.js
+++ b/dashboard-ui/scripts/medialibrarypage.js
@@ -1,4 +1,4 @@
-define(['jQuery', 'apphost', 'cardStyle'], function ($, appHost) {
+define(['jQuery', 'apphost', 'scripts/taskbutton', 'cardStyle'], function ($, appHost, taskButton) {
function changeCollectionType(page, virtualFolder) {
@@ -461,10 +461,11 @@
var page = this;
// on here
- $('.btnRefresh', page).taskButton({
+ taskButton({
mode: 'on',
progressElem: page.querySelector('.refreshProgress'),
- taskKey: 'RefreshLibrary'
+ taskKey: 'RefreshLibrary',
+ button: page.querySelector('.btnRefresh')
});
});
@@ -474,8 +475,11 @@
var page = this;
// off here
- $('.btnRefresh', page).taskButton({
- mode: 'off'
+ taskButton({
+ mode: 'off',
+ progressElem: page.querySelector('.refreshProgress'),
+ taskKey: 'RefreshLibrary',
+ button: page.querySelector('.btnRefresh')
});
});
diff --git a/dashboard-ui/scripts/syncactivity.js b/dashboard-ui/scripts/syncactivity.js
index d0f88a1fef..fbb5161776 100644
--- a/dashboard-ui/scripts/syncactivity.js
+++ b/dashboard-ui/scripts/syncactivity.js
@@ -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() {
return [
@@ -57,6 +57,22 @@
view.addEventListener('viewshow', function () {
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 () {
diff --git a/dashboard-ui/scripts/taskbutton.js b/dashboard-ui/scripts/taskbutton.js
index b163337c02..add214ac57 100644
--- a/dashboard-ui/scripts/taskbutton.js
+++ b/dashboard-ui/scripts/taskbutton.js
@@ -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({
IsEnabled: true
- }).then(function (tasks) {
-
- updateTasks(button, tasks);
- });
-
+ }).then(updateTasks);
}
- function updateTasks(button, tasks) {
+ function updateTasks(tasks) {
var task = tasks.filter(function (t) {
@@ -36,12 +34,12 @@
}
if (task.State == 'Idle') {
- $(button).removeAttr('disabled');
+ button.removeAttribute('disabled');
} 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);
@@ -72,11 +70,8 @@
}
}
- function onScheduledTaskMessageConfirmed(instance, id) {
- ApiClient.startScheduledTask(id).then(function () {
-
- pollTasks(instance);
- });
+ function onScheduledTaskMessageConfirmed(id) {
+ ApiClient.startScheduledTask(id).then(pollTasks);
}
function onButtonClick() {
@@ -88,7 +83,7 @@
var expectedValue = new Date().getMonth() + '6';
if (appStorage.getItem(key) == expectedValue) {
- onScheduledTaskMessageConfirmed(button, id);
+ onScheduledTaskMessageConfirmed(id);
} else {
var msg = Globalize.translate('ConfirmMessageScheduledTaskButton');
@@ -107,7 +102,7 @@
}).then(function () {
appStorage.setItem(key, expectedValue);
- onScheduledTaskMessageConfirmed(button, id);
+ onScheduledTaskMessageConfirmed(id);
});
});
@@ -123,17 +118,16 @@
var tasks = msg.Data;
- updateTasks(self, tasks);
+ updateTasks(tasks);
}
}
- var self = this;
var pollInterval;
function onPollIntervalFired() {
if (!ApiClient.isWebSocketOpen()) {
- pollTasks(self);
+ pollTasks();
}
}
@@ -162,23 +156,21 @@
if (options.mode == 'off') {
- this.off('click', onButtonClick);
+ button.removeEventListener('click', onButtonClick);
Events.off(ApiClient, 'websocketmessage', onSocketMessage);
Events.off(ApiClient, 'websocketopen', onSocketOpen);
stopInterval();
- } else if (this.length) {
+ } else {
- this.on('click', onButtonClick);
+ button.addEventListener('click', onButtonClick);
- pollTasks(self);
+ pollTasks();
startInterval();
Events.on(ApiClient, 'websocketmessage', onSocketMessage);
Events.on(ApiClient, 'websocketopen', onSocketOpen);
}
-
- return this;
};
});
\ No newline at end of file