1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/sync.js

155 lines
4.9 KiB
JavaScript
Raw Normal View History

(function (window, $) {
2014-12-12 22:56:30 -05:00
function submitJob(userId, syncOptions, form) {
if (!userId) {
throw new Error('userId cannot be null');
}
if (!syncOptions) {
throw new Error('syncOptions cannot be null');
}
if (!form) {
throw new Error('form cannot be null');
}
2014-07-22 12:36:34 -04:00
2014-07-26 13:30:15 -04:00
var target = $('.radioSync:checked', form).get().map(function (c) {
2014-07-22 12:36:34 -04:00
return c.getAttribute('data-targetid');
2014-07-26 13:30:15 -04:00
})[0];
if (!target) {
2014-07-22 12:36:34 -04:00
2014-12-12 22:56:30 -05:00
Dashboard.alert(Globalize.translate('MessagePleaseSelectDeviceToSyncTo'));
2014-07-22 12:36:34 -04:00
return;
}
var options = {
userId: userId,
2014-07-26 13:30:15 -04:00
TargetId: target,
2014-07-22 12:36:34 -04:00
2014-12-12 22:56:30 -05:00
ItemIds: syncOptions.items.map(function (i) {
return i.Id || i;
2014-07-22 12:36:34 -04:00
}).join(','),
2014-12-11 01:20:28 -05:00
Quality: $('.radioSyncQuality', form)[0].getAttribute('data-value'),
Name: $('#txtSyncJobName', form).val()
2014-07-22 12:36:34 -04:00
};
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl("Sync/Jobs"),
data: JSON.stringify(options),
contentType: "application/json"
}).done(function () {
2014-12-11 01:20:28 -05:00
$('.syncPanel').panel('close');
$(window.SyncManager).trigger('jobsubmit');
2014-12-12 22:56:30 -05:00
Dashboard.alert(Globalize.translate('MessageSyncJobCreated'));
2014-07-22 12:36:34 -04:00
});
}
2014-12-12 22:56:30 -05:00
function showSyncMenu(options) {
2014-07-22 12:36:34 -04:00
var userId = Dashboard.getCurrentUserId();
ApiClient.getJSON(ApiClient.getUrl('Sync/Targets', {
UserId: userId
})).done(function (targets) {
var html = '<div data-role="panel" data-position="right" data-display="overlay" class="syncPanel" data-position-fixed="true" data-theme="a">';
html += '<div>';
2014-12-11 01:20:28 -05:00
html += '<h1 style="margin-top:.5em;">' + Globalize.translate('SyncMedia') + '</h1>';
2014-07-22 12:36:34 -04:00
html += '<form class="formSubmitSyncRequest">';
2014-12-12 22:56:30 -05:00
if (options.items.length > 1) {
2014-12-11 01:20:28 -05:00
html += '<p>';
2014-12-12 22:56:30 -05:00
html += '<label for="txtSyncJobName">' + Globalize.translate('LabelSyncJobName') + '</label>';
2014-12-11 01:20:28 -05:00
html += '<input type="text" id="txtSyncJobName" class="txtSyncJobName" required="required" />';
html += '</p>';
}
2014-07-22 12:36:34 -04:00
html += '<div>';
html += '<fieldset data-role="controlgroup">';
2014-12-12 22:56:30 -05:00
html += '<legend>' + Globalize.translate('LabelSyncTo') + '</legend>';
2014-07-22 12:36:34 -04:00
2014-12-11 01:20:28 -05:00
var index = 0;
2014-07-22 12:36:34 -04:00
html += targets.map(function (t) {
2014-07-26 13:30:15 -04:00
var targetHtml = '<label for="radioSync' + t.Id + '">' + t.Name + '</label>';
2014-07-22 12:36:34 -04:00
2014-12-11 01:20:28 -05:00
var checkedHtml = index ? '' : ' checked="checked"';
targetHtml += '<input class="radioSync" data-targetid="' + t.Id + '" type="radio" id="radioSync' + t.Id + '"' + checkedHtml + ' />';
index++;
2014-07-22 12:36:34 -04:00
return targetHtml;
}).join('');
html += '</fieldset>';
html += '</div>';
html += '<br/>';
html += '<div>';
html += '<fieldset data-role="controlgroup">';
2014-12-12 22:56:30 -05:00
html += '<legend>' + Globalize.translate('LabelQuality') + '</legend>';
html += '<label for="radioHighSyncQuality">' + Globalize.translate('OptionHigh') + '</label>';
2014-07-22 12:36:34 -04:00
html += '<input type="radio" id="radioHighSyncQuality" name="radioSyncQuality" checked="checked" class="radioSyncQuality" data-value="High" />';
2014-12-12 22:56:30 -05:00
html += '<label for="radioMediumSyncQuality">' + Globalize.translate('OptionMedium') + '</label>';
2014-07-22 12:36:34 -04:00
html += '<input type="radio" id="radioMediumSyncQuality" name="radioSyncQuality" class="radioSyncQuality" data-value="Medium" />';
2014-12-12 22:56:30 -05:00
html += '<label for="radioLowSyncQuality">' + Globalize.translate('OptionLow') + '</label>';
2014-07-22 12:36:34 -04:00
html += '<input type="radio" id="radioLowSyncQuality" name="radioSyncQuality" class="radioSyncQuality" data-value="Low" />';
html += '</fieldset>';
html += '</div>';
html += '<br/>';
html += '<p>';
2014-12-12 22:56:30 -05:00
html += '<button type="submit" data-icon="refresh" data-theme="b">' + Globalize.translate('ButtonSync') + '</button>';
2014-07-22 12:36:34 -04:00
html += '</p>';
html += '</form>';
html += '</div>';
html += '</div>';
$(document.body).append(html);
var elem = $('.syncPanel').panel({}).trigger('create').panel("open").on("panelclose", function () {
$(this).off("panelclose").remove();
});
$('form', elem).on('submit', function () {
2014-12-12 22:56:30 -05:00
submitJob(userId, options, this);
2014-07-22 12:36:34 -04:00
return false;
});
});
2014-07-20 00:46:29 -04:00
}
2014-07-20 00:46:29 -04:00
function isAvailable(item, user) {
2014-07-26 13:30:15 -04:00
2014-12-11 01:20:28 -05:00
//return false;
2014-07-22 12:36:34 -04:00
return item.SupportsSync;
}
window.SyncManager = {
2014-07-20 00:46:29 -04:00
showMenu: showSyncMenu,
isAvailable: isAvailable
};
})(window, jQuery);