2013-04-03 20:56:02 -07:00
|
|
|
|
(function ($, document) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
2013-07-29 08:27:43 -07:00
|
|
|
|
TargetSystems: 'Server'
|
2013-04-03 21:36:02 -07:00
|
|
|
|
};
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-10-01 16:33:24 -07:00
|
|
|
|
function getApps() {
|
|
|
|
|
|
|
|
|
|
var apps = [];
|
|
|
|
|
|
|
|
|
|
apps.push({
|
|
|
|
|
type: "UserInstalled",
|
|
|
|
|
name: "MBKinect",
|
|
|
|
|
category: "Voice Control",
|
|
|
|
|
isApp: true,
|
|
|
|
|
tileColor: "#050810",
|
|
|
|
|
thumbImage: "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/images/mbkinect/thumb.png",
|
2013-10-10 07:45:07 -07:00
|
|
|
|
externalUrl: "http://mediabrowser3.com/community/index.php?/topic/850-media-browser-kinect-sensor-plug-in-support/",
|
2013-10-01 16:33:24 -07:00
|
|
|
|
isPremium: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return apps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAppsPromise() {
|
|
|
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [[getApps()]]);
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2013-10-01 16:33:24 -07:00
|
|
|
|
var promise1 = query.TargetSystems == "Apps" ? getAppsPromise() : ApiClient.getAvailablePlugins(query);
|
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
var promise2 = ApiClient.getInstalledPlugins();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
populateList(page, response1[0], response2[0]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
function populateList(page, availablePlugins, installedPlugins) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-25 16:28:01 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
availablePlugins = availablePlugins.filter(function (p) {
|
|
|
|
|
return p.type == "UserInstalled";
|
|
|
|
|
}).sort(function (a, b) {
|
2013-07-29 08:27:43 -07:00
|
|
|
|
|
|
|
|
|
var aName = (a.category || "General") + " " + a.name;
|
|
|
|
|
var bame = (b.category || "General") + " " + b.name;
|
|
|
|
|
|
|
|
|
|
return aName > bame ? 1 : -1;
|
2013-04-03 21:36:02 -07:00
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
var pluginhtml = '';
|
|
|
|
|
|
|
|
|
|
var currentCategory;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
for (var i = 0, length = availablePlugins.length; i < length; i++) {
|
2013-04-25 16:28:01 -07:00
|
|
|
|
var html = '';
|
2013-04-03 21:36:02 -07:00
|
|
|
|
var plugin = availablePlugins[i];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
var category = plugin.category || "General";
|
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
|
|
|
|
|
|
|
|
|
if (currentCategory) {
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
html += '<br/>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '<div class="ui-bar-a" style="padding: 0 1em;"><h3>' + category + '</h3></div>';
|
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
currentCategory = category;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 09:50:21 -07:00
|
|
|
|
var href = plugin.externalUrl ? plugin.externalUrl : "addplugin.html?name=" + encodeURIComponent(plugin.name) + "&guid=" + plugin.guid;
|
2013-10-01 16:33:24 -07:00
|
|
|
|
var target = plugin.externalUrl ? ' target="_blank"' : '';
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
html += "<a class='backdropPosterItem posterItem' style='margin: .75em 5px 1em;' href='" + href + "' " + target + ">";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
if (plugin.thumbImage) {
|
2013-12-28 22:32:03 -07:00
|
|
|
|
html += '<div class="posterItemImage" style="background-image:url(\'' + plugin.thumbImage + '\');background-size:cover;">';
|
2013-04-03 21:36:02 -07:00
|
|
|
|
} else {
|
2013-12-28 22:32:03 -07:00
|
|
|
|
html += '<div class="posterItemImage defaultPosterItemImage" style="background-image:url(\'css/images/items/list/collection.png\');">';
|
2013-04-03 21:36:02 -07:00
|
|
|
|
}
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2013-04-03 21:36: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-12-28 22:32:03 -07:00
|
|
|
|
html += "</div>";
|
2013-02-22 08:08:51 -07:00
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
html += "<div class='posterItemText' style='color:#000;'>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
html += plugin.name;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
html += "</div>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
html += "<div class='posterItemText packageReviewText' style='color:#000;'>";
|
2013-11-07 10:27:05 -07:00
|
|
|
|
html += plugin.price > 0 ? "$" + plugin.price.toFixed(2) : "Free";
|
2013-11-08 08:37:22 -07:00
|
|
|
|
html += Dashboard.getStoreRatingHtml(plugin.avgRating, plugin.id, plugin.name);
|
2013-11-07 11:04:51 -07:00
|
|
|
|
|
|
|
|
|
html += "<span class='storeReviewCount'>";
|
2013-11-07 10:27:05 -07:00
|
|
|
|
html += " " + plugin.totalRatings + " Reviews";
|
2013-11-07 11:04:51 -07:00
|
|
|
|
html += "</span>";
|
|
|
|
|
|
2013-11-07 10:27:05 -07:00
|
|
|
|
html += "</div>";
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
|
|
|
|
var installedPlugin = plugin.isApp ? null : installedPlugins.filter(function (ip) {
|
|
|
|
|
return ip.Name == plugin.name;
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
html += "<div class='posterItemText' style='color:#000;'>";
|
|
|
|
|
|
|
|
|
|
if (installedPlugin) {
|
|
|
|
|
html += installedPlugin.Version + ' installed';
|
|
|
|
|
} else {
|
|
|
|
|
html += ' ';
|
|
|
|
|
}
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
2013-12-28 22:32:03 -07:00
|
|
|
|
html += "</a>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
pluginhtml += html;
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
}
|
2013-04-03 19:25:14 -07:00
|
|
|
|
|
2013-04-25 16:28:01 -07:00
|
|
|
|
if (!availablePlugins.length) {
|
|
|
|
|
$("#noPlugins", page).hide();
|
|
|
|
|
}
|
2013-04-08 18:38:18 -07:00
|
|
|
|
|
2013-07-29 08:27:43 -07:00
|
|
|
|
$('#pluginTiles', page).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-25 16:28:01 -07:00
|
|
|
|
reloadList(page);
|
2013-04-11 17:58:30 -07:00
|
|
|
|
|
2013-04-11 09:11:04 -07:00
|
|
|
|
$('.chkPremiumFilter', page).on('change', function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
if (this.checked) {
|
2013-08-26 12:15:44 -07:00
|
|
|
|
query.IsPremium = false;
|
2013-04-03 21:36:02 -07:00
|
|
|
|
} else {
|
2013-04-03 21:46:14 -07:00
|
|
|
|
query.IsPremium = null;
|
2013-04-03 21:36:02 -07:00
|
|
|
|
}
|
2013-04-11 09:11:04 -07:00
|
|
|
|
reloadList(page);
|
2013-04-03 21:36:02 -07:00
|
|
|
|
});
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2014-01-02 14:21:06 -07:00
|
|
|
|
$('.radioPackageTypes', page).on('change', function () {
|
2013-07-29 08:27:43 -07:00
|
|
|
|
|
2014-01-02 14:21:06 -07:00
|
|
|
|
var val = $('.radioPackageTypes:checked', page).val();
|
|
|
|
|
|
|
|
|
|
query.TargetSystems = val;
|
2013-07-29 08:27:43 -07:00
|
|
|
|
reloadList(page);
|
|
|
|
|
});
|
|
|
|
|
|
2013-04-08 18:38:18 -07:00
|
|
|
|
}).on('pageshow', "#pluginCatalogPage", function () {
|
2013-04-25 16:28:01 -07:00
|
|
|
|
|
2013-04-11 09:11:04 -07:00
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-01-02 14:21:06 -07:00
|
|
|
|
$(".radioPackageTypes", page).each(function() {
|
|
|
|
|
|
|
|
|
|
this.checked = this.value == query.TargetSystems;
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
2013-11-05 10:13:29 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
// Reset form values using the last used query
|
2013-04-11 09:11:04 -07:00
|
|
|
|
$('.chkPremiumFilter', page).each(function () {
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
var filters = query.IsPremium || false;
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
this.checked = filters;
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
2013-04-03 21:36:02 -07:00
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
});
|
2013-04-03 20:56:02 -07:00
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|