diff --git a/dashboard-ui/bower_components/emby-webcomponents/itemcontextmenu.js b/dashboard-ui/bower_components/emby-webcomponents/itemcontextmenu.js index 96ecf3b0a1..9494f6e98e 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/itemcontextmenu.js +++ b/dashboard-ui/bower_components/emby-webcomponents/itemcontextmenu.js @@ -425,10 +425,7 @@ define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'embyRouter', { require(['syncDialog'], function (syncDialog) { syncDialog.showMenu({ - items: [ - { - Id: itemId - }], + items: [item], serverId: serverId }); }); @@ -439,10 +436,7 @@ define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'embyRouter', { require(['syncDialog'], function (syncDialog) { syncDialog.showMenu({ - items: [ - { - Id: itemId - }], + items: [item], isLocalSync: true, serverId: serverId }); diff --git a/dashboard-ui/bower_components/emby-webcomponents/sync/sync.js b/dashboard-ui/bower_components/emby-webcomponents/sync/sync.js index 57f64cb58f..cbcbc2ab35 100644 --- a/dashboard-ui/bower_components/emby-webcomponents/sync/sync.js +++ b/dashboard-ui/bower_components/emby-webcomponents/sync/sync.js @@ -1,4 +1,4 @@ -define(['apphost', 'globalize', 'connectionManager', 'layoutManager', 'shell', 'focusManager', 'scrollHelper', 'paper-icon-button-light', 'formDialogStyle'], function (appHost, globalize, connectionManager, layoutManager, shell, focusManager, scrollHelper) { +define(['apphost', 'globalize', 'connectionManager', 'layoutManager', 'shell', 'focusManager', 'scrollHelper', 'appSettings', 'paper-icon-button-light', 'formDialogStyle'], function (appHost, globalize, connectionManager, layoutManager, shell, focusManager, scrollHelper, appSettings) { var currentDialogOptions; @@ -66,6 +66,56 @@ return true; } + function submitQuickSyncJob(apiClient, userId, targetId, syncOptions) { + + if (!userId) { + throw new Error('userId cannot be null'); + } + + if (!syncOptions) { + throw new Error('syncOptions cannot be null'); + } + + if (!targetId) { + throw new Error('targetId cannot be null'); + } + + var options = { + + userId: userId, + TargetId: targetId, + + ParentId: syncOptions.ParentId, + Category: syncOptions.Category, + Quality: syncOptions.Quality, + Bitrate: syncOptions.Bitrate + }; + + if (syncOptions.items && syncOptions.items.length) { + options.ItemIds = (syncOptions.items || []).map(function (i) { + return i.Id || i; + }).join(','); + } + + return apiClient.ajax({ + + type: "POST", + url: apiClient.getUrl("Sync/Jobs"), + data: JSON.stringify(options), + contentType: "application/json", + dataType: 'json' + + }).then(function () { + + require(['toast'], function (toast) { + + var msg = targetId == apiClient.deviceId() ? globalize.translate('sharedcomponents#DownloadScheduled') : globalize.translate('sharedcomponents#SyncJobCreated'); + + toast(msg); + }); + }); + } + function setJobValues(job, form) { var txtBitrate = form.querySelector('#txtBitrate'); @@ -253,7 +303,7 @@ } // This isn't ideal, but allow time for the change handlers above to run - setTimeout(function() { + setTimeout(function () { focusManager.autoFocus(elem); }, 100); } @@ -272,12 +322,44 @@ }); } + function enableAutoSync(options) { + + if (!options.isLocalSync) { + return false; + } + + var firstItem = (options.items || [])[0] || {}; + + if (firstItem.Type == 'Audio') { + return true; + } + if (firstItem.Type == 'MusicAlbum') { + return true; + } + if (firstItem.Type == 'MusicArtist') { + return true; + } + if (firstItem.Type == 'MusicGenre') { + return true; + } + + return false; + } + function showSyncMenuInternal(dialogHelper, options) { var apiClient = connectionManager.getApiClient(options.serverId); - var userId = apiClient.getCurrentUserId(); + if (enableAutoSync(options)) { + + return submitQuickSyncJob(apiClient, userId, apiClient.deviceId(), { + items: options.items, + Quality: 'custom', + Bitrate: appSettings.maxStaticMusicBitrate() + }); + } + var dialogOptionsQuery = { UserId: userId, ItemIds: (options.items || []).map(function (i) {