2013-04-03 20:56:02 -07:00
|
|
|
|
(function ($, document) {
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
2014-06-07 17:06:01 -04:00
|
|
|
|
TargetSystems: 'Server',
|
|
|
|
|
IsAdult: false
|
2013-04-04 00:36:02 -04:00
|
|
|
|
};
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
function reloadList(page) {
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2015-05-16 15:09:02 -04:00
|
|
|
|
if (AppInfo.enableAppStorePolicy) {
|
|
|
|
|
$('.optionAdultContainer', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.optionAdultContainer', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.IsAppStoreSafe = true;
|
|
|
|
|
|
2014-07-16 23:17:14 -04:00
|
|
|
|
var promise1 = ApiClient.getAvailablePlugins(query);
|
2013-10-01 19:33:24 -04:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
var promise2 = ApiClient.getInstalledPlugins();
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
2015-06-02 01:46:06 -04:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
populateList({
|
|
|
|
|
|
|
|
|
|
catalogElement: $('#pluginTiles', page),
|
|
|
|
|
noItemsElement: $("#noPlugins", page),
|
|
|
|
|
availablePlugins: response1[0],
|
|
|
|
|
installedPlugins: response2[0]
|
|
|
|
|
|
|
|
|
|
});
|
2013-04-04 00:36:02 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
2015-03-08 12:25:46 -04:00
|
|
|
|
function populateList(options) {
|
2015-06-02 01:46:06 -04:00
|
|
|
|
requirejs(['scripts/ratingdialog'], function () {
|
|
|
|
|
populateListInternal(options);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function populateListInternal(options) {
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
var availablePlugins = options.availablePlugins;
|
|
|
|
|
var installedPlugins = options.installedPlugins;
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
availablePlugins = availablePlugins.filter(function (p) {
|
2015-03-08 12:25:46 -04: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 14:21:39 -04:00
|
|
|
|
if (options.targetSystem) {
|
|
|
|
|
if (p.targetSystem != options.targetSystem) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
return p.type == "UserInstalled";
|
2015-03-08 12:25:46 -04:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
}).sort(function (a, b) {
|
2013-07-29 11:27:43 -04:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
var aName = (a.category) + " " + a.name;
|
|
|
|
|
var bame = (b.category) + " " + b.name;
|
2013-07-29 11:27:43 -04:00
|
|
|
|
|
|
|
|
|
return aName > bame ? 1 : -1;
|
2013-04-04 00:36:02 -04:00
|
|
|
|
});
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-07-29 11:27:43 -04:00
|
|
|
|
var pluginhtml = '';
|
|
|
|
|
|
|
|
|
|
var currentCategory;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
for (var i = 0, length = availablePlugins.length; i < length; i++) {
|
2013-04-25 19:28:01 -04:00
|
|
|
|
var html = '';
|
2013-04-04 00:36:02 -04:00
|
|
|
|
var plugin = availablePlugins[i];
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
var category = plugin.categoryDisplayName;
|
2013-10-01 19:33:24 -04:00
|
|
|
|
|
2013-07-29 11:27:43 -04:00
|
|
|
|
if (category != currentCategory) {
|
2014-05-03 00:20:04 -04:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
if (options.showCategory !== false) {
|
|
|
|
|
if (currentCategory) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
}
|
2014-05-03 00:20:04 -04:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
html += '<div class="detailSectionHeader">' + category + '</div>';
|
|
|
|
|
}
|
2014-06-07 17:06:01 -04:00
|
|
|
|
|
2013-07-29 11:27:43 -04:00
|
|
|
|
currentCategory = category;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 11:50:21 -05:00
|
|
|
|
var href = plugin.externalUrl ? plugin.externalUrl : "addplugin.html?name=" + encodeURIComponent(plugin.name) + "&guid=" + plugin.guid;
|
2015-03-08 13:34:02 -04:00
|
|
|
|
|
|
|
|
|
if (options.context) {
|
|
|
|
|
href += "&context=" + options.context;
|
|
|
|
|
}
|
2013-10-01 19:33:24 -04:00
|
|
|
|
var target = plugin.externalUrl ? ' target="_blank"' : '';
|
|
|
|
|
|
2014-08-02 22:16:37 -04:00
|
|
|
|
html += "<div class='card backdropCard alternateHover bottomPaddedCard'>";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += '<div class="cardBox visualCardBox">';
|
|
|
|
|
html += '<div class="cardScalable">';
|
|
|
|
|
|
|
|
|
|
html += '<div class="cardPadder"></div>';
|
|
|
|
|
|
|
|
|
|
html += '<a class="cardContent" href="' + href + '"' + target + '>';
|
2013-04-04 00:36:02 -04:00
|
|
|
|
if (plugin.thumbImage) {
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += '<div class="cardImage" style="background-image:url(\'' + plugin.thumbImage + '\');">';
|
2013-04-04 00:36:02 -04:00
|
|
|
|
} else {
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += '<div class="cardImage" style="background-image:url(\'css/images/items/list/collection.png\');">';
|
2013-04-04 00:36:02 -04:00
|
|
|
|
}
|
2013-02-22 09:08:51 -06:00
|
|
|
|
|
2013-04-04 00:36:02 -04: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>";
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-29 00:32:03 -05:00
|
|
|
|
html += "</div>";
|
2013-02-22 09:08:51 -06:00
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
// cardContent
|
|
|
|
|
html += "</a>";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
// cardScalable
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
html += '<div class="cardFooter">';
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += "<div class='cardText'>";
|
|
|
|
|
html += plugin.name;
|
2013-04-04 00:36:02 -04:00
|
|
|
|
html += "</div>";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-05-09 15:43:06 -04:00
|
|
|
|
if (!plugin.isExternal) {
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += "<div class='cardText packageReviewText'>";
|
2014-05-30 15:23:56 -04:00
|
|
|
|
html += plugin.price > 0 ? "$" + plugin.price.toFixed(2) : Globalize.translate('LabelFree');
|
2015-05-16 15:09:02 -04:00
|
|
|
|
html += RatingHelpers.getStoreRatingHtml(plugin.avgRating, plugin.id, plugin.name, true);
|
2013-11-07 13:04:51 -05:00
|
|
|
|
|
2014-05-09 15:43:06 -04:00
|
|
|
|
html += "<span class='storeReviewCount'>";
|
2014-05-30 15:23:56 -04:00
|
|
|
|
html += " " + Globalize.translate('LabelNumberReviews').replace("{0}", plugin.totalRatings);
|
2014-05-09 15:43:06 -04:00
|
|
|
|
html += "</span>";
|
2013-11-07 13:04:51 -05:00
|
|
|
|
|
2014-05-09 15:43:06 -04:00
|
|
|
|
html += "</div>";
|
|
|
|
|
}
|
2014-05-03 00:20:04 -04:00
|
|
|
|
|
|
|
|
|
var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) {
|
2015-03-08 13:58:45 -04:00
|
|
|
|
return ip.Id == plugin.guid;
|
2014-05-03 00:20:04 -04:00
|
|
|
|
})[0];
|
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
html += "<div class='cardText'>";
|
2014-06-07 17:06:01 -04:00
|
|
|
|
|
2014-05-03 00:20:04 -04:00
|
|
|
|
if (installedPlugin) {
|
2014-05-30 15:23:56 -04:00
|
|
|
|
html += Globalize.translate('LabelVersionInstalled').replace("{0}", installedPlugin.Version);
|
2014-05-03 00:20:04 -04:00
|
|
|
|
} else {
|
|
|
|
|
html += ' ';
|
|
|
|
|
}
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
2014-07-26 13:30:15 -04:00
|
|
|
|
// cardFooter
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
// cardBox
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
|
|
// card
|
|
|
|
|
html += "</div>";
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-07-29 11:27:43 -04:00
|
|
|
|
pluginhtml += html;
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
}
|
2013-04-03 19:25:14 -07:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
if (!availablePlugins.length && options.noItemsElement) {
|
|
|
|
|
$(options.noItemsElement).hide();
|
2013-04-25 19:28:01 -04:00
|
|
|
|
}
|
2013-04-08 18:38:18 -07:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
$(options.catalogElement).html(pluginhtml);
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-08 18:38:18 -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
|
|
|
|
|
2013-04-11 12:11:04 -04:00
|
|
|
|
$('.chkPremiumFilter', page).on('change', function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
if (this.checked) {
|
2013-08-26 15:15:44 -04:00
|
|
|
|
query.IsPremium = false;
|
2013-04-04 00:36:02 -04:00
|
|
|
|
} else {
|
2013-04-04 00:46:14 -04:00
|
|
|
|
query.IsPremium = null;
|
2013-04-04 00:36:02 -04:00
|
|
|
|
}
|
2013-04-11 12:11:04 -04:00
|
|
|
|
reloadList(page);
|
2013-04-04 00:36:02 -04:00
|
|
|
|
});
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2014-01-02 16:21:06 -05:00
|
|
|
|
$('.radioPackageTypes', page).on('change', function () {
|
2013-07-29 11:27:43 -04:00
|
|
|
|
|
2014-01-02 16:21:06 -05:00
|
|
|
|
var val = $('.radioPackageTypes:checked', page).val();
|
|
|
|
|
|
|
|
|
|
query.TargetSystems = val;
|
2013-07-29 11:27:43 -04:00
|
|
|
|
reloadList(page);
|
|
|
|
|
});
|
|
|
|
|
|
2014-06-07 17:06:01 -04:00
|
|
|
|
$('#chkAdult', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
query.IsAdult = this.checked ? null : false;
|
|
|
|
|
reloadList(page);
|
|
|
|
|
});
|
|
|
|
|
|
2013-04-08 18:38:18 -07:00
|
|
|
|
}).on('pageshow', "#pluginCatalogPage", function () {
|
2013-04-25 19:28:01 -04:00
|
|
|
|
|
2013-04-11 12:11:04 -04:00
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-06-07 17:06:01 -04:00
|
|
|
|
$(".radioPackageTypes", page).each(function () {
|
2014-01-02 16:21:06 -05:00
|
|
|
|
|
|
|
|
|
this.checked = this.value == query.TargetSystems;
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
2013-11-05 12:13:29 -05:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
// Reset form values using the last used query
|
2013-04-11 12:11:04 -04:00
|
|
|
|
$('.chkPremiumFilter', page).each(function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
var filters = query.IsPremium || false;
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
this.checked = filters;
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-04 00:36:02 -04:00
|
|
|
|
}).checkboxradio('refresh');
|
2015-03-08 12:25:46 -04:00
|
|
|
|
|
|
|
|
|
reloadList(page);
|
2013-04-04 00:36:02 -04:00
|
|
|
|
});
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2015-03-08 12:25:46 -04:00
|
|
|
|
window.PluginCatalog = {
|
|
|
|
|
renderCatalog: populateList
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
})(jQuery, document);
|