(function ($, document) {
// The base query options
var query = {
TargetSystems: 'Server',
IsAdult: false
};
function reloadList(page) {
Dashboard.showLoadingMsg();
if (AppInfo.enableAppStorePolicy) {
$('.optionAdultContainer', page).hide();
} else {
$('.optionAdultContainer', page).show();
}
query.IsAppStoreSafe = true;
var promise1 = ApiClient.getAvailablePlugins(query);
var promise2 = ApiClient.getInstalledPlugins();
$.when(promise1, promise2).done(function (response1, response2) {
populateList({
catalogElement: $('#pluginTiles', page),
noItemsElement: $("#noPlugins", page),
availablePlugins: response1[0],
installedPlugins: response2[0]
});
});
}
function populateList(options) {
requirejs(['scripts/ratingdialog'], function () {
populateListInternal(options);
});
}
function populateListInternal(options) {
var availablePlugins = options.availablePlugins;
var installedPlugins = options.installedPlugins;
availablePlugins = availablePlugins.filter(function (p) {
p.category = p.category || "General";
p.categoryDisplayName = Globalize.translate('PluginCategory' + p.category.replace(' ', ''));
if (options.categories) {
if (options.categories.indexOf(p.category) == -1) {
return false;
}
}
if (options.targetSystem) {
if (p.targetSystem != options.targetSystem) {
return false;
}
}
return p.type == "UserInstalled";
}).sort(function (a, b) {
var aName = (a.category) + " " + a.name;
var bame = (b.category) + " " + b.name;
return aName > bame ? 1 : -1;
});
var pluginhtml = '';
var currentCategory;
for (var i = 0, length = availablePlugins.length; i < length; i++) {
var html = '';
var plugin = availablePlugins[i];
var category = plugin.categoryDisplayName;
if (category != currentCategory) {
if (options.showCategory !== false) {
if (currentCategory) {
html += '
';
html += '
';
html += '
';
}
html += '