2016-03-18 21:26:17 -07:00
|
|
|
|
define(['jQuery'], function ($) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
2014-06-07 14:06:01 -07:00
|
|
|
|
TargetSystems: 'Server',
|
|
|
|
|
IsAdult: false
|
2013-04-03 21:36:02 -07:00
|
|
|
|
};
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
function reloadList(page) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-05-16 12:09:02 -07:00
|
|
|
|
if (AppInfo.enableAppStorePolicy) {
|
|
|
|
|
$('.optionAdultContainer', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.optionAdultContainer', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.IsAppStoreSafe = true;
|
|
|
|
|
|
2014-07-16 20:17:14 -07:00
|
|
|
|
var promise1 = ApiClient.getAvailablePlugins(query);
|
2013-10-01 16:33:24 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
var promise2 = ApiClient.getInstalledPlugins();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
2015-06-01 22:46:06 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
populateList({
|
|
|
|
|
|
|
|
|
|
catalogElement: $('#pluginTiles', page),
|
|
|
|
|
noItemsElement: $("#noPlugins", page),
|
2015-12-14 08:43:03 -07:00
|
|
|
|
availablePlugins: responses[0],
|
|
|
|
|
installedPlugins: responses[1]
|
2015-03-08 09:25:46 -07:00
|
|
|
|
|
|
|
|
|
});
|
2013-04-03 21:36:02 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2015-03-08 09:25:46 -07:00
|
|
|
|
function populateList(options) {
|
2016-05-12 12:21:43 -07:00
|
|
|
|
populateListInternal(options);
|
2015-06-01 22:46:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function populateListInternal(options) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
var availablePlugins = options.availablePlugins;
|
|
|
|
|
var installedPlugins = options.installedPlugins;
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
var allPlugins = availablePlugins.filter(function (p) {
|
2015-03-08 09:25:46 -07:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 11:21:39 -07:00
|
|
|
|
if (options.targetSystem) {
|
|
|
|
|
if (p.targetSystem != options.targetSystem) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
return p.type == "UserInstalled";
|
2015-03-08 09:25:46 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
availablePlugins = allPlugins.sort(function (a, b) {
|
|
|
|
|
|
|
|
|
|
var aName = (a.category);
|
|
|
|
|
var bName = (b.category);
|
|
|
|
|
|
|
|
|
|
if (aName > bName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (bName > aName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-07-29 08:27:43 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
aName = (a.name);
|
|
|
|
|
bName = (b.name);
|
2013-07-29 08:27:43 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
if (aName > bName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (bName > aName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2013-04-03 21:36:02 -07:00
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
var html = '';
|
|
|
|
|
var i, length, plugin;
|
2013-07-29 08:27:43 -07:00
|
|
|
|
|
2015-08-22 12:46:55 -07:00
|
|
|
|
var currentCategory;
|
2015-08-22 09:30:36 -07:00
|
|
|
|
|
2015-08-22 12:46:55 -07:00
|
|
|
|
if (!options.categories) {
|
|
|
|
|
currentCategory = Globalize.translate('HeaderTopPlugins');
|
|
|
|
|
html += '<div class="detailSectionHeader">' + currentCategory + '</div>';
|
|
|
|
|
var topPlugins = allPlugins.slice(0).sort(function (a, b) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-25 19:13:28 -07:00
|
|
|
|
if (a.installs > b.installs) {
|
|
|
|
|
return -1;
|
2015-08-22 12:46:55 -07:00
|
|
|
|
}
|
|
|
|
|
if (b.installs > a.installs) {
|
2015-08-25 19:13:28 -07:00
|
|
|
|
return 1;
|
2015-08-22 12:46:55 -07:00
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
|
2015-08-22 12:46:55 -07:00
|
|
|
|
var aName = (a.name);
|
|
|
|
|
var bName = (b.name);
|
2015-08-22 09:30:36 -07:00
|
|
|
|
|
2015-08-22 12:46:55 -07:00
|
|
|
|
if (aName > bName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (bName > aName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
|
2015-08-22 12:46:55 -07:00
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var limit = screen.availWidth >= 1920 ? 15 : 12;
|
|
|
|
|
for (i = 0, length = Math.min(topPlugins.length, limit) ; i < length; i++) {
|
|
|
|
|
html += getPluginHtml(topPlugins[i], options, installedPlugins);
|
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0, length = availablePlugins.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
plugin = availablePlugins[i];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
var category = plugin.categoryDisplayName;
|
2013-10-01 16:33:24 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
if (category != currentCategory) {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
if (options.showCategory !== false) {
|
|
|
|
|
if (currentCategory) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
}
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
html += '<div class="detailSectionHeader">' + category + '</div>';
|
|
|
|
|
}
|
2014-06-07 14:06:01 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
currentCategory = category;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += getPluginHtml(plugin, options, installedPlugins);
|
2015-03-08 10:34:02 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
}
|
2013-10-01 16:33:24 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
if (!availablePlugins.length && options.noItemsElement) {
|
|
|
|
|
$(options.noItemsElement).hide();
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
$(options.catalogElement).html(html);
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
function getPluginHtml(plugin, options, installedPlugins) {
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
var html = '';
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
var href = plugin.externalUrl ? plugin.externalUrl : "addplugin.html?name=" + encodeURIComponent(plugin.name) + "&guid=" + plugin.guid;
|
|
|
|
|
if (options.context) {
|
|
|
|
|
href += "&context=" + options.context;
|
|
|
|
|
}
|
|
|
|
|
var target = plugin.externalUrl ? ' target="_blank"' : '';
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-10-15 10:21:18 -07:00
|
|
|
|
html += "<div class='card backdropCard bottomPaddedCard'>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += '<div class="cardBox visualCardBox">';
|
|
|
|
|
html += '<div class="cardScalable">';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += '<div class="cardPadder"></div>';
|
2013-11-07 11:04:51 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += '<a class="cardContent" href="' + href + '"' + target + '>';
|
|
|
|
|
if (plugin.thumbImage) {
|
|
|
|
|
html += '<div class="cardImage" style="background-image:url(\'' + plugin.thumbImage + '\');">';
|
|
|
|
|
} else {
|
|
|
|
|
html += '<div class="cardImage" style="background-image:url(\'css/images/items/list/collection.png\');">';
|
|
|
|
|
}
|
2013-11-07 11:04:51 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
if (plugin.isPremium) {
|
|
|
|
|
if (plugin.price > 0) {
|
|
|
|
|
html += "<div class='premiumBanner'><img src='css/images/supporter/premiumflag.png' /></div>";
|
|
|
|
|
} else {
|
|
|
|
|
html += "<div class='premiumBanner'><img src='css/images/supporter/supporterflag.png' /></div>";
|
2014-05-09 12:43:06 -07:00
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
}
|
|
|
|
|
html += "</div>";
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
// cardContent
|
|
|
|
|
html += "</a>";
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
// cardScalable
|
|
|
|
|
html += "</div>";
|
2014-06-07 14:06:01 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += '<div class="cardFooter">';
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += "<div class='cardText'>";
|
|
|
|
|
html += plugin.name;
|
|
|
|
|
html += "</div>";
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
if (!plugin.isExternal) {
|
2016-05-12 12:21:43 -07:00
|
|
|
|
html += "<div class='cardText' style='display:flex;align-items:center;'>";
|
|
|
|
|
|
|
|
|
|
if (plugin.avgRating) {
|
2016-07-22 12:48:47 -07:00
|
|
|
|
html += '<i class="md-icon" style="color:#cc3333;margin-right:.25em;">star</i>';
|
2016-05-12 12:21:43 -07:00
|
|
|
|
html += plugin.avgRating.toFixed(1);
|
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
|
2016-05-12 12:21:43 -07:00
|
|
|
|
if (plugin.totalRatings) {
|
|
|
|
|
html += "<div style='margin-left:.5em;'>";
|
|
|
|
|
html += " " + Globalize.translate('LabelNumberReviews').replace("{0}", plugin.totalRatings);
|
|
|
|
|
}
|
|
|
|
|
html += "</div>";
|
2014-07-26 10:30:15 -07:00
|
|
|
|
|
|
|
|
|
html += "</div>";
|
2015-08-22 09:30:36 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) {
|
|
|
|
|
return ip.Id == plugin.guid;
|
|
|
|
|
})[0];
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += "<div class='cardText'>";
|
2013-04-03 19:25:14 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
if (installedPlugin) {
|
|
|
|
|
html += Globalize.translate('LabelVersionInstalled').replace("{0}", installedPlugin.Version);
|
|
|
|
|
} else {
|
|
|
|
|
html += ' ';
|
2013-04-25 16:28:01 -07:00
|
|
|
|
}
|
2015-08-22 09:30:36 -07:00
|
|
|
|
html += "</div>";
|
2013-04-08 18:38:18 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
// cardFooter
|
|
|
|
|
html += "</div>";
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2015-08-22 09:30:36 -07:00
|
|
|
|
// cardBox
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
// card
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
return html;
|
2013-04-11 17:58:30 -07:00
|
|
|
|
}
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2016-04-12 23:02:07 -07:00
|
|
|
|
function getTabs() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
href: 'plugins.html',
|
|
|
|
|
name: Globalize.translate('TabMyPlugins')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
href: 'plugincatalog.html',
|
|
|
|
|
name: Globalize.translate('TabCatalog')
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 07:01:59 -07:00
|
|
|
|
$(document).on('pageinit', "#pluginCatalogPage", function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-08 18:38:18 -07:00
|
|
|
|
var page = this;
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2016-03-29 20:10:01 -07:00
|
|
|
|
$('#selectSystem', page).on('change', function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2016-03-29 20:10:01 -07:00
|
|
|
|
query.TargetSystems = this.value;
|
2013-07-29 08:27:43 -07:00
|
|
|
|
reloadList(page);
|
|
|
|
|
});
|
|
|
|
|
|
2014-06-07 14:06:01 -07:00
|
|
|
|
$('#chkAdult', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
query.IsAdult = this.checked ? null : false;
|
|
|
|
|
reloadList(page);
|
|
|
|
|
});
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
}).on('pageshow', "#pluginCatalogPage", function () {
|
2013-04-25 16:28:01 -07:00
|
|
|
|
|
2016-04-12 23:02:07 -07:00
|
|
|
|
LibraryMenu.setTabs('plugins', 1, getTabs);
|
2013-04-11 09:11:04 -07:00
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
reloadList(page);
|
2013-04-03 21:36:02 -07:00
|
|
|
|
});
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2015-03-08 09:25:46 -07:00
|
|
|
|
window.PluginCatalog = {
|
|
|
|
|
renderCatalog: populateList
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|