From d2dab357703f8823851d2ea4062c7f3591c2cd6a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 4 Apr 2013 00:36:02 -0400 Subject: [PATCH] pass page instead of using $.mobile.activePage --- dashboard-ui/scripts/plugincatalogpage.js | 178 +++++++++++----------- 1 file changed, 87 insertions(+), 91 deletions(-) diff --git a/dashboard-ui/scripts/plugincatalogpage.js b/dashboard-ui/scripts/plugincatalogpage.js index c32860717..45414b6bf 100644 --- a/dashboard-ui/scripts/plugincatalogpage.js +++ b/dashboard-ui/scripts/plugincatalogpage.js @@ -1,139 +1,135 @@ (function ($, document) { - // The base query options - var query = { - IsPremium: false, - TargetSystems: "" - }; + // The base query options + var query = { + IsPremium: false, + TargetSystems: "" + }; - function reloadList() { + function reloadList(page) { - Dashboard.showLoadingMsg(); + Dashboard.showLoadingMsg(); - var promise1 = ApiClient.getAvailablePlugins(query); - var promise2 = ApiClient.getInstalledPlugins(); + var promise1 = ApiClient.getAvailablePlugins(query); + var promise2 = ApiClient.getInstalledPlugins(); - $.when(promise1, promise2).done(function (response1, response2) { - populateList(response1[0], response2[0]); - }); + $.when(promise1, promise2).done(function (response1, response2) { + populateList(page, response1[0], response2[0]); + }); - Dashboard.hideLoadingMsg(); - } + Dashboard.hideLoadingMsg(); + } - function populateList(availablePlugins, installedPlugins) { + function populateList(page, availablePlugins, installedPlugins) { - var page = $($.mobile.activePage); - availablePlugins = availablePlugins.filter(function (p) { - return p.type == "UserInstalled"; - }).sort(function (a, b) { - return a.name > b.name ? 1 : -1; - }); + availablePlugins = availablePlugins.filter(function (p) { + return p.type == "UserInstalled"; + }).sort(function (a, b) { + return a.name > b.name ? 1 : -1; + }); - var html = ""; + var html = ""; - for (var i = 0, length = availablePlugins.length; i < length; i++) { + for (var i = 0, length = availablePlugins.length; i < length; i++) { - var plugin = availablePlugins[i]; + var plugin = availablePlugins[i]; - html += "
"; + html += ""; + html += "
"; - } + } - $('#pluginTiles', page).html(html); + $('#pluginTiles', page).html(html); - Dashboard.hideLoadingMsg(); - } + Dashboard.hideLoadingMsg(); + } - $(document).on('pageinit', "#pluginCatalogPage", function () { + $(document).on('pageinit', "#pluginCatalogPage", function () { - var page = this; + var page = this; + $('.chkStandardFilter', this).on('change', function () { - $('.chkStandardFilter', this).on('change', function () { + var filterName = this.getAttribute('data-filter'); + var filters = query.TargetSystems || ""; - var filterName = this.getAttribute('data-filter'); - var filters = query.TargetSystems || ""; + filters = (',' + filters).replace(',' + filterName, '').substring(1); - filters = (',' + filters).replace(',' + filterName, '').substring(1); + if (this.checked) { + filters = filters ? (filters + ',' + filterName) : filterName; + } - if (this.checked) { - filters = filters ? (filters + ',' + filterName) : filterName; - } + query.TargetSystems = filters; - query.TargetSystems = filters; + reloadList(page); + }); - reloadList(); - }); + $('.chkPremiumFilter', this).on('change', function () { - $('.chkPremiumFilter', this).on('change', function () { + if (this.checked) { + query.IsPremium = true; + } else { + query.IsPremium = false; + } - var filterName = this.getAttribute('data-filter'); + reloadList(page); + }); - if (this.checked) { - query.IsPremium = true; - }else { - query.IsPremium = false; - } + }).on('pageshow', "#pluginCatalogPage", function () { - reloadList(); - }); + reloadList(this); - }).on('pageshow', "#pluginCatalogPage", function () { + // Reset form values using the last used query - reloadList(); + $('.chkStandardFilter', this).each(function () { - // Reset form values using the last used query + var filters = "," + (query.TargetSystems || ""); + var filterName = this.getAttribute('data-filter'); - $('.chkStandardFilter', this).each(function () { + this.checked = filters.indexOf(',' + filterName) != -1; - var filters = "," + (query.TargetSystems || ""); - var filterName = this.getAttribute('data-filter'); + }).checkboxradio('refresh'); - this.checked = filters.indexOf(',' + filterName) != -1; + $('.chkPremiumFilter', this).each(function () { - }).checkboxradio('refresh'); + var filters = query.IsPremium || false; - $('.chkPremiumFilter', this).each(function () { + this.checked = filters; - var filters = query.IsPremium || false; - - this.checked = filters; - - }).checkboxradio('refresh'); - }); + }).checkboxradio('refresh'); + }); })(jQuery, document); \ No newline at end of file