2014-07-18 12:07:28 -07:00
|
|
|
|
(function (window, $) {
|
|
|
|
|
|
2014-12-12 20:56:30 -07: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 09:36:34 -07:00
|
|
|
|
|
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-12-12 20:56:30 -07:00
|
|
|
|
Dashboard.alert(Globalize.translate('MessagePleaseSelectDeviceToSyncTo'));
|
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
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
ItemIds: (syncOptions.items || []).map(function (i) {
|
2014-12-12 20:56:30 -07:00
|
|
|
|
return i.Id || i;
|
2014-07-22 09:36:34 -07:00
|
|
|
|
}).join(','),
|
|
|
|
|
|
2014-12-13 14:26:04 -07:00
|
|
|
|
Quality: $('#selectQuality', form).val(),
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2014-12-13 14:26:04 -07:00
|
|
|
|
Name: $('#txtSyncJobName', form).val(),
|
|
|
|
|
|
|
|
|
|
SyncNewContent: $('#chkSyncNewContent', form).checked(),
|
2014-12-16 22:30:31 -07:00
|
|
|
|
UnwatchedOnly: $('#chkUnwatchedOnly', form).checked(),
|
2014-12-18 21:20:07 -07:00
|
|
|
|
ItemLimit: $('#txtItemLimit').val() || null,
|
|
|
|
|
|
|
|
|
|
ParentId: syncOptions.ParentId,
|
|
|
|
|
Category: syncOptions.Category
|
2014-07-22 09:36:34 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: ApiClient.getUrl("Sync/Jobs"),
|
|
|
|
|
data: JSON.stringify(options),
|
|
|
|
|
contentType: "application/json"
|
|
|
|
|
|
|
|
|
|
}).done(function () {
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
$('.syncPanel').panel('close');
|
|
|
|
|
$(window.SyncManager).trigger('jobsubmit');
|
2014-12-12 20:56:30 -07:00
|
|
|
|
Dashboard.alert(Globalize.translate('MessageSyncJobCreated'));
|
2014-07-22 09:36:34 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 20:56:30 -07:00
|
|
|
|
function showSyncMenu(options) {
|
2014-07-18 12:07:28 -07:00
|
|
|
|
|
2014-07-22 09:36:34 -07:00
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Sync/Options', {
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
UserId: userId,
|
2014-12-18 21:20:07 -07:00
|
|
|
|
ItemIds: (options.items || []).map(function (i) {
|
2014-12-16 22:30:31 -07:00
|
|
|
|
return i.Id || i;
|
2014-12-18 21:20:07 -07:00
|
|
|
|
}).join(','),
|
|
|
|
|
|
|
|
|
|
ParentId: options.ParentId,
|
|
|
|
|
Category: options.Category
|
2014-12-16 22:30:31 -07:00
|
|
|
|
|
|
|
|
|
})).done(function (result) {
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
var targets = result.Targets;
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
|
|
|
|
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-10 23:20:28 -07:00
|
|
|
|
html += '<h1 style="margin-top:.5em;">' + Globalize.translate('SyncMedia') + '</h1>';
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
|
|
|
|
html += '<form class="formSubmitSyncRequest">';
|
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
if (result.Options.indexOf('Name') != -1) {
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
|
|
|
|
html += '<p>';
|
2014-12-12 20:56:30 -07:00
|
|
|
|
html += '<label for="txtSyncJobName">' + Globalize.translate('LabelSyncJobName') + '</label>';
|
2014-12-10 23:20:28 -07:00
|
|
|
|
html += '<input type="text" id="txtSyncJobName" class="txtSyncJobName" required="required" />';
|
|
|
|
|
html += '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 09:36:34 -07:00
|
|
|
|
html += '<div>';
|
|
|
|
|
html += '<fieldset data-role="controlgroup">';
|
2014-12-12 20:56:30 -07:00
|
|
|
|
html += '<legend>' + Globalize.translate('LabelSyncTo') + '</legend>';
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
var index = 0;
|
|
|
|
|
|
2014-07-22 09:36:34 -07:00
|
|
|
|
html += targets.map(function (t) {
|
|
|
|
|
|
2014-07-26 10:30:15 -07:00
|
|
|
|
var targetHtml = '<label for="radioSync' + t.Id + '">' + t.Name + '</label>';
|
2014-07-22 09:36:34 -07:00
|
|
|
|
|
2014-12-10 23:20:28 -07: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 09:36:34 -07:00
|
|
|
|
return targetHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
html += '</fieldset>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
|
|
|
|
|
html += '<div>';
|
2014-12-13 14:26:04 -07:00
|
|
|
|
html += '<label for="selectQuality">' + Globalize.translate('LabelQuality') + '</label>';
|
|
|
|
|
html += '<select id="selectQuality" data-mini="true">';
|
|
|
|
|
html += '<option value="High">' + Globalize.translate('OptionHigh') + '</option>';
|
|
|
|
|
html += '<option value="Medium">' + Globalize.translate('OptionMedium') + '</option>';
|
|
|
|
|
html += '<option value="Low">' + Globalize.translate('OptionLow') + '</option>';
|
|
|
|
|
html += '</select>';
|
2014-07-22 09:36:34 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-12-13 14:26:04 -07:00
|
|
|
|
//html += '<div data-role="collapsible" style="margin:1.5em 0">';
|
|
|
|
|
//html += '<h2>' + Globalize.translate('HeaderSettings') + '</h2>';
|
|
|
|
|
//html += '<div style="margin:0 -.5em 0 -.25em;">';
|
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
if (result.Options.indexOf('UnwatchedOnly') != -1) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += '<label for="chkUnwatchedOnly">' + Globalize.translate('OptionSyncUnwatchedVideosOnly') + '</label>';
|
|
|
|
|
html += '<input type="checkbox" id="chkUnwatchedOnly" data-mini="true" />';
|
|
|
|
|
html += '<div class="fieldDescription">' + Globalize.translate('OptionSyncUnwatchedVideosOnlyHelp') + '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
2014-12-13 14:26:04 -07:00
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
if (result.Options.indexOf('SyncNewContent') != -1) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += '<label for="chkSyncNewContent">' + Globalize.translate('OptionAutomaticallySyncNewContent') + '</label>';
|
|
|
|
|
html += '<input type="checkbox" id="chkSyncNewContent" data-mini="true" />';
|
|
|
|
|
html += '<div class="fieldDescription">' + Globalize.translate('OptionAutomaticallySyncNewContentHelp') + '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.Options.indexOf('ItemLimit') != -1) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += '<label for="txtItemLimit">' + Globalize.translate('LabelItemLimit') + '</label>';
|
|
|
|
|
html += '<input type="number" id="txtItemLimit" data-mini="true" step="1" min="1" />';
|
|
|
|
|
html += '<div class="fieldDescription">' + Globalize.translate('LabelItemLimitHelp') + '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
2014-12-13 14:26:04 -07:00
|
|
|
|
|
|
|
|
|
//html += '</div>';
|
|
|
|
|
//html += '</div>';
|
|
|
|
|
|
2014-07-22 09:36:34 -07:00
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<p>';
|
2014-12-18 21:20:07 -07:00
|
|
|
|
html += '<button type="submit" data-icon="cloud" data-theme="b">' + Globalize.translate('ButtonSync') + '</button>';
|
2014-07-22 09:36:34 -07: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-07-18 12:07:28 -07:00
|
|
|
|
|
2014-12-12 20:56:30 -07:00
|
|
|
|
submitJob(userId, options, this);
|
2014-07-22 09:36:34 -07:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-07-19 21:46:29 -07:00
|
|
|
|
}
|
2014-07-18 12:07:28 -07:00
|
|
|
|
|
2014-12-16 22:30:31 -07:00
|
|
|
|
function showUnwatchedFilter(items) {
|
|
|
|
|
|
|
|
|
|
return items.filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.MediaType == "Video" || i.IsFolder || i.Type == "Person" || i.Type == "Genre" || i.Type == "MusicGenre" || i.Type == "GameGenre" || i.Type == "Studio" || i.Type == "MusicArtist";
|
|
|
|
|
|
|
|
|
|
}).length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showItemLimit(items) {
|
|
|
|
|
|
|
|
|
|
return items.length > 1 || items.filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.IsFolder || i.Type == "Person" || i.Type == "Genre" || i.Type == "MusicGenre" || i.Type == "GameGenre" || i.Type == "Studio" || i.Type == "MusicArtist";
|
|
|
|
|
|
|
|
|
|
}).length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSyncNew(items) {
|
|
|
|
|
|
|
|
|
|
return items.filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.IsFolder || i.Type == "Person" || i.Type == "Genre" || i.Type == "MusicGenre" || i.Type == "GameGenre" || i.Type == "Studio" || i.Type == "MusicArtist";
|
|
|
|
|
|
|
|
|
|
}).length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 21:46:29 -07:00
|
|
|
|
function isAvailable(item, user) {
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
//return false;
|
2014-07-22 09:36:34 -07:00
|
|
|
|
return item.SupportsSync;
|
2014-07-18 12:07:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.SyncManager = {
|
|
|
|
|
|
2014-07-19 21:46:29 -07:00
|
|
|
|
showMenu: showSyncMenu,
|
|
|
|
|
|
|
|
|
|
isAvailable: isAvailable
|
2014-07-18 12:07:28 -07:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
function showSyncButtonsPerUser(page) {
|
|
|
|
|
|
2014-12-29 13:18:48 -07:00
|
|
|
|
var apiClient = ConnectionManager.currentApiClient();
|
|
|
|
|
|
|
|
|
|
if (!apiClient) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 21:20:07 -07:00
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
|
|
|
|
|
|
|
|
|
if (user.Policy.EnableSync) {
|
|
|
|
|
$('.categorySyncButton', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.categorySyncButton', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onCategorySyncButtonClick(page, button) {
|
|
|
|
|
|
|
|
|
|
var category = button.getAttribute('data-category');
|
|
|
|
|
var parentId = LibraryMenu.getTopParentId();
|
|
|
|
|
|
|
|
|
|
SyncManager.showMenu({
|
|
|
|
|
ParentId: parentId,
|
|
|
|
|
Category: category
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', ".libraryPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.categorySyncButton', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
onCategorySyncButtonClick(page, this);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pagebeforeshow', ".libraryPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
showSyncButtonsPerUser(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2014-07-18 12:07:28 -07:00
|
|
|
|
})(window, jQuery);
|