(function (window, $) { 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'); } var target = $('.radioSync:checked', form).get().map(function (c) { return c.getAttribute('data-targetid'); })[0]; if (!target) { Dashboard.alert(Globalize.translate('MessagePleaseSelectDeviceToSyncTo')); return; } var options = { userId: userId, TargetId: target, ItemIds: syncOptions.items.map(function (i) { return i.Id || i; }).join(','), Quality: $('#selectQuality', form).val(), Name: $('#txtSyncJobName', form).val(), SyncNewContent: $('#chkSyncNewContent', form).checked(), UnwatchedOnly: $('#chkUnwatchedOnly', form).checked() }; ApiClient.ajax({ type: "POST", url: ApiClient.getUrl("Sync/Jobs"), data: JSON.stringify(options), contentType: "application/json" }).done(function () { $('.syncPanel').panel('close'); $(window.SyncManager).trigger('jobsubmit'); Dashboard.alert(Globalize.translate('MessageSyncJobCreated')); }); } function showSyncMenu(options) { var userId = Dashboard.getCurrentUserId(); ApiClient.getJSON(ApiClient.getUrl('Sync/Targets', { UserId: userId })).done(function (targets) { var html = '
'; html += '
'; html += '

' + Globalize.translate('SyncMedia') + '

'; html += '
'; if (options.items.length > 1) { html += '

'; html += ''; html += ''; html += '

'; } html += '
'; html += '
'; html += '' + Globalize.translate('LabelSyncTo') + ''; var index = 0; html += targets.map(function (t) { var targetHtml = ''; var checkedHtml = index ? '' : ' checked="checked"'; targetHtml += ''; index++; return targetHtml; }).join(''); html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += ''; html += '
'; //html += '
'; //html += '

' + Globalize.translate('HeaderSettings') + '

'; //html += '
'; html += '
'; html += '
'; html += ''; html += ''; html += '
' + Globalize.translate('OptionAutomaticallySyncNewContentHelp') + '
'; html += '
'; html += '
'; html += '
'; html += ''; html += ''; html += '
' + Globalize.translate('OptionSyncUnwatchedVideosOnlyHelp') + '
'; html += '
'; //html += '
'; //html += '
'; html += '
'; html += '

'; html += ''; html += '

'; html += '
'; html += '
'; html += '
'; $(document.body).append(html); var elem = $('.syncPanel').panel({}).trigger('create').panel("open").on("panelclose", function () { $(this).off("panelclose").remove(); }); $('form', elem).on('submit', function () { submitJob(userId, options, this); return false; }); }); } function isAvailable(item, user) { return false; return item.SupportsSync; } window.SyncManager = { showMenu: showSyncMenu, isAvailable: isAvailable }; })(window, jQuery);