From d564176c9c1a73ff761f33c79b050fea6aa6b8da Mon Sep 17 00:00:00 2001 From: Dale Price Date: Wed, 13 Mar 2013 03:01:18 -0500 Subject: [PATCH 1/2] fix localStorage bug by not trying (and failing) to make it a multidimensional array; use JSON to store array of filters in localStorage --- octoprint/static/js/ui.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/octoprint/static/js/ui.js b/octoprint/static/js/ui.js index eb7f54c..c611b31 100644 --- a/octoprint/static/js/ui.js +++ b/octoprint/static/js/ui.js @@ -1326,16 +1326,16 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor var currentSorting = self.currentSorting(); if (currentSorting !== undefined) - localStorage[self.listType]["currentSorting"] = currentSorting; + localStorage[self.listType + "." + "currentSorting"] = currentSorting; else - localStorage[self.listType]["currentSorting"] = undefined; + localStorage[self.listType + "." + "currentSorting"] = undefined; } self._loadCurrentSortingFromLocalStorage = function() { self._initializeLocalStorage(); - if (_.contains(_.keys(supportedSorting), localStorage[self.listType]["currentSorting"])) - self.currentSorting(localStorage[self.listType]["currentSorting"]); + if (_.contains(_.keys(supportedSorting), localStorage[self.listType + "." + "currentSorting"])) + self.currentSorting(localStorage[self.listType + "." + "currentSorting"]); else self.currentSorting(defaultSorting); } @@ -1344,23 +1344,21 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor self._initializeLocalStorage(); var filters = _.intersection(_.keys(self.supportedFilters), self.currentFilters()); - localStorage[self.listType]["currentFilters"] = filters; + localStorage[self.listType + "." + "currentFilters"] = JSON.stringify(filters); } self._loadCurrentFiltersFromLocalStorage = function() { self._initializeLocalStorage(); - self.currentFilters(_.intersection(_.keys(self.supportedFilters), localStorage[self.listType, "currentFilters"])); + self.currentFilters(_.intersection(_.keys(self.supportedFilters), JSON.parse(localStorage[self.listType + "." + "currentFilters"]))); } self._initializeLocalStorage = function() { - if (localStorage[self.listType] !== undefined) + if (localStorage[self.listType + "." + "currentSorting"] !== undefined && localStorage[self.listType + "." + "currentFilters"] !== undefined && JSON.parse(localStorage[self.listType + "." + "currentFilters"]) instanceof Array) return; - localStorage[self.listType] = { - "currentSorting": self.defaultSorting, - "currentFilters": self.defaultFilters - } + localStorage[self.listType + "." + "currentSorting"] = self.defaultSorting; + localStorage[self.listType + "." + "currentFilters"] = JSON.stringify(self.defaultFilters); } self._loadCurrentFiltersFromLocalStorage(); From 088253e5647bbcad8e85af55a9ca38d43aa5466a Mon Sep 17 00:00:00 2001 From: Dale Price Date: Thu, 14 Mar 2013 20:55:02 -0500 Subject: [PATCH 2/2] work around a bug in iOS 6 where ajax requests get cached and only work once --- octoprint/static/js/ui.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/octoprint/static/js/ui.js b/octoprint/static/js/ui.js index c611b31..665693a 100644 --- a/octoprint/static/js/ui.js +++ b/octoprint/static/js/ui.js @@ -1391,6 +1391,12 @@ $(function() { webcamViewModel, gcodeViewModel ); + + //work around a stupid iOS6 bug where ajax requests get cached and only work once, as described at http://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results + $.ajaxSetup({ + type: 'POST', + headers: { "cache-control": "no-cache" } + }); //~~ Show settings - to ensure centered $('#navbar_show_settings').click(function() {