(function ($, document, window) {
var currentType;
function loadTabs(page, tabs) {
var html = '';
html += '
';
for (var i = 0, length = tabs.length; i < length; i++) {
var tab = tabs[i];
var isChecked = i == 0 ? ' checked="checked"' : '';
html += '';
html += '';
}
html += '
';
var elem = $('.tabs', page).html(html).trigger('create');
Dashboard.hideLoadingMsg();
$('.radioTypeTab', elem).on('change', function () {
if (this.checked) {
loadType(page, this.id);
}
}).trigger('change');
}
function loadType(page, type) {
Dashboard.showLoadingMsg();
currentType = type;
var promise1 = ApiClient.getServerConfiguration();
var promise2 = $.getJSON(ApiClient.getUrl("System/Configuration/MetadataPlugins"));
$.when(promise1, promise2).done(function (response1, response2) {
var config = response1[0];
var metadataPlugins = response2[0];
config = config.MetadataOptions.filter(function (c) {
return c.ItemType == type;
})[0];
if (config) {
renderType(page, type, config, metadataPlugins);
Dashboard.hideLoadingMsg();
} else {
$.getJSON(ApiClient.getUrl("System/Configuration/MetadataOptions/Default")).done(function (defaultConfig) {
config = defaultConfig;
renderType(page, type, config, metadataPlugins);
Dashboard.hideLoadingMsg();
});
}
});
}
function setVisibilityOfBackdrops(elem, visible) {
if (visible) {
elem.show();
$('input', elem).attr('required', 'required');
} else {
elem.hide();
$('input', elem).attr('required', '').removeAttr('required');
}
}
function renderType(page, type, config, metadataPlugins) {
var metadataInfo = metadataPlugins.filter(function (f) {
return type == f.ItemType;
})[0];
setVisibilityOfBackdrops($('.backdropFields', page), metadataInfo.SupportedImageTypes.indexOf('Backdrop') != -1);
setVisibilityOfBackdrops($('.screenshotFields', page), metadataInfo.SupportedImageTypes.indexOf('Screenshot') != -1);
$('.imageType', page).each(function () {
var imageType = this.getAttribute('data-imagetype');
if (metadataInfo.SupportedImageTypes.indexOf(imageType) == -1) {
$(this).hide();
} else {
$(this).show();
}
if (getImageConfig(config, imageType).Limit) {
$('input', this).checked(true).checkboxradio('refresh');
} else {
$('input', this).checked(false).checkboxradio('refresh');
}
});
var backdropConfig = getImageConfig(config, 'Backdrop');
$('#txtMaxBackdrops', page).val(backdropConfig.Limit);
$('#txtMinBackdropDownloadWidth', page).val(backdropConfig.MinWidth);
var screenshotConfig = getImageConfig(config, 'Screenshot');
$('#txtMaxScreenshots', page).val(screenshotConfig.Limit);
$('#txtMinScreenshotDownloadWidth', page).val(screenshotConfig.MinWidth);
renderMetadataLocals(page, type, config, metadataInfo);
renderMetadataFetchers(page, type, config, metadataInfo);
renderMetadataSavers(page, type, config, metadataInfo);
renderImageFetchers(page, type, config, metadataInfo);
}
function getImageConfig(config, type) {
return config.ImageOptions.filter(function (i) {
return i.Type == type;
})[0] || {
Type: type,
MinWidth: type == 'Backdrop' ? 1280 : 0,
Limit: type == 'Backdrop' ? 3 : 1
};
}
function renderImageFetchers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'ImageFetcher';
});
var html = '';
if (!plugins.length) {
$('.imageFetchers', page).html(html).hide().trigger('create');
return;
}
var i, length, plugin, id;
html += '
Image Fetchers:
';
html += '
';
html += '
';
for (i = 0, length = plugins.length; i < length; i++) {
plugin = plugins[i];
id = 'chkImageFetcher' + i;
var isChecked = config.DisabledImageFetchers.indexOf(plugin.Name) == -1 ? ' checked="checked"' : '';
html += '';
html += '';
}
html += '
';
html += '
';
if (plugins.length > 1) {
html += '
';
for (i = 0, length = plugins.length; i < length; i++) {
html += '
';
if (i == 0) {
html += '';
html += '';
} else if (i == (plugins.length - 1)) {
html += '';
html += '';
}
else {
html += '';
html += '';
}
html += '
';
}
}
html += '
';
html += '
Enable and rank your preferred image fetchers in order of priority.
';
var elem = $('.imageFetchers', page).html(html).show().trigger('create');
$('.btnDown', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.imageFetcherGroup .ui-checkbox', page)[index];
var insertAfter = $(elemToMove).next('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertAfter(insertAfter);
$('.imageFetcherGroup', page).controlgroup('destroy').controlgroup();
});
$('.btnUp', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.imageFetcherGroup .ui-checkbox', page)[index];
var insertBefore = $(elemToMove).prev('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertBefore(insertBefore);
$('.imageFetcherGroup', page).controlgroup('destroy').controlgroup();
});
}
function renderMetadataSavers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'MetadataSaver';
});
var html = '';
if (!plugins.length) {
$('.metadataSavers', page).html(html).hide().trigger('create');
return;
}
html += '';
html += '
Choose the file formats to save your metadata to.
';
$('.metadataSavers', page).html(html).show().trigger('create');
}
function renderMetadataFetchers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'MetadataFetcher';
});
var html = '';
if (!plugins.length) {
$('.metadataFetchers', page).html(html).hide().trigger('create');
return;
}
var i, length, plugin, id;
html += '
Metadata Downloaders:
';
html += '
';
html += '
';
for (i = 0, length = plugins.length; i < length; i++) {
plugin = plugins[i];
id = 'chkMetadataFetcher' + i;
var isChecked = config.DisabledMetadataFetchers.indexOf(plugin.Name) == -1 ? ' checked="checked"' : '';
html += '';
html += '';
}
html += '
';
html += '
';
if (plugins.length > 1) {
html += '
';
for (i = 0, length = plugins.length; i < length; i++) {
html += '
';
if (i == 0) {
html += '';
html += '';
} else if (i == (plugins.length - 1)) {
html += '';
html += '';
}
else {
html += '';
html += '';
}
html += '
';
}
}
html += '
';
html += '
Enable and rank your preferred metadata downloaders in order of priority. Lower priority downloaders will only be used to fill in missing information.
';
var elem = $('.metadataFetchers', page).html(html).show().trigger('create');
$('.btnDown', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.metadataFetcherGroup .ui-checkbox', page)[index];
var insertAfter = $(elemToMove).next('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertAfter(insertAfter);
$('.metadataFetcherGroup', page).controlgroup('destroy').controlgroup();
});
$('.btnUp', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.metadataFetcherGroup .ui-checkbox', page)[index];
var insertBefore = $(elemToMove).prev('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertBefore(insertBefore);
$('.metadataFetcherGroup', page).controlgroup('destroy').controlgroup();
});
}
function renderMetadataLocals(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'LocalMetadataProvider';
});
var html = '';
if (plugins.length < 2) {
$('.metadataReaders', page).html(html).hide().trigger('create');
return;
}
html += '
Preferred Local Metadata:
';
html += '
';
for (var i = 0, length = plugins.length; i < length; i++) {
var plugin = plugins[i];
if (i > 0) {
html += '