jellyfin-web/dashboard-ui/scripts/sync.js

125 lines
3.6 KiB
JavaScript
Raw Normal View History

(function (window, $) {
2014-07-22 09:36:34 -07:00
function submitJob(userId, items, form) {
2014-07-26 10:30:15 -07:00
var target = $('.radioSync:checked', form).get().map(function (c) {
2014-07-22 09:36:34 -07:00
return c.getAttribute('data-targetid');
2014-07-26 10:30:15 -07:00
})[0];
if (!target) {
2014-07-22 09:36:34 -07:00
2014-07-26 10:30:15 -07:00
Dashboard.alert('Please select a device to sync to.');
2014-07-22 09:36:34 -07:00
return;
}
var options = {
userId: userId,
2014-07-26 10:30:15 -07:00
TargetId: target,
2014-07-22 09:36:34 -07:00
ItemIds: items.map(function (i) {
return i.Id;
}).join(','),
Quality: $('.radioSyncQuality', form)[0].getAttribute('data-value')
};
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl("Sync/Jobs"),
data: JSON.stringify(options),
contentType: "application/json"
}).done(function () {
});
}
function showSyncMenu(items) {
2014-07-22 09:36:34 -07: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>';
html += '<h1 style="margin-top:.5em;">Sync Media</h1>';
html += '<form class="formSubmitSyncRequest">';
html += '<div>';
html += '<fieldset data-role="controlgroup">';
html += '<legend>Sync to:</legend>';
html += targets.map(function (t) {
2014-07-26 10:30:15 -07:00
var targetHtml = '<label for="radioSync' + t.Id + '">' + t.Name + '</label>';
targetHtml += '<input class="radioSync" data-targetid="' + t.Id + '" type="radio" id="radioSync' + t.Id + '" />';
2014-07-22 09:36:34 -07:00
return targetHtml;
}).join('');
html += '</fieldset>';
html += '</div>';
html += '<br/>';
html += '<div>';
html += '<fieldset data-role="controlgroup">';
html += '<legend>Quality:</legend>';
html += '<label for="radioHighSyncQuality">High</label>';
html += '<input type="radio" id="radioHighSyncQuality" name="radioSyncQuality" checked="checked" class="radioSyncQuality" data-value="High" />';
html += '<label for="radioMediumSyncQuality">Medium</label>';
html += '<input type="radio" id="radioMediumSyncQuality" name="radioSyncQuality" class="radioSyncQuality" data-value="Medium" />';
html += '<label for="radioLowSyncQuality">Low</label>';
html += '<input type="radio" id="radioLowSyncQuality" name="radioSyncQuality" class="radioSyncQuality" data-value="Low" />';
html += '</fieldset>';
html += '</div>';
html += '<br/>';
html += '<p>';
html += '<button type="submit" data-icon="refresh" data-theme="b">Sync</button>';
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-07-22 09:36:34 -07:00
submitJob(userId, items, this);
return false;
});
});
2014-07-19 21:46:29 -07:00
}
2014-07-19 21:46:29 -07:00
function isAvailable(item, user) {
2014-07-26 10:30:15 -07:00
2014-07-29 20:31:35 -07:00
return false;
2014-07-22 09:36:34 -07:00
return item.SupportsSync;
}
window.SyncManager = {
2014-07-19 21:46:29 -07:00
showMenu: showSyncMenu,
isAvailable: isAvailable
};
})(window, jQuery);