2013-04-03 20:56:02 -07:00
|
|
|
|
(function ($, document) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
|
|
|
|
IsPremium: false,
|
|
|
|
|
TargetSystems: ""
|
|
|
|
|
};
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
function reloadList() {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var promise1 = ApiClient.getAvailablePlugins(query);
|
|
|
|
|
var promise2 = ApiClient.getInstalledPlugins();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
populateList(response1[0], response2[0]);
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
function populateList(availablePlugins, installedPlugins) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var page = $($.mobile.activePage);
|
|
|
|
|
availablePlugins = availablePlugins.filter(function (p) {
|
|
|
|
|
return p.type == "UserInstalled";
|
|
|
|
|
}).sort(function (a, b) {
|
|
|
|
|
return a.name > b.name ? 1 : -1;
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var html = "";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
for (var i = 0, length = availablePlugins.length; i < length; i++) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var plugin = availablePlugins[i];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
html += "<div class='posterViewItem'><a href='addPlugin.html?name=" + encodeURIComponent(plugin.name) + "'>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
if (plugin.thumbImage) {
|
|
|
|
|
html += "<img src='" + plugin.thumbImage + "' />";
|
|
|
|
|
} else {
|
|
|
|
|
html += "<img style='background:#444444;' src='css/images/items/list/collection.png' />";
|
|
|
|
|
}
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -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>";
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var color = plugin.tileColor || LibraryBrowser.getMetroColor(plugin.name);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
html += "<div class='posterViewItemText' style='background:" + color + "'>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
var installedPlugin = installedPlugins.filter(function (ip) {
|
|
|
|
|
return ip.Name == plugin.name;
|
|
|
|
|
})[0];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
html += "<div>";
|
|
|
|
|
if (installedPlugin) {
|
|
|
|
|
html += plugin.name + " (Installed)";
|
|
|
|
|
} else {
|
|
|
|
|
html += plugin.name;
|
|
|
|
|
}
|
|
|
|
|
html += "</div>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
html += "</div>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
html += "</a></div>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
}
|
2013-04-03 19:25:14 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
$('#pluginTiles', page).html(html);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 20:56:02 -07:00
|
|
|
|
$(document).on('pageinit', "#pluginCatalogPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.chkStandardFilter', this).on('change', function () {
|
|
|
|
|
|
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
var filters = query.TargetSystems || "";
|
|
|
|
|
|
|
|
|
|
filters = (',' + filters).replace(',' + filterName, '').substring(1);
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
filters = filters ? (filters + ',' + filterName) : filterName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.TargetSystems = filters;
|
|
|
|
|
|
|
|
|
|
reloadList();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.chkPremiumFilter', this).on('change', function () {
|
|
|
|
|
|
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
query.IsPremium = true;
|
|
|
|
|
}else {
|
|
|
|
|
query.IsPremium = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reloadList();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#pluginCatalogPage", function () {
|
|
|
|
|
|
|
|
|
|
reloadList();
|
|
|
|
|
|
|
|
|
|
// Reset form values using the last used query
|
|
|
|
|
|
|
|
|
|
$('.chkStandardFilter', this).each(function () {
|
|
|
|
|
|
|
|
|
|
var filters = "," + (query.TargetSystems || "");
|
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
|
|
|
|
|
this.checked = filters.indexOf(',' + filterName) != -1;
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
|
|
|
|
|
$('.chkPremiumFilter', this).each(function () {
|
|
|
|
|
|
|
|
|
|
var filters = query.IsPremium || false;
|
|
|
|
|
|
|
|
|
|
this.checked = filters;
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|